[Fix] removed check for duplicate keys
This commit is contained in:
parent
8525bbdf6a
commit
b46c59e890
|
@ -218,18 +218,6 @@ public class ObjectFilter {
|
|||
|
||||
if (cached == null) {
|
||||
|
||||
List<ObjectCache> allElements = this.cache.getAllElements();
|
||||
|
||||
// check if the object is already in the cache with an other key
|
||||
if (allElements.stream().anyMatch(oCache -> oCache.getObject().equals(objectToUpdate))) {
|
||||
String msg = "Invalid key provided for object with transaction ID {0} and operation {1}: existing key is {2}, new key is {3}. Object may be present in the same filter instance only once, registered using one key only. Object:{4}"; //$NON-NLS-1$
|
||||
|
||||
Optional<ObjectCache> duplicateObj = allElements.stream()
|
||||
.filter(oCache -> oCache.getObject().equals(objectToUpdate)).findFirst();
|
||||
throw new IllegalArgumentException(MessageFormat.format(msg, Long.toString(id),
|
||||
Operation.MODIFY.toString(), duplicateObj.get().getKey(), key, objectToUpdate.toString()));
|
||||
}
|
||||
|
||||
// The object got an ID during this run, but was not added to this cache.
|
||||
// Hence, we add it now, with the current operation.
|
||||
ObjectCache cacheObj = new ObjectCache(dispenseID(), key, objectKey, objectToUpdate, Operation.MODIFY);
|
||||
|
|
|
@ -192,24 +192,6 @@ public class ObjectFilterTest {
|
|||
testAssertions(filter, 1, 1, 0, 0, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotAcceptDifferentKeyForSameObject() {
|
||||
Object myObj = new Object();
|
||||
|
||||
ObjectFilter filter = new ObjectFilter();
|
||||
filter.add(myObj, myObj);
|
||||
|
||||
try {
|
||||
filter.update("different_key", myObj, myObj);
|
||||
fail("Should have failed because of different key for already registered object");
|
||||
} catch (RuntimeException e) {
|
||||
String msg = "Object may be present in the same filter instance only once, registered using one key only";
|
||||
assertTrue("Encountered exception: " + e.getMessage(), e.getMessage().contains(msg));
|
||||
}
|
||||
|
||||
testAssertions(filter, 1, 1, 1, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReplaceOnAddAfterRemove() {
|
||||
|
||||
|
|
Loading…
Reference in New Issue