* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.pcep.pcc.mock;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.opendaylight.protocol.pcep.pcc.mock.PCCMockCommon.checkSessionListenerNotNull;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.protocol.concepts.KeyMapping;
import org.opendaylight.protocol.pcep.PCEPDispatcher;
import org.opendaylight.protocol.pcep.PCEPDispatcherDependencies;
import org.opendaylight.protocol.pcep.spi.pojo.DefaultPCEPExtensionConsumerContext;
import org.opendaylight.protocol.util.InetSocketAddressUtil;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class PCCDispatcherImplTest {
- private static final PCEPSessionProposalFactory PROPOSAL
- = new BasePCEPSessionProposalFactory(10, 40, new ArrayList<>());
- private final DefaultPCEPSessionNegotiatorFactory nf
- = new DefaultPCEPSessionNegotiatorFactory(PROPOSAL, 0);
+ private static final PCEPSessionProposalFactory PROPOSAL = new BasePCEPSessionProposalFactory(10, 40,
+ new ArrayList<>());
+ private final DefaultPCEPSessionNegotiatorFactory nf = new DefaultPCEPSessionNegotiatorFactory(PROPOSAL, 0);
+
private PCCDispatcherImpl dispatcher;
private PCEPDispatcher pcepDispatcher;
private InetSocketAddress serverAddress;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
- this.workerGroup = new NioEventLoopGroup();
- this.bossGroup = new NioEventLoopGroup();
+ workerGroup = new NioEventLoopGroup();
+ bossGroup = new NioEventLoopGroup();
registry = new DefaultPCEPExtensionConsumerContext().getMessageHandlerRegistry();
- this.dispatcher = new PCCDispatcherImpl(this.registry);
- this.pcepDispatcher = new PCEPDispatcherImpl(this.registry, this.nf, this.bossGroup, this.workerGroup);
- this.serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
- this.clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
- doReturn(KeyMapping.getKeyMapping()).when(this.dispatcherDependencies).getKeys();
- doReturn(this.serverAddress).when(this.dispatcherDependencies).getAddress();
- doReturn(null).when(this.dispatcherDependencies).getPeerProposal();
+ dispatcher = new PCCDispatcherImpl(registry);
+ pcepDispatcher = new PCEPDispatcherImpl(registry, nf, bossGroup, workerGroup);
+ serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
+ clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
+ doReturn(KeyMapping.getKeyMapping()).when(dispatcherDependencies).getKeys();
+ doReturn(serverAddress).when(dispatcherDependencies).getAddress();
+ doReturn(null).when(dispatcherDependencies).getPeerProposal();
}
@After
public void tearDown() {
- this.dispatcher.close();
+ dispatcher.close();
closeEventLoopGroups();
}
private void closeEventLoopGroups() {
- this.workerGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS);
- this.bossGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS);
+ workerGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS);
+ bossGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS);
}
@Test(timeout = 20000)
public void testClientReconnect() throws Exception {
- final Future<PCEPSession> futureSession = this.dispatcher
- .createClient(this.serverAddress, 1, new TestingSessionListenerFactory(), this.nf,
- KeyMapping.getKeyMapping(), this.clientAddress);
+ final Future<PCEPSession> futureSession = dispatcher.createClient(serverAddress, 1,
+ new TestingSessionListenerFactory(), nf, KeyMapping.getKeyMapping(), clientAddress);
final TestingSessionListenerFactory slf = new TestingSessionListenerFactory();
- doReturn(slf).when(this.dispatcherDependencies).getListenerFactory();
+ doReturn(slf).when(dispatcherDependencies).getListenerFactory();
- final ChannelFuture futureServer = this.pcepDispatcher.createServer(this.dispatcherDependencies);
+ final ChannelFuture futureServer = pcepDispatcher.createServer(dispatcherDependencies);
futureServer.sync();
final Channel channel = futureServer.channel();
- Assert.assertNotNull(futureSession.get());
- checkSessionListenerNotNull(slf, this.clientAddress.getHostString());
- final TestingSessionListener sl
- = checkSessionListenerNotNull(slf, this.clientAddress.getAddress().getHostAddress());
- Assert.assertNotNull(sl.getSession());
- Assert.assertTrue(sl.isUp());
+ assertNotNull(futureSession.get());
+ checkSessionListenerNotNull(slf, clientAddress.getHostString());
+ final TestingSessionListener sl = checkSessionListenerNotNull(slf, clientAddress.getAddress().getHostAddress());
+ assertNotNull(sl.getSession());
+ assertTrue(sl.isUp());
channel.close().get();
closeEventLoopGroups();
- this.workerGroup = new NioEventLoopGroup();
- this.bossGroup = new NioEventLoopGroup();
- this.pcepDispatcher = new PCEPDispatcherImpl(this.registry, this.nf, this.bossGroup, this.workerGroup);
+ workerGroup = new NioEventLoopGroup();
+ bossGroup = new NioEventLoopGroup();
+ pcepDispatcher = new PCEPDispatcherImpl(registry, nf, bossGroup, workerGroup);
final TestingSessionListenerFactory slf2 = new TestingSessionListenerFactory();
- doReturn(slf2).when(this.dispatcherDependencies).getListenerFactory();
- final ChannelFuture future2 = this.pcepDispatcher.createServer(this.dispatcherDependencies);
+ doReturn(slf2).when(dispatcherDependencies).getListenerFactory();
+ final ChannelFuture future2 = pcepDispatcher.createServer(dispatcherDependencies);
future2.sync();
final Channel channel2 = future2.channel();
- final TestingSessionListener sl2
- = checkSessionListenerNotNull(slf2, this.clientAddress.getAddress().getHostAddress());
- Assert.assertNotNull(sl2.getSession());
- Assert.assertTrue(sl2.isUp());
+ final TestingSessionListener sl2 = checkSessionListenerNotNull(slf2,
+ clientAddress.getAddress().getHostAddress());
+ assertNotNull(sl2.getSession());
+ assertTrue(sl2.isUp());
channel2.close();
}
}
*/
package org.opendaylight.protocol.pcep.pcc.mock;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.protocol.pcep.pcc.mock.api.PCCSession;
import org.opendaylight.protocol.pcep.pcc.mock.api.PCCTunnelManager;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
import org.opendaylight.yangtools.yang.common.Uint32;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class PCCSessionListenerTest {
+ private final List<Message> sendMessages = new ArrayList<>();
@Mock
private PCEPSession mockedSession;
-
@Mock
private PCCTunnelManager tunnelManager;
- private final List<Message> sendMessages = new ArrayList<>();
-
@Before
public void setup() {
- MockitoAnnotations.initMocks(this);
- Mockito.doAnswer(invocation -> {
+ doAnswer(invocation -> {
PCCSessionListenerTest.this.sendMessages.add((Message) invocation.getArguments()[0]);
return null;
- }).when(this.mockedSession).sendMessage(Mockito.any(Message.class));
+ }).when(mockedSession).sendMessage(any());
}
@After
public void cleanup() {
- this.sendMessages.clear();
+ sendMessages.clear();
}
@Test
public void testOnMessage() {
- final PCCSessionListener listener = new PCCSessionListener(1, this.tunnelManager, false);
- listener.onMessage(this.mockedSession, createUpdMsg(true));
- verify(this.tunnelManager).onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
- verify(this.tunnelManager, Mockito.never())
- .onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
- listener.onMessage(this.mockedSession, createUpdMsg(false));
- verify(this.tunnelManager, Mockito.times(2))
- .onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
- verify(this.tunnelManager, Mockito.never())
- .onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
- listener.onMessage(this.mockedSession, createInitMsg(false, true));
- verify(this.tunnelManager, Mockito.times(2))
- .onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
- verify(this.tunnelManager).onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
- listener.onMessage(this.mockedSession, createInitMsg(true, false));
- verify(this.tunnelManager, Mockito.times(2))
- .onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
- verify(this.tunnelManager, Mockito.times(2))
- .onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
- listener.onMessage(this.mockedSession, createInitMsg(false, false));
- verify(this.tunnelManager, Mockito.times(2))
- .onMessagePcupd(Mockito.any(Updates.class), Mockito.any(PCCSession.class));
- verify(this.tunnelManager, Mockito.times(3))
- .onMessagePcInitiate(Mockito.any(Requests.class), Mockito.any(PCCSession.class));
+ final PCCSessionListener listener = new PCCSessionListener(1, tunnelManager, false);
+ listener.onMessage(mockedSession, createUpdMsg(true));
+ verify(tunnelManager).onMessagePcupd(any(Updates.class), any(PCCSession.class));
+ verify(tunnelManager, never()).onMessagePcInitiate(any(Requests.class), any(PCCSession.class));
+ listener.onMessage(mockedSession, createUpdMsg(false));
+ verify(tunnelManager, times(2)).onMessagePcupd(any(Updates.class), any(PCCSession.class));
+ verify(tunnelManager, never()).onMessagePcInitiate(any(Requests.class), any(PCCSession.class));
+ listener.onMessage(mockedSession, createInitMsg(false, true));
+ verify(tunnelManager, times(2)).onMessagePcupd(any(Updates.class), any(PCCSession.class));
+ verify(tunnelManager).onMessagePcInitiate(any(Requests.class), any(PCCSession.class));
+ listener.onMessage(mockedSession, createInitMsg(true, false));
+ verify(tunnelManager, times(2)).onMessagePcupd(any(Updates.class), any(PCCSession.class));
+ verify(tunnelManager, times(2)).onMessagePcInitiate(any(Requests.class), any(PCCSession.class));
+ listener.onMessage(mockedSession, createInitMsg(false, false));
+ verify(tunnelManager, times(2)).onMessagePcupd(any(Updates.class), any(PCCSession.class));
+ verify(tunnelManager, times(3)).onMessagePcInitiate(any(Requests.class), any(PCCSession.class));
}
@Test
public void testOnMessageErrorMode() {
- final PCCSessionListener listener = new PCCSessionListener(1, this.tunnelManager, true);
- listener.onMessage(this.mockedSession, createUpdMsg(true));
- verify(this.mockedSession).sendMessage(Mockito.any(Message.class));
+ final PCCSessionListener listener = new PCCSessionListener(1, tunnelManager, true);
+ listener.onMessage(mockedSession, createUpdMsg(true));
+ verify(mockedSession).sendMessage(any(Message.class));
}
@Test
public void testOnSessionUp() {
- final PCCSessionListener listener = new PCCSessionListener(1, this.tunnelManager, false);
- listener.onSessionUp(this.mockedSession);
- verify(this.tunnelManager).onSessionUp(Mockito.any(PCCSession.class));
+ final PCCSessionListener listener = new PCCSessionListener(1, tunnelManager, false);
+ listener.onSessionUp(mockedSession);
+ verify(tunnelManager).onSessionUp(any(PCCSession.class));
}
@Test
public void testOnSessionDown() {
- final PCCSessionListener listener = new PCCSessionListener(1, this.tunnelManager, false);
- listener.onSessionDown(this.mockedSession, new Exception());
- verify(this.tunnelManager).onSessionDown(Mockito.any(PCCSession.class));
+ final PCCSessionListener listener = new PCCSessionListener(1, tunnelManager, false);
+ listener.onSessionDown(mockedSession, new Exception());
+ verify(tunnelManager).onSessionDown(any(PCCSession.class));
}
@Test
public void testSendError() {
- final PCCSessionListener listener = new PCCSessionListener(1, this.tunnelManager, false);
- listener.onSessionUp(this.mockedSession);
+ final PCCSessionListener listener = new PCCSessionListener(1, tunnelManager, false);
+ listener.onSessionUp(mockedSession);
listener.sendError(MsgBuilderUtil.createErrorMsg(PCEPErrors.ATTEMPT_2ND_SESSION, Uint32.ZERO));
- verify(this.mockedSession).sendMessage(Mockito.any());
+ verify(mockedSession).sendMessage(any());
}
@Test
public void testSendReport() {
- final PCCSessionListener listener = new PCCSessionListener(1, this.tunnelManager, false);
- listener.onSessionUp(this.mockedSession);
+ final PCCSessionListener listener = new PCCSessionListener(1, tunnelManager, false);
+ listener.onSessionUp(mockedSession);
listener.sendReport(null);
- verify(this.mockedSession).sendMessage(Mockito.any());
+ verify(mockedSession).sendMessage(any());
}
@Test
public void testGetId() {
- final PCCSessionListener listener = new PCCSessionListener(1, this.tunnelManager, false);
- Assert.assertEquals(1, listener.getId());
+ final PCCSessionListener listener = new PCCSessionListener(1, tunnelManager, false);
+ assertEquals(1, listener.getId());
}
private static PcinitiateMessage createInitMsg(final boolean remove, final boolean endpoint) {
- // lsp with "unknown" plsp-id
- final LspBuilder lspBuilder = new LspBuilder()
- .setAdministrative(true)
- .setDelegate(true)
- .setIgnore(false)
- .setOperational(OperationalStatus.Up)
- .setPlspId(new PlspId(Uint32.valueOf(999)))
- .setProcessingRule(false)
- .setRemove(remove)
- .setSync(true);
-
- final List<Requests> requests = new ArrayList<>();
final RequestsBuilder reqBuilder = new RequestsBuilder()
- .setLsp(lspBuilder.build())
- .setSrp(new SrpBuilder(MsgBuilderUtil.createSrp(Uint32.valueOf(123))).addAugmentation(
- new Srp1Builder().setRemove(remove).build()).build());
+ // lsp with "unknown" plsp-id
+ .setLsp(new LspBuilder()
+ .setAdministrative(true)
+ .setDelegate(true)
+ .setIgnore(false)
+ .setOperational(OperationalStatus.Up)
+ .setPlspId(new PlspId(Uint32.valueOf(999)))
+ .setProcessingRule(false)
+ .setRemove(remove)
+ .setSync(true)
+ .build())
+ .setSrp(new SrpBuilder(MsgBuilderUtil.createSrp(Uint32.valueOf(123)))
+ .addAugmentation(new Srp1Builder().setRemove(remove).build())
+ .build());
if (endpoint) {
reqBuilder.setEndpointsObj(new EndpointsObjBuilder().build());
}
- requests.add(reqBuilder.build());
- final PcinitiateMessageBuilder initBuilder = new PcinitiateMessageBuilder().setRequests(requests);
- return new PcinitiateBuilder().setPcinitiateMessage(initBuilder.build()).build();
+ return new PcinitiateBuilder()
+ .setPcinitiateMessage(new PcinitiateMessageBuilder().setRequests(List.of(reqBuilder.build())).build())
+ .build();
}
private static Pcupd createUpdMsg(final boolean delegation) {
- final PcupdMessageBuilder msgBuilder = new PcupdMessageBuilder();
- final UpdatesBuilder updsBuilder = new UpdatesBuilder();
- updsBuilder.setLsp(new LspBuilder().setDelegate(delegation).setPlspId(new PlspId(Uint32.ONE)).build());
- final PathBuilder pathBuilder = new PathBuilder();
- pathBuilder.setEro(new EroBuilder().setSubobject(Collections.singletonList(new SubobjectBuilder()
- .setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder()
- .setIpPrefix(new IpPrefix(new Ipv4Prefix("127.0.0.2/32"))).build()).build()).build())).build());
- updsBuilder.setPath(pathBuilder.build());
- updsBuilder.setSrp(new SrpBuilder().setOperationId(new SrpIdNumber(Uint32.ZERO)).build());
- msgBuilder.setUpdates(Collections.singletonList(updsBuilder.build()));
- return new PcupdBuilder().setPcupdMessage(msgBuilder.build()).build();
+ return new PcupdBuilder()
+ .setPcupdMessage(new PcupdMessageBuilder()
+ .setUpdates(List.of(new UpdatesBuilder()
+ .setLsp(new LspBuilder().setDelegate(delegation).setPlspId(new PlspId(Uint32.ONE)).build())
+ .setPath(new PathBuilder()
+ .setEro(new EroBuilder()
+ .setSubobject(List.of(new SubobjectBuilder()
+ .setSubobjectType(new IpPrefixCaseBuilder()
+ .setIpPrefix(new IpPrefixBuilder()
+ .setIpPrefix(new IpPrefix(new Ipv4Prefix("127.0.0.2/32")))
+ .build())
+ .build())
+ .build()))
+ .build())
+ .build())
+ .setSrp(new SrpBuilder().setOperationId(new SrpIdNumber(Uint32.ZERO)).build())
+ .build()))
+ .build())
+ .build();
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.pcep.pcc.mock;
import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import com.google.common.collect.Lists;
import com.google.common.net.InetAddresses;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.protocol.pcep.pcc.mock.api.PCCSession;
import org.opendaylight.protocol.pcep.pcc.mock.api.PCCTunnelManager;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
import org.opendaylight.yangtools.yang.common.Uint32;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class PCCTunnelManagerImplTest {
-
private static final InetAddress ADDRESS = InetAddresses.forString("1.2.4.5");
private static final Timer TIMER = new HashedWheelTimer();
private static final byte[] SYMBOLIC_NAME = "tets".getBytes(StandardCharsets.UTF_8);
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
- Mockito.doNothing().when(this.session1).sendReport(Mockito.any(Pcrpt.class));
- Mockito.doAnswer(invocation -> {
+ doNothing().when(session1).sendReport(any(Pcrpt.class));
+ doAnswer(invocation -> {
PCCTunnelManagerImplTest.this.errorsSession1.add(getError((Pcerr) invocation.getArguments()[0]));
return null;
- }).when(this.session1).sendError(Mockito.any(Pcerr.class));
- Mockito.doReturn(0).when(this.session1).getId();
- Mockito.doNothing().when(this.session2).sendReport(Mockito.any(Pcrpt.class));
- Mockito.doAnswer(invocation -> {
+ }).when(session1).sendError(any(Pcerr.class));
+ doReturn(0).when(session1).getId();
+ doNothing().when(session2).sendReport(any(Pcrpt.class));
+ doAnswer(invocation -> {
PCCTunnelManagerImplTest.this.errorsSession2.add(getError((Pcerr) invocation.getArguments()[0]));
return null;
- }).when(this.session2).sendError(Mockito.any(Pcerr.class));
- Mockito.doReturn(1).when(this.session2).getId();
+ }).when(session2).sendError(any(Pcerr.class));
+ doReturn(1).when(session2).getId();
}
@After
public void tearDown() {
- this.errorsSession1.clear();
- this.errorsSession2.clear();
+ errorsSession1.clear();
+ errorsSession2.clear();
}
@Test
public void testOnSessionUp() {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
- checkSessionUp(this.session1, tunnelManager);
- checkSessionUp(this.session2, tunnelManager);
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, timerHandler);
+ checkSessionUp(session1, tunnelManager);
+ checkSessionUp(session2, tunnelManager);
}
@Test
public void testOnSessionDownAndDelegateBack() {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 1, 10, TIMER, this.timerHandler);
- checkSessionUp(this.session1, tunnelManager);
- checkSessionUp(this.session2, tunnelManager);
- checkSessionDown(this.session1, tunnelManager);
- tunnelManager.onSessionUp(this.session1);
- Mockito.verify(this.session1, Mockito.times(4)).sendReport(Mockito.any(Pcrpt.class));
- Mockito.verify(this.session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 1, 10, TIMER, timerHandler);
+ checkSessionUp(session1, tunnelManager);
+ checkSessionUp(session2, tunnelManager);
+ checkSessionDown(session1, tunnelManager);
+ tunnelManager.onSessionUp(session1);
+ verify(session1, times(4)).sendReport(any(Pcrpt.class));
+ verify(session2, times(2)).sendReport(any(Pcrpt.class));
}
private static void checkSessionDown(final PCCSession session, final PCCTunnelManager tunnelManager) {
tunnelManager.onSessionDown(session);
- Mockito.verify(session, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+ verify(session, times(2)).sendReport(any(Pcrpt.class));
}
private static void checkSessionUp(final PCCSession session, final PCCTunnelManager tunnelManager) {
//1 reported LSP + 1 end-of-sync marker
tunnelManager.onSessionUp(session);
- Mockito.verify(session, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+ verify(session, times(2)).sendReport(any(Pcrpt.class));
}
@Test
public void testOnSessionDownAndDelegateToOther() throws InterruptedException {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, -1, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session2);
- checkSessionUp(this.session1, tunnelManager);
- checkSessionDown(this.session1, tunnelManager);
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, -1, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session2);
+ checkSessionUp(session1, tunnelManager);
+ checkSessionDown(session1, tunnelManager);
//wait for re-delegation timeout expires
Thread.sleep(500);
- Mockito.verify(this.session2, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
- tunnelManager.onSessionUp(this.session1);
- Mockito.verify(this.session1, Mockito.times(4)).sendReport(Mockito.any(Pcrpt.class));
+ verify(session2, times(3)).sendReport(any(Pcrpt.class));
+ tunnelManager.onSessionUp(session1);
+ verify(session1, times(4)).sendReport(any(Pcrpt.class));
}
@Test
public void testReportToAll() {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onSessionUp(this.session2);
- tunnelManager.onMessagePcupd(createUpdateDelegate(1), this.session1);
- Mockito.verify(this.session1, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
- Mockito.verify(this.session2, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onSessionUp(session2);
+ tunnelManager.onMessagePcupd(createUpdateDelegate(1), session1);
+ verify(session1, times(3)).sendReport(any(Pcrpt.class));
+ verify(session2, times(3)).sendReport(any(Pcrpt.class));
}
@Test
public void testReportToAllUnknownLsp() {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onMessagePcupd(createUpdateDelegate(2), this.session1);
- Mockito.verify(this.session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
- assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, this.errorsSession1.get(0));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onMessagePcupd(createUpdateDelegate(2), session1);
+ verify(session1, times(1)).sendError(any(Pcerr.class));
+ assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, errorsSession1.get(0));
}
@Test
public void testReportToAllNonDelegatedLsp() {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onSessionUp(this.session2);
- tunnelManager.onMessagePcupd(createUpdateDelegate(1), this.session2);
- Mockito.verify(this.session2, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
- assertEquals(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, this.errorsSession2.get(0));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onSessionUp(session2);
+ tunnelManager.onMessagePcupd(createUpdateDelegate(1), session2);
+ verify(session2, times(1)).sendError(any(Pcerr.class));
+ assertEquals(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, errorsSession2.get(0));
}
@Test
public void testReturnDelegationPccLsp() throws InterruptedException {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 1, -1, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onSessionUp(this.session2);
- tunnelManager.onMessagePcupd(createUpdate(1), this.session1);
- Mockito.verify(this.session1, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
- Mockito.verify(this.session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 1, -1, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onSessionUp(session2);
+ tunnelManager.onMessagePcupd(createUpdate(1), session1);
+ verify(session1, times(3)).sendReport(any(Pcrpt.class));
+ verify(session2, times(2)).sendReport(any(Pcrpt.class));
//wait for re-delegation timer expires
Thread.sleep(1200);
- Mockito.verify(this.session2, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
+ verify(session2, times(3)).sendReport(any(Pcrpt.class));
}
@Test
public void testReturnDelegationUnknownLsp() {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onMessagePcupd(createUpdate(2), this.session1);
- Mockito.verify(this.session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
- assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, this.errorsSession1.get(0));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onMessagePcupd(createUpdate(2), session1);
+ verify(session1, times(1)).sendError(any(Pcerr.class));
+ assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, errorsSession1.get(0));
}
@Test
public void testReturnDelegationNonDelegatedLsp() {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onSessionUp(this.session2);
- tunnelManager.onMessagePcupd(createUpdate(1), this.session2);
- Mockito.verify(this.session2, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
- assertEquals(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, this.errorsSession2.get(0));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onSessionUp(session2);
+ tunnelManager.onMessagePcupd(createUpdate(1), session2);
+ verify(session2, times(1)).sendError(any(Pcerr.class));
+ assertEquals(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, errorsSession2.get(0));
}
@Test
public void testAddTunnel() {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onSessionUp(this.session2);
- tunnelManager.onMessagePcInitiate(createRequests(1), this.session1);
- Mockito.verify(this.session1, Mockito.times(1)).sendReport(Mockito.any(Pcrpt.class));
- Mockito.verify(this.session2, Mockito.times(1)).sendReport(Mockito.any(Pcrpt.class));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onSessionUp(session2);
+ tunnelManager.onMessagePcInitiate(createRequests(1), session1);
+ verify(session1, times(1)).sendReport(any(Pcrpt.class));
+ verify(session2, times(1)).sendReport(any(Pcrpt.class));
}
@Test
public void testRemoveTunnel() {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onSessionUp(this.session2);
- tunnelManager.onMessagePcInitiate(createRequests(1), this.session1);
- tunnelManager.onMessagePcInitiate(createRequestsRemove(1), this.session1);
- Mockito.verify(this.session1, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
- Mockito.verify(this.session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onSessionUp(session2);
+ tunnelManager.onMessagePcInitiate(createRequests(1), session1);
+ tunnelManager.onMessagePcInitiate(createRequestsRemove(1), session1);
+ verify(session1, times(2)).sendReport(any(Pcrpt.class));
+ verify(session2, times(2)).sendReport(any(Pcrpt.class));
}
@Test
public void testRemoveTunnelUnknownLsp() {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onMessagePcInitiate(createRequestsRemove(1), this.session1);
- Mockito.verify(this.session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
- assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, this.errorsSession1.get(0));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onMessagePcInitiate(createRequestsRemove(1), session1);
+ verify(session1, times(1)).sendError(any(Pcerr.class));
+ assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, errorsSession1.get(0));
}
@Test
public void testRemoveTunnelNotPceInitiatedLsp() {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onMessagePcInitiate(createRequestsRemove(1), this.session1);
- Mockito.verify(this.session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
- assertEquals(PCEPErrors.LSP_NOT_PCE_INITIATED, this.errorsSession1.get(0));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onMessagePcInitiate(createRequestsRemove(1), session1);
+ verify(session1, times(1)).sendError(any(Pcerr.class));
+ assertEquals(PCEPErrors.LSP_NOT_PCE_INITIATED, errorsSession1.get(0));
}
@Test
public void testRemoveTunnelNotDelegated() {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onSessionUp(this.session2);
- tunnelManager.onMessagePcInitiate(createRequests(1), this.session1);
- tunnelManager.onMessagePcInitiate(createRequestsRemove(1), this.session2);
- Mockito.verify(this.session2, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
- assertEquals(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, this.errorsSession2.get(0));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onSessionUp(session2);
+ tunnelManager.onMessagePcInitiate(createRequests(1), session1);
+ tunnelManager.onMessagePcInitiate(createRequestsRemove(1), session2);
+ verify(session2, times(1)).sendError(any(Pcerr.class));
+ assertEquals(PCEPErrors.UPDATE_REQ_FOR_NON_LSP, errorsSession2.get(0));
}
@Test
public void testTakeDelegation() throws InterruptedException {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, -1, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onSessionUp(this.session2);
- tunnelManager.onMessagePcInitiate(createRequests(1), this.session1); //AddTunel
- tunnelManager.onMessagePcupd(createUpdate(1), this.session1); //returnDelegation
- Mockito.verify(this.session1, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
- Mockito.verify(this.session2, Mockito.times(1)).sendReport(Mockito.any(Pcrpt.class));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, -1, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onSessionUp(session2);
+ tunnelManager.onMessagePcInitiate(createRequests(1), session1); //AddTunel
+ tunnelManager.onMessagePcupd(createUpdate(1), session1); //returnDelegation
+ verify(session1, times(2)).sendReport(any(Pcrpt.class));
+ verify(session2, times(1)).sendReport(any(Pcrpt.class));
Thread.sleep(500);
- tunnelManager.onMessagePcInitiate(createRequestsDelegate(1), this.session2);//takeDelegation
- Mockito.verify(this.session1, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
- Mockito.verify(this.session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+ tunnelManager.onMessagePcInitiate(createRequestsDelegate(1), session2);//takeDelegation
+ verify(session1, times(2)).sendReport(any(Pcrpt.class));
+ verify(session2, times(2)).sendReport(any(Pcrpt.class));
}
@Test
public void testTakeDelegationUnknownLsp() {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onMessagePcInitiate(createRequestsDelegate(1), this.session1);
- Mockito.verify(this.session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
- assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, this.errorsSession1.get(0));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onMessagePcInitiate(createRequestsDelegate(1), session1);
+ verify(session1, times(1)).sendError(any(Pcerr.class));
+ assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, errorsSession1.get(0));
}
@Test
public void testTakeDelegationNotPceInitiatedLsp() {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onMessagePcInitiate(createRequestsDelegate(1), this.session1);
- Mockito.verify(this.session1, Mockito.times(1)).sendError(Mockito.any(Pcerr.class));
- assertEquals(PCEPErrors.LSP_NOT_PCE_INITIATED, this.errorsSession1.get(0));
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(1, ADDRESS, 0, 0, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onMessagePcInitiate(createRequestsDelegate(1), session1);
+ verify(session1, times(1)).sendError(any(Pcerr.class));
+ assertEquals(PCEPErrors.LSP_NOT_PCE_INITIATED, errorsSession1.get(0));
}
@Test
public void testReturnDelegationNoRetake() throws InterruptedException {
- final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, this.timerHandler);
- tunnelManager.onSessionUp(this.session1);
- tunnelManager.onSessionUp(this.session2);
- tunnelManager.onMessagePcInitiate(createRequests(1), this.session1);
- tunnelManager.onMessagePcupd(createUpdate(1), this.session1);
+ final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(0, ADDRESS, 0, 0, TIMER, timerHandler);
+ tunnelManager.onSessionUp(session1);
+ tunnelManager.onSessionUp(session2);
+ tunnelManager.onMessagePcInitiate(createRequests(1), session1);
+ tunnelManager.onMessagePcupd(createUpdate(1), session1);
//wait for state timeout expires
Thread.sleep(500);
- Mockito.verify(this.session1, Mockito.times(3)).sendReport(Mockito.any(Pcrpt.class));
- Mockito.verify(this.session2, Mockito.times(2)).sendReport(Mockito.any(Pcrpt.class));
+ verify(session1, times(3)).sendReport(any(Pcrpt.class));
+ verify(session2, times(2)).sendReport(any(Pcrpt.class));
}
private static Updates createUpdateDelegate(final long plspId) {
}
private static Updates createUpdate(final long plspId, final Optional<Boolean> delegate) {
- final UpdatesBuilder updsBuilder = new UpdatesBuilder();
final LspBuilder lsp = new LspBuilder().setPlspId(new PlspId(Uint32.valueOf(plspId)));
if (delegate.isPresent()) {
lsp.setDelegate(Boolean.TRUE);
}
- updsBuilder.setLsp(lsp.build());
- final PathBuilder pathBuilder = new PathBuilder();
- pathBuilder.setEro(ERO);
- updsBuilder.setPath(pathBuilder.build());
- updsBuilder.setSrp(new SrpBuilder().setOperationId(new SrpIdNumber(Uint32.ZERO)).build());
- return updsBuilder.build();
+ return new UpdatesBuilder()
+ .setLsp(lsp.build())
+ .setPath(new PathBuilder().setEro(ERO).build())
+ .setSrp(new SrpBuilder().setOperationId(new SrpIdNumber(Uint32.ZERO)).build())
+ .build();
}
private static Requests createRequests(final long plspId, final Optional<Boolean> remove,
final Optional<Boolean> delegate) {
- final RequestsBuilder reqBuilder = new RequestsBuilder();
- reqBuilder.setEro(ERO);
final LspBuilder lsp = new LspBuilder().setTlvs(new TlvsBuilder()
.setSymbolicPathName(new SymbolicPathNameBuilder().setPathName(
new SymbolicPathName(SYMBOLIC_NAME)).build()).build()).setPlspId(new PlspId(Uint32.valueOf(plspId)));
lsp.setDelegate(Boolean.TRUE);
}
- reqBuilder.setLsp(lsp.build());
final SrpBuilder srpBuilder = new SrpBuilder();
if (remove.isPresent()) {
srpBuilder.addAugmentation(new Srp1Builder().setRemove(Boolean.TRUE).build());
}
- return reqBuilder
- .setSrp(srpBuilder.setOperationId(new SrpIdNumber(Uint32.ZERO)).build())
- .build();
+ return new RequestsBuilder()
+ .setEro(ERO)
+ .setLsp(lsp.build())
+ .setSrp(srpBuilder.setOperationId(new SrpIdNumber(Uint32.ZERO)).build())
+ .build();
+ }
+
+ private static Requests createRequests(final long plspId) {
+ return createRequests(plspId, Optional.empty(), Optional.empty());
}
private static Requests createRequestsRemove(final long plspId) {
return createRequests(plspId, Optional.empty(), Optional.of(Boolean.TRUE));
}
- @SuppressWarnings("checkstyle:OverloadMethodsDeclarationOrder")
- private static Requests createRequests(final long plspId) {
- return createRequests(plspId, Optional.empty(), Optional.empty());
- }
-
private static PCEPErrors getError(final Pcerr errorMessage) {
final ErrorObject errorObject = errorMessage.getPcerrMessage().getErrors().get(0).getErrorObject();
return PCEPErrors.forValue(errorObject.getType(), errorObject.getValue());
}
-
}