Search in sources :

Example 6 with RepositoryFactory

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));
}
Also used : FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) IslEndpoint(org.openkilda.model.IslEndpoint) PathSegmentRepository(org.openkilda.persistence.repositories.PathSegmentRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) FlowThrottlingData(org.openkilda.wfm.topology.reroute.model.FlowThrottlingData) 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 7 with RepositoryFactory

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));
}
Also used : YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) FlowThrottlingData(org.openkilda.wfm.topology.reroute.model.FlowThrottlingData) YFlowRerouteRequest(org.openkilda.messaging.command.yflow.YFlowRerouteRequest) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) Test(org.junit.Test)

Example 8 with RepositoryFactory

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()));
}
Also used : LagLogicalPortRepository(org.openkilda.persistence.repositories.LagLogicalPortRepository) Cookie(org.openkilda.model.cookie.Cookie) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) ValidateRulesResult(org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) MeterId(org.openkilda.model.MeterId) Before(org.junit.Before)

Example 9 with RepositoryFactory

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);
}
Also used : PathComputerConfig(org.openkilda.pce.PathComputerConfig) PropertiesBasedConfigurationProvider(org.openkilda.config.provider.PropertiesBasedConfigurationProvider) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) BeforeClass(org.junit.BeforeClass)

Example 10 with RepositoryFactory

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);
}
Also used : PersistenceManager(org.openkilda.persistence.PersistenceManager) SharedEndpoint(org.openkilda.model.YFlow.SharedEndpoint) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) Before(org.junit.Before)

Aggregations

RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)23 PersistenceManager (org.openkilda.persistence.PersistenceManager)13 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)11 FlowRepository (org.openkilda.persistence.repositories.FlowRepository)11 Test (org.junit.Test)10 YFlowRepository (org.openkilda.persistence.repositories.YFlowRepository)10 FlowThrottlingData (org.openkilda.wfm.topology.reroute.model.FlowThrottlingData)6 Before (org.junit.Before)5 BeforeClass (org.junit.BeforeClass)5 PathSegmentRepository (org.openkilda.persistence.repositories.PathSegmentRepository)5 SwitchRepository (org.openkilda.persistence.repositories.SwitchRepository)4 RerouteAffectedFlows (org.openkilda.messaging.command.reroute.RerouteAffectedFlows)3 PathNode (org.openkilda.messaging.info.event.PathNode)3 FlowPath (org.openkilda.model.FlowPath)3 IslRepository (org.openkilda.persistence.repositories.IslRepository)3 PropertiesBasedConfigurationProvider (org.openkilda.config.provider.PropertiesBasedConfigurationProvider)2 YFlowRerouteRequest (org.openkilda.messaging.command.yflow.YFlowRerouteRequest)2 IslEndpoint (org.openkilda.model.IslEndpoint)2 PathSegment (org.openkilda.model.PathSegment)2 SwitchId (org.openkilda.model.SwitchId)2