use of org.onosproject.net.group.GroupEvent in project onos by opennetworkinglab.
the class SimpleVirtualGroupStore method addOrUpdateExtraneousGroupEntry.
@Override
public void addOrUpdateExtraneousGroupEntry(NetworkId networkId, Group group) {
ConcurrentMap<GroupId, Group> extraneousIdTable = getExtraneousGroupIdTable(networkId, group.deviceId());
extraneousIdTable.put(group.id(), group);
// Check the reference counter
if (group.referenceCount() == 0) {
notifyDelegate(networkId, new GroupEvent(GroupEvent.Type.GROUP_REMOVE_REQUESTED, group));
}
}
use of org.onosproject.net.group.GroupEvent in project onos by opennetworkinglab.
the class DistributedGroupStoreTest method testGroupOperationFailedWithErrorCode.
/**
* Tests group operation failed interface, with error codes for failures.
*/
@Test
public void testGroupOperationFailedWithErrorCode() {
TestDelegate delegate = new TestDelegate();
groupStore.setDelegate(delegate);
groupStore.deviceInitialAuditCompleted(deviceId1, true);
groupStore.storeGroupDescription(groupDescription1);
groupStore.deviceInitialAuditCompleted(deviceId2, true);
groupStore.storeGroupDescription(groupDescription2);
List<GroupEvent> eventsAfterAdds = delegate.eventsSeen();
assertThat(eventsAfterAdds, hasSize(2));
eventsAfterAdds.forEach(event -> assertThat(event.type(), is(GroupEvent.Type.GROUP_ADD_REQUESTED)));
delegate.resetEvents();
// test group exists
GroupOperation opAdd = GroupOperation.createAddGroupOperation(groupId1, ALL, allGroupBuckets);
GroupOperation addFailedExists = GroupOperation.createFailedGroupOperation(opAdd, GroupMsgErrorCode.GROUP_EXISTS);
groupStore.groupOperationFailed(deviceId1, addFailedExists);
List<GroupEvent> eventsAfterAddFailed = delegate.eventsSeen();
assertThat(eventsAfterAddFailed, hasSize(2));
assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADDED));
assertThat(eventsAfterAddFailed.get(1).type(), is(GroupEvent.Type.GROUP_ADDED));
Group g1 = groupStore.getGroup(deviceId1, groupId1);
assertEquals(0, g1.failedRetryCount());
delegate.resetEvents();
// test invalid group
Group g2 = groupStore.getGroup(deviceId2, groupId2);
assertEquals(0, g2.failedRetryCount());
assertEquals(GroupState.PENDING_ADD, g2.state());
GroupOperation opAdd1 = GroupOperation.createAddGroupOperation(groupId2, INDIRECT, indirectGroupBuckets);
GroupOperation addFailedInvalid = GroupOperation.createFailedGroupOperation(opAdd1, GroupMsgErrorCode.INVALID_GROUP);
groupStore.groupOperationFailed(deviceId2, addFailedInvalid);
groupStore.pushGroupMetrics(deviceId2, ImmutableList.of());
List<GroupEvent> eventsAfterAddFailed1 = delegate.eventsSeen();
assertThat(eventsAfterAddFailed1, hasSize(1));
assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADD_REQUESTED));
g2 = groupStore.getGroup(deviceId2, groupId2);
assertEquals(1, g2.failedRetryCount());
assertEquals(GroupState.PENDING_ADD_RETRY, g2.state());
delegate.resetEvents();
groupStore.groupOperationFailed(deviceId2, addFailedInvalid);
groupStore.pushGroupMetrics(deviceId2, ImmutableList.of());
List<GroupEvent> eventsAfterAddFailed2 = delegate.eventsSeen();
assertThat(eventsAfterAddFailed2, hasSize(1));
assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADD_REQUESTED));
g2 = groupStore.getGroup(deviceId2, groupId2);
assertEquals(2, g2.failedRetryCount());
assertEquals(GroupState.PENDING_ADD_RETRY, g2.state());
delegate.resetEvents();
groupStore.groupOperationFailed(deviceId2, addFailedInvalid);
groupStore.pushGroupMetrics(deviceId2, ImmutableList.of());
List<GroupEvent> eventsAfterAddFailed3 = delegate.eventsSeen();
assertThat(eventsAfterAddFailed3, hasSize(2));
assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADD_FAILED));
assertThat(eventsAfterAddFailed.get(1).type(), is(GroupEvent.Type.GROUP_REMOVED));
g2 = groupStore.getGroup(deviceId2, groupId2);
assertEquals(null, g2);
delegate.resetEvents();
}
Aggregations