From 6e3de9c3e99fdf284e63f303d3a32bd4dfbd124e Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Mon, 27 Jun 2016 10:16:31 +0200 Subject: HONEYCOMB-100: introduce default 5s timeout in TranslateUtils.getReplyFor* calls Change-Id: Iac2bb428ea6adcc8d3da2238db1dec708df550f0 Signed-off-by: Marek Gradzki --- .../translate/v3po/util/TranslateUtilsTest.java | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'v3po/vpp-translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtilsTest.java') diff --git a/v3po/vpp-translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtilsTest.java b/v3po/vpp-translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtilsTest.java index 89e7d9d89..334887430 100644 --- a/v3po/vpp-translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtilsTest.java +++ b/v3po/vpp-translate-utils/src/test/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtilsTest.java @@ -3,12 +3,62 @@ package io.fd.honeycomb.v3po.translate.v3po.util; import static io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils.reverseBytes; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.anyLong; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.junit.Test; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yangtools.yang.binding.DataContainer; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.dto.JVppReply; public class TranslateUtilsTest { + private static class AnDataObject implements DataObject { + @Override + public Class getImplementedInterface() { + return null; + } + } + + @Test + public void testGetReplyForWriteTimeout() throws Exception { + final Future> future = mock(Future.class); + when(future.get(anyLong(), eq(TimeUnit.SECONDS))).thenThrow(TimeoutException.class); + final InstanceIdentifier replyType = InstanceIdentifier.create(AnDataObject.class); + try { + TranslateUtils.getReplyForWrite(future, replyType); + } catch (WriteTimeoutException e) { + assertTrue(e.getCause() instanceof TimeoutException); + assertEquals(replyType, e.getFailedId()); + return; + } + fail("WriteTimeoutException was expected"); + } + + @Test + public void testGetReplyForReadTimeout() throws Exception { + final Future> future = mock(Future.class); + final InstanceIdentifier replyType = InstanceIdentifier.create(AnDataObject.class); + when(future.get(anyLong(), eq(TimeUnit.SECONDS))).thenThrow(TimeoutException.class); + try { + TranslateUtils.getReplyForRead(future, replyType); + } catch (ReadTimeoutException e) { + assertTrue(e.getCause() instanceof TimeoutException); + assertEquals(replyType, e.getFailedId()); + return; + } + fail("ReadTimeoutException was expected"); + } + @Test public void testIpv4NoZone() throws Exception { final Ipv4AddressNoZone ipv4Addr = new Ipv4AddressNoZone("192.168.1.1"); @@ -83,4 +133,5 @@ public class TranslateUtilsTest { public void testByteToBooleanFailed() { TranslateUtils.byteToBoolean((byte) 123); } + } \ No newline at end of file -- cgit 1.2.3-korg