* 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
*/
* 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;
package org.opendaylight.openflowplugin.applications.frsync.util;
import com.google.common.base.Splitter;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
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.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
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.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.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.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.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
Mockito.when(flowCapableService.sendBarrier(barrierInputCaptor.capture()))
.thenReturn(RpcResultBuilder.<SendBarrierOutput>success().buildFuture());
Mockito.when(flowCapableService.sendBarrier(barrierInputCaptor.capture()))
.thenReturn(RpcResultBuilder.<SendBarrierOutput>success().buildFuture());
- 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);
- 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);
- 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));
- 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));
final List<Group> pendingGroups = new ArrayList<>();
pendingGroups.add(createGroupWithPreconditions(1L, 2L));
- 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));
final List<Group> pendingGroups = new ArrayList<>();
pendingGroups.add(createGroupWithPreconditions(1L, 2L));
- 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));
final List<Group> pendingGroups = new ArrayList<>();
pendingGroups.add(createGroupWithPreconditions(3L, 4L));
- 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));
final List<Group> pendingGroups = new ArrayList<>();
pendingGroups.add(createGroupWithPreconditions(1L, 3L));
- 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));
final Group pendingGroup1 = createGroupWithPreconditions(3L, 2L, 4L);
Assert.assertFalse(ReconcileUtil.checkGroupPrecondition(installedGroups, pendingGroup1));
for (long groupIdPrecondition : requiredId) {
final GroupAction groupAction = new GroupActionBuilder()
.setGroupId(groupIdPrecondition)
for (long groupIdPrecondition : requiredId) {
final GroupAction groupAction = new GroupActionBuilder()
.setGroupId(groupIdPrecondition)
- 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) {
List<ItemSyncBox<String>> syncPlan = new ArrayList<>();
ItemSyncBox<String> syncBox1 = createSyncBox("a,b", "x,y,z");
syncPlan.add(syncBox1);
List<ItemSyncBox<String>> syncPlan = new ArrayList<>();
ItemSyncBox<String> syncBox1 = createSyncBox("a,b", "x,y,z");
syncPlan.add(syncBox1);