Skip to content

Commit

Permalink
Bug 37097260 - [37096406->24.09.1] Cache.getOrDefault() for RWBM does…
Browse files Browse the repository at this point in the history
… not propagate through to the cache store when an entry does not exist.

[git-p4: depot-paths = "//dev/coherence-ce/release/coherence-ce-v24.09/": change = 111695]
  • Loading branch information
lsho committed Oct 1, 2024
1 parent 9eafd8c commit 02e375d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,12 @@ public default <R> R aggregate(EntryAggregator<? super K, ? super V, R> 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]))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 02e375d

Please sign in to comment.