-/**
+/*
* Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowplugin.applications.frsync.util;
import com.google.common.base.Splitter;
+import com.google.common.collect.Maps;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
+import org.mockito.ArgumentMatchers;
import org.mockito.Captor;
-import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
/**
* Test for {@link ReconcileUtil}.
public class ReconcileUtilTest {
private static final NodeId NODE_ID = new NodeId("unit-node-id");
- private final InstanceIdentifier<Node> NODE_IDENT = InstanceIdentifier.create(Nodes.class)
+ private static final InstanceIdentifier<Node> NODE_IDENT = InstanceIdentifier.create(Nodes.class)
.child(Node.class, new NodeKey(NODE_ID));
private static final Splitter COMMA_SPLITTER = Splitter.on(",");
Futures.transformAsync(testRabbit, ReconcileUtil.chainBarrierFlush(NODE_IDENT, flowCapableService),
MoreExecutors.directExecutor());
Mockito.when(flowCapableService.sendBarrier(barrierInputCaptor.capture()))
- .thenReturn(RpcResultBuilder.<Void>success().buildFuture());
+ .thenReturn(RpcResultBuilder.<SendBarrierOutput>success().buildFuture());
- Mockito.verify(flowCapableService, Mockito.never()).sendBarrier(Matchers.<SendBarrierInput>any());
+ Mockito.verify(flowCapableService, Mockito.never()).sendBarrier(ArgumentMatchers.any());
Assert.assertFalse(vehicle.isDone());
testRabbit.set(RpcResultBuilder.<Void>success().build());
- Mockito.verify(flowCapableService).sendBarrier(Matchers.<SendBarrierInput>any());
+ Mockito.verify(flowCapableService).sendBarrier(ArgumentMatchers.any());
Assert.assertTrue(vehicle.isDone());
Assert.assertTrue(vehicle.get().isSuccessful());
}
/**
- * add one missing group
- *
- * @throws Exception
+ * add one missing group.
*/
@Test
- public void testResolveAndDivideGroupDiffs1() throws Exception {
- final Map<Long, Group> installedGroups = new HashMap<>();
- installedGroups.put(1L, createGroup(1L));
- installedGroups.put(2L, createGroup(2L));
- installedGroups.put(3L, createGroup(3L));
+ public void testResolveAndDivideGroupDiffs1() {
+ final Map<Uint32, Group> installedGroups = createGroups(1, 2, 3);
final List<Group> pendingGroups = new ArrayList<>();
pendingGroups.add(createGroup(2L));
Assert.assertEquals(1, plan.size());
Assert.assertEquals(1, plan.get(0).getItemsToPush().size());
- Assert.assertEquals(4L, plan.get(0).getItemsToPush().iterator().next().getKey().getGroupId().getValue().longValue());
+ Assert.assertEquals(4L, plan.get(0).getItemsToPush().iterator().next().key()
+ .getGroupId().getValue().longValue());
Assert.assertEquals(0, plan.get(0).getItemsToUpdate().size());
}
/**
- * add 3 groups with dependencies - 3 steps involved
- *
- * @throws Exception
+ * add 3 groups with dependencies - 3 steps involved.
*/
@Test
- public void testResolveAndDivideGroupDiffs2() throws Exception {
- final Map<Long, Group> installedGroups = new HashMap<>();
- installedGroups.put(1L, createGroup(1L));
+ public void testResolveAndDivideGroupDiffs2() {
+ final Map<Uint32, Group> installedGroups = createGroups(1);
final List<Group> pendingGroups = new ArrayList<>();
pendingGroups.add(createGroup(2L));
Assert.assertEquals(3, plan.size());
Assert.assertEquals(1, plan.get(0).getItemsToPush().size());
- Assert.assertEquals(2L, plan.get(0).getItemsToPush().iterator().next().getKey().getGroupId().getValue().longValue());
+ Assert.assertEquals(2L, plan.get(0).getItemsToPush().iterator().next().key()
+ .getGroupId().getValue().longValue());
Assert.assertEquals(0, plan.get(0).getItemsToUpdate().size());
Assert.assertEquals(1, plan.get(1).getItemsToPush().size());
- Assert.assertEquals(4L, plan.get(1).getItemsToPush().iterator().next().getKey().getGroupId().getValue().longValue());
+ Assert.assertEquals(4L, plan.get(1).getItemsToPush().iterator().next().key()
+ .getGroupId().getValue().longValue());
Assert.assertEquals(0, plan.get(1).getItemsToUpdate().size());
Assert.assertEquals(1, plan.get(2).getItemsToPush().size());
- Assert.assertEquals(3L, plan.get(2).getItemsToPush().iterator().next().getKey().getGroupId().getValue().longValue());
+ Assert.assertEquals(3L, plan.get(2).getItemsToPush().iterator().next().key()
+ .getGroupId().getValue().longValue());
Assert.assertEquals(0, plan.get(2).getItemsToUpdate().size());
}
/**
- * no actions taken - installed and pending groups are the same
- *
- * @throws Exception
+ * no actions taken - installed and pending groups are the same.
*/
@Test
- public void testResolveAndDivideGroupDiffs3() throws Exception {
- final Map<Long, Group> installedGroups = new HashMap<>();
- installedGroups.put(1L, createGroup(1L));
- installedGroups.put(2L, createGroupWithPreconditions(2L, 1L));
+ public void testResolveAndDivideGroupDiffs3() {
+ final Map<Uint32, Group> installedGroups = new HashMap<>();
+ installedGroups.put(Uint32.ONE, createGroup(1L));
+ installedGroups.put(Uint32.valueOf(2), createGroupWithPreconditions(2L, 1L));
final List<Group> pendingGroups = new ArrayList<>();
pendingGroups.add(createGroup(1L));
}
/**
- * update 1 group
- *
- * @throws Exception
+ * update 1 group.
*/
@Test
- public void testResolveAndDivideGroupDiffs4() throws Exception {
- final Map<Long, Group> installedGroups = new HashMap<>();
- installedGroups.put(1L, createGroup(1L));
- installedGroups.put(2L, createGroup(2L));
+ public void testResolveAndDivideGroupDiffs4() {
+ final Map<Uint32, Group> installedGroups = createGroups(1, 2);
final List<Group> pendingGroups = new ArrayList<>();
pendingGroups.add(createGroupWithPreconditions(1L, 2L));
Assert.assertEquals(1, plan.size());
Assert.assertEquals(0, plan.get(0).getItemsToPush().size());
Assert.assertEquals(1, plan.get(0).getItemsToUpdate().size());
- final ItemSyncBox.ItemUpdateTuple<Group> firstItemUpdateTuple = plan.get(0).getItemsToUpdate().iterator().next();
+ final ItemSyncBox.ItemUpdateTuple<Group> firstItemUpdateTuple =
+ plan.get(0).getItemsToUpdate().iterator().next();
Assert.assertEquals(1L, firstItemUpdateTuple.getOriginal().getGroupId().getValue().longValue());
Assert.assertEquals(1L, firstItemUpdateTuple.getUpdated().getGroupId().getValue().longValue());
}
/**
- * no action taken - update 1 group will be ignored
- *
- * @throws Exception
+ * no action taken - update 1 group will be ignored.
*/
@Test
- public void testResolveAndDivideGroupDiffs5() throws Exception {
- final Map<Long, Group> installedGroups = new HashMap<>();
- installedGroups.put(1L, createGroup(1L));
- installedGroups.put(2L, createGroup(2L));
+ public void testResolveAndDivideGroupDiffs5() {
+ final Map<Uint32, Group> installedGroups = createGroups(1, 2);
final List<Group> pendingGroups = new ArrayList<>();
pendingGroups.add(createGroupWithPreconditions(1L, 2L));
}
/**
- * should add 1 group but preconditions are not met
- *
- * @throws Exception
+ * should add 1 group but preconditions are not met.
*/
@Test
- public void testResolveAndDivideGroupDiffs_negative1() throws Exception {
- final Map<Long, Group> installedGroups = new HashMap<>();
- installedGroups.put(1L, createGroup(1L));
- installedGroups.put(2L, createGroup(2L));
+ public void testResolveAndDivideGroupDiffs_negative1() {
+ final Map<Uint32, Group> installedGroups = createGroups(1, 2);
final List<Group> pendingGroups = new ArrayList<>();
pendingGroups.add(createGroupWithPreconditions(3L, 4L));
}
/**
- * should update 1 group but preconditions are not met
- *
- * @throws Exception
+ * should update 1 group but preconditions are not met.
*/
@Test
- public void testResolveAndDivideGroupDiffs_negative2() throws Exception {
- final Map<Long, Group> installedGroups = new HashMap<>();
- installedGroups.put(1L, createGroup(1L));
- installedGroups.put(2L, createGroup(2L));
+ public void testResolveAndDivideGroupDiffs_negative2() {
+ final Map<Uint32, Group> installedGroups = createGroups(1, 2);
final List<Group> pendingGroups = new ArrayList<>();
pendingGroups.add(createGroupWithPreconditions(1L, 3L));
}
@Test
- public void testCheckGroupPrecondition() throws Exception {
- final Set<Long> installedGroups = new HashSet<>(Arrays.asList(new Long[]{1L, 2L}));
+ public void testCheckGroupPrecondition() {
+ final Set<Uint32> installedGroups = new HashSet<>(Arrays.asList(Uint32.ONE, Uint32.valueOf(2)));
final Group pendingGroup1 = createGroupWithPreconditions(3L, 2L, 4L);
Assert.assertFalse(ReconcileUtil.checkGroupPrecondition(installedGroups, pendingGroup1));
Assert.assertTrue(ReconcileUtil.checkGroupPrecondition(installedGroups, pendingGroup3));
}
- private Group createGroupWithPreconditions(final long groupIdValue, final long... requiredId) {
+ private static Group createGroupWithPreconditions(final long groupIdValue, final long... requiredId) {
final List<Action> actionBag = new ArrayList<>();
+ int key = 0;
for (long groupIdPrecondition : requiredId) {
final GroupAction groupAction = new GroupActionBuilder()
.setGroupId(groupIdPrecondition)
.build();
final Action action = new ActionBuilder()
.setAction(groupActionCase)
+ .withKey(new ActionKey(key++))
.build();
actionBag.add(action);
}
.build();
}
- private Group createGroup(final long groupIdValue) {
+ private static Map<Uint32, Group> createGroups(long... groupIds) {
+ final Map<Uint32, Group> ret = Maps.newHashMapWithExpectedSize(groupIds.length);
+ for (long groupId : groupIds) {
+ ret.put(Uint32.valueOf(groupId), createGroup(groupId));
+ }
+ return ret;
+ }
+
+ private static Group createGroup(final long groupIdValue) {
final Buckets buckets = new BucketsBuilder()
- .setBucket(Collections.<Bucket>emptyList())
+ .setBucket(Collections.emptyList())
.build();
return new GroupBuilder()
.setGroupId(new GroupId(groupIdValue))
}
/**
- * covers {@link ReconcileUtil#countTotalUpdated(Iterable)} too
- *
- * @throws Exception
+ * covers {@link ReconcileUtil#countTotalUpdated(Iterable)} too.
*/
@Test
- public void testCountTotalAdds() throws Exception {
+ public void testCountTotalAdds() {
List<ItemSyncBox<String>> syncPlan = new ArrayList<>();
ItemSyncBox<String> syncBox1 = createSyncBox("a,b", "x,y,z");
syncPlan.add(syncBox1);
}
return syncBox1;
}
-}
\ No newline at end of file
+}