Committed by
Gerrit Code Review
Fix bug: Prevent a resource with the existing ID from being registered
This resolves a part of issues found in ONOS-3827 Change-Id: I429a84b2dad7300501758f8b842dbb653e38d13b
Showing
1 changed file
with
10 additions
and
2 deletions
... | @@ -509,13 +509,21 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour | ... | @@ -509,13 +509,21 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour |
509 | return true; | 509 | return true; |
510 | } | 510 | } |
511 | 511 | ||
512 | - if (oldValues.containsAll(values)) { | 512 | + Set<ResourceId> oldIds = oldValues.stream() |
513 | + .map(Resource::id) | ||
514 | + .collect(Collectors.toSet()); | ||
515 | + // values whose IDs don't match any IDs of oldValues | ||
516 | + Set<Resource> addedValues = values.stream() | ||
517 | + .filter(x -> !oldIds.contains(x.id())) | ||
518 | + .collect(Collectors.toCollection(LinkedHashSet::new)); | ||
519 | + // no new ID, then no-op | ||
520 | + if (addedValues.isEmpty()) { | ||
513 | // don't write to map because all values are already stored | 521 | // don't write to map because all values are already stored |
514 | return true; | 522 | return true; |
515 | } | 523 | } |
516 | 524 | ||
517 | LinkedHashSet<Resource> newValues = new LinkedHashSet<>(oldValues); | 525 | LinkedHashSet<Resource> newValues = new LinkedHashSet<>(oldValues); |
518 | - newValues.addAll(values); | 526 | + newValues.addAll(addedValues); |
519 | return map.replace(key, oldValues, newValues); | 527 | return map.replace(key, oldValues, newValues); |
520 | } | 528 | } |
521 | 529 | ... | ... |
-
Please register or login to post a comment