Skip to content

Commit d4a1f5b

Browse files
committed
Bug 37097258 - [37096406->14.1.2.0.0] Cache.getOrDefault() for RWBM does not propagate through to the cache store when an entry does not exist. (14.1.2.0 cl 112560 --> ce/14.1.2.0)
[git-p4: depot-paths = "//dev/coherence-ce/release/coherence-ce-v14.1.2.0/": change = 113190]
1 parent d304ea8 commit d4a1f5b

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

prj/coherence-core/src/main/java/com/tangosol/util/InvocableMap.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
55
* https://oss.oracle.com/licenses/upl.
@@ -176,11 +176,12 @@ public default <R> R aggregate(EntryAggregator<? super K, ? super V, R> aggregat
176176
public default V getOrDefault(Object key, V defaultValue)
177177
{
178178
Object[] aoResult = invoke((K) key, entry -> {
179-
if (entry.isPresent())
179+
V value = entry.getValue();
180+
if (value != null || entry.isPresent())
180181
{
181-
return new Object[]{true, entry.getValue()};
182+
return new Object[] {true, value};
182183
}
183-
return new Object[]{false};
184+
return new Object[] {false};
184185
});
185186

186187
if (Boolean.TRUE.equals(aoResult[0]))

prj/coherence-testing-support/src/main/java/com/oracle/coherence/testing/TestBinaryCacheStore.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
5-
* http://oss.oracle.com/licenses/upl.
5+
* https://oss.oracle.com/licenses/upl.
66
*/
77

88
package com.oracle.coherence.testing;
@@ -88,6 +88,13 @@ public void load(BinaryEntry binEntry)
8888
log(isVerboseLoad(), "load[BinaryEntry](" + oKey + ")");
8989
logMethodInvocation("load");
9090

91+
// Note: This is for the getOrDefault() test in ReadWriteBackingMapTests.readThroughBasic()
92+
// when the entry does not exist.
93+
if (!getStorageMap().containsKey(oKey) && oKey.equals("Key10"))
94+
{
95+
binEntry.setValue(oKey);
96+
}
97+
9198
delay(getDurationLoad());
9299

93100
checkForFailure(getFailureKeyLoad(), oKey);

prj/coherence-testing-support/src/main/java/com/oracle/coherence/testing/TestCacheStore.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
5-
* http://oss.oracle.com/licenses/upl.
5+
* https://oss.oracle.com/licenses/upl.
66
*/
77

88
package com.oracle.coherence.testing;
@@ -85,6 +85,13 @@ public Object load(Object oKey)
8585
log(isVerboseLoad(), "load(" + oKey + ")");
8686
logMethodInvocation("load");
8787

88+
// Note: This is for the getOrDefault() test in ReadWriteBackingMapTests.readThroughBasic()
89+
// when the entry does not exist.
90+
if (!getStorageMap().containsKey(oKey) && oKey.equals("Key10"))
91+
{
92+
return oKey;
93+
}
94+
8895
delay(getDurationLoad());
8996

9097
checkForFailure(getFailureKeyLoad(), oKey);

prj/test/functional/rwbm/src/main/java/rwbm/ReadWriteBackingMapTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
55
* https://oss.oracle.com/licenses/upl.
@@ -566,6 +566,15 @@ private void readThroughBasic(String sCacheName)
566566

567567
// reset
568568
cache.clear();
569+
570+
// Test getOrDefault() to make sure that the call gets through to the cache store.
571+
// For the purpose of this test, when the entry does not exist,
572+
// the cache store load("Key10") (TestBinaryCacheStore, TestCacheStore)
573+
// returns the key as its value.
574+
String sExpected = (String) cache.getOrDefault("Key10", "V10");
575+
assertEquals(sExpected, "Key10");
576+
cache.clear();
577+
569578
store.getStorageMap().putAll(mapContents);
570579
store.resetStats();
571580

0 commit comments

Comments
 (0)