blob: fd9b484277ce49ffac1821c1b972d4c54c3026ce [file] [log] [blame]
Ray Milkeyb3c5ce22015-08-10 09:07:36 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Ray Milkeyb3c5ce22015-08-10 09:07:36 -07003 *
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.group.impl;
17
Sivachidambaram Subramanian9f816de2017-06-13 07:16:54 +053018import com.google.common.collect.ImmutableList;
19import com.google.common.collect.Lists;
20import com.google.common.testing.EqualsTester;
Ray Milkeyb3c5ce22015-08-10 09:07:36 -070021import org.junit.After;
22import org.junit.Before;
23import org.junit.Test;
24import org.onlab.junit.TestUtils;
alshabibb0285992016-03-28 23:30:37 -070025import org.onosproject.cfg.ComponentConfigAdapter;
Charles Chanf4838a72015-12-07 18:13:45 -080026import org.onosproject.cluster.NodeId;
Ray Milkeyb3c5ce22015-08-10 09:07:36 -070027import org.onosproject.core.GroupId;
28import org.onosproject.mastership.MastershipServiceAdapter;
29import org.onosproject.net.DeviceId;
30import org.onosproject.net.MastershipRole;
31import org.onosproject.net.PortNumber;
32import org.onosproject.net.flow.DefaultTrafficTreatment;
33import org.onosproject.net.flow.TrafficTreatment;
34import org.onosproject.net.group.DefaultGroup;
35import org.onosproject.net.group.DefaultGroupBucket;
36import org.onosproject.net.group.DefaultGroupDescription;
37import org.onosproject.net.group.DefaultGroupKey;
38import org.onosproject.net.group.Group;
39import org.onosproject.net.group.GroupBucket;
40import org.onosproject.net.group.GroupBuckets;
41import org.onosproject.net.group.GroupDescription;
42import org.onosproject.net.group.GroupEvent;
43import org.onosproject.net.group.GroupKey;
44import org.onosproject.net.group.GroupOperation;
45import org.onosproject.net.group.GroupStore;
46import org.onosproject.net.group.GroupStoreDelegate;
47import org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter;
Madan Jampani0b847532016-03-03 13:44:15 -080048import org.onosproject.store.service.ConsistentMap;
Ray Milkeyb3c5ce22015-08-10 09:07:36 -070049import org.onosproject.store.service.TestStorageService;
50
Sivachidambaram Subramanian9f816de2017-06-13 07:16:54 +053051import java.util.ArrayList;
52import java.util.LinkedList;
53import java.util.List;
Ray Milkeyb3c5ce22015-08-10 09:07:36 -070054
55import static org.hamcrest.MatcherAssert.assertThat;
56import static org.hamcrest.Matchers.hasSize;
57import static org.hamcrest.Matchers.instanceOf;
58import static org.hamcrest.Matchers.is;
59import static org.hamcrest.Matchers.notNullValue;
60import static org.hamcrest.Matchers.nullValue;
Victor Silvadf1eeae2016-08-12 15:28:57 -030061import static org.junit.Assert.assertEquals;
Ray Milkeyb3c5ce22015-08-10 09:07:36 -070062import static org.onosproject.net.NetTestTools.APP_ID;
63import static org.onosproject.net.NetTestTools.did;
Sivachidambaram Subramanian9f816de2017-06-13 07:16:54 +053064import static org.onosproject.net.group.GroupDescription.Type.ALL;
65import static org.onosproject.net.group.GroupDescription.Type.INDIRECT;
66import static org.onosproject.net.group.GroupDescription.Type.SELECT;
67import static org.onosproject.net.group.GroupStore.UpdateType.ADD;
68import static org.onosproject.net.group.GroupStore.UpdateType.SET;
Ray Milkeyb3c5ce22015-08-10 09:07:36 -070069/**
70 * Distributed group store test.
71 */
72public class DistributedGroupStoreTest {
73
74 DeviceId deviceId1 = did("dev1");
75 DeviceId deviceId2 = did("dev2");
Yi Tsengfa394de2017-02-01 11:26:40 -080076 GroupId groupId1 = new GroupId(1);
77 GroupId groupId2 = new GroupId(2);
78 GroupId groupId3 = new GroupId(3);
Ray Milkeyb3c5ce22015-08-10 09:07:36 -070079 GroupKey groupKey1 = new DefaultGroupKey("abc".getBytes());
80 GroupKey groupKey2 = new DefaultGroupKey("def".getBytes());
Charles Chan0c7c43b2016-01-14 17:39:20 -080081 GroupKey groupKey3 = new DefaultGroupKey("ghi".getBytes());
Ray Milkeyb3c5ce22015-08-10 09:07:36 -070082
83 TrafficTreatment treatment =
84 DefaultTrafficTreatment.emptyTreatment();
85 GroupBucket selectGroupBucket =
86 DefaultGroupBucket.createSelectGroupBucket(treatment);
87 GroupBucket failoverGroupBucket =
88 DefaultGroupBucket.createFailoverGroupBucket(treatment,
89 PortNumber.IN_PORT, groupId1);
90
91 GroupBuckets buckets = new GroupBuckets(ImmutableList.of(selectGroupBucket));
92 GroupDescription groupDescription1 = new DefaultGroupDescription(
93 deviceId1,
Jayasree Ghosh2d459852016-07-02 19:06:52 +053094 ALL,
Ray Milkeyb3c5ce22015-08-10 09:07:36 -070095 buckets,
96 groupKey1,
97 groupId1.id(),
98 APP_ID);
99 GroupDescription groupDescription2 = new DefaultGroupDescription(
100 deviceId2,
Jayasree Ghosh2d459852016-07-02 19:06:52 +0530101 INDIRECT,
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700102 buckets,
103 groupKey2,
104 groupId2.id(),
105 APP_ID);
Charles Chan0c7c43b2016-01-14 17:39:20 -0800106 GroupDescription groupDescription3 = new DefaultGroupDescription(
107 deviceId2,
Jayasree Ghosh2d459852016-07-02 19:06:52 +0530108 INDIRECT,
Charles Chan0c7c43b2016-01-14 17:39:20 -0800109 buckets,
110 groupKey3,
111 groupId3.id(),
112 APP_ID);
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700113
114 DistributedGroupStore groupStoreImpl;
115 GroupStore groupStore;
Madan Jampani0b847532016-03-03 13:44:15 -0800116 ConsistentMap auditPendingReqQueue;
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700117
118 static class MasterOfAll extends MastershipServiceAdapter {
119 @Override
120 public MastershipRole getLocalRole(DeviceId deviceId) {
121 return MastershipRole.MASTER;
122 }
Charles Chanf4838a72015-12-07 18:13:45 -0800123
124 @Override
125 public NodeId getMasterFor(DeviceId deviceId) {
126 return new NodeId("foo");
127 }
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700128 }
129
Sivachidambaram Subramanian9f816de2017-06-13 07:16:54 +0530130 static class MasterNull extends MastershipServiceAdapter {
131 @Override
132 public MastershipRole getLocalRole(DeviceId deviceId) {
133 return null;
134 }
135
136 @Override
137 public NodeId getMasterFor(DeviceId deviceId) {
138 return null;
139 }
140 }
141
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700142 @Before
143 public void setUp() throws Exception {
144 groupStoreImpl = new DistributedGroupStore();
145 groupStoreImpl.storageService = new TestStorageService();
146 groupStoreImpl.clusterCommunicator = new ClusterCommunicationServiceAdapter();
147 groupStoreImpl.mastershipService = new MasterOfAll();
alshabibb0285992016-03-28 23:30:37 -0700148 groupStoreImpl.cfgService = new ComponentConfigAdapter();
sisubram4beea652017-08-09 10:38:14 +0000149 groupStoreImpl.activate(null);
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700150 groupStore = groupStoreImpl;
151 auditPendingReqQueue =
152 TestUtils.getField(groupStoreImpl, "auditPendingReqQueue");
153 }
154
155 @After
156 public void tearDown() throws Exception {
157 groupStoreImpl.deactivate();
158 }
159
160 /**
161 * Tests the initial state of the store.
162 */
163 @Test
164 public void testEmptyStore() {
165 assertThat(groupStore.getGroupCount(deviceId1), is(0));
166 assertThat(groupStore.getGroup(deviceId1, groupId1), nullValue());
167 assertThat(groupStore.getGroup(deviceId1, groupKey1), nullValue());
168 }
169
170 /**
171 * Tests adding a pending group.
172 */
173 @Test
174 public void testAddPendingGroup() throws Exception {
175 // Make sure the pending list starts out empty
176 assertThat(auditPendingReqQueue.size(), is(0));
177
178 // Add a new pending group. Make sure that the store remains empty
179 groupStore.storeGroupDescription(groupDescription1);
180 assertThat(groupStore.getGroupCount(deviceId1), is(0));
181 assertThat(groupStore.getGroup(deviceId1, groupId1), nullValue());
182 assertThat(groupStore.getGroup(deviceId1, groupKey1), nullValue());
183
184 // Make sure the group is pending
185 assertThat(auditPendingReqQueue.size(), is(1));
186
187 groupStore.deviceInitialAuditCompleted(deviceId1, true);
188
189 // Make sure the group isn't pending anymore
190 assertThat(auditPendingReqQueue.size(), is(0));
191 }
192
193
194 /**
195 * Tests adding and removing a group.
196 */
197 @Test
198 public void testAddRemoveGroup() throws Exception {
199 groupStore.deviceInitialAuditCompleted(deviceId1, true);
200 assertThat(groupStore.deviceInitialAuditStatus(deviceId1), is(true));
201
202 // Make sure the pending list starts out empty
203 assertThat(auditPendingReqQueue.size(), is(0));
204
205 groupStore.storeGroupDescription(groupDescription1);
206 assertThat(groupStore.getGroupCount(deviceId1), is(1));
207 assertThat(groupStore.getGroup(deviceId1, groupId1), notNullValue());
208 assertThat(groupStore.getGroup(deviceId1, groupKey1), notNullValue());
209
210 // Make sure that nothing is pending
211 assertThat(auditPendingReqQueue.size(), is(0));
212
213 Group groupById = groupStore.getGroup(deviceId1, groupId1);
214 Group groupByKey = groupStore.getGroup(deviceId1, groupKey1);
215 assertThat(groupById, notNullValue());
216 assertThat(groupByKey, notNullValue());
217 assertThat(groupById, is(groupByKey));
218 assertThat(groupById.deviceId(), is(did("dev1")));
219
220 groupStore.removeGroupEntry(groupById);
221
222 assertThat(groupStore.getGroupCount(deviceId1), is(0));
223 assertThat(groupStore.getGroup(deviceId1, groupId1), nullValue());
224 assertThat(groupStore.getGroup(deviceId1, groupKey1), nullValue());
225
226 // Make sure that nothing is pending
227 assertThat(auditPendingReqQueue.size(), is(0));
228 }
229
230 /**
Charles Chan0c7c43b2016-01-14 17:39:20 -0800231 * Tests removing all groups on the given device.
232 */
233 @Test
234 public void testRemoveGroupOnDevice() throws Exception {
235 groupStore.deviceInitialAuditCompleted(deviceId1, true);
236 assertThat(groupStore.deviceInitialAuditStatus(deviceId1), is(true));
237 groupStore.deviceInitialAuditCompleted(deviceId2, true);
238 assertThat(groupStore.deviceInitialAuditStatus(deviceId2), is(true));
239
240 // Make sure the pending list starts out empty
241 assertThat(auditPendingReqQueue.size(), is(0));
242
243 groupStore.storeGroupDescription(groupDescription1);
244 groupStore.storeGroupDescription(groupDescription2);
245 groupStore.storeGroupDescription(groupDescription3);
246 assertThat(groupStore.getGroupCount(deviceId1), is(1));
247 assertThat(groupStore.getGroupCount(deviceId2), is(2));
248
249 groupStore.purgeGroupEntry(deviceId2);
250 assertThat(groupStore.getGroupCount(deviceId1), is(1));
251 assertThat(groupStore.getGroupCount(deviceId2), is(0));
Victor Silva4e8b7832016-08-17 17:11:19 -0300252
253 groupStore.purgeGroupEntries();
254 assertThat(groupStore.getGroupCount(deviceId1), is(0));
255 assertThat(groupStore.getGroupCount(deviceId2), is(0));
Charles Chan0c7c43b2016-01-14 17:39:20 -0800256 }
257
258 /**
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700259 * Tests adding and removing a group.
260 */
261 @Test
262 public void testRemoveGroupDescription() throws Exception {
263 groupStore.deviceInitialAuditCompleted(deviceId1, true);
264
265 groupStore.storeGroupDescription(groupDescription1);
266
267 groupStore.deleteGroupDescription(deviceId1, groupKey1);
268
269 // Group should still be there, marked for removal
270 assertThat(groupStore.getGroupCount(deviceId1), is(1));
271 Group queriedGroup = groupStore.getGroup(deviceId1, groupId1);
272 assertThat(queriedGroup.state(), is(Group.GroupState.PENDING_DELETE));
273
274 }
275
276 /**
277 * Tests pushing group metrics.
278 */
279 @Test
280 public void testPushGroupMetrics() {
281 groupStore.deviceInitialAuditCompleted(deviceId1, true);
282 groupStore.deviceInitialAuditCompleted(deviceId2, true);
283
284 GroupDescription groupDescription3 = new DefaultGroupDescription(
285 deviceId1,
Jayasree Ghosh2d459852016-07-02 19:06:52 +0530286 SELECT,
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700287 buckets,
288 new DefaultGroupKey("aaa".getBytes()),
289 null,
290 APP_ID);
291
292 groupStore.storeGroupDescription(groupDescription1);
293 groupStore.storeGroupDescription(groupDescription2);
294 groupStore.storeGroupDescription(groupDescription3);
295 Group group1 = groupStore.getGroup(deviceId1, groupId1);
296
297 assertThat(group1, instanceOf(DefaultGroup.class));
298 DefaultGroup defaultGroup1 = (DefaultGroup) group1;
299 defaultGroup1.setPackets(55L);
300 defaultGroup1.setBytes(66L);
301 groupStore.pushGroupMetrics(deviceId1, ImmutableList.of(group1));
302
303 // Make sure the group was updated.
304
305 Group requeryGroup1 = groupStore.getGroup(deviceId1, groupId1);
306 assertThat(requeryGroup1.packets(), is(55L));
307 assertThat(requeryGroup1.bytes(), is(66L));
308
309 }
310
311 class TestDelegate implements GroupStoreDelegate {
312 private List<GroupEvent> eventsSeen = new LinkedList<>();
313 @Override
314 public void notify(GroupEvent event) {
315 eventsSeen.add(event);
316 }
317
318 public List<GroupEvent> eventsSeen() {
319 return eventsSeen;
320 }
321
322 public void resetEvents() {
323 eventsSeen.clear();
324 }
325 }
326
327 /**
328 * Tests group operation failed interface.
329 */
330 @Test
331 public void testGroupOperationFailed() {
332 TestDelegate delegate = new TestDelegate();
333 groupStore.setDelegate(delegate);
334 groupStore.deviceInitialAuditCompleted(deviceId1, true);
335 groupStore.deviceInitialAuditCompleted(deviceId2, true);
336
337 groupStore.storeGroupDescription(groupDescription1);
338 groupStore.storeGroupDescription(groupDescription2);
339
340 List<GroupEvent> eventsAfterAdds = delegate.eventsSeen();
341 assertThat(eventsAfterAdds, hasSize(2));
Sho SHIMIZUa09e1bb2016-08-01 14:25:25 -0700342 eventsAfterAdds.forEach(event -> assertThat(event.type(), is(GroupEvent.Type.GROUP_ADD_REQUESTED)));
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700343 delegate.resetEvents();
344
345 GroupOperation opAdd =
346 GroupOperation.createAddGroupOperation(groupId1,
Jayasree Ghosh2d459852016-07-02 19:06:52 +0530347 INDIRECT,
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700348 buckets);
349 groupStore.groupOperationFailed(deviceId1, opAdd);
350
351 List<GroupEvent> eventsAfterAddFailed = delegate.eventsSeen();
352 assertThat(eventsAfterAddFailed, hasSize(2));
353 assertThat(eventsAfterAddFailed.get(0).type(),
354 is(GroupEvent.Type.GROUP_ADD_FAILED));
355 assertThat(eventsAfterAddFailed.get(1).type(),
356 is(GroupEvent.Type.GROUP_REMOVED));
357 delegate.resetEvents();
358
359 GroupOperation opModify =
360 GroupOperation.createModifyGroupOperation(groupId2,
Jayasree Ghosh2d459852016-07-02 19:06:52 +0530361 INDIRECT,
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700362 buckets);
363 groupStore.groupOperationFailed(deviceId2, opModify);
364 List<GroupEvent> eventsAfterModifyFailed = delegate.eventsSeen();
365 assertThat(eventsAfterModifyFailed, hasSize(1));
366 assertThat(eventsAfterModifyFailed.get(0).type(),
367 is(GroupEvent.Type.GROUP_UPDATE_FAILED));
368 delegate.resetEvents();
369
370 GroupOperation opDelete =
371 GroupOperation.createDeleteGroupOperation(groupId2,
Jayasree Ghosh2d459852016-07-02 19:06:52 +0530372 INDIRECT);
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700373 groupStore.groupOperationFailed(deviceId2, opDelete);
374 List<GroupEvent> eventsAfterDeleteFailed = delegate.eventsSeen();
375 assertThat(eventsAfterDeleteFailed, hasSize(1));
376 assertThat(eventsAfterDeleteFailed.get(0).type(),
377 is(GroupEvent.Type.GROUP_REMOVE_FAILED));
378 delegate.resetEvents();
379 }
380
381 /**
382 * Tests extraneous group operations.
383 */
384 @Test
385 public void testExtraneousOperations() {
386 ArrayList<Group> extraneous;
387 groupStore.deviceInitialAuditCompleted(deviceId1, true);
388
389 groupStore.storeGroupDescription(groupDescription1);
390 Group group1 = groupStore.getGroup(deviceId1, groupId1);
391
392 extraneous = Lists.newArrayList(groupStore.getExtraneousGroups(deviceId1));
393 assertThat(extraneous, hasSize(0));
394
395 groupStore.addOrUpdateExtraneousGroupEntry(group1);
396 extraneous = Lists.newArrayList(groupStore.getExtraneousGroups(deviceId1));
397 assertThat(extraneous, hasSize(1));
398
399 groupStore.removeExtraneousGroupEntry(group1);
400 extraneous = Lists.newArrayList(groupStore.getExtraneousGroups(deviceId1));
401 assertThat(extraneous, hasSize(0));
402 }
403
404 /**
405 * Tests updating of group descriptions.
406 */
407 @Test
408 public void testUpdateGroupDescription() {
409
410 GroupBuckets buckets =
Victor Silvadf1eeae2016-08-12 15:28:57 -0300411 new GroupBuckets(ImmutableList.of(failoverGroupBucket, selectGroupBucket));
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700412
413 groupStore.deviceInitialAuditCompleted(deviceId1, true);
414 groupStore.storeGroupDescription(groupDescription1);
415
416 GroupKey newKey = new DefaultGroupKey("123".getBytes());
417 groupStore.updateGroupDescription(deviceId1,
418 groupKey1,
Jayasree Ghosh2d459852016-07-02 19:06:52 +0530419 ADD,
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700420 buckets,
421 newKey);
422 Group group1 = groupStore.getGroup(deviceId1, groupId1);
423 assertThat(group1.appCookie(), is(newKey));
424 assertThat(group1.buckets().buckets(), hasSize(2));
Victor Silvadf1eeae2016-08-12 15:28:57 -0300425
426 short weight = 5;
427 GroupBucket selectGroupBucketWithWeight =
428 DefaultGroupBucket.createSelectGroupBucket(treatment, weight);
429 buckets = new GroupBuckets(ImmutableList.of(failoverGroupBucket,
430 selectGroupBucketWithWeight));
431
432 groupStore.updateGroupDescription(deviceId1,
433 newKey,
434 ADD,
435 buckets,
436 newKey);
437
438 group1 = groupStore.getGroup(deviceId1, groupId1);
439 assertThat(group1.appCookie(), is(newKey));
440 assertThat(group1.buckets().buckets(), hasSize(2));
441 for (GroupBucket bucket : group1.buckets().buckets()) {
442 if (bucket.type() == SELECT) {
443 assertEquals(weight, bucket.weight());
444 }
445 }
Victor Silva0282ab82016-11-15 16:30:27 -0300446
447 buckets = new GroupBuckets(ImmutableList.of(selectGroupBucketWithWeight));
448
449 groupStore.updateGroupDescription(deviceId1,
450 newKey,
451 SET,
452 buckets,
453 newKey);
454
455 group1 = groupStore.getGroup(deviceId1, groupId1);
456 assertThat(group1.appCookie(), is(newKey));
457 assertThat(group1.buckets().buckets(), hasSize(1));
458 GroupBucket onlyBucket = group1.buckets().buckets().iterator().next();
459 assertEquals(weight, onlyBucket.weight());
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700460 }
461
462 @Test
463 public void testEqualsGroupStoreIdMapKey() {
464 DistributedGroupStore.GroupStoreIdMapKey key1 =
465 new DistributedGroupStore.GroupStoreIdMapKey(deviceId1, groupId1);
466 DistributedGroupStore.GroupStoreIdMapKey sameAsKey1 =
467 new DistributedGroupStore.GroupStoreIdMapKey(deviceId1, groupId1);
468 DistributedGroupStore.GroupStoreIdMapKey key2 =
469 new DistributedGroupStore.GroupStoreIdMapKey(deviceId2, groupId1);
470 DistributedGroupStore.GroupStoreIdMapKey key3 =
471 new DistributedGroupStore.GroupStoreIdMapKey(deviceId1, groupId2);
472
473 new EqualsTester()
474 .addEqualityGroup(key1, sameAsKey1)
475 .addEqualityGroup(key2)
476 .addEqualityGroup(key3)
477 .testEquals();
478 }
479
480 @Test
481 public void testEqualsGroupStoreKeyMapKey() {
482 DistributedGroupStore.GroupStoreKeyMapKey key1 =
483 new DistributedGroupStore.GroupStoreKeyMapKey(deviceId1, groupKey1);
484 DistributedGroupStore.GroupStoreKeyMapKey sameAsKey1 =
485 new DistributedGroupStore.GroupStoreKeyMapKey(deviceId1, groupKey1);
486 DistributedGroupStore.GroupStoreKeyMapKey key2 =
487 new DistributedGroupStore.GroupStoreKeyMapKey(deviceId2, groupKey1);
488 DistributedGroupStore.GroupStoreKeyMapKey key3 =
489 new DistributedGroupStore.GroupStoreKeyMapKey(deviceId1, groupKey2);
490
491 new EqualsTester()
492 .addEqualityGroup(key1, sameAsKey1)
493 .addEqualityGroup(key2)
494 .addEqualityGroup(key3)
495 .testEquals();
496 }
497
498 @Test
499 public void testEqualsGroupStoreMapKey() {
500 DistributedGroupStore.GroupStoreMapKey key1 =
501 new DistributedGroupStore.GroupStoreMapKey(deviceId1);
502 DistributedGroupStore.GroupStoreMapKey sameAsKey1 =
503 new DistributedGroupStore.GroupStoreMapKey(deviceId1);
504 DistributedGroupStore.GroupStoreMapKey key2 =
505 new DistributedGroupStore.GroupStoreMapKey(deviceId2);
506 DistributedGroupStore.GroupStoreMapKey key3 =
507 new DistributedGroupStore.GroupStoreMapKey(did("dev3"));
508
509 new EqualsTester()
510 .addEqualityGroup(key1, sameAsKey1)
511 .addEqualityGroup(key2)
512 .addEqualityGroup(key3)
513 .testEquals();
514 }
Sivachidambaram Subramanian9f816de2017-06-13 07:16:54 +0530515
516 @Test
517 public void testMasterNull() throws Exception {
518 groupStore.deviceInitialAuditCompleted(deviceId1, true);
519 assertThat(groupStore.deviceInitialAuditStatus(deviceId1), is(true));
520 // Make sure the pending list starts out empty
521 assertThat(auditPendingReqQueue.size(), is(0));
522 //Simulate master null
523 groupStoreImpl.mastershipService = new MasterNull();
524 //Add a group
525 groupStore.storeGroupDescription(groupDescription1);
526 assertThat(groupStore.getGroupCount(deviceId1), is(0));
527 assertThat(groupStore.getGroup(deviceId1, groupId1), nullValue());
528 assertThat(groupStore.getGroup(deviceId1, groupKey1), nullValue());
529 //reset master
530 groupStoreImpl.mastershipService = new MasterOfAll();
531 // Master was null when the group add attempt is made.
532 // So size of the pending list should be 1 now.
533 assertThat(auditPendingReqQueue.size(), is(1));
534 groupStore.deviceInitialAuditCompleted(deviceId1, true);
535 //After the audit , the group should be removed from pending audit queue
536 assertThat(auditPendingReqQueue.size(), is(0));
537 //test whether the group is added to the store
538 assertThat(groupStore.getGroupCount(deviceId1), is(1));
539 assertThat(groupStore.getGroup(deviceId1, groupId1), notNullValue());
540 assertThat(groupStore.getGroup(deviceId1, groupKey1), notNullValue());
541 }
542
543
Ray Milkeyb3c5ce22015-08-10 09:07:36 -0700544}