use of org.openkilda.persistence.repositories.FlowPathRepository 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);
}
use of org.openkilda.persistence.repositories.FlowPathRepository in project open-kilda by telstra.
the class RerouteServiceTest method handlePathNoFoundException.
@Test
public void handlePathNoFoundException() {
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);
RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
when(repositoryFactory.createPathSegmentRepository()).thenReturn(mock(PathSegmentRepository.class));
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);
verify(flowRepository).updateStatusSafe(eq(regularFlow), eq(FlowStatus.DOWN), any());
FlowThrottlingData expected = FlowThrottlingData.builder().correlationId(CORRELATION_ID).priority(regularFlow.getPriority()).timeCreate(regularFlow.getTimeCreate()).affectedIsl(Collections.singleton(new IslEndpoint(islSide.getSwitchId(), islSide.getPortNo()))).force(false).effectivelyDown(true).reason(request.getReason()).build();
verify(carrier).emitRerouteCommand(eq(regularFlow.getFlowId()), eq(expected));
}
use of org.openkilda.persistence.repositories.FlowPathRepository in project open-kilda by telstra.
the class SwitchValidateServiceImplTest method setUp.
@Before
public void setUp() {
RepositoryFactory repositoryFactory = Mockito.mock(RepositoryFactory.class);
FlowPathRepository flowPathRepository = Mockito.mock(FlowPathRepository.class);
SwitchRepository switchRepository = Mockito.mock(SwitchRepository.class);
when(switchRepository.findById(eq(SWITCH_ID))).thenReturn(Optional.of(SWITCH_1));
when(switchRepository.findById(eq(SWITCH_ID_MISSING))).thenReturn(Optional.empty());
LagLogicalPortRepository lagLogicalPortRepository = Mockito.mock(LagLogicalPortRepository.class);
when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
when(repositoryFactory.createSwitchRepository()).thenReturn(switchRepository);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
service = new SwitchValidateServiceImpl(carrier, persistenceManager, validationService, ruleManager);
request = SwitchValidateRequest.builder().switchId(SWITCH_ID).processMeters(true).build();
flowSpeakerData = FlowSpeakerData.builder().ofVersion(OfVersion.OF_13).cookie(new Cookie(1L)).table(OfTable.INPUT).priority(10).match(emptySet()).instructions(Instructions.builder().build()).flags(emptySet()).build();
meterSpeakerData = MeterSpeakerData.builder().meterId(new MeterId(32)).rate(10000).burst(10500).ofVersion(OfVersion.OF_13).flags(Sets.newHashSet(MeterFlag.KBPS, MeterFlag.BURST, MeterFlag.STATS)).build();
when(validationService.validateRules(any(), any(), any())).thenReturn(new ValidateRulesResult(newHashSet(flowSpeakerData.getCookie().getValue()), emptySet(), emptySet(), emptySet()));
when(validationService.validateMeters(any(), any(), any())).thenReturn(new ValidateMetersResult(emptyList(), emptyList(), emptyList(), emptyList()));
}
use of org.openkilda.persistence.repositories.FlowPathRepository 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.FlowPathRepository in project open-kilda by telstra.
the class RerouteServiceTest method handleRerouteInactiveAffectedFlows.
@Test
public void handleRerouteInactiveAffectedFlows() {
FlowPathRepository pathRepository = mock(FlowPathRepository.class);
when(pathRepository.findInactiveBySegmentSwitch(regularFlow.getSrcSwitchId())).thenReturn(asList(regularFlow.getForwardPath(), regularFlow.getReversePath()));
RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
PersistenceManager persistenceManager = mock(PersistenceManager.class);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
RerouteService rerouteService = new RerouteService(persistenceManager);
regularFlow.setStatus(FlowStatus.DOWN);
rerouteService.rerouteInactiveAffectedFlows(carrier, CORRELATION_ID, regularFlow.getSrcSwitchId());
FlowThrottlingData expected = FlowThrottlingData.builder().correlationId(CORRELATION_ID).priority(regularFlow.getPriority()).timeCreate(regularFlow.getTimeCreate()).affectedIsl(Collections.emptySet()).force(false).effectivelyDown(true).reason(format("Switch '%s' online", regularFlow.getSrcSwitchId())).build();
verify(carrier).emitRerouteCommand(eq(regularFlow.getFlowId()), eq(expected));
regularFlow.setStatus(FlowStatus.UP);
}
Aggregations