use of org.openkilda.persistence.repositories.RepositoryFactory 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.RepositoryFactory in project open-kilda by telstra.
the class RerouteServiceTest method processManualRerouteRequestForYFlow.
@Test
public void processManualRerouteRequestForYFlow() {
RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
YFlowRepository yFlowRepository = mock(YFlowRepository.class);
when(repositoryFactory.createYFlowRepository()).thenReturn(yFlowRepository);
PersistenceManager persistenceManager = mock(PersistenceManager.class);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
when(yFlowRepository.findById(YFLOW_ID)).thenReturn(Optional.of(regularYFlow));
RerouteService rerouteService = new RerouteService(persistenceManager);
YFlowRerouteRequest request = new YFlowRerouteRequest(regularYFlow.getYFlowId(), Collections.emptySet(), true, "reason", false);
rerouteService.processRerouteRequest(carrier, CORRELATION_ID, request);
FlowThrottlingData expected = FlowThrottlingData.builder().correlationId(CORRELATION_ID).priority(regularYFlow.getPriority()).timeCreate(regularYFlow.getTimeCreate()).affectedIsl(Collections.emptySet()).force(true).reason("reason").yFlow(true).build();
verify(carrier).emitManualRerouteCommand(eq(regularYFlow.getYFlowId()), eq(expected));
}
use of org.openkilda.persistence.repositories.RepositoryFactory 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.RepositoryFactory in project open-kilda by telstra.
the class PathsServiceTest method setUpOnce.
@BeforeClass
public static void setUpOnce() {
RepositoryFactory repositoryFactory = persistenceManager.getRepositoryFactory();
kildaConfigurationRepository = repositoryFactory.createKildaConfigurationRepository();
switchRepository = repositoryFactory.createSwitchRepository();
switchPropertiesRepository = repositoryFactory.createSwitchPropertiesRepository();
islRepository = repositoryFactory.createIslRepository();
kildaConfigurationRepository = repositoryFactory.createKildaConfigurationRepository();
PathComputerConfig pathComputerConfig = new PropertiesBasedConfigurationProvider().getConfiguration(PathComputerConfig.class);
pathsService = new PathsService(repositoryFactory, pathComputerConfig);
}
use of org.openkilda.persistence.repositories.RepositoryFactory in project open-kilda by telstra.
the class RerouteQueueServiceTest method setup.
@Before
public void setup() {
flow = Flow.builder().flowId(FLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_B).priority(2).build();
when(flowRepository.findById(FLOW_ID)).thenReturn(Optional.of(flow));
yFlow = YFlow.builder().yFlowId(YFLOW_ID).sharedEndpoint(new SharedEndpoint(SWITCH_A.getSwitchId(), 10)).priority(2).build();
when(yFlowRepository.findById(YFLOW_ID)).thenReturn(Optional.of(yFlow));
RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
when(repositoryFactory.createYFlowRepository()).thenReturn(yFlowRepository);
PersistenceManager persistenceManager = mock(PersistenceManager.class);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
rerouteQueueService = new RerouteQueueService(carrier, persistenceManager, 0, 3);
}
Aggregations