Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-7668

Merge implementation is not correct on SimpleCache

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 9.0.0.Final
    • Component/s: Core
    • Labels:
      None
    • Steps to Reproduce:
      Hide
      SimpleCacheTest.java
       public void testMerge() throws Exception {
      
            cache.put("existing", "foo");
            Object mergeResult = cache.merge("existing", "bar", (oldValue, newValue) -> "" + oldValue + newValue);
            assertEquals("foobar", mergeResult);
            assertEquals("foobar", cache.get("existing"));
      
            mergeResult = cache.merge("existing", "bar", (oldValue, newValue) -> null);
            assertNull(mergeResult);
            assertNull(cache.get("existing"));
      
            mergeResult = cache.merge("notExisting", "foo", (oldValue, newValue) -> "" + oldValue + newValue);
            assertEquals("foo", mergeResult);
            assertEquals("foo", cache.get("notExisting"));
      
         }
      
      Show
      SimpleCacheTest.java public void testMerge() throws Exception { cache.put( "existing" , "foo" ); Object mergeResult = cache.merge( "existing" , "bar" , (oldValue, newValue) -> "" + oldValue + newValue); assertEquals( "foobar" , mergeResult); assertEquals( "foobar" , cache.get( "existing" )); mergeResult = cache.merge( "existing" , "bar" , (oldValue, newValue) -> null ); assertNull(mergeResult); assertNull(cache.get( "existing" )); mergeResult = cache.merge( "notExisting" , "foo" , (oldValue, newValue) -> "" + oldValue + newValue); assertEquals( "foo" , mergeResult); assertEquals( "foo" , cache.get( "notExisting" )); }
    • Estimated Difficulty:
      Low

      Description

      Merge method is not correctly implemented in SimpleCache.
      Merge should work this way :

      • if the key is not present, add the value
      • If the key is present, apply the function between the existing key's value and the given value and replace the key with the merged result
      • If the merge function returns null, remove the key

      The case that should work as "putIfAbsent" does't work. Merge function is applied to null and the given value.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  rvansa Radim Vansa
                  Reporter:
                  karesti Katia Aresti
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: