Search in sources :

Example 1 with PathSegmentRepository

use of org.openkilda.persistence.repositories.PathSegmentRepository in project open-kilda by telstra.

the class RerouteServiceTest method shouldSkipRerouteRequestsForFlowWithoutAffectedPathSegment.

@Test
public void shouldSkipRerouteRequestsForFlowWithoutAffectedPathSegment() {
    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(regularFlow.getForwardPath(), regularFlow.getReversePath()));
    FlowRepository flowRepository = mock(FlowRepository.class);
    PathSegmentRepository pathSegmentRepository = mock(PathSegmentRepository.class);
    doThrow(new EntityNotFoundException("Not found")).when(pathSegmentRepository).updateFailedStatus(any(), any(), anyBoolean());
    RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
    when(repositoryFactory.createPathSegmentRepository()).thenReturn(pathSegmentRepository);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
    when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
    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);
    verifyZeroInteractions(carrier);
}
Also used : FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) PathSegmentRepository(org.openkilda.persistence.repositories.PathSegmentRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) EntityNotFoundException(org.openkilda.persistence.exceptions.EntityNotFoundException) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) RerouteAffectedFlows(org.openkilda.messaging.command.reroute.RerouteAffectedFlows) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 2 with PathSegmentRepository

use of org.openkilda.persistence.repositories.PathSegmentRepository 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());
            }
        }
    }
}
Also used : FlowRepository(org.openkilda.persistence.repositories.FlowRepository) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) PathSegmentRepository(org.openkilda.persistence.repositories.PathSegmentRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) MessageSender(org.openkilda.wfm.topology.reroute.bolts.MessageSender) TransactionManager(org.openkilda.persistence.tx.TransactionManager) PathSegment(org.openkilda.model.PathSegment) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) FlowPath(org.openkilda.model.FlowPath) FlowStatus(org.openkilda.model.FlowStatus) Test(org.junit.Test)

Example 3 with PathSegmentRepository

use of org.openkilda.persistence.repositories.PathSegmentRepository 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());
            }
        }
    }
}
Also used : FlowRepository(org.openkilda.persistence.repositories.FlowRepository) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) PathSegmentRepository(org.openkilda.persistence.repositories.PathSegmentRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) MessageSender(org.openkilda.wfm.topology.reroute.bolts.MessageSender) PathSegment(org.openkilda.model.PathSegment) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) FlowPath(org.openkilda.model.FlowPath) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 PersistenceManager (org.openkilda.persistence.PersistenceManager)3 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)3 FlowRepository (org.openkilda.persistence.repositories.FlowRepository)3 PathSegmentRepository (org.openkilda.persistence.repositories.PathSegmentRepository)3 RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)3 YFlowRepository (org.openkilda.persistence.repositories.YFlowRepository)3 FlowPath (org.openkilda.model.FlowPath)2 PathSegment (org.openkilda.model.PathSegment)2 MessageSender (org.openkilda.wfm.topology.reroute.bolts.MessageSender)2 RerouteAffectedFlows (org.openkilda.messaging.command.reroute.RerouteAffectedFlows)1 PathNode (org.openkilda.messaging.info.event.PathNode)1 FlowStatus (org.openkilda.model.FlowStatus)1 EntityNotFoundException (org.openkilda.persistence.exceptions.EntityNotFoundException)1 TransactionManager (org.openkilda.persistence.tx.TransactionManager)1