use of org.openkilda.wfm.topology.reroute.bolts.MessageSender in project open-kilda by telstra.
the class RerouteServiceTest method testRerouteInactivePinnedFlowsOneFailedSegment.
@Test
public void testRerouteInactivePinnedFlowsOneFailedSegment() throws Throwable {
pinnedFlow.setStatus(FlowStatus.DOWN);
for (FlowPath flowPath : pinnedFlow.getPaths()) {
flowPath.setStatus(FlowPathStatus.INACTIVE);
for (PathSegment pathSegment : flowPath.getSegments()) {
if (pathSegment.containsNode(SWITCH_ID_A, PORT)) {
pathSegment.setFailed(true);
}
}
}
RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
FlowRepository flowRepository = mock(FlowRepository.class);
when(flowRepository.findInactiveFlows()).thenReturn(Collections.singletonList(pinnedFlow));
doAnswer(invocation -> {
FlowStatus status = invocation.getArgument(1);
pinnedFlow.setStatus(status);
return null;
}).when(flowRepository).updateStatusSafe(eq(pinnedFlow), any(), any());
when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
FlowPathRepository pathRepository = mock(FlowPathRepository.class);
when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
PathSegmentRepository pathSegmentRepository = mock(PathSegmentRepository.class);
when(repositoryFactory.createPathSegmentRepository()).thenReturn(pathSegmentRepository);
MessageSender messageSender = mock(MessageSender.class);
PersistenceManager persistenceManager = mock(PersistenceManager.class);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
TransactionManager transactionManager = mock(TransactionManager.class);
doAnswer(invocation -> {
TransactionCallback<?, ?> arg = invocation.getArgument(0);
return arg.doInTransaction();
}).when(transactionManager).doInTransaction(Mockito.<TransactionCallback<?, ?>>any());
when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
RerouteService rerouteService = new RerouteService(persistenceManager);
rerouteService.rerouteInactiveFlows(messageSender, CORRELATION_ID, REROUTE_INACTIVE_FLOWS_COMMAND);
assertEquals(FlowStatus.UP, pinnedFlow.getStatus());
for (FlowPath fp : pinnedFlow.getPaths()) {
assertEquals(FlowPathStatus.ACTIVE, fp.getStatus());
for (PathSegment ps : fp.getSegments()) {
if (ps.containsNode(SWITCH_ID_A, PORT)) {
assertFalse(ps.isFailed());
}
}
}
}
use of org.openkilda.wfm.topology.reroute.bolts.MessageSender in project open-kilda by telstra.
the class RerouteServiceTest method testRerouteInactivePinnedFlowsTwoFailedSegments.
@Test
public void testRerouteInactivePinnedFlowsTwoFailedSegments() {
pinnedFlow.setStatus(FlowStatus.DOWN);
for (FlowPath flowPath : pinnedFlow.getPaths()) {
flowPath.setStatus(FlowPathStatus.INACTIVE);
for (PathSegment pathSegment : flowPath.getSegments()) {
pathSegment.setFailed(true);
}
}
RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
FlowRepository flowRepository = mock(FlowRepository.class);
when(flowRepository.findInactiveFlows()).thenReturn(Collections.singletonList(pinnedFlow));
when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
FlowPathRepository pathRepository = mock(FlowPathRepository.class);
when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
PathSegmentRepository pathSegmentRepository = mock(PathSegmentRepository.class);
when(repositoryFactory.createPathSegmentRepository()).thenReturn(pathSegmentRepository);
MessageSender messageSender = mock(MessageSender.class);
PersistenceManager persistenceManager = mock(PersistenceManager.class);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
RerouteService rerouteService = new RerouteService(persistenceManager);
rerouteService.rerouteInactiveFlows(messageSender, CORRELATION_ID, REROUTE_INACTIVE_FLOWS_COMMAND);
verify(pathRepository, times(0)).updateStatus(any(), any());
assertTrue(FlowStatus.DOWN.equals(pinnedFlow.getStatus()));
for (FlowPath fp : pinnedFlow.getPaths()) {
assertTrue(FlowPathStatus.INACTIVE.equals(fp.getStatus()));
for (PathSegment ps : fp.getSegments()) {
if (ps.containsNode(SWITCH_ID_A, PORT)) {
assertFalse(ps.isFailed());
} else {
assertTrue(ps.isFailed());
}
}
}
}
Aggregations