import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep;
+import org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob;
import org.opendaylight.openflowplugin.impl.services.batch.BatchStepType;
+import org.opendaylight.openflowplugin.impl.util.FlatBatchUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.BatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddFlowCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddFlowCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddGroupCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddMeterCaseBuilder;
private SalGroupsBatchService salGroupsBatchService;
@Mock
private SalMetersBatchService salMetersBatchService;
- @Mock
- private AsyncFunction<RpcResult<ProcessFlatBatchOutput>, RpcResult<ProcessFlatBatchOutput>> chainElement1;
- @Mock
- private AsyncFunction<RpcResult<ProcessFlatBatchOutput>, RpcResult<ProcessFlatBatchOutput>> chainElement2;
@Captor
private ArgumentCaptor<AddFlowsBatchInput> addFlowsBatchInputCpt;
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());
}
@Test
@Test
public void testExecuteBatchPlan() throws Exception {
- final ListenableFuture<RpcResult<ProcessFlatBatchOutput>> succeededChainOutput =
- RpcResultBuilder.<ProcessFlatBatchOutput>success().buildFuture();
+ 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")))
+ .withResult(createFlatBatchOutput(createFlowBatchFailure(0, "f1"), createFlowBatchFailure(1, "f2")))
.buildFuture();
- Mockito.when(chainElement1.apply(Matchers.<RpcResult<ProcessFlatBatchOutput>>any()))
+ Mockito.when(batchStepJob1.getStepFunction().apply(Matchers.<RpcResult<ProcessFlatBatchOutput>>any()))
.thenReturn(succeededChainOutput);
- Mockito.when(chainElement2.apply(Matchers.<RpcResult<ProcessFlatBatchOutput>>any()))
+ Mockito.when(batchStepJob2.getStepFunction().apply(Matchers.<RpcResult<ProcessFlatBatchOutput>>any()))
.thenReturn(failedChainOutput);
- final List<AsyncFunction<RpcResult<ProcessFlatBatchOutput>, RpcResult<ProcessFlatBatchOutput>>> batchChainElements =
- Lists.newArrayList(chainElement1, chainElement2);
+ final List<BatchStepJob> batchChainElements = Lists.newArrayList(batchStepJob1, batchStepJob2);
final Future<RpcResult<ProcessFlatBatchOutput>> rpcResultFuture = salFlatBatchService.executeBatchPlan(batchChainElements);
Assert.assertTrue(rpcResultFuture.isDone());
@Test
public void testPrepareBatchPlan_success() throws Exception {
- final FlatBatchAddFlowCase flatBatchAddFlowCase = new FlatBatchAddFlowCaseBuilder()
- .setFlatBatchAddFlow(Collections.singletonList(new FlatBatchAddFlowBuilder()
- .setFlowId(new FlowId("f1"))
- .build()))
+ final FlatBatchAddFlow flatBatchAddFlow = new FlatBatchAddFlowBuilder()
+ .setFlowId(new FlowId("f1"))
.build();
- final BatchPlanStep batchPlanStep =
- new BatchPlanStep(BatchStepType.FLOW_ADD);
+ final BatchPlanStep batchPlanStep = new BatchPlanStep(BatchStepType.FLOW_ADD);
+ batchPlanStep.getTaskBag().addAll(Lists.newArrayList(flatBatchAddFlow, flatBatchAddFlow));
final List<BatchPlanStep> batchPlan = Lists.newArrayList(batchPlanStep);
- final List<AsyncFunction<RpcResult<ProcessFlatBatchOutput>, RpcResult<ProcessFlatBatchOutput>>> batchChain =
- salFlatBatchService.prepareBatchChain(batchPlan, NODE_REF, true);
+ final List<BatchStepJob> batchChain = salFlatBatchService.prepareBatchChain(batchPlan, NODE_REF, true);
Assert.assertEquals(1, batchChain.size());
final FlatBatchAddFlow flatBatchAddFlow = new FlatBatchAddFlowBuilder()
.setFlowId(new FlowId("f1"))
.build();
- final BatchPlanStep batchPlanStep =
- new BatchPlanStep(BatchStepType.FLOW_ADD);
- batchPlanStep.getTaskBag().addAll(Lists.newArrayList(
- flatBatchAddFlow,
- flatBatchAddFlow));
+ final BatchPlanStep batchPlanStep = new BatchPlanStep(BatchStepType.FLOW_ADD);
+ batchPlanStep.getTaskBag().addAll(Lists.newArrayList(flatBatchAddFlow, flatBatchAddFlow));
final List<BatchPlanStep> batchPlan = Lists.newArrayList(batchPlanStep, batchPlanStep);
- final List<AsyncFunction<RpcResult<ProcessFlatBatchOutput>, RpcResult<ProcessFlatBatchOutput>>> batchChain =
- salFlatBatchService.prepareBatchChain(batchPlan, NODE_REF, true);
+ final List<BatchStepJob> batchChain = salFlatBatchService.prepareBatchChain(batchPlan, NODE_REF, true);
Assert.assertEquals(2, batchChain.size());
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(2, rpcResult.getErrors().size());
+ Assert.assertEquals(4, rpcResult.getResult().getBatchFailure().size());
- Mockito.verify(salFlowsBatchService).addFlowsBatch(addFlowsBatchInputCpt.capture());
+ Mockito.verify(salFlowsBatchService, Mockito.times(2)).addFlowsBatch(addFlowsBatchInputCpt.capture());
Assert.assertEquals(2, addFlowsBatchInputCpt.getValue().getBatchAddFlows().size());
}
}
\ No newline at end of file