use of org.openkilda.persistence.repositories.FlowRepository in project open-kilda by telstra.
the class FlowDeleteServiceTest method shouldFailDeleteFlowIfNoFlowFound.
@Test
public void shouldFailDeleteFlowIfNoFlowFound() throws DuplicateKeyException {
String flowId = "dummy-flow";
// make sure flow is missing
FlowRepository repository = persistenceManager.getRepositoryFactory().createFlowRepository();
Assert.assertFalse(repository.findById(flowId).isPresent());
makeService().handleRequest(dummyRequestKey, commandContext, flowId);
verifyNoSpeakerInteraction(carrier);
verifyNorthboundErrorResponse(carrier, ErrorType.NOT_FOUND);
}
use of org.openkilda.persistence.repositories.FlowRepository in project open-kilda by telstra.
the class FlowDeleteServiceTest method verifyFlowIsMissing.
private void verifyFlowIsMissing(Flow flow) {
RepositoryFactory repositoryFactory = persistenceManager.getRepositoryFactory();
FlowRepository flowRepository = repositoryFactory.createFlowRepository();
FlowPathRepository flowPathRepository = repositoryFactory.createFlowPathRepository();
Assert.assertFalse(flowRepository.findById(flow.getFlowId()).isPresent());
for (FlowPath path : flow.getPaths()) {
Assert.assertFalse(String.format("Flow path %s still exists", path.getPathId()), flowPathRepository.findById(path.getPathId()).isPresent());
}
// TODO(surabujin): maybe we should make more deep scanning for flow related resources and nested objects
}
use of org.openkilda.persistence.repositories.FlowRepository in project open-kilda by telstra.
the class RerouteServiceTest method handlePathNoFoundExceptionForSubYFlow.
@Test
public void handlePathNoFoundExceptionForSubYFlow() {
PathNode islSide = new PathNode(SWITCH_A.getSwitchId(), 1, 0);
FlowPathRepository pathRepository = mock(FlowPathRepository.class);
when(pathRepository.findBySegmentEndpoint(eq(islSide.getSwitchId()), eq(islSide.getPortNo()))).thenReturn(asList(subFlow.getForwardPath(), subFlow.getReversePath()));
FlowRepository flowRepository = mock(FlowRepository.class);
YFlowRepository yFlowRepository = mock(YFlowRepository.class);
RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
when(repositoryFactory.createPathSegmentRepository()).thenReturn(mock(PathSegmentRepository.class));
when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
when(repositoryFactory.createYFlowRepository()).thenReturn(yFlowRepository);
PersistenceManager persistenceManager = mock(PersistenceManager.class);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
RerouteService rerouteService = new RerouteService(persistenceManager);
RerouteAffectedFlows request = new RerouteAffectedFlows(islSide, "dummy-reason - unittest");
rerouteService.rerouteAffectedFlows(carrier, CORRELATION_ID, request);
verify(flowRepository).updateStatusSafe(eq(subFlow), eq(FlowStatus.DOWN), any());
FlowThrottlingData expected = FlowThrottlingData.builder().correlationId(CORRELATION_ID).priority(regularYFlow.getPriority()).timeCreate(regularYFlow.getTimeCreate()).affectedIsl(Collections.singleton(new IslEndpoint(islSide.getSwitchId(), islSide.getPortNo()))).force(false).effectivelyDown(true).reason(request.getReason()).yFlow(true).build();
verify(carrier).emitRerouteCommand(eq(regularYFlow.getYFlowId()), eq(expected));
}
use of org.openkilda.persistence.repositories.FlowRepository 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.persistence.repositories.FlowRepository in project open-kilda by telstra.
the class RerouteServiceTest method handleUpdateSingleSwitchFlows.
@Test
public void handleUpdateSingleSwitchFlows() {
FlowRepository flowRepository = mock(FlowRepository.class);
when(flowRepository.findOneSwitchFlows(oneSwitchFlow.getSrcSwitch().getSwitchId())).thenReturn(Collections.singletonList(oneSwitchFlow));
FlowPathRepository flowPathRepository = mock(FlowPathRepository.class);
RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
PersistenceManager persistenceManager = mock(PersistenceManager.class);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
RerouteService rerouteService = new RerouteService(persistenceManager);
rerouteService.processSingleSwitchFlowStatusUpdate(new SwitchStateChanged(oneSwitchFlow.getSrcSwitchId(), SwitchStatus.INACTIVE));
assertEquals(format("Switch %s is inactive", oneSwitchFlow.getSrcSwitchId()), FlowStatus.DOWN, oneSwitchFlow.getStatus());
}
Aggregations