Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 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 | */ |
Thomas Vachuska | c97aa61 | 2015-06-23 16:00:18 -0700 | [diff] [blame] | 16 | package org.onosproject.store.trivial; |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 19 | import static org.junit.Assert.assertThat; |
| 20 | import static org.hamcrest.Matchers.is; |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 21 | import static org.onosproject.net.DeviceId.deviceId; |
| 22 | |
| 23 | import java.util.ArrayList; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 24 | import java.util.Arrays; |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 25 | import java.util.Collections; |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 26 | import java.util.List; |
Sho SHIMIZU | 30d639b | 2015-05-05 09:30:35 -0700 | [diff] [blame] | 27 | import java.util.Optional; |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 28 | |
| 29 | import org.junit.After; |
| 30 | import org.junit.Before; |
| 31 | import org.junit.Test; |
| 32 | import org.onlab.packet.MacAddress; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 33 | import org.onlab.packet.MplsLabel; |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 34 | import org.onosproject.core.ApplicationId; |
| 35 | import org.onosproject.core.DefaultApplicationId; |
| 36 | import org.onosproject.core.GroupId; |
| 37 | import org.onosproject.net.DeviceId; |
| 38 | import org.onosproject.net.PortNumber; |
| 39 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 40 | import org.onosproject.net.flow.TrafficTreatment; |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 41 | import org.onosproject.net.group.DefaultGroup; |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 42 | import org.onosproject.net.group.DefaultGroupBucket; |
| 43 | import org.onosproject.net.group.DefaultGroupDescription; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 44 | import org.onosproject.net.group.DefaultGroupKey; |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 45 | import org.onosproject.net.group.Group; |
| 46 | import org.onosproject.net.group.GroupBucket; |
| 47 | import org.onosproject.net.group.GroupBuckets; |
| 48 | import org.onosproject.net.group.GroupDescription; |
| 49 | import org.onosproject.net.group.GroupEvent; |
| 50 | import org.onosproject.net.group.GroupKey; |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 51 | import org.onosproject.net.group.GroupOperation; |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 52 | import org.onosproject.net.group.GroupStore.UpdateType; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 53 | import org.onosproject.net.group.GroupStoreDelegate; |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 54 | import org.onosproject.net.group.StoredGroupBucketEntry; |
| 55 | import org.onosproject.net.group.StoredGroupEntry; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 56 | |
| 57 | import com.google.common.collect.Iterables; |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * Test of the simple DeviceStore implementation. |
| 61 | */ |
| 62 | public class SimpleGroupStoreTest { |
| 63 | |
| 64 | private SimpleGroupStore simpleGroupStore; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 65 | private final ApplicationId appId = |
| 66 | new DefaultApplicationId(2, "org.groupstore.test"); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 67 | |
| 68 | public static final DeviceId D1 = deviceId("of:1"); |
| 69 | |
| 70 | @Before |
| 71 | public void setUp() throws Exception { |
| 72 | simpleGroupStore = new SimpleGroupStore(); |
| 73 | simpleGroupStore.activate(); |
| 74 | } |
| 75 | |
| 76 | @After |
| 77 | public void tearDown() throws Exception { |
| 78 | simpleGroupStore.deactivate(); |
| 79 | } |
| 80 | |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 81 | private class InternalGroupStoreDelegate |
| 82 | implements GroupStoreDelegate { |
| 83 | private GroupId createdGroupId = null; |
| 84 | private GroupKey createdGroupKey; |
| 85 | private GroupBuckets createdBuckets; |
| 86 | private GroupEvent.Type expectedEvent; |
| 87 | |
| 88 | public InternalGroupStoreDelegate(GroupKey key, |
| 89 | GroupBuckets buckets, |
| 90 | GroupEvent.Type expectedEvent) { |
| 91 | this.createdBuckets = buckets; |
| 92 | this.createdGroupKey = key; |
| 93 | this.expectedEvent = expectedEvent; |
| 94 | } |
| 95 | @Override |
| 96 | public void notify(GroupEvent event) { |
| 97 | assertEquals(expectedEvent, event.type()); |
| 98 | assertEquals(Group.Type.SELECT, event.subject().type()); |
| 99 | assertEquals(D1, event.subject().deviceId()); |
| 100 | assertEquals(createdGroupKey, event.subject().appCookie()); |
| 101 | assertEquals(createdBuckets.buckets(), event.subject().buckets().buckets()); |
| 102 | if (expectedEvent == GroupEvent.Type.GROUP_ADD_REQUESTED) { |
| 103 | createdGroupId = event.subject().id(); |
| 104 | assertEquals(Group.GroupState.PENDING_ADD, |
| 105 | event.subject().state()); |
| 106 | } else if (expectedEvent == GroupEvent.Type.GROUP_ADDED) { |
| 107 | createdGroupId = event.subject().id(); |
| 108 | assertEquals(Group.GroupState.ADDED, |
| 109 | event.subject().state()); |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 110 | } else if (expectedEvent == GroupEvent.Type.GROUP_UPDATED) { |
| 111 | createdGroupId = event.subject().id(); |
| 112 | assertEquals(true, |
| 113 | event.subject().buckets(). |
| 114 | buckets().containsAll(createdBuckets.buckets())); |
| 115 | assertEquals(true, |
| 116 | createdBuckets.buckets(). |
| 117 | containsAll(event.subject().buckets().buckets())); |
| 118 | for (GroupBucket bucket:event.subject().buckets().buckets()) { |
Sho SHIMIZU | 30d639b | 2015-05-05 09:30:35 -0700 | [diff] [blame] | 119 | Optional<GroupBucket> matched = createdBuckets.buckets() |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 120 | .stream() |
| 121 | .filter((expected) -> expected.equals(bucket)) |
| 122 | .findFirst(); |
| 123 | assertEquals(matched.get().packets(), |
| 124 | bucket.packets()); |
| 125 | assertEquals(matched.get().bytes(), |
| 126 | bucket.bytes()); |
| 127 | } |
| 128 | assertEquals(Group.GroupState.ADDED, |
| 129 | event.subject().state()); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 130 | } else if (expectedEvent == GroupEvent.Type.GROUP_UPDATE_REQUESTED) { |
| 131 | assertEquals(Group.GroupState.PENDING_UPDATE, |
| 132 | event.subject().state()); |
Victor Silva | df1eeae | 2016-08-12 15:28:57 -0300 | [diff] [blame] | 133 | for (GroupBucket bucket:event.subject().buckets().buckets()) { |
| 134 | Optional<GroupBucket> matched = createdBuckets.buckets() |
| 135 | .stream() |
| 136 | .filter((expected) -> expected.equals(bucket)) |
| 137 | .findFirst(); |
| 138 | assertEquals(matched.get().weight(), |
| 139 | bucket.weight()); |
| 140 | assertEquals(matched.get().watchGroup(), |
| 141 | bucket.watchGroup()); |
| 142 | assertEquals(matched.get().watchPort(), |
| 143 | bucket.watchPort()); |
| 144 | } |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 145 | } else if (expectedEvent == GroupEvent.Type.GROUP_REMOVE_REQUESTED) { |
| 146 | assertEquals(Group.GroupState.PENDING_DELETE, |
| 147 | event.subject().state()); |
| 148 | } else if (expectedEvent == GroupEvent.Type.GROUP_REMOVED) { |
| 149 | createdGroupId = event.subject().id(); |
| 150 | assertEquals(Group.GroupState.PENDING_DELETE, |
| 151 | event.subject().state()); |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 152 | } else if (expectedEvent == GroupEvent.Type.GROUP_ADD_FAILED) { |
| 153 | createdGroupId = event.subject().id(); |
| 154 | assertEquals(Group.GroupState.PENDING_ADD, |
| 155 | event.subject().state()); |
| 156 | } else if (expectedEvent == GroupEvent.Type.GROUP_UPDATE_FAILED) { |
| 157 | createdGroupId = event.subject().id(); |
| 158 | assertEquals(Group.GroupState.PENDING_UPDATE, |
| 159 | event.subject().state()); |
| 160 | } else if (expectedEvent == GroupEvent.Type.GROUP_REMOVE_FAILED) { |
| 161 | createdGroupId = event.subject().id(); |
| 162 | assertEquals(Group.GroupState.PENDING_DELETE, |
| 163 | event.subject().state()); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
| 167 | public void verifyGroupId(GroupId id) { |
| 168 | assertEquals(createdGroupId, id); |
| 169 | } |
| 170 | } |
| 171 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 172 | /** |
| 173 | * Tests group store operations. The following operations are tested: |
| 174 | * a)Tests device group audit completion status change |
| 175 | * b)Tests storeGroup operation |
| 176 | * c)Tests getGroupCount operation |
| 177 | * d)Tests getGroup operation |
| 178 | * e)Tests getGroups operation |
| 179 | * f)Tests addOrUpdateGroupEntry operation from southbound |
| 180 | * g)Tests updateGroupDescription for ADD operation from northbound |
| 181 | * h)Tests updateGroupDescription for REMOVE operation from northbound |
| 182 | * i)Tests deleteGroupDescription operation from northbound |
| 183 | * j)Tests removeGroupEntry operation from southbound |
| 184 | */ |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 185 | @Test |
| 186 | public void testGroupStoreOperations() { |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 187 | // Set the Device AUDIT completed in the store |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 188 | simpleGroupStore.deviceInitialAuditCompleted(D1, true); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 189 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 190 | // Testing storeGroup operation |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 191 | GroupKey newKey = new DefaultGroupKey("group1".getBytes()); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 192 | testStoreAndGetGroup(newKey); |
| 193 | |
| 194 | // Testing addOrUpdateGroupEntry operation from southbound |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 195 | GroupKey currKey = newKey; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 196 | testAddGroupEntryFromSB(currKey); |
| 197 | |
| 198 | // Testing updateGroupDescription for ADD operation from northbound |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 199 | newKey = new DefaultGroupKey("group1AddBuckets".getBytes()); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 200 | testAddBuckets(currKey, newKey); |
| 201 | |
| 202 | // Testing updateGroupDescription for REMOVE operation from northbound |
| 203 | currKey = newKey; |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 204 | newKey = new DefaultGroupKey("group1RemoveBuckets".getBytes()); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 205 | testRemoveBuckets(currKey, newKey); |
| 206 | |
Victor Silva | 0282ab8 | 2016-11-15 16:30:27 -0300 | [diff] [blame] | 207 | // Testing updateGroupDescription for SET operation from northbound |
| 208 | currKey = newKey; |
| 209 | newKey = new DefaultGroupKey("group1SetBuckets".getBytes()); |
| 210 | testSetBuckets(currKey, newKey); |
| 211 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 212 | // Testing addOrUpdateGroupEntry operation from southbound |
| 213 | currKey = newKey; |
| 214 | testUpdateGroupEntryFromSB(currKey); |
| 215 | |
| 216 | // Testing deleteGroupDescription operation from northbound |
| 217 | testDeleteGroup(currKey); |
| 218 | |
| 219 | // Testing removeGroupEntry operation from southbound |
| 220 | testRemoveGroupFromSB(currKey); |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 221 | |
Victor Silva | 4e8b783 | 2016-08-17 17:11:19 -0300 | [diff] [blame] | 222 | // Testing removing all groups on the given device by deviceid |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 223 | newKey = new DefaultGroupKey("group1".getBytes()); |
| 224 | testStoreAndGetGroup(newKey); |
| 225 | testDeleteGroupOnDevice(newKey); |
Victor Silva | 4e8b783 | 2016-08-17 17:11:19 -0300 | [diff] [blame] | 226 | |
| 227 | // Testing removing all groups on the given device |
| 228 | newKey = new DefaultGroupKey("group1".getBytes()); |
| 229 | testStoreAndGetGroup(newKey); |
| 230 | testPurgeGroupEntries(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | // Testing storeGroup operation |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 234 | private void testStoreAndGetGroup(GroupKey key) { |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 235 | PortNumber[] ports = {PortNumber.portNumber(31), |
| 236 | PortNumber.portNumber(32)}; |
Sho SHIMIZU | 7a4087b | 2015-09-10 09:23:16 -0700 | [diff] [blame] | 237 | List<PortNumber> outPorts = new ArrayList<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 238 | outPorts.addAll(Arrays.asList(ports)); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 239 | |
Sho SHIMIZU | 7a4087b | 2015-09-10 09:23:16 -0700 | [diff] [blame] | 240 | List<GroupBucket> buckets = new ArrayList<>(); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 241 | for (PortNumber portNumber: outPorts) { |
| 242 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 243 | tBuilder.setOutput(portNumber) |
| 244 | .setEthDst(MacAddress.valueOf("00:00:00:00:00:02")) |
| 245 | .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")) |
| 246 | .pushMpls() |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 247 | .setMpls(MplsLabel.mplsLabel(106)); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 248 | buckets.add(DefaultGroupBucket.createSelectGroupBucket( |
| 249 | tBuilder.build())); |
| 250 | } |
| 251 | GroupBuckets groupBuckets = new GroupBuckets(buckets); |
| 252 | GroupDescription groupDesc = new DefaultGroupDescription( |
| 253 | D1, |
| 254 | Group.Type.SELECT, |
| 255 | groupBuckets, |
| 256 | key, |
Saurav Das | 100e3b8 | 2015-04-30 11:12:10 -0700 | [diff] [blame] | 257 | null, |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 258 | appId); |
| 259 | InternalGroupStoreDelegate checkStoreGroupDelegate = |
| 260 | new InternalGroupStoreDelegate(key, |
| 261 | groupBuckets, |
| 262 | GroupEvent.Type.GROUP_ADD_REQUESTED); |
| 263 | simpleGroupStore.setDelegate(checkStoreGroupDelegate); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 264 | // Testing storeGroup operation |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 265 | simpleGroupStore.storeGroupDescription(groupDesc); |
| 266 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 267 | // Testing getGroupCount operation |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 268 | assertEquals(1, simpleGroupStore.getGroupCount(D1)); |
| 269 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 270 | // Testing getGroup operation |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 271 | Group createdGroup = simpleGroupStore.getGroup(D1, key); |
| 272 | checkStoreGroupDelegate.verifyGroupId(createdGroup.id()); |
| 273 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 274 | // Testing getGroups operation |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 275 | Iterable<Group> createdGroups = simpleGroupStore.getGroups(D1); |
| 276 | int groupCount = 0; |
| 277 | for (Group group:createdGroups) { |
| 278 | checkStoreGroupDelegate.verifyGroupId(group.id()); |
| 279 | groupCount++; |
| 280 | } |
| 281 | assertEquals(1, groupCount); |
| 282 | simpleGroupStore.unsetDelegate(checkStoreGroupDelegate); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 283 | } |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 284 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 285 | // Testing addOrUpdateGroupEntry operation from southbound |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 286 | private void testAddGroupEntryFromSB(GroupKey currKey) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 287 | Group existingGroup = simpleGroupStore.getGroup(D1, currKey); |
| 288 | |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 289 | InternalGroupStoreDelegate addGroupEntryDelegate = |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 290 | new InternalGroupStoreDelegate(currKey, |
| 291 | existingGroup.buckets(), |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 292 | GroupEvent.Type.GROUP_ADDED); |
| 293 | simpleGroupStore.setDelegate(addGroupEntryDelegate); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 294 | simpleGroupStore.addOrUpdateGroupEntry(existingGroup); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 295 | simpleGroupStore.unsetDelegate(addGroupEntryDelegate); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 296 | } |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 297 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 298 | // Testing addOrUpdateGroupEntry operation from southbound |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 299 | private void testUpdateGroupEntryFromSB(GroupKey currKey) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 300 | Group existingGroup = simpleGroupStore.getGroup(D1, currKey); |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 301 | int totalPkts = 0; |
| 302 | int totalBytes = 0; |
Sho SHIMIZU | 7a4087b | 2015-09-10 09:23:16 -0700 | [diff] [blame] | 303 | List<GroupBucket> newBucketList = new ArrayList<>(); |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 304 | for (GroupBucket bucket:existingGroup.buckets().buckets()) { |
| 305 | StoredGroupBucketEntry newBucket = |
| 306 | (StoredGroupBucketEntry) |
| 307 | DefaultGroupBucket.createSelectGroupBucket(bucket.treatment()); |
| 308 | newBucket.setPackets(10); |
| 309 | newBucket.setBytes(10 * 256 * 8); |
| 310 | totalPkts += 10; |
| 311 | totalBytes += 10 * 256 * 8; |
| 312 | newBucketList.add(newBucket); |
| 313 | } |
| 314 | GroupBuckets updatedBuckets = new GroupBuckets(newBucketList); |
| 315 | Group updatedGroup = new DefaultGroup(existingGroup.id(), |
| 316 | existingGroup.deviceId(), |
| 317 | existingGroup.type(), |
| 318 | updatedBuckets); |
| 319 | ((StoredGroupEntry) updatedGroup).setPackets(totalPkts); |
| 320 | ((StoredGroupEntry) updatedGroup).setBytes(totalBytes); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 321 | |
| 322 | InternalGroupStoreDelegate updateGroupEntryDelegate = |
| 323 | new InternalGroupStoreDelegate(currKey, |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 324 | updatedBuckets, |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 325 | GroupEvent.Type.GROUP_UPDATED); |
| 326 | simpleGroupStore.setDelegate(updateGroupEntryDelegate); |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 327 | simpleGroupStore.addOrUpdateGroupEntry(updatedGroup); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 328 | simpleGroupStore.unsetDelegate(updateGroupEntryDelegate); |
| 329 | } |
| 330 | |
| 331 | // Testing updateGroupDescription for ADD operation from northbound |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 332 | private void testAddBuckets(GroupKey currKey, GroupKey addKey) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 333 | Group existingGroup = simpleGroupStore.getGroup(D1, currKey); |
Sho SHIMIZU | 7a4087b | 2015-09-10 09:23:16 -0700 | [diff] [blame] | 334 | List<GroupBucket> buckets = new ArrayList<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 335 | buckets.addAll(existingGroup.buckets().buckets()); |
| 336 | |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 337 | PortNumber[] newNeighborPorts = {PortNumber.portNumber(41), |
| 338 | PortNumber.portNumber(42)}; |
Sho SHIMIZU | 7a4087b | 2015-09-10 09:23:16 -0700 | [diff] [blame] | 339 | List<PortNumber> newOutPorts = new ArrayList<>(); |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 340 | newOutPorts.addAll(Collections.singletonList(newNeighborPorts[0])); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 341 | |
Sho SHIMIZU | 7a4087b | 2015-09-10 09:23:16 -0700 | [diff] [blame] | 342 | List<GroupBucket> toAddBuckets = new ArrayList<>(); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 343 | for (PortNumber portNumber: newOutPorts) { |
| 344 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 345 | tBuilder.setOutput(portNumber) |
| 346 | .setEthDst(MacAddress.valueOf("00:00:00:00:00:03")) |
| 347 | .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")) |
| 348 | .pushMpls() |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 349 | .setMpls(MplsLabel.mplsLabel(106)); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 350 | toAddBuckets.add(DefaultGroupBucket.createSelectGroupBucket( |
| 351 | tBuilder.build())); |
| 352 | } |
| 353 | GroupBuckets toAddGroupBuckets = new GroupBuckets(toAddBuckets); |
| 354 | buckets.addAll(toAddBuckets); |
| 355 | GroupBuckets updatedGroupBuckets = new GroupBuckets(buckets); |
| 356 | InternalGroupStoreDelegate updateGroupDescDelegate = |
| 357 | new InternalGroupStoreDelegate(addKey, |
| 358 | updatedGroupBuckets, |
| 359 | GroupEvent.Type.GROUP_UPDATE_REQUESTED); |
| 360 | simpleGroupStore.setDelegate(updateGroupDescDelegate); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 361 | simpleGroupStore.updateGroupDescription(D1, |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 362 | currKey, |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 363 | UpdateType.ADD, |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 364 | toAddGroupBuckets, |
| 365 | addKey); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 366 | simpleGroupStore.unsetDelegate(updateGroupDescDelegate); |
Victor Silva | df1eeae | 2016-08-12 15:28:57 -0300 | [diff] [blame] | 367 | |
| 368 | short weight = 5; |
| 369 | toAddBuckets = new ArrayList<>(); |
| 370 | for (PortNumber portNumber: newOutPorts) { |
| 371 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 372 | tBuilder.setOutput(portNumber) |
| 373 | .setEthDst(MacAddress.valueOf("00:00:00:00:00:03")) |
| 374 | .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")) |
| 375 | .pushMpls() |
| 376 | .setMpls(MplsLabel.mplsLabel(106)); |
| 377 | toAddBuckets.add(DefaultGroupBucket.createSelectGroupBucket( |
| 378 | tBuilder.build(), weight)); |
| 379 | } |
| 380 | |
| 381 | toAddGroupBuckets = new GroupBuckets(toAddBuckets); |
| 382 | buckets = new ArrayList<>(); |
| 383 | buckets.addAll(existingGroup.buckets().buckets()); |
| 384 | buckets.addAll(toAddBuckets); |
| 385 | updatedGroupBuckets = new GroupBuckets(buckets); |
| 386 | updateGroupDescDelegate = |
| 387 | new InternalGroupStoreDelegate(addKey, |
| 388 | updatedGroupBuckets, |
| 389 | GroupEvent.Type.GROUP_UPDATE_REQUESTED); |
| 390 | simpleGroupStore.setDelegate(updateGroupDescDelegate); |
| 391 | simpleGroupStore.updateGroupDescription(D1, |
| 392 | addKey, |
| 393 | UpdateType.ADD, |
| 394 | toAddGroupBuckets, |
| 395 | addKey); |
| 396 | simpleGroupStore.unsetDelegate(updateGroupDescDelegate); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 397 | } |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 398 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 399 | // Testing updateGroupDescription for REMOVE operation from northbound |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 400 | private void testRemoveBuckets(GroupKey currKey, GroupKey removeKey) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 401 | Group existingGroup = simpleGroupStore.getGroup(D1, currKey); |
Sho SHIMIZU | 7a4087b | 2015-09-10 09:23:16 -0700 | [diff] [blame] | 402 | List<GroupBucket> buckets = new ArrayList<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 403 | buckets.addAll(existingGroup.buckets().buckets()); |
| 404 | |
Sho SHIMIZU | 7a4087b | 2015-09-10 09:23:16 -0700 | [diff] [blame] | 405 | List<GroupBucket> toRemoveBuckets = new ArrayList<>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 406 | |
| 407 | // There should be 4 buckets in the current group |
| 408 | toRemoveBuckets.add(buckets.remove(0)); |
| 409 | toRemoveBuckets.add(buckets.remove(1)); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 410 | GroupBuckets toRemoveGroupBuckets = new GroupBuckets(toRemoveBuckets); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 411 | |
| 412 | GroupBuckets remainingGroupBuckets = new GroupBuckets(buckets); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 413 | InternalGroupStoreDelegate removeGroupDescDelegate = |
| 414 | new InternalGroupStoreDelegate(removeKey, |
| 415 | remainingGroupBuckets, |
| 416 | GroupEvent.Type.GROUP_UPDATE_REQUESTED); |
| 417 | simpleGroupStore.setDelegate(removeGroupDescDelegate); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 418 | simpleGroupStore.updateGroupDescription(D1, |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 419 | currKey, |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 420 | UpdateType.REMOVE, |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 421 | toRemoveGroupBuckets, |
| 422 | removeKey); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 423 | simpleGroupStore.unsetDelegate(removeGroupDescDelegate); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 424 | } |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 425 | |
Victor Silva | 0282ab8 | 2016-11-15 16:30:27 -0300 | [diff] [blame] | 426 | // Testing updateGroupDescription for SET operation from northbound |
| 427 | private void testSetBuckets(GroupKey currKey, GroupKey setKey) { |
| 428 | List<GroupBucket> toSetBuckets = new ArrayList<>(); |
| 429 | |
| 430 | short weight = 5; |
| 431 | PortNumber portNumber = PortNumber.portNumber(42); |
| 432 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 433 | tBuilder.setOutput(portNumber) |
| 434 | .setEthDst(MacAddress.valueOf("00:00:00:00:00:03")) |
| 435 | .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")) |
| 436 | .pushMpls() |
| 437 | .setMpls(MplsLabel.mplsLabel(106)); |
| 438 | toSetBuckets.add(DefaultGroupBucket.createSelectGroupBucket( |
| 439 | tBuilder.build(), weight)); |
| 440 | |
| 441 | GroupBuckets toSetGroupBuckets = new GroupBuckets(toSetBuckets); |
| 442 | InternalGroupStoreDelegate updateGroupDescDelegate = |
| 443 | new InternalGroupStoreDelegate(setKey, |
| 444 | toSetGroupBuckets, |
| 445 | GroupEvent.Type.GROUP_UPDATE_REQUESTED); |
| 446 | simpleGroupStore.setDelegate(updateGroupDescDelegate); |
| 447 | simpleGroupStore.updateGroupDescription(D1, |
| 448 | currKey, |
| 449 | UpdateType.SET, |
| 450 | toSetGroupBuckets, |
| 451 | setKey); |
| 452 | simpleGroupStore.unsetDelegate(updateGroupDescDelegate); |
| 453 | } |
| 454 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 455 | // Testing deleteGroupDescription operation from northbound |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 456 | private void testDeleteGroup(GroupKey currKey) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 457 | Group existingGroup = simpleGroupStore.getGroup(D1, currKey); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 458 | InternalGroupStoreDelegate deleteGroupDescDelegate = |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 459 | new InternalGroupStoreDelegate(currKey, |
| 460 | existingGroup.buckets(), |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 461 | GroupEvent.Type.GROUP_REMOVE_REQUESTED); |
| 462 | simpleGroupStore.setDelegate(deleteGroupDescDelegate); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 463 | simpleGroupStore.deleteGroupDescription(D1, currKey); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 464 | simpleGroupStore.unsetDelegate(deleteGroupDescDelegate); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 465 | } |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 466 | |
Charles Chan | 0c7c43b | 2016-01-14 17:39:20 -0800 | [diff] [blame] | 467 | // Testing deleteGroupDescription operation from northbound |
| 468 | private void testDeleteGroupOnDevice(GroupKey currKey) { |
| 469 | assertThat(simpleGroupStore.getGroupCount(D1), is(1)); |
| 470 | simpleGroupStore.purgeGroupEntry(D1); |
| 471 | assertThat(simpleGroupStore.getGroupCount(D1), is(0)); |
| 472 | } |
| 473 | |
Victor Silva | 4e8b783 | 2016-08-17 17:11:19 -0300 | [diff] [blame] | 474 | // Testing purgeGroupEntries |
| 475 | private void testPurgeGroupEntries() { |
| 476 | assertThat(simpleGroupStore.getGroupCount(D1), is(1)); |
| 477 | simpleGroupStore.purgeGroupEntries(); |
| 478 | assertThat(simpleGroupStore.getGroupCount(D1), is(0)); |
| 479 | } |
| 480 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 481 | // Testing removeGroupEntry operation from southbound |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 482 | private void testRemoveGroupFromSB(GroupKey currKey) { |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 483 | Group existingGroup = simpleGroupStore.getGroup(D1, currKey); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 484 | InternalGroupStoreDelegate removeGroupEntryDelegate = |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 485 | new InternalGroupStoreDelegate(currKey, |
| 486 | existingGroup.buckets(), |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 487 | GroupEvent.Type.GROUP_REMOVED); |
| 488 | simpleGroupStore.setDelegate(removeGroupEntryDelegate); |
| 489 | simpleGroupStore.removeGroupEntry(existingGroup); |
| 490 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 491 | // Testing getGroup operation |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 492 | existingGroup = simpleGroupStore.getGroup(D1, currKey); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 493 | assertEquals(null, existingGroup); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 494 | assertEquals(0, Iterables.size(simpleGroupStore.getGroups(D1))); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 495 | assertEquals(0, simpleGroupStore.getGroupCount(D1)); |
| 496 | |
| 497 | simpleGroupStore.unsetDelegate(removeGroupEntryDelegate); |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | @Test |
| 501 | public void testGroupOperationFailure() { |
| 502 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 503 | simpleGroupStore.deviceInitialAuditCompleted(D1, true); |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 504 | |
| 505 | ApplicationId appId = |
| 506 | new DefaultApplicationId(2, "org.groupstore.test"); |
Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [diff] [blame] | 507 | GroupKey key = new DefaultGroupKey("group1".getBytes()); |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 508 | PortNumber[] ports = {PortNumber.portNumber(31), |
| 509 | PortNumber.portNumber(32)}; |
Sho SHIMIZU | 7a4087b | 2015-09-10 09:23:16 -0700 | [diff] [blame] | 510 | List<PortNumber> outPorts = new ArrayList<>(); |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 511 | outPorts.add(ports[0]); |
| 512 | outPorts.add(ports[1]); |
| 513 | |
Sho SHIMIZU | 7a4087b | 2015-09-10 09:23:16 -0700 | [diff] [blame] | 514 | List<GroupBucket> buckets = new ArrayList<>(); |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 515 | for (PortNumber portNumber: outPorts) { |
| 516 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 517 | tBuilder.setOutput(portNumber) |
| 518 | .setEthDst(MacAddress.valueOf("00:00:00:00:00:02")) |
| 519 | .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")) |
| 520 | .pushMpls() |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 521 | .setMpls(MplsLabel.mplsLabel(106)); |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 522 | buckets.add(DefaultGroupBucket.createSelectGroupBucket( |
| 523 | tBuilder.build())); |
| 524 | } |
| 525 | GroupBuckets groupBuckets = new GroupBuckets(buckets); |
| 526 | GroupDescription groupDesc = new DefaultGroupDescription( |
| 527 | D1, |
| 528 | Group.Type.SELECT, |
| 529 | groupBuckets, |
| 530 | key, |
Saurav Das | 100e3b8 | 2015-04-30 11:12:10 -0700 | [diff] [blame] | 531 | null, |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 532 | appId); |
| 533 | InternalGroupStoreDelegate checkStoreGroupDelegate = |
| 534 | new InternalGroupStoreDelegate(key, |
| 535 | groupBuckets, |
| 536 | GroupEvent.Type.GROUP_ADD_REQUESTED); |
| 537 | simpleGroupStore.setDelegate(checkStoreGroupDelegate); |
| 538 | // Testing storeGroup operation |
| 539 | simpleGroupStore.storeGroupDescription(groupDesc); |
| 540 | simpleGroupStore.unsetDelegate(checkStoreGroupDelegate); |
| 541 | |
| 542 | // Testing Group add operation failure |
| 543 | Group createdGroup = simpleGroupStore.getGroup(D1, key); |
| 544 | checkStoreGroupDelegate.verifyGroupId(createdGroup.id()); |
| 545 | |
| 546 | GroupOperation groupAddOp = GroupOperation. |
| 547 | createAddGroupOperation(createdGroup.id(), |
| 548 | createdGroup.type(), |
| 549 | createdGroup.buckets()); |
| 550 | InternalGroupStoreDelegate checkGroupAddFailureDelegate = |
| 551 | new InternalGroupStoreDelegate(key, |
| 552 | groupBuckets, |
| 553 | GroupEvent.Type.GROUP_ADD_FAILED); |
| 554 | simpleGroupStore.setDelegate(checkGroupAddFailureDelegate); |
| 555 | simpleGroupStore.groupOperationFailed(D1, groupAddOp); |
| 556 | |
| 557 | |
| 558 | // Testing Group modify operation failure |
| 559 | simpleGroupStore.unsetDelegate(checkGroupAddFailureDelegate); |
| 560 | GroupOperation groupModOp = GroupOperation. |
| 561 | createModifyGroupOperation(createdGroup.id(), |
| 562 | createdGroup.type(), |
| 563 | createdGroup.buckets()); |
| 564 | InternalGroupStoreDelegate checkGroupModFailureDelegate = |
| 565 | new InternalGroupStoreDelegate(key, |
| 566 | groupBuckets, |
| 567 | GroupEvent.Type.GROUP_UPDATE_FAILED); |
| 568 | simpleGroupStore.setDelegate(checkGroupModFailureDelegate); |
| 569 | simpleGroupStore.groupOperationFailed(D1, groupModOp); |
| 570 | |
| 571 | // Testing Group modify operation failure |
| 572 | simpleGroupStore.unsetDelegate(checkGroupModFailureDelegate); |
| 573 | GroupOperation groupDelOp = GroupOperation. |
| 574 | createDeleteGroupOperation(createdGroup.id(), |
| 575 | createdGroup.type()); |
| 576 | InternalGroupStoreDelegate checkGroupDelFailureDelegate = |
| 577 | new InternalGroupStoreDelegate(key, |
| 578 | groupBuckets, |
| 579 | GroupEvent.Type.GROUP_REMOVE_FAILED); |
| 580 | simpleGroupStore.setDelegate(checkGroupDelFailureDelegate); |
| 581 | simpleGroupStore.groupOperationFailed(D1, groupDelOp); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 582 | } |
| 583 | } |
| 584 | |