From: Dana Kutenicsova Date: Thu, 28 Nov 2013 09:38:50 +0000 (+0100) Subject: BUG-76 : fixed all FSM tests. X-Git-Tag: jenkins-bgpcep-bulk-release-prepare-only-1~185^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=7db78e4b497e1bab6421c8137156b6161bac1e83;p=bgpcep.git BUG-76 : fixed all FSM tests. Change-Id: I1994c25b7273fd7f4b5860ed84ddf5ee90147ef4 Signed-off-by: Dana Kutenicsova --- diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java index cc7228d130..24c44cec59 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java @@ -111,7 +111,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession implements this.remoteOpen = Preconditions.checkNotNull(remoteOpen); this.lastMessageReceivedAt = System.nanoTime(); - if (this.maxUnknownMessages != 0) { + if (maxUnknownMessages != 0) { this.maxUnknownMessages = maxUnknownMessages; } diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/FiniteStateMachineTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/FiniteStateMachineTest.java index 56e77c36ce..66b0878f03 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/FiniteStateMachineTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/FiniteStateMachineTest.java @@ -17,6 +17,7 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.DefaultChannelPromise; import io.netty.util.HashedWheelTimer; import io.netty.util.concurrent.DefaultPromise; import io.netty.util.concurrent.GlobalEventExecutor; @@ -74,22 +75,24 @@ public class FiniteStateMachineTest { final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open localPrefs = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder().setKeepalive( (short) 1).build(); this.serverSession = new DefaultPCEPSessionNegotiator(new HashedWheelTimer(), new DefaultPromise(GlobalEventExecutor.INSTANCE), this.clientListener, new SimpleSessionListener(), (short) 1, 20, localPrefs); + final ChannelFuture future = new DefaultChannelPromise(this.clientListener); doAnswer(new Answer() { @Override public Object answer(final InvocationOnMock invocation) { final Object[] args = invocation.getArguments(); FiniteStateMachineTest.this.receivedMsgs.add((Notification) args[0]); - return null; + return future; } }).when(this.clientListener).writeAndFlush(any(Notification.class)); doReturn("TestingChannel").when(this.clientListener).toString(); doReturn(this.pipeline).when(this.clientListener).pipeline(); doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class)); + doReturn(true).when(this.clientListener).isActive(); doReturn(mock(ChannelFuture.class)).when(this.clientListener).close(); this.openmsg = new OpenBuilder().setOpenMessage( new OpenMessageBuilder().setOpen( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder().setDeadTimer( - (short) 3).build()).build()).build(); + (short) 45).setKeepalive((short) 15).build()).build()).build(); this.kamsg = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build(); } @@ -210,41 +213,43 @@ public class FiniteStateMachineTest { @Test @Ignore public void testUnknownMessage() throws InterruptedException { - // this.serverSession.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); - // assertEquals(1, this.serverSession.unknownMessagesTimes.size()); - // Thread.sleep(10000); - // this.serverSession.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); - // assertEquals(2, this.serverSession.unknownMessagesTimes.size()); - // Thread.sleep(10000); - // this.serverSession.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); - // assertEquals(3, this.serverSession.unknownMessagesTimes.size()); - // Thread.sleep(20000); - // this.serverSession.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); - // assertEquals(4, this.serverSession.unknownMessagesTimes.size()); - // Thread.sleep(30000); - // this.serverSession.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); - // assertEquals(3, this.serverSession.unknownMessagesTimes.size()); - // Thread.sleep(10000); - // this.serverSession.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); - // assertEquals(3, this.serverSession.unknownMessagesTimes.size()); - // Thread.sleep(5000); - // this.serverSession.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); - // assertEquals(4, this.serverSession.unknownMessagesTimes.size()); - // Thread.sleep(1000); - // this.serverSession.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); - // assertEquals(5, this.serverSession.unknownMessagesTimes.size()); - // Thread.sleep(1000); - // this.serverSession.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); - // synchronized (this.client) { - // while (!this.client.down) { - // try { - // this.client.wait(); - // } catch (final InterruptedException e) { - // e.printStackTrace(); - // } - // } - // } - // assertTrue(this.client.down); + final SimpleSessionListener client = new SimpleSessionListener(); + final PCEPSessionImpl s = new PCEPSessionImpl(new HashedWheelTimer(), client, 5, this.clientListener, this.openmsg.getOpenMessage().getOpen(), this.openmsg.getOpenMessage().getOpen()); + s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); + assertEquals(1, s.unknownMessagesTimes.size()); + Thread.sleep(10000); + s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); + assertEquals(2, s.unknownMessagesTimes.size()); + Thread.sleep(10000); + s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); + assertEquals(3, s.unknownMessagesTimes.size()); + Thread.sleep(20000); + s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); + assertEquals(4, s.unknownMessagesTimes.size()); + Thread.sleep(30000); + s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); + assertEquals(3, s.unknownMessagesTimes.size()); + Thread.sleep(10000); + s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); + assertEquals(3, s.unknownMessagesTimes.size()); + Thread.sleep(5000); + s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); + assertEquals(4, s.unknownMessagesTimes.size()); + Thread.sleep(1000); + s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); + assertEquals(5, s.unknownMessagesTimes.size()); + Thread.sleep(1000); + s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED); + synchronized (client) { + while (client.up) { + try { + client.wait(); + } catch (final InterruptedException e) { + e.printStackTrace(); + } + } + } + assertTrue(!client.up); } @After diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/SimpleSessionListener.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/SimpleSessionListener.java index 6fbfe31c23..ec55ee4ff0 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/SimpleSessionListener.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/SimpleSessionListener.java @@ -54,6 +54,6 @@ public class SimpleSessionListener implements PCEPSessionListener { @Override public void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason cause) { - logger.debug("Session terminated. Cause : ", cause.toString()); + logger.debug("Session terminated. Cause : {}", cause.toString()); } }