Search in sources :

Example 1 with UpdateMeterInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput in project openflowplugin by opendaylight.

the class MeterForwarderTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    Mockito.when(salMeterService.updateMeter(updateMeterInputCpt.capture())).thenReturn(RpcResultBuilder.success(new UpdateMeterOutputBuilder().setTransactionId(txId).build()).buildFuture());
    Meter meterOriginal = new MeterBuilder(meter).build();
    Meter meterUpdate = new MeterBuilder(meter).setMeterName("another-test").build();
    final Future<RpcResult<UpdateMeterOutput>> updateResult = meterForwarder.update(meterPath, meterOriginal, meterUpdate, flowCapableNodePath);
    Mockito.verify(salMeterService).updateMeter(Matchers.<UpdateMeterInput>any());
    Assert.assertTrue(updateResult.isDone());
    final RpcResult<UpdateMeterOutput> meterResult = updateResult.get(2, TimeUnit.SECONDS);
    Assert.assertTrue(meterResult.isSuccessful());
    Assert.assertEquals(1, meterResult.getResult().getTransactionId().getValue().intValue());
    final UpdateMeterInput updateMeterInput = updateMeterInputCpt.getValue();
    Assert.assertEquals(meterPath, updateMeterInput.getMeterRef().getValue());
    Assert.assertEquals(nodePath, updateMeterInput.getNode().getValue());
    Assert.assertEquals("test-meter", updateMeterInput.getOriginalMeter().getMeterName());
    Assert.assertEquals("another-test", updateMeterInput.getUpdatedMeter().getMeterName());
}
Also used : MeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder) Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter) UpdateMeterOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) UpdateMeterOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutputBuilder) UpdateMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput) Test(org.junit.Test)

Example 2 with UpdateMeterInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput in project openflowplugin by opendaylight.

the class SalMeterServiceImplTest method updateMeter.

private void updateMeter() throws Exception {
    final UpdatedMeter dummyUpdatedMeter = new UpdatedMeterBuilder().setMeterId(new MeterId(DUMMY_METTER_ID)).build();
    final OriginalMeter dummyOriginalMeter = new OriginalMeterBuilder().setMeterId(new MeterId(DUMMY_METTER_ID)).build();
    final UpdateMeterInput updateMeterInput = new UpdateMeterInputBuilder().setUpdatedMeter(dummyUpdatedMeter).setOriginalMeter(dummyOriginalMeter).build();
    this.<AddMeterOutput>mockSuccessfulFuture();
    salMeterService.updateMeter(updateMeterInput);
    verify(mockedRequestContextStack).createRequestContext();
}
Also used : OriginalMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.OriginalMeter) UpdateMeterInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInputBuilder) AddMeterOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput) UpdatedMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeter) UpdatedMeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeterBuilder) OriginalMeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.OriginalMeterBuilder) UpdateMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId)

Example 3 with UpdateMeterInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput 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());
}
Also used : UpdateMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInput) InOrder(org.mockito.InOrder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) UpdateMetersBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInputBuilder) UpdateMeterOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutputBuilder) UpdateMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput) Test(org.junit.Test)

Example 4 with UpdateMeterInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput in project openflowplugin by opendaylight.

the class MeterListenerTest method updateMeterTest.

@Test
public void updateMeterTest() throws Exception {
    addFlowCapableNode(NODE_KEY);
    MeterKey meterKey = new MeterKey(new MeterId((long) 2000));
    InstanceIdentifier<Meter> meterII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class).child(Meter.class, meterKey);
    Meter meter = new MeterBuilder().setKey(meterKey).setMeterName("meter_one").setBarrier(false).build();
    WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, meterII, meter);
    assertCommit(writeTx.submit());
    SalMeterServiceMock salMeterService = (SalMeterServiceMock) forwardingRulesManager.getSalMeterService();
    List<AddMeterInput> addMeterCalls = salMeterService.getAddMeterCalls();
    assertEquals(1, addMeterCalls.size());
    assertEquals("DOM-0", addMeterCalls.get(0).getTransactionUri().getValue());
    meter = new MeterBuilder().setKey(meterKey).setMeterName("meter_two").setBarrier(true).build();
    writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, meterII, meter);
    assertCommit(writeTx.submit());
    salMeterService = (SalMeterServiceMock) forwardingRulesManager.getSalMeterService();
    List<UpdateMeterInput> updateMeterCalls = salMeterService.getUpdateMeterCalls();
    assertEquals(1, updateMeterCalls.size());
    assertEquals("DOM-1", updateMeterCalls.get(0).getTransactionUri().getValue());
    assertEquals(meterII, updateMeterCalls.get(0).getMeterRef().getValue());
}
Also used : MeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder) StaleMeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeterBuilder) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter) StaleMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeter) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) UpdateMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId) MeterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey) StaleMeterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeterKey) SalMeterServiceMock(test.mock.util.SalMeterServiceMock) AddMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput) FRMTest(test.mock.util.FRMTest) Test(org.junit.Test)

Example 5 with UpdateMeterInput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput 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());
}
Also used : UpdateMetersBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInput) InOrder(org.mockito.InOrder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) UpdateMetersBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInputBuilder) UpdateMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput) Test(org.junit.Test)

Aggregations

UpdateMeterInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput)6 Test (org.junit.Test)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 InOrder (org.mockito.InOrder)2 Meter (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter)2 MeterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder)2 UpdateMeterInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInputBuilder)2 UpdateMeterOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput)2 UpdateMeterOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutputBuilder)2 OriginalMeterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.OriginalMeterBuilder)2 UpdatedMeterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeterBuilder)2 MeterId (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId)2 UpdateMetersBatchInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInput)2 UpdateMetersBatchInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInputBuilder)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ArrayList (java.util.ArrayList)1 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)1 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)1 MeterKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey)1 StaleMeter (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeter)1