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());
}
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());
}
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();
}
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();
}
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();
}
Aggregations