blob: 712adcbf359bdefd55c59fe5b9bf48f83853dbf4 [file] [log] [blame]
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.store.trivial.impl;
17
18import static org.junit.Assert.assertEquals;
19import static org.onosproject.net.DeviceId.deviceId;
20
21import java.util.ArrayList;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080022import java.util.Arrays;
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080023import java.util.List;
24
25import org.junit.After;
26import org.junit.Before;
27import org.junit.Test;
28import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010029import org.onlab.packet.MplsLabel;
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080030import org.onosproject.core.ApplicationId;
31import org.onosproject.core.DefaultApplicationId;
32import org.onosproject.core.GroupId;
33import org.onosproject.net.DeviceId;
34import org.onosproject.net.PortNumber;
35import org.onosproject.net.flow.DefaultTrafficTreatment;
36import org.onosproject.net.flow.TrafficTreatment;
37import org.onosproject.net.group.DefaultGroupBucket;
38import org.onosproject.net.group.DefaultGroupDescription;
39import org.onosproject.net.group.Group;
40import org.onosproject.net.group.GroupBucket;
41import org.onosproject.net.group.GroupBuckets;
42import org.onosproject.net.group.GroupDescription;
43import org.onosproject.net.group.GroupEvent;
44import org.onosproject.net.group.GroupKey;
sangho7ff01812015-02-09 16:21:53 -080045import org.onosproject.net.group.GroupOperation;
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080046import org.onosproject.net.group.GroupStore.UpdateType;
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080047import org.onosproject.net.group.GroupStoreDelegate;
48
49import com.google.common.collect.Iterables;
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080050
51/**
52 * Test of the simple DeviceStore implementation.
53 */
54public class SimpleGroupStoreTest {
55
56 private SimpleGroupStore simpleGroupStore;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080057 private final ApplicationId appId =
58 new DefaultApplicationId(2, "org.groupstore.test");
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080059
60 public static final DeviceId D1 = deviceId("of:1");
61
62 @Before
63 public void setUp() throws Exception {
64 simpleGroupStore = new SimpleGroupStore();
65 simpleGroupStore.activate();
66 }
67
68 @After
69 public void tearDown() throws Exception {
70 simpleGroupStore.deactivate();
71 }
72
73 public class TestGroupKey implements GroupKey {
74 private String groupId;
75
76 public TestGroupKey(String id) {
77 this.groupId = id;
78 }
79
80 public String id() {
81 return this.groupId;
82 }
83
84 @Override
85 public int hashCode() {
86 return groupId.hashCode();
87 }
88
89 @Override
90 public boolean equals(Object obj) {
91 if (obj instanceof TestGroupKey) {
92 return this.groupId.equals(((TestGroupKey) obj).id());
93 }
94 return false;
95 }
96 }
97
98 private class InternalGroupStoreDelegate
99 implements GroupStoreDelegate {
100 private GroupId createdGroupId = null;
101 private GroupKey createdGroupKey;
102 private GroupBuckets createdBuckets;
103 private GroupEvent.Type expectedEvent;
104
105 public InternalGroupStoreDelegate(GroupKey key,
106 GroupBuckets buckets,
107 GroupEvent.Type expectedEvent) {
108 this.createdBuckets = buckets;
109 this.createdGroupKey = key;
110 this.expectedEvent = expectedEvent;
111 }
112 @Override
113 public void notify(GroupEvent event) {
114 assertEquals(expectedEvent, event.type());
115 assertEquals(Group.Type.SELECT, event.subject().type());
116 assertEquals(D1, event.subject().deviceId());
117 assertEquals(createdGroupKey, event.subject().appCookie());
118 assertEquals(createdBuckets.buckets(), event.subject().buckets().buckets());
119 if (expectedEvent == GroupEvent.Type.GROUP_ADD_REQUESTED) {
120 createdGroupId = event.subject().id();
121 assertEquals(Group.GroupState.PENDING_ADD,
122 event.subject().state());
123 } else if (expectedEvent == GroupEvent.Type.GROUP_ADDED) {
124 createdGroupId = event.subject().id();
125 assertEquals(Group.GroupState.ADDED,
126 event.subject().state());
127 } else if (expectedEvent == GroupEvent.Type.GROUP_UPDATE_REQUESTED) {
128 assertEquals(Group.GroupState.PENDING_UPDATE,
129 event.subject().state());
130 } else if (expectedEvent == GroupEvent.Type.GROUP_REMOVE_REQUESTED) {
131 assertEquals(Group.GroupState.PENDING_DELETE,
132 event.subject().state());
133 } else if (expectedEvent == GroupEvent.Type.GROUP_REMOVED) {
134 createdGroupId = event.subject().id();
135 assertEquals(Group.GroupState.PENDING_DELETE,
136 event.subject().state());
sangho7ff01812015-02-09 16:21:53 -0800137 } else if (expectedEvent == GroupEvent.Type.GROUP_ADD_FAILED) {
138 createdGroupId = event.subject().id();
139 assertEquals(Group.GroupState.PENDING_ADD,
140 event.subject().state());
141 } else if (expectedEvent == GroupEvent.Type.GROUP_UPDATE_FAILED) {
142 createdGroupId = event.subject().id();
143 assertEquals(Group.GroupState.PENDING_UPDATE,
144 event.subject().state());
145 } else if (expectedEvent == GroupEvent.Type.GROUP_REMOVE_FAILED) {
146 createdGroupId = event.subject().id();
147 assertEquals(Group.GroupState.PENDING_DELETE,
148 event.subject().state());
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800149 }
150 }
151
152 public void verifyGroupId(GroupId id) {
153 assertEquals(createdGroupId, id);
154 }
155 }
156
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800157 /**
158 * Tests group store operations. The following operations are tested:
159 * a)Tests device group audit completion status change
160 * b)Tests storeGroup operation
161 * c)Tests getGroupCount operation
162 * d)Tests getGroup operation
163 * e)Tests getGroups operation
164 * f)Tests addOrUpdateGroupEntry operation from southbound
165 * g)Tests updateGroupDescription for ADD operation from northbound
166 * h)Tests updateGroupDescription for REMOVE operation from northbound
167 * i)Tests deleteGroupDescription operation from northbound
168 * j)Tests removeGroupEntry operation from southbound
169 */
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800170 @Test
171 public void testGroupStoreOperations() {
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800172 // Set the Device AUDIT completed in the store
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800173 simpleGroupStore.deviceInitialAuditCompleted(D1, true);
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800174
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800175 // Testing storeGroup operation
176 TestGroupKey newKey = new TestGroupKey("group1");
177 testStoreAndGetGroup(newKey);
178
179 // Testing addOrUpdateGroupEntry operation from southbound
180 TestGroupKey currKey = newKey;
181 testAddGroupEntryFromSB(currKey);
182
183 // Testing updateGroupDescription for ADD operation from northbound
184 newKey = new TestGroupKey("group1AddBuckets");
185 testAddBuckets(currKey, newKey);
186
187 // Testing updateGroupDescription for REMOVE operation from northbound
188 currKey = newKey;
189 newKey = new TestGroupKey("group1RemoveBuckets");
190 testRemoveBuckets(currKey, newKey);
191
192 // Testing addOrUpdateGroupEntry operation from southbound
193 currKey = newKey;
194 testUpdateGroupEntryFromSB(currKey);
195
196 // Testing deleteGroupDescription operation from northbound
197 testDeleteGroup(currKey);
198
199 // Testing removeGroupEntry operation from southbound
200 testRemoveGroupFromSB(currKey);
201 }
202
203 // Testing storeGroup operation
204 private void testStoreAndGetGroup(TestGroupKey key) {
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800205 PortNumber[] ports = {PortNumber.portNumber(31),
206 PortNumber.portNumber(32)};
207 List<PortNumber> outPorts = new ArrayList<PortNumber>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800208 outPorts.addAll(Arrays.asList(ports));
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800209
210 List<GroupBucket> buckets = new ArrayList<GroupBucket>();
211 for (PortNumber portNumber: outPorts) {
212 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
213 tBuilder.setOutput(portNumber)
214 .setEthDst(MacAddress.valueOf("00:00:00:00:00:02"))
215 .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01"))
216 .pushMpls()
Michele Santuari4b6019e2014-12-19 11:31:45 +0100217 .setMpls(MplsLabel.mplsLabel(106));
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800218 buckets.add(DefaultGroupBucket.createSelectGroupBucket(
219 tBuilder.build()));
220 }
221 GroupBuckets groupBuckets = new GroupBuckets(buckets);
222 GroupDescription groupDesc = new DefaultGroupDescription(
223 D1,
224 Group.Type.SELECT,
225 groupBuckets,
226 key,
227 appId);
228 InternalGroupStoreDelegate checkStoreGroupDelegate =
229 new InternalGroupStoreDelegate(key,
230 groupBuckets,
231 GroupEvent.Type.GROUP_ADD_REQUESTED);
232 simpleGroupStore.setDelegate(checkStoreGroupDelegate);
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800233 // Testing storeGroup operation
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800234 simpleGroupStore.storeGroupDescription(groupDesc);
235
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800236 // Testing getGroupCount operation
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800237 assertEquals(1, simpleGroupStore.getGroupCount(D1));
238
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800239 // Testing getGroup operation
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800240 Group createdGroup = simpleGroupStore.getGroup(D1, key);
241 checkStoreGroupDelegate.verifyGroupId(createdGroup.id());
242
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800243 // Testing getGroups operation
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800244 Iterable<Group> createdGroups = simpleGroupStore.getGroups(D1);
245 int groupCount = 0;
246 for (Group group:createdGroups) {
247 checkStoreGroupDelegate.verifyGroupId(group.id());
248 groupCount++;
249 }
250 assertEquals(1, groupCount);
251 simpleGroupStore.unsetDelegate(checkStoreGroupDelegate);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800252 }
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800253
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800254 // Testing addOrUpdateGroupEntry operation from southbound
255 private void testAddGroupEntryFromSB(TestGroupKey currKey) {
256 Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
257
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800258 InternalGroupStoreDelegate addGroupEntryDelegate =
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800259 new InternalGroupStoreDelegate(currKey,
260 existingGroup.buckets(),
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800261 GroupEvent.Type.GROUP_ADDED);
262 simpleGroupStore.setDelegate(addGroupEntryDelegate);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800263 simpleGroupStore.addOrUpdateGroupEntry(existingGroup);
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800264 simpleGroupStore.unsetDelegate(addGroupEntryDelegate);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800265 }
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800266
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800267 // Testing addOrUpdateGroupEntry operation from southbound
268 private void testUpdateGroupEntryFromSB(TestGroupKey currKey) {
269 Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
270
271 InternalGroupStoreDelegate updateGroupEntryDelegate =
272 new InternalGroupStoreDelegate(currKey,
273 existingGroup.buckets(),
274 GroupEvent.Type.GROUP_UPDATED);
275 simpleGroupStore.setDelegate(updateGroupEntryDelegate);
276 simpleGroupStore.addOrUpdateGroupEntry(existingGroup);
277 simpleGroupStore.unsetDelegate(updateGroupEntryDelegate);
278 }
279
280 // Testing updateGroupDescription for ADD operation from northbound
281 private void testAddBuckets(TestGroupKey currKey, TestGroupKey addKey) {
282 Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
283 List<GroupBucket> buckets = new ArrayList<GroupBucket>();
284 buckets.addAll(existingGroup.buckets().buckets());
285
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800286 PortNumber[] newNeighborPorts = {PortNumber.portNumber(41),
287 PortNumber.portNumber(42)};
288 List<PortNumber> newOutPorts = new ArrayList<PortNumber>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800289 newOutPorts.addAll(Arrays.asList(newNeighborPorts[0]));
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800290
291 List<GroupBucket> toAddBuckets = new ArrayList<GroupBucket>();
292 for (PortNumber portNumber: newOutPorts) {
293 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
294 tBuilder.setOutput(portNumber)
295 .setEthDst(MacAddress.valueOf("00:00:00:00:00:03"))
296 .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01"))
297 .pushMpls()
Michele Santuari4b6019e2014-12-19 11:31:45 +0100298 .setMpls(MplsLabel.mplsLabel(106));
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800299 toAddBuckets.add(DefaultGroupBucket.createSelectGroupBucket(
300 tBuilder.build()));
301 }
302 GroupBuckets toAddGroupBuckets = new GroupBuckets(toAddBuckets);
303 buckets.addAll(toAddBuckets);
304 GroupBuckets updatedGroupBuckets = new GroupBuckets(buckets);
305 InternalGroupStoreDelegate updateGroupDescDelegate =
306 new InternalGroupStoreDelegate(addKey,
307 updatedGroupBuckets,
308 GroupEvent.Type.GROUP_UPDATE_REQUESTED);
309 simpleGroupStore.setDelegate(updateGroupDescDelegate);
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800310 simpleGroupStore.updateGroupDescription(D1,
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800311 currKey,
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800312 UpdateType.ADD,
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800313 toAddGroupBuckets,
314 addKey);
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800315 simpleGroupStore.unsetDelegate(updateGroupDescDelegate);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800316 }
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800317
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800318 // Testing updateGroupDescription for REMOVE operation from northbound
319 private void testRemoveBuckets(TestGroupKey currKey, TestGroupKey removeKey) {
320 Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
321 List<GroupBucket> buckets = new ArrayList<GroupBucket>();
322 buckets.addAll(existingGroup.buckets().buckets());
323
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800324 List<GroupBucket> toRemoveBuckets = new ArrayList<GroupBucket>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800325
326 // There should be 4 buckets in the current group
327 toRemoveBuckets.add(buckets.remove(0));
328 toRemoveBuckets.add(buckets.remove(1));
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800329 GroupBuckets toRemoveGroupBuckets = new GroupBuckets(toRemoveBuckets);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800330
331 GroupBuckets remainingGroupBuckets = new GroupBuckets(buckets);
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800332 InternalGroupStoreDelegate removeGroupDescDelegate =
333 new InternalGroupStoreDelegate(removeKey,
334 remainingGroupBuckets,
335 GroupEvent.Type.GROUP_UPDATE_REQUESTED);
336 simpleGroupStore.setDelegate(removeGroupDescDelegate);
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800337 simpleGroupStore.updateGroupDescription(D1,
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800338 currKey,
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800339 UpdateType.REMOVE,
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800340 toRemoveGroupBuckets,
341 removeKey);
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800342 simpleGroupStore.unsetDelegate(removeGroupDescDelegate);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800343 }
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800344
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800345 // Testing deleteGroupDescription operation from northbound
346 private void testDeleteGroup(TestGroupKey currKey) {
347 Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800348 InternalGroupStoreDelegate deleteGroupDescDelegate =
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800349 new InternalGroupStoreDelegate(currKey,
350 existingGroup.buckets(),
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800351 GroupEvent.Type.GROUP_REMOVE_REQUESTED);
352 simpleGroupStore.setDelegate(deleteGroupDescDelegate);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800353 simpleGroupStore.deleteGroupDescription(D1, currKey);
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800354 simpleGroupStore.unsetDelegate(deleteGroupDescDelegate);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800355 }
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800356
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800357 // Testing removeGroupEntry operation from southbound
358 private void testRemoveGroupFromSB(TestGroupKey currKey) {
359 Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800360 InternalGroupStoreDelegate removeGroupEntryDelegate =
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800361 new InternalGroupStoreDelegate(currKey,
362 existingGroup.buckets(),
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800363 GroupEvent.Type.GROUP_REMOVED);
364 simpleGroupStore.setDelegate(removeGroupEntryDelegate);
365 simpleGroupStore.removeGroupEntry(existingGroup);
366
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800367 // Testing getGroup operation
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800368 existingGroup = simpleGroupStore.getGroup(D1, currKey);
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800369 assertEquals(null, existingGroup);
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800370 assertEquals(0, Iterables.size(simpleGroupStore.getGroups(D1)));
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800371 assertEquals(0, simpleGroupStore.getGroupCount(D1));
372
373 simpleGroupStore.unsetDelegate(removeGroupEntryDelegate);
sangho7ff01812015-02-09 16:21:53 -0800374 }
375
376 @Test
377 public void testGroupOperationFailure() {
378
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800379 simpleGroupStore.deviceInitialAuditCompleted(D1, true);
sangho7ff01812015-02-09 16:21:53 -0800380
381 ApplicationId appId =
382 new DefaultApplicationId(2, "org.groupstore.test");
383 TestGroupKey key = new TestGroupKey("group1");
384 PortNumber[] ports = {PortNumber.portNumber(31),
385 PortNumber.portNumber(32)};
386 List<PortNumber> outPorts = new ArrayList<PortNumber>();
387 outPorts.add(ports[0]);
388 outPorts.add(ports[1]);
389
390 List<GroupBucket> buckets = new ArrayList<GroupBucket>();
391 for (PortNumber portNumber: outPorts) {
392 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
393 tBuilder.setOutput(portNumber)
394 .setEthDst(MacAddress.valueOf("00:00:00:00:00:02"))
395 .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01"))
396 .pushMpls()
Michele Santuari4b6019e2014-12-19 11:31:45 +0100397 .setMpls(MplsLabel.mplsLabel(106));
sangho7ff01812015-02-09 16:21:53 -0800398 buckets.add(DefaultGroupBucket.createSelectGroupBucket(
399 tBuilder.build()));
400 }
401 GroupBuckets groupBuckets = new GroupBuckets(buckets);
402 GroupDescription groupDesc = new DefaultGroupDescription(
403 D1,
404 Group.Type.SELECT,
405 groupBuckets,
406 key,
407 appId);
408 InternalGroupStoreDelegate checkStoreGroupDelegate =
409 new InternalGroupStoreDelegate(key,
410 groupBuckets,
411 GroupEvent.Type.GROUP_ADD_REQUESTED);
412 simpleGroupStore.setDelegate(checkStoreGroupDelegate);
413 // Testing storeGroup operation
414 simpleGroupStore.storeGroupDescription(groupDesc);
415 simpleGroupStore.unsetDelegate(checkStoreGroupDelegate);
416
417 // Testing Group add operation failure
418 Group createdGroup = simpleGroupStore.getGroup(D1, key);
419 checkStoreGroupDelegate.verifyGroupId(createdGroup.id());
420
421 GroupOperation groupAddOp = GroupOperation.
422 createAddGroupOperation(createdGroup.id(),
423 createdGroup.type(),
424 createdGroup.buckets());
425 InternalGroupStoreDelegate checkGroupAddFailureDelegate =
426 new InternalGroupStoreDelegate(key,
427 groupBuckets,
428 GroupEvent.Type.GROUP_ADD_FAILED);
429 simpleGroupStore.setDelegate(checkGroupAddFailureDelegate);
430 simpleGroupStore.groupOperationFailed(D1, groupAddOp);
431
432
433 // Testing Group modify operation failure
434 simpleGroupStore.unsetDelegate(checkGroupAddFailureDelegate);
435 GroupOperation groupModOp = GroupOperation.
436 createModifyGroupOperation(createdGroup.id(),
437 createdGroup.type(),
438 createdGroup.buckets());
439 InternalGroupStoreDelegate checkGroupModFailureDelegate =
440 new InternalGroupStoreDelegate(key,
441 groupBuckets,
442 GroupEvent.Type.GROUP_UPDATE_FAILED);
443 simpleGroupStore.setDelegate(checkGroupModFailureDelegate);
444 simpleGroupStore.groupOperationFailed(D1, groupModOp);
445
446 // Testing Group modify operation failure
447 simpleGroupStore.unsetDelegate(checkGroupModFailureDelegate);
448 GroupOperation groupDelOp = GroupOperation.
449 createDeleteGroupOperation(createdGroup.id(),
450 createdGroup.type());
451 InternalGroupStoreDelegate checkGroupDelFailureDelegate =
452 new InternalGroupStoreDelegate(key,
453 groupBuckets,
454 GroupEvent.Type.GROUP_REMOVE_FAILED);
455 simpleGroupStore.setDelegate(checkGroupDelFailureDelegate);
456 simpleGroupStore.groupOperationFailed(D1, groupDelOp);
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800457 }
458}
459