use of org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInputBuilder in project openflowplugin by opendaylight.
the class SalMetersBatchServiceImplTest method testUpdateMetersBatch_success.
@Test
public void testUpdateMetersBatch_success() throws Exception {
Mockito.when(salMeterService.updateMeter(Mockito.<UpdateMeterInput>any())).thenReturn(RpcResultBuilder.success(new UpdateMeterOutputBuilder().build()).buildFuture());
final UpdateMetersBatchInput input = new UpdateMetersBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchUpdateMeters(Lists.newArrayList(createEmptyBatchUpdateMeter(42L), createEmptyBatchUpdateMeter(44L))).build();
final Future<RpcResult<UpdateMetersBatchOutput>> resultFuture = salMetersBatchService.updateMetersBatch(input);
Assert.assertTrue(resultFuture.isDone());
Assert.assertTrue(resultFuture.get().isSuccessful());
final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService);
inOrder.verify(salMeterService, Mockito.times(2)).updateMeter(updateMeterInputCpt.capture());
final List<UpdateMeterInput> allValues = updateMeterInputCpt.getAllValues();
Assert.assertEquals(2, allValues.size());
Assert.assertEquals(42, allValues.get(0).getOriginalMeter().getMeterId().getValue().longValue());
Assert.assertEquals(43, allValues.get(0).getUpdatedMeter().getMeterId().getValue().longValue());
Assert.assertEquals(44, allValues.get(1).getOriginalMeter().getMeterId().getValue().longValue());
Assert.assertEquals(45, allValues.get(1).getUpdatedMeter().getMeterId().getValue().longValue());
inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInputBuilder in project openflowplugin by opendaylight.
the class FlatBatchMeterAdapters method adaptFlatBatchUpdateMeter.
/**
* Adapt flat batch update meter.
* @param planStep batch step containing changes of the same type
* @param node pointer for RPC routing
* @return input suitable for {@link org.opendaylight.yang.gen.v1.urn
* .opendaylight.meters.service.rev160316.SalMetersBatchService#updateMetersBatch(UpdateMetersBatchInput)}
*/
public static UpdateMetersBatchInput adaptFlatBatchUpdateMeter(final BatchPlanStep planStep, final NodeRef node) {
final List<BatchUpdateMeters> batchMeters = new ArrayList<>();
for (FlatBatchUpdateMeter batchUpdateMeter : planStep.<FlatBatchUpdateMeter>getTaskBag()) {
final BatchUpdateMeters updateMeters = new BatchUpdateMetersBuilder(batchUpdateMeter).build();
batchMeters.add(updateMeters);
}
return new UpdateMetersBatchInputBuilder().setBarrierAfter(planStep.isBarrierAfter()).setNode(node).setBatchUpdateMeters(batchMeters).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInputBuilder in project openflowplugin by opendaylight.
the class SalMetersBatchServiceImplTest method testUpdateMetersBatch_failure.
@Test
public void testUpdateMetersBatch_failure() throws Exception {
Mockito.when(salMeterService.updateMeter(Mockito.<UpdateMeterInput>any())).thenReturn(RpcResultBuilder.<UpdateMeterOutput>failed().withError(RpcError.ErrorType.APPLICATION, "ur-groupUpdateError").buildFuture());
final UpdateMetersBatchInput input = new UpdateMetersBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchUpdateMeters(Lists.newArrayList(createEmptyBatchUpdateMeter(42L), createEmptyBatchUpdateMeter(44L))).build();
final Future<RpcResult<UpdateMetersBatchOutput>> resultFuture = salMetersBatchService.updateMetersBatch(input);
Assert.assertTrue(resultFuture.isDone());
Assert.assertFalse(resultFuture.get().isSuccessful());
Assert.assertEquals(2, resultFuture.get().getResult().getBatchFailedMetersOutput().size());
Assert.assertEquals(43L, resultFuture.get().getResult().getBatchFailedMetersOutput().get(0).getMeterId().getValue().longValue());
Assert.assertEquals(45L, resultFuture.get().getResult().getBatchFailedMetersOutput().get(1).getMeterId().getValue().longValue());
Assert.assertEquals(2, resultFuture.get().getErrors().size());
final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService);
inOrder.verify(salMeterService, Mockito.times(2)).updateMeter(updateMeterInputCpt.capture());
final List<UpdateMeterInput> allValues = updateMeterInputCpt.getAllValues();
Assert.assertEquals(2, allValues.size());
Assert.assertEquals(42, allValues.get(0).getOriginalMeter().getMeterId().getValue().longValue());
Assert.assertEquals(43, allValues.get(0).getUpdatedMeter().getMeterId().getValue().longValue());
Assert.assertEquals(44, allValues.get(1).getOriginalMeter().getMeterId().getValue().longValue());
Assert.assertEquals(45, allValues.get(1).getUpdatedMeter().getMeterId().getValue().longValue());
inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
Aggregations