use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput in project openflowplugin by opendaylight.
the class FlatBatchFlowAdaptersTest method testCreateBatchFlowChainingFunction_successes.
@Test
public void testCreateBatchFlowChainingFunction_successes() throws Exception {
final RpcResult<BatchFlowOutputListGrouping> input = RpcResultBuilder.<BatchFlowOutputListGrouping>success(new AddFlowsBatchOutputBuilder().build()).build();
final RpcResult<ProcessFlatBatchOutput> rpcResult = FlatBatchFlowAdapters.convertBatchFlowResult(0).apply(input);
Assert.assertTrue(rpcResult.isSuccessful());
Assert.assertEquals(0, rpcResult.getErrors().size());
Assert.assertEquals(0, rpcResult.getResult().getBatchFailure().size());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput in project openflowplugin by opendaylight.
the class FlatBatchMeterAdaptersTest method testCreateBatchMeterChainingFunction_successes.
@Test
public void testCreateBatchMeterChainingFunction_successes() throws Exception {
final RpcResult<BatchMeterOutputListGrouping> input = RpcResultBuilder.<BatchMeterOutputListGrouping>success(new AddMetersBatchOutputBuilder().build()).build();
final RpcResult<ProcessFlatBatchOutput> rpcResult = FlatBatchMeterAdapters.convertBatchMeterResult(0).apply(input);
Assert.assertTrue(rpcResult.isSuccessful());
Assert.assertEquals(0, rpcResult.getErrors().size());
Assert.assertEquals(0, rpcResult.getResult().getBatchFailure().size());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput in project openflowplugin by opendaylight.
the class SalFlatBatchServiceImplTest method testProcessFlatBatch_firstFailedInterrupted.
@Test
public void testProcessFlatBatch_firstFailedInterrupted() throws Exception {
prepareFirstFailingMockService();
int idx = 0;
ProcessFlatBatchInput batchInput = new ProcessFlatBatchInputBuilder().setNode(NODE_REF).setBatch(Lists.newArrayList(createFlowAddBatch(idx++, "f1", 2), createFlowRemoveBatch(idx++, "f2"), createFlowUpdateBatch(idx++, "f3"), createGroupAddBatch(idx++, 1L), createGroupRemoveBatch(idx++, 2L), createGroupUpdateBatch(idx++, 3L), createMeterAddBatch(idx++, 1L), createMeterRemoveBatch(idx++, 2L), createMeterUpdateBatch(idx++, 3L))).setExitOnFirstError(true).build();
final Future<RpcResult<ProcessFlatBatchOutput>> rpcResultFuture = salFlatBatchService.processFlatBatch(batchInput);
Assert.assertTrue(rpcResultFuture.isDone());
final RpcResult<ProcessFlatBatchOutput> rpcResult = rpcResultFuture.get();
Assert.assertFalse(rpcResult.isSuccessful());
Assert.assertEquals(1, rpcResult.getErrors().size());
Assert.assertEquals(1, rpcResult.getResult().getBatchFailure().size());
Assert.assertEquals(3, rpcResult.getResult().getBatchFailure().get(0).getBatchOrder().intValue());
final InOrder inOrder = Mockito.inOrder(salFlowsBatchService, salGroupsBatchService, salMetersBatchService);
inOrder.verify(salFlowsBatchService).addFlowsBatch(Matchers.<AddFlowsBatchInput>any());
inOrder.verify(salFlowsBatchService).removeFlowsBatch(Matchers.<RemoveFlowsBatchInput>any());
inOrder.verify(salFlowsBatchService).updateFlowsBatch(Matchers.<UpdateFlowsBatchInput>any());
inOrder.verify(salGroupsBatchService).addGroupsBatch(Matchers.<AddGroupsBatchInput>any());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput in project openflowplugin by opendaylight.
the class SalFlatBatchServiceImplTest method testExecuteBatchPlan.
@Test
public void testExecuteBatchPlan() throws Exception {
BatchStepJob batchStepJob1 = Mockito.mock(BatchStepJob.class);
BatchStepJob batchStepJob2 = Mockito.mock(BatchStepJob.class);
AsyncFunction<RpcResult<ProcessFlatBatchOutput>, RpcResult<ProcessFlatBatchOutput>> function1 = Mockito.mock(AsyncFunction.class);
AsyncFunction<RpcResult<ProcessFlatBatchOutput>, RpcResult<ProcessFlatBatchOutput>> function2 = Mockito.mock(AsyncFunction.class);
Mockito.when(batchStepJob1.getStepFunction()).thenReturn(function1);
Mockito.when(batchStepJob2.getStepFunction()).thenReturn(function2);
BatchPlanStep batchPlanStep1 = new BatchPlanStep(BatchStepType.GROUP_ADD);
batchPlanStep1.setBarrierAfter(true);
BatchPlanStep batchPlanStep2 = new BatchPlanStep(BatchStepType.FLOW_ADD);
batchPlanStep1.setBarrierAfter(false);
Mockito.when(batchStepJob1.getPlanStep()).thenReturn(batchPlanStep1);
Mockito.when(batchStepJob2.getPlanStep()).thenReturn(batchPlanStep2);
final ListenableFuture<RpcResult<ProcessFlatBatchOutput>> succeededChainOutput = FlatBatchUtil.createEmptyRpcBatchResultFuture(true);
final ListenableFuture<RpcResult<ProcessFlatBatchOutput>> failedChainOutput = RpcResultBuilder.<ProcessFlatBatchOutput>failed().withError(RpcError.ErrorType.APPLICATION, "ut-chainError").withResult(createFlatBatchOutput(createFlowBatchFailure(0, "f1"), createFlowBatchFailure(1, "f2"))).buildFuture();
Mockito.when(batchStepJob1.getStepFunction().apply(Matchers.<RpcResult<ProcessFlatBatchOutput>>any())).thenReturn(succeededChainOutput);
Mockito.when(batchStepJob2.getStepFunction().apply(Matchers.<RpcResult<ProcessFlatBatchOutput>>any())).thenReturn(failedChainOutput);
final List<BatchStepJob> batchChainElements = Lists.newArrayList(batchStepJob1, batchStepJob2);
final Future<RpcResult<ProcessFlatBatchOutput>> rpcResultFuture = salFlatBatchService.executeBatchPlan(batchChainElements);
Assert.assertTrue(rpcResultFuture.isDone());
final RpcResult<ProcessFlatBatchOutput> rpcResult = rpcResultFuture.get();
Assert.assertFalse(rpcResult.isSuccessful());
Assert.assertEquals(1, rpcResult.getErrors().size());
Assert.assertEquals(2, rpcResult.getResult().getBatchFailure().size());
Assert.assertEquals("f2", ((FlatBatchFailureFlowIdCase) rpcResult.getResult().getBatchFailure().get(1).getBatchItemIdChoice()).getFlowId().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput in project openflowplugin by opendaylight.
the class SalFlatBatchServiceImpl method executeBatchPlan.
@VisibleForTesting
Future<RpcResult<ProcessFlatBatchOutput>> executeBatchPlan(final List<BatchStepJob> batchJobsChain) {
BatchStepJob batchJob;
final List<ListenableFuture<RpcResult<ProcessFlatBatchOutput>>> firedJobs = new ArrayList<>();
ListenableFuture<RpcResult<ProcessFlatBatchOutput>> chainSummaryResult = FlatBatchUtil.createEmptyRpcBatchResultFuture(true);
for (int i = 0; i < batchJobsChain.size(); i++) {
batchJob = batchJobsChain.get(i);
// wire actual job with chain
firedJobs.add(Futures.transformAsync(chainSummaryResult, batchJob.getStepFunction(), MoreExecutors.directExecutor()));
// if barrier after actual job is needed or it is the last job -> merge fired job results with chain result
if ((batchJob.getPlanStep().isBarrierAfter()) || (i == batchJobsChain.size() - 1)) {
firedJobs.add(0, chainSummaryResult);
chainSummaryResult = FlatBatchUtil.mergeJobsResultsFutures(firedJobs);
firedJobs.clear();
}
}
return chainSummaryResult;
}
Aggregations