Search in sources :

Example 76 with RpcResult

use of org.opendaylight.yangtools.yang.common.RpcResult in project openflowplugin by opendaylight.

the class MeterForwarderTest method testAdd.

@Test
public void testAdd() throws Exception {
    Mockito.when(salMeterService.addMeter(addMeterInputCpt.capture())).thenReturn(RpcResultBuilder.success(new AddMeterOutputBuilder().setTransactionId(txId).build()).buildFuture());
    final Future<RpcResult<AddMeterOutput>> addResult = meterForwarder.add(meterPath, meter, flowCapableNodePath);
    Mockito.verify(salMeterService).addMeter(Matchers.<AddMeterInput>any());
    Assert.assertTrue(addResult.isDone());
    final RpcResult<AddMeterOutput> meterResult = addResult.get(2, TimeUnit.SECONDS);
    Assert.assertTrue(meterResult.isSuccessful());
    Assert.assertEquals(1, meterResult.getResult().getTransactionId().getValue().intValue());
    final AddMeterInput addMeterInput = addMeterInputCpt.getValue();
    Assert.assertEquals(meterPath, addMeterInput.getMeterRef().getValue());
    Assert.assertEquals(nodePath, addMeterInput.getNode().getValue());
    Assert.assertEquals("test-meter", addMeterInput.getMeterName());
}
Also used : AddMeterOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput) AddMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddMeterOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutputBuilder) Test(org.junit.Test)

Example 77 with RpcResult

use of org.opendaylight.yangtools.yang.common.RpcResult in project openflowplugin by opendaylight.

the class SyncPlanPushStrategyFlatBatchImplTest method testExecuteSyncStrategy.

@Test
public void testExecuteSyncStrategy() throws Exception {
    final SynchronizationDiffInput diffInput = new SynchronizationDiffInput(NODE_IDENT, groupsToAddOrUpdate, metersToAddOrUpdate, flowsToAddOrUpdate, flowsToRemove, metersToRemove, groupsToRemove);
    Mockito.when(flatBatchService.processFlatBatch(Matchers.<ProcessFlatBatchInput>any())).thenReturn(RpcResultBuilder.success(new ProcessFlatBatchOutputBuilder().build()).buildFuture());
    final SyncCrudCounters counters = new SyncCrudCounters();
    final ListenableFuture<RpcResult<Void>> rpcResult = syncPlanPushStrategy.executeSyncStrategy(RpcResultBuilder.<Void>success().buildFuture(), diffInput, counters);
    Mockito.verify(flatBatchService).processFlatBatch(processFlatBatchInputCpt.capture());
    final ProcessFlatBatchInput processFlatBatchInput = processFlatBatchInputCpt.getValue();
    Assert.assertFalse(processFlatBatchInput.isExitOnFirstError());
    Assert.assertEquals(13, processFlatBatchInput.getBatch().size());
    Assert.assertTrue(rpcResult.isDone());
    Assert.assertTrue(rpcResult.get().isSuccessful());
    Assert.assertEquals(6, counters.getFlowCrudCounts().getAdded());
    Assert.assertEquals(3, counters.getFlowCrudCounts().getUpdated());
    Assert.assertEquals(6, counters.getFlowCrudCounts().getRemoved());
    Assert.assertEquals(6, counters.getGroupCrudCounts().getAdded());
    Assert.assertEquals(3, counters.getGroupCrudCounts().getUpdated());
    Assert.assertEquals(6, counters.getGroupCrudCounts().getRemoved());
    Assert.assertEquals(3, counters.getMeterCrudCounts().getAdded());
    Assert.assertEquals(3, counters.getMeterCrudCounts().getUpdated());
    Assert.assertEquals(3, counters.getMeterCrudCounts().getRemoved());
}
Also used : ProcessFlatBatchOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutputBuilder) SyncCrudCounters(org.opendaylight.openflowplugin.applications.frsync.util.SyncCrudCounters) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ProcessFlatBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInput) Test(org.junit.Test)

Example 78 with RpcResult

use of org.opendaylight.yangtools.yang.common.RpcResult in project openflowplugin by opendaylight.

the class SyncPlanPushStrategyIncrementalImplTest method testRemoveRedundantMeters.

@Test
public void testRemoveRedundantMeters() throws Exception {
    Mockito.when(meterCommitter.remove(Matchers.<InstanceIdentifier<Meter>>any(), meterCaptor.capture(), Matchers.same(NODE_IDENT))).thenReturn(RpcResultBuilder.success(new RemoveMeterOutputBuilder().build()).buildFuture());
    final ItemSyncBox<Meter> meterSyncBox = new ItemSyncBox<>();
    meterSyncBox.getItemsToPush().add(DSInputFactory.createMeter(2L));
    meterSyncBox.getItemsToPush().add(DSInputFactory.createMeter(4L));
    meterSyncBox.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(DSInputFactory.createMeter(1L), DSInputFactory.createMeterWithBody(1L)));
    final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.removeRedundantMeters(NODE_ID, NODE_IDENT, meterSyncBox, counters);
    Assert.assertTrue(result.isDone());
    Assert.assertTrue(result.get().isSuccessful());
    final List<Meter> metercaptorAllValues = meterCaptor.getAllValues();
    Assert.assertEquals(2, metercaptorAllValues.size());
    Assert.assertEquals(2L, metercaptorAllValues.get(0).getMeterId().getValue().longValue());
    Assert.assertEquals(4L, metercaptorAllValues.get(1).getMeterId().getValue().longValue());
    final InOrder inOrderMeter = Mockito.inOrder(flowCapableTxService, meterCommitter);
    inOrderMeter.verify(meterCommitter, Mockito.times(2)).remove(Matchers.<InstanceIdentifier<Meter>>any(), Matchers.<Meter>any(), Matchers.eq(NODE_IDENT));
    // TODO: uncomment when enabled in impl
    // inOrderMeter.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());
    inOrderMeter.verifyNoMoreInteractions();
}
Also used : RemoveMeterOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutputBuilder) InOrder(org.mockito.InOrder) ItemSyncBox(org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox) Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Test(org.junit.Test)

Example 79 with RpcResult

use of org.opendaylight.yangtools.yang.common.RpcResult in project openflowplugin by opendaylight.

the class SyncPlanPushStrategyIncrementalImplTest method testAddMissingFlows_withUpdate.

@Test
public void testAddMissingFlows_withUpdate() throws Exception {
    Mockito.when(flowCommitter.add(Matchers.<InstanceIdentifier<Flow>>any(), flowCaptor.capture(), Matchers.same(NODE_IDENT))).thenReturn(RpcResultBuilder.success(new AddFlowOutputBuilder().build()).buildFuture());
    Mockito.when(flowCommitter.update(Matchers.<InstanceIdentifier<Flow>>any(), flowUpdateCaptor.capture(), flowUpdateCaptor.capture(), Matchers.same(NODE_IDENT))).thenReturn(RpcResultBuilder.success(new UpdateFlowOutputBuilder().build()).buildFuture());
    final ItemSyncBox<Flow> flowBox = new ItemSyncBox<>();
    flowBox.getItemsToPush().add(DSInputFactory.createFlow("f3", 3));
    flowBox.getItemsToPush().add(DSInputFactory.createFlow("f4", 4));
    flowBox.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(DSInputFactory.createFlow("f1", 1), DSInputFactory.createFlowWithInstruction("f1", 1)));
    final Map<TableKey, ItemSyncBox<Flow>> flowBoxMap = new LinkedHashMap<>();
    flowBoxMap.put(new TableKey((short) 0), flowBox);
    // TODO: replace null
    final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.addMissingFlows(NODE_ID, NODE_IDENT, flowBoxMap, counters);
    Assert.assertTrue(result.isDone());
    Assert.assertTrue(result.get().isSuccessful());
    final List<Flow> flowCaptorAllValues = flowCaptor.getAllValues();
    Assert.assertEquals(2, flowCaptorAllValues.size());
    Assert.assertEquals("f3", flowCaptorAllValues.get(0).getId().getValue());
    Assert.assertEquals("f4", flowCaptorAllValues.get(1).getId().getValue());
    final List<Flow> flowUpdateCaptorAllValues = flowUpdateCaptor.getAllValues();
    Assert.assertEquals(2, flowUpdateCaptorAllValues.size());
    Assert.assertEquals("f1", flowUpdateCaptorAllValues.get(0).getId().getValue());
    Assert.assertEquals("f1", flowUpdateCaptorAllValues.get(1).getId().getValue());
    final InOrder inOrderFlow = Mockito.inOrder(flowCapableTxService, flowCommitter);
    // add f3, f4
    inOrderFlow.verify(flowCommitter, Mockito.times(2)).add(Matchers.<InstanceIdentifier<Flow>>any(), Matchers.<Flow>any(), Matchers.eq(NODE_IDENT));
    // update f1
    inOrderFlow.verify(flowCommitter).update(Matchers.<InstanceIdentifier<Flow>>any(), Matchers.<Flow>any(), Matchers.<Flow>any(), Matchers.eq(NODE_IDENT));
    // TODO: uncomment when enabled in impl
    // inOrderFlow.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());
    inOrderFlow.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) ItemSyncBox(org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) AddFlowOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) LinkedHashMap(java.util.LinkedHashMap) UpdateFlowOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder) Test(org.junit.Test)

Example 80 with RpcResult

use of org.opendaylight.yangtools.yang.common.RpcResult in project openflowplugin by opendaylight.

the class SyncPlanPushStrategyIncrementalImplTest method testAddMissingGroups.

@Test
public void testAddMissingGroups() throws Exception {
    Mockito.when(groupCommitter.add(Matchers.<InstanceIdentifier<Group>>any(), groupCaptor.capture(), Matchers.same(NODE_IDENT))).thenReturn(RpcResultBuilder.success(new AddGroupOutputBuilder().build()).buildFuture());
    ItemSyncBox<Group> groupBox1 = new ItemSyncBox<>();
    groupBox1.getItemsToPush().add(DSInputFactory.createGroup(2L));
    ItemSyncBox<Group> groupBox2 = new ItemSyncBox<>();
    groupBox2.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(3L, 2L));
    groupBox2.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(4L, 2L));
    ItemSyncBox<Group> groupBox3 = new ItemSyncBox<>();
    groupBox3.getItemsToPush().add(DSInputFactory.createGroupWithPreconditions(5L, 3L, 4L));
    final List<ItemSyncBox<Group>> groupBoxLot = Lists.newArrayList(groupBox1, groupBox2, groupBox3);
    final ListenableFuture<RpcResult<Void>> result = syncPlanPushStrategy.addMissingGroups(NODE_ID, NODE_IDENT, groupBoxLot, counters);
    Assert.assertTrue(result.isDone());
    Assert.assertTrue(result.get().isSuccessful());
    final List<Group> groupCaptorAllValues = groupCaptor.getAllValues();
    Assert.assertEquals(4, groupCaptorAllValues.size());
    Assert.assertEquals(2L, groupCaptorAllValues.get(0).getGroupId().getValue().longValue());
    Assert.assertEquals(3L, groupCaptorAllValues.get(1).getGroupId().getValue().longValue());
    Assert.assertEquals(4L, groupCaptorAllValues.get(2).getGroupId().getValue().longValue());
    Assert.assertEquals(5L, groupCaptorAllValues.get(3).getGroupId().getValue().longValue());
    final InOrder inOrderGroups = Mockito.inOrder(flowCapableTxService, groupCommitter);
    // add 2
    inOrderGroups.verify(groupCommitter).add(Matchers.<InstanceIdentifier<Group>>any(), Matchers.<Group>any(), Matchers.eq(NODE_IDENT));
    inOrderGroups.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());
    // add 3, 4
    inOrderGroups.verify(groupCommitter, Mockito.times(2)).add(Matchers.<InstanceIdentifier<Group>>any(), Matchers.<Group>any(), Matchers.eq(NODE_IDENT));
    inOrderGroups.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());
    // add 5
    inOrderGroups.verify(groupCommitter).add(Matchers.<InstanceIdentifier<Group>>any(), Matchers.<Group>any(), Matchers.eq(NODE_IDENT));
    inOrderGroups.verify(flowCapableTxService).sendBarrier(Matchers.<SendBarrierInput>any());
    inOrderGroups.verifyNoMoreInteractions();
}
Also used : Group(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group) InOrder(org.mockito.InOrder) ItemSyncBox(org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddGroupOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder) Test(org.junit.Test)

Aggregations

RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)360 Test (org.junit.Test)120 ExecutionException (java.util.concurrent.ExecutionException)118 ArrayList (java.util.ArrayList)61 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)37 InOrder (org.mockito.InOrder)30 List (java.util.List)29 BigInteger (java.math.BigInteger)26 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)25 FutureCallback (com.google.common.util.concurrent.FutureCallback)24 AllocateIdInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput)24 AllocateIdOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput)24 RpcError (org.opendaylight.yangtools.yang.common.RpcError)24 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)23 AllocateIdInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder)23 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)22 Future (java.util.concurrent.Future)21 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)21 Logger (org.slf4j.Logger)21 LoggerFactory (org.slf4j.LoggerFactory)21