diff --git a/prj/coherence-core/src/main/java/com/tangosol/util/InvocableMap.java b/prj/coherence-core/src/main/java/com/tangosol/util/InvocableMap.java index 1ccffde17482..d77a652f97ff 100644 --- a/prj/coherence-core/src/main/java/com/tangosol/util/InvocableMap.java +++ b/prj/coherence-core/src/main/java/com/tangosol/util/InvocableMap.java @@ -176,11 +176,12 @@ public default R aggregate(EntryAggregator aggregat public default V getOrDefault(Object key, V defaultValue) { Object[] aoResult = invoke((K) key, entry -> { - if (entry.isPresent()) + V value = entry.getValue(); + if (value != null || entry.isPresent()) { - return new Object[]{true, entry.getValue()}; + return new Object[] {true, value}; } - return new Object[]{false}; + return new Object[] {false}; }); if (Boolean.TRUE.equals(aoResult[0])) diff --git a/prj/coherence-testing-support/src/main/java/com/oracle/coherence/testing/TestBinaryCacheStore.java b/prj/coherence-testing-support/src/main/java/com/oracle/coherence/testing/TestBinaryCacheStore.java index 5ed1934680d9..3f1b0a063e5f 100644 --- a/prj/coherence-testing-support/src/main/java/com/oracle/coherence/testing/TestBinaryCacheStore.java +++ b/prj/coherence-testing-support/src/main/java/com/oracle/coherence/testing/TestBinaryCacheStore.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2000, 2022, Oracle and/or its affiliates. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. * * Licensed under the Universal Permissive License v 1.0 as shown at - * http://oss.oracle.com/licenses/upl. + * https://oss.oracle.com/licenses/upl. */ package com.oracle.coherence.testing; @@ -88,6 +88,13 @@ public void load(BinaryEntry binEntry) log(isVerboseLoad(), "load[BinaryEntry](" + oKey + ")"); logMethodInvocation("load"); + // Note: This is for the getOrDefault() test in ReadWriteBackingMapTests.readThroughBasic() + // when the entry does not exist. + if (!getStorageMap().containsKey(oKey) && oKey.equals("Key10")) + { + binEntry.setValue(oKey); + } + delay(getDurationLoad()); checkForFailure(getFailureKeyLoad(), oKey); diff --git a/prj/coherence-testing-support/src/main/java/com/oracle/coherence/testing/TestCacheStore.java b/prj/coherence-testing-support/src/main/java/com/oracle/coherence/testing/TestCacheStore.java index 6aa99a207bb1..658619ccd1d6 100644 --- a/prj/coherence-testing-support/src/main/java/com/oracle/coherence/testing/TestCacheStore.java +++ b/prj/coherence-testing-support/src/main/java/com/oracle/coherence/testing/TestCacheStore.java @@ -1,8 +1,8 @@ /* - * Copyright (c) 2000, 2022, Oracle and/or its affiliates. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. * * Licensed under the Universal Permissive License v 1.0 as shown at - * http://oss.oracle.com/licenses/upl. + * https://oss.oracle.com/licenses/upl. */ package com.oracle.coherence.testing; @@ -85,6 +85,13 @@ public Object load(Object oKey) log(isVerboseLoad(), "load(" + oKey + ")"); logMethodInvocation("load"); + // Note: This is for the getOrDefault() test in ReadWriteBackingMapTests.readThroughBasic() + // when the entry does not exist. + if (!getStorageMap().containsKey(oKey) && oKey.equals("Key10")) + { + return oKey; + } + delay(getDurationLoad()); checkForFailure(getFailureKeyLoad(), oKey); diff --git a/prj/test/functional/rwbm/src/main/java/rwbm/ReadWriteBackingMapTests.java b/prj/test/functional/rwbm/src/main/java/rwbm/ReadWriteBackingMapTests.java index 25f7a136e87c..616d59d33107 100644 --- a/prj/test/functional/rwbm/src/main/java/rwbm/ReadWriteBackingMapTests.java +++ b/prj/test/functional/rwbm/src/main/java/rwbm/ReadWriteBackingMapTests.java @@ -566,6 +566,15 @@ private void readThroughBasic(String sCacheName) // reset cache.clear(); + + // Test getOrDefault() to make sure that the call gets through to the cache store. + // For the purpose of this test, when the entry does not exist, + // the cache store load("Key10") (TestBinaryCacheStore, TestCacheStore) + // returns the key as its value. + String sExpected = (String) cache.getOrDefault("Key10", "V10"); + assertEquals(sExpected, "Key10"); + cache.clear(); + store.getStorageMap().putAll(mapContents); store.resetStats();