Skip to content

Commit b866ed2

Browse files
committed
Fixing flaky ehcache test
Signed-off-by: Sagar Upadhyaya <[email protected]>
1 parent e902526 commit b866ed2

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

plugins/cache-ehcache/src/main/java/org/opensearch/cache/EhcacheDiskCacheSettings.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ public class EhcacheDiskCacheSettings {
102102
(key) -> Setting.longSetting(key, 1073741824L, NodeScope)
103103
);
104104

105+
/**
106+
* Disk cache listener mode setting.
107+
*/
108+
public static final Setting.AffixSetting<Boolean> DISK_CACHE_LISTENER_MODE_SYNC_SETTING = Setting.suffixKeySetting(
109+
EhcacheDiskCache.EhcacheDiskCacheFactory.EHCACHE_DISK_CACHE_NAME + ".is_event_listener_sync",
110+
(key) -> Setting.boolSetting(key, false, NodeScope)
111+
);
112+
105113
/**
106114
* Key for disk segment.
107115
*/
@@ -138,6 +146,10 @@ public class EhcacheDiskCacheSettings {
138146
* Key for storage path.
139147
*/
140148
public static final String DISK_STORAGE_PATH_KEY = "disk_storage_path";
149+
/**
150+
* Key for listener mode
151+
*/
152+
public static final String DISK_LISTENER_MODE_SYNC_KEY = "disk_listener_mode";
141153

142154
/**
143155
* Map of key to setting.
@@ -160,7 +172,9 @@ public class EhcacheDiskCacheSettings {
160172
DISK_STORAGE_PATH_KEY,
161173
DISK_STORAGE_PATH_SETTING,
162174
DISK_MAX_SIZE_IN_BYTES_KEY,
163-
DISK_CACHE_MAX_SIZE_IN_BYTES_SETTING
175+
DISK_CACHE_MAX_SIZE_IN_BYTES_SETTING,
176+
DISK_LISTENER_MODE_SYNC_KEY,
177+
DISK_CACHE_LISTENER_MODE_SYNC_SETTING
164178
);
165179

166180
/**

plugins/cache-ehcache/src/main/java/org/opensearch/cache/store/disk/EhcacheDiskCache.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_CACHE_ALIAS_KEY;
6262
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_CACHE_EXPIRE_AFTER_ACCESS_KEY;
63+
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_LISTENER_MODE_SYNC_KEY;
6364
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_MAX_SIZE_IN_BYTES_KEY;
6465
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_SEGMENT_KEY;
6566
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_STORAGE_PATH_KEY;
@@ -475,6 +476,7 @@ public <K, V> ICache<K, V> create(CacheConfig<K, V> config, CacheType cacheType,
475476
Settings settings = config.getSettings();
476477
return new Builder<K, V>().setStoragePath((String) settingList.get(DISK_STORAGE_PATH_KEY).get(settings))
477478
.setDiskCacheAlias((String) settingList.get(DISK_CACHE_ALIAS_KEY).get(settings))
479+
.setIsEventListenerModeSync((Boolean) settingList.get(DISK_LISTENER_MODE_SYNC_KEY).get(settings))
478480
.setCacheType(cacheType)
479481
.setKeyType((config.getKeyType()))
480482
.setValueType(config.getValueType())

plugins/cache-ehcache/src/test/java/org/opensearch/cache/store/disk/EhCacheDiskCacheTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.concurrent.ExecutionException;
3333
import java.util.concurrent.Phaser;
3434

35+
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_LISTENER_MODE_SYNC_KEY;
3536
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_MAX_SIZE_IN_BYTES_KEY;
3637
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_STORAGE_PATH_KEY;
3738
import static org.hamcrest.CoreMatchers.instanceOf;
@@ -46,6 +47,7 @@ public void testBasicGetAndPut() throws IOException {
4647
try (NodeEnvironment env = newNodeEnvironment(settings)) {
4748
ICache<String, String> ehcacheTest = new EhcacheDiskCache.Builder<String, String>().setThreadPoolAlias("ehcacheTest")
4849
.setStoragePath(env.nodePaths()[0].indicesPath.toString() + "/request_cache")
50+
.setIsEventListenerModeSync(true)
4951
.setKeyType(String.class)
5052
.setValueType(String.class)
5153
.setCacheType(CacheType.INDICES_REQUEST_CACHE)
@@ -100,6 +102,12 @@ public void testBasicGetAndPutUsingFactory() throws IOException {
100102
.getKey(),
101103
env.nodePaths()[0].indicesPath.toString() + "/request_cache"
102104
)
105+
.put(
106+
EhcacheDiskCacheSettings.getSettingListForCacheType(CacheType.INDICES_REQUEST_CACHE)
107+
.get(DISK_LISTENER_MODE_SYNC_KEY)
108+
.getKey(),
109+
true
110+
)
103111
.build()
104112
)
105113
.build(),
@@ -225,6 +233,7 @@ public void testEhcacheKeyIterator() throws Exception {
225233
ICache<String, String> ehcacheTest = new EhcacheDiskCache.Builder<String, String>().setDiskCacheAlias("test1")
226234
.setThreadPoolAlias("ehcacheTest")
227235
.setStoragePath(env.nodePaths()[0].indicesPath.toString() + "/request_cache")
236+
.setIsEventListenerModeSync(true)
228237
.setKeyType(String.class)
229238
.setValueType(String.class)
230239
.setCacheType(CacheType.INDICES_REQUEST_CACHE)

0 commit comments

Comments
 (0)