Search in sources :

Example 1 with FlowPathRepository

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

the class FlowDeleteServiceTest method shouldCompleteDeleteOnErrorDuringCompletingFlowPathRemoval.

@Test
public void shouldCompleteDeleteOnErrorDuringCompletingFlowPathRemoval() throws DuplicateKeyException, UnknownKeyException {
    Flow target = makeFlow();
    FlowPath forwardPath = target.getForwardPath();
    Assert.assertNotNull(forwardPath);
    FlowPathRepository repository = setupFlowPathRepositorySpy();
    doThrow(new RuntimeException(injectedErrorMessage)).when(repository).remove(eq(forwardPath.getPathId()));
    FlowDeleteService service = makeService();
    service.handleRequest(dummyRequestKey, commandContext, target.getFlowId());
    verifyFlowStatus(target.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    produceSpeakerResponses(service);
    // 4 flow rules + 4 mirror rules
    verify(carrier, times(8)).sendSpeakerRequest(any());
    verifyFlowIsMissing(target);
}
Also used : FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 2 with FlowPathRepository

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

the class FlowRerouteServiceTest method shouldCompleteRerouteOnErrorDuringCompletingFlowPathRemoval.

@Test
public void shouldCompleteRerouteOnErrorDuringCompletingFlowPathRemoval() throws RecoverableException, UnroutableFlowException, UnknownKeyException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    FlowPathRepository repository = setupFlowPathRepositorySpy();
    doThrow(new RuntimeException(injectedErrorMessage)).when(repository).remove(eq(origin.getForwardPathId()));
    FlowRerouteService service = makeService();
    FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
    service.handleRequest(currentRequestKey, request, commandContext);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        produceAsyncResponse(service, speakerRequest);
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    verifyPathReplace(origin, result);
}
Also used : FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 3 with FlowPathRepository

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

the class FlowRerouteServiceTest method shouldFailRerouteOnErrorDuringCompletingFlowPathInstallation.

@Test
public void shouldFailRerouteOnErrorDuringCompletingFlowPathInstallation() throws RecoverableException, UnroutableFlowException, UnknownKeyException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    FlowPathRepository repository = setupFlowPathRepositorySpy();
    Set<PathId> originalPaths = origin.getPaths().stream().map(FlowPath::getPathId).collect(toSet());
    doThrow(new RuntimeException(injectedErrorMessage)).when(repository).updateStatus(ArgumentMatchers.argThat(argument -> !originalPaths.contains(argument)), eq(FlowPathStatus.ACTIVE));
    FlowRerouteService service = makeService();
    FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
    service.handleRequest(currentRequestKey, request, commandContext);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        if (speakerRequest.isVerifyRequest()) {
            service.handleAsyncResponse(currentRequestKey, buildResponseOnVerifyRequest(speakerRequest));
        } else {
            produceAsyncResponse(service, speakerRequest);
        }
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    verifyNoPathReplace(origin, result);
}
Also used : PathId(org.openkilda.model.PathId) MAX_LATENCY(org.openkilda.model.PathComputationStrategy.MAX_LATENCY) ArgumentMatchers(org.mockito.ArgumentMatchers) FlowPath(org.openkilda.model.FlowPath) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) FlowStatus(org.openkilda.model.FlowStatus) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) Mockito.doThrow(org.mockito.Mockito.doThrow) FlowPathStatus(org.openkilda.model.FlowPathStatus) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) Flow(org.openkilda.model.Flow) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Mockito.doReturn(org.mockito.Mockito.doReturn) Collectors.toSet(java.util.stream.Collectors.toSet) IslEndpoint(org.openkilda.model.IslEndpoint) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) Collection(java.util.Collection) Set(java.util.Set) CommandContext(org.openkilda.wfm.CommandContext) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ErrorCode(org.openkilda.floodlight.flow.response.FlowErrorResponse.ErrorCode) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RerouteResultInfoData(org.openkilda.messaging.info.reroute.RerouteResultInfoData) PathSegment(org.openkilda.model.PathSegment) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) RecoverableException(org.openkilda.pce.exception.RecoverableException) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) IslRepository(org.openkilda.persistence.repositories.IslRepository) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) FlowRerouteResponse(org.openkilda.messaging.info.flow.FlowRerouteResponse) PathId(org.openkilda.model.PathId) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) Before(org.junit.Before) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) Assert.assertNotNull(org.junit.Assert.assertNotNull) ErrorType(org.openkilda.messaging.error.ErrorType) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) LATENCY(org.openkilda.model.PathComputationStrategy.LATENCY) Mockito.verify(org.mockito.Mockito.verify) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) GetPathsResult(org.openkilda.pce.GetPathsResult) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 4 with FlowPathRepository

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

the class FlowRerouteServiceTest method shouldFailRerouteOnSwapPathsError.

@Ignore("FIXME: need to replace mocking of updateStatus with another approach")
@Test
public void shouldFailRerouteOnSwapPathsError() throws RecoverableException, UnroutableFlowException, UnknownKeyException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    FlowPathRepository flowPathRepository = setupFlowPathRepositorySpy();
    doThrow(new RuntimeException(injectedErrorMessage)).when(flowPathRepository).updateStatus(eq(origin.getForwardPathId()), eq(FlowPathStatus.IN_PROGRESS));
    FlowRerouteService service = makeService();
    FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
    service.handleRequest(currentRequestKey, request, commandContext);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        if (speakerRequest.isVerifyRequest()) {
            service.handleAsyncResponse(currentRequestKey, buildResponseOnVerifyRequest(speakerRequest));
        } else {
            produceAsyncResponse(service, speakerRequest);
        }
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    verifyNoPathReplace(origin, result);
}
Also used : FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Flow(org.openkilda.model.Flow) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with FlowPathRepository

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

the class FlowRerouteServiceTest method shouldFailRerouteFlowOnResourcesAllocationConstraint.

@Test
public void shouldFailRerouteFlowOnResourcesAllocationConstraint() throws RecoverableException, UnroutableFlowException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    FlowPathRepository repository = setupFlowPathRepositorySpy();
    doThrow(new RuntimeException(injectedErrorMessage)).when(repository).add(any(FlowPath.class));
    FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
    testExpectedFailure(dummyRequestKey, request, commandContext, origin, FlowStatus.UP, ErrorType.INTERNAL_ERROR);
}
Also used : FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Aggregations

FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)20 Test (org.junit.Test)17 RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)11 Flow (org.openkilda.model.Flow)9 FlowPath (org.openkilda.model.FlowPath)8 FlowRepository (org.openkilda.persistence.repositories.FlowRepository)8 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)6 PersistenceManager (org.openkilda.persistence.PersistenceManager)6 YFlowRepository (org.openkilda.persistence.repositories.YFlowRepository)5 Before (org.junit.Before)4 Ignore (org.junit.Ignore)4 FlowRequest (org.openkilda.messaging.command.flow.FlowRequest)4 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)4 RerouteAffectedFlows (org.openkilda.messaging.command.reroute.RerouteAffectedFlows)3 PathNode (org.openkilda.messaging.info.event.PathNode)3 FlowStatus (org.openkilda.model.FlowStatus)3 IslEndpoint (org.openkilda.model.IslEndpoint)3 PathSegmentRepository (org.openkilda.persistence.repositories.PathSegmentRepository)3 FlowThrottlingData (org.openkilda.wfm.topology.reroute.model.FlowThrottlingData)3 Set (java.util.Set)2