Skip to content

Commit

Permalink
Fixing flaky ehcache test
Browse files Browse the repository at this point in the history
Signed-off-by: Sagar Upadhyaya <sagar.upadhyaya.121@gmail.com>
  • Loading branch information
sgup432 committed Mar 1, 2024
1 parent e902526 commit b866ed2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ public class EhcacheDiskCacheSettings {
(key) -> Setting.longSetting(key, 1073741824L, NodeScope)
);

/**
* Disk cache listener mode setting.
*/
public static final Setting.AffixSetting<Boolean> DISK_CACHE_LISTENER_MODE_SYNC_SETTING = Setting.suffixKeySetting(
EhcacheDiskCache.EhcacheDiskCacheFactory.EHCACHE_DISK_CACHE_NAME + ".is_event_listener_sync",
(key) -> Setting.boolSetting(key, false, NodeScope)
);

/**
* Key for disk segment.
*/
Expand Down Expand Up @@ -138,6 +146,10 @@ public class EhcacheDiskCacheSettings {
* Key for storage path.
*/
public static final String DISK_STORAGE_PATH_KEY = "disk_storage_path";
/**
* Key for listener mode
*/
public static final String DISK_LISTENER_MODE_SYNC_KEY = "disk_listener_mode";

/**
* Map of key to setting.
Expand All @@ -160,7 +172,9 @@ public class EhcacheDiskCacheSettings {
DISK_STORAGE_PATH_KEY,
DISK_STORAGE_PATH_SETTING,
DISK_MAX_SIZE_IN_BYTES_KEY,
DISK_CACHE_MAX_SIZE_IN_BYTES_SETTING
DISK_CACHE_MAX_SIZE_IN_BYTES_SETTING,
DISK_LISTENER_MODE_SYNC_KEY,
DISK_CACHE_LISTENER_MODE_SYNC_SETTING
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_CACHE_ALIAS_KEY;
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_CACHE_EXPIRE_AFTER_ACCESS_KEY;
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_LISTENER_MODE_SYNC_KEY;
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_MAX_SIZE_IN_BYTES_KEY;
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_SEGMENT_KEY;
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_STORAGE_PATH_KEY;
Expand Down Expand Up @@ -475,6 +476,7 @@ public <K, V> ICache<K, V> create(CacheConfig<K, V> config, CacheType cacheType,
Settings settings = config.getSettings();
return new Builder<K, V>().setStoragePath((String) settingList.get(DISK_STORAGE_PATH_KEY).get(settings))
.setDiskCacheAlias((String) settingList.get(DISK_CACHE_ALIAS_KEY).get(settings))
.setIsEventListenerModeSync((Boolean) settingList.get(DISK_LISTENER_MODE_SYNC_KEY).get(settings))
.setCacheType(cacheType)
.setKeyType((config.getKeyType()))
.setValueType(config.getValueType())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Phaser;

import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_LISTENER_MODE_SYNC_KEY;
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_MAX_SIZE_IN_BYTES_KEY;
import static org.opensearch.cache.EhcacheDiskCacheSettings.DISK_STORAGE_PATH_KEY;
import static org.hamcrest.CoreMatchers.instanceOf;
Expand All @@ -46,6 +47,7 @@ public void testBasicGetAndPut() throws IOException {
try (NodeEnvironment env = newNodeEnvironment(settings)) {
ICache<String, String> ehcacheTest = new EhcacheDiskCache.Builder<String, String>().setThreadPoolAlias("ehcacheTest")
.setStoragePath(env.nodePaths()[0].indicesPath.toString() + "/request_cache")
.setIsEventListenerModeSync(true)
.setKeyType(String.class)
.setValueType(String.class)
.setCacheType(CacheType.INDICES_REQUEST_CACHE)
Expand Down Expand Up @@ -100,6 +102,12 @@ public void testBasicGetAndPutUsingFactory() throws IOException {
.getKey(),
env.nodePaths()[0].indicesPath.toString() + "/request_cache"
)
.put(
EhcacheDiskCacheSettings.getSettingListForCacheType(CacheType.INDICES_REQUEST_CACHE)
.get(DISK_LISTENER_MODE_SYNC_KEY)
.getKey(),
true
)
.build()
)
.build(),
Expand Down Expand Up @@ -225,6 +233,7 @@ public void testEhcacheKeyIterator() throws Exception {
ICache<String, String> ehcacheTest = new EhcacheDiskCache.Builder<String, String>().setDiskCacheAlias("test1")
.setThreadPoolAlias("ehcacheTest")
.setStoragePath(env.nodePaths()[0].indicesPath.toString() + "/request_cache")
.setIsEventListenerModeSync(true)
.setKeyType(String.class)
.setValueType(String.class)
.setCacheType(CacheType.INDICES_REQUEST_CACHE)
Expand Down

0 comments on commit b866ed2

Please sign in to comment.