use of org.openkilda.persistence.repositories.FlowPathRepository in project open-kilda by telstra.
the class FlowUpdateServiceTest method shouldCompleteUpdateOnErrorDuringCompletingFlowPathRemoval.
@Test
public void shouldCompleteUpdateOnErrorDuringCompletingFlowPathRemoval() throws RecoverableException, UnroutableFlowException, DuplicateKeyException, UnknownKeyException {
Flow origin = makeFlow();
preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
FlowRequest request = makeRequest().flowId(origin.getFlowId()).build();
FlowPathRepository repository = setupFlowPathRepositorySpy();
doThrow(new RuntimeException(injectedErrorMessage)).when(repository).remove(eq(origin.getForwardPathId()));
FlowUpdateService service = makeService();
service.handleUpdateRequest(dummyRequestKey, commandContext, request);
verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
verifyNorthboundSuccessResponse(carrier);
FlowSegmentRequest speakerRequest;
while ((speakerRequest = requests.poll()) != null) {
if (speakerRequest.isVerifyRequest()) {
service.handleAsyncResponse(dummyRequestKey, buildResponseOnVerifyRequest(speakerRequest));
} else {
service.handleAsyncResponse(dummyRequestKey, SpeakerFlowSegmentResponse.builder().messageContext(speakerRequest.getMessageContext()).commandId(speakerRequest.getCommandId()).metadata(speakerRequest.getMetadata()).switchId(speakerRequest.getSwitchId()).success(true).build());
}
}
Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
verifyPathReplace(origin, result);
}
use of org.openkilda.persistence.repositories.FlowPathRepository in project open-kilda by telstra.
the class FlowUpdateServiceTest method shouldFailUpdateFlowOnResourcesAllocationConstraint.
@Test
public void shouldFailUpdateFlowOnResourcesAllocationConstraint() throws RecoverableException, UnroutableFlowException, DuplicateKeyException {
Flow origin = makeFlow();
preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
FlowPathRepository repository = setupFlowPathRepositorySpy();
doThrow(new RuntimeException(injectedErrorMessage)).when(repository).add(any(FlowPath.class));
FlowRequest request = makeRequest().flowId(origin.getFlowId()).build();
testExpectedFailure(request, origin, ErrorType.INTERNAL_ERROR);
}
use of org.openkilda.persistence.repositories.FlowPathRepository in project open-kilda by telstra.
the class FlowUpdateServiceTest method shouldFailUpdateOnSwapPathsError.
@Ignore("FIXME: need to replace mocking of updateStatus with another approach")
@Test
public void shouldFailUpdateOnSwapPathsError() throws RecoverableException, UnroutableFlowException, DuplicateKeyException, UnknownKeyException {
Flow origin = makeFlow();
preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
FlowRequest request = makeRequest().flowId(origin.getFlowId()).build();
FlowPathRepository flowPathRepository = setupFlowPathRepositorySpy();
doThrow(new RuntimeException(injectedErrorMessage)).when(flowPathRepository).updateStatus(eq(origin.getForwardPathId()), eq(FlowPathStatus.IN_PROGRESS));
FlowUpdateService service = makeService();
service.handleUpdateRequest(dummyRequestKey, commandContext, request);
verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
verifyNorthboundSuccessResponse(carrier);
FlowSegmentRequest speakerRequest;
while ((speakerRequest = requests.poll()) != null) {
if (speakerRequest.isVerifyRequest()) {
service.handleAsyncResponse(dummyRequestKey, buildResponseOnVerifyRequest(speakerRequest));
} else {
service.handleAsyncResponse(dummyRequestKey, SpeakerFlowSegmentResponse.builder().messageContext(speakerRequest.getMessageContext()).commandId(speakerRequest.getCommandId()).metadata(speakerRequest.getMetadata()).switchId(speakerRequest.getSwitchId()).success(true).build());
}
}
Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
verifyNoPathReplace(origin, result);
}
use of org.openkilda.persistence.repositories.FlowPathRepository in project open-kilda by telstra.
the class FlowUpdateServiceTest method shouldFailUpdateOnErrorDuringCompletingFlowPathInstallation.
@Test
public void shouldFailUpdateOnErrorDuringCompletingFlowPathInstallation() throws RecoverableException, UnroutableFlowException, DuplicateKeyException, UnknownKeyException {
Flow origin = makeFlow();
preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
FlowRequest request = makeRequest().flowId(origin.getFlowId()).build();
FlowPathRepository repository = setupFlowPathRepositorySpy();
Set<PathId> originalPaths = origin.getPaths().stream().map(FlowPath::getPathId).collect(Collectors.toSet());
doThrow(new RuntimeException(injectedErrorMessage)).when(repository).updateStatus(ArgumentMatchers.argThat(argument -> !originalPaths.contains(argument)), eq(FlowPathStatus.ACTIVE));
FlowUpdateService service = makeService();
service.handleUpdateRequest(dummyRequestKey, commandContext, request);
verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
verifyNorthboundSuccessResponse(carrier);
FlowSegmentRequest speakerRequest;
while ((speakerRequest = requests.poll()) != null) {
if (speakerRequest.isVerifyRequest()) {
service.handleAsyncResponse(dummyRequestKey, buildResponseOnVerifyRequest(speakerRequest));
} else {
service.handleAsyncResponse(dummyRequestKey, SpeakerFlowSegmentResponse.builder().messageContext(speakerRequest.getMessageContext()).commandId(speakerRequest.getCommandId()).metadata(speakerRequest.getMetadata()).switchId(speakerRequest.getSwitchId()).success(true).build());
}
}
Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
verifyNoPathReplace(origin, result);
}
use of org.openkilda.persistence.repositories.FlowPathRepository in project open-kilda by telstra.
the class SwitchSyncServiceImplTest method setUp.
@Before
public void setUp() {
RepositoryFactory repositoryFactory = Mockito.mock(RepositoryFactory.class);
FlowRepository flowRepository = Mockito.mock(FlowRepository.class);
FlowPathRepository flowPathRepository = Mockito.mock(FlowPathRepository.class);
TransitVlanRepository transitVlanRepository = Mockito.mock(TransitVlanRepository.class);
when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
when(repositoryFactory.createTransitVlanRepository()).thenReturn(transitVlanRepository);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
Properties configProps = new Properties();
configProps.setProperty("flow.meter-id.max", "40");
configProps.setProperty("flow.vlan.max", "50");
PropertiesBasedConfigurationProvider configurationProvider = new PropertiesBasedConfigurationProvider(configProps);
FlowResourcesConfig flowResourcesConfig = configurationProvider.getConfiguration(FlowResourcesConfig.class);
service = new SwitchSyncServiceImpl(carrier, persistenceManager, flowResourcesConfig);
service.commandBuilder = commandBuilder;
request = SwitchValidateRequest.builder().switchId(SWITCH_ID).performSync(true).build();
flowEntry = new FlowEntry(new FlowSegmentCookie(FlowPathDirection.FORWARD, 7).getValue(), 0, 0, 0, 0, "", 0, 0, 0, 0, null, null, null);
InstallIngressFlow installingRule = new InstallIngressFlow(UUID.randomUUID(), FLOW_ID, flowEntry.getCookie(), SWITCH_ID, 1, 2, 50, 0, 60, FlowEncapsulationType.TRANSIT_VLAN, OutputVlanType.POP, 10L, 100L, EGRESS_SWITCH_ID, false, false, false, null);
when(commandBuilder.buildCommandsToSyncMissingRules(eq(SWITCH_ID), any())).thenReturn(singletonList(installingRule));
missingRules = singletonList(flowEntry.getCookie());
excessRules = emptyList();
misconfiguredRules = emptyList();
excessMeters = emptyList();
}
Aggregations