Skip to content

Commit

Permalink
Fixing CacheService 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 5, 2024
1 parent 1cafda4 commit 0eff4a5
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.opensearch.common.cache.CacheType;
import org.opensearch.common.cache.ICache;
import org.opensearch.common.cache.RemovalListener;
import org.opensearch.common.cache.module.CacheModule;
import org.opensearch.common.cache.settings.CacheSettings;
import org.opensearch.common.cache.store.OpenSearchOnHeapCache;
Expand Down Expand Up @@ -61,7 +62,24 @@ public void testWithCreateCacheWithNoStoreNamePresentForCacheType() {
IllegalArgumentException.class,
() -> cacheService.createCache(config, CacheType.INDICES_REQUEST_CACHE)
);
assertEquals("No configuration exists for cache type: INDICES_REQUEST_CACHE", ex.getMessage());
assertEquals("No store name: [opensearch_onheap] is registered for cache type: INDICES_REQUEST_CACHE", ex.getMessage());
}

public void testWithCreateCacheWithDefaultStoreNameForIRC() {
CachePlugin mockPlugin1 = mock(CachePlugin.class);
ICache.Factory factory1 = mock(ICache.Factory.class);
Map<String, ICache.Factory> factoryMap = Map.of("cache1", factory1);
when(mockPlugin1.getCacheFactoryMap()).thenReturn(factoryMap);

CacheModule cacheModule = new CacheModule(List.of(mockPlugin1), Settings.EMPTY);
CacheConfig<String, String> config = mock(CacheConfig.class);
when(config.getSettings()).thenReturn(Settings.EMPTY);
when(config.getWeigher()).thenReturn((k, v) -> 100);
when(config.getRemovalListener()).thenReturn(mock(RemovalListener.class));

CacheService cacheService = cacheModule.getCacheService();
ICache<String, String> iCache = cacheService.createCache(config, CacheType.INDICES_REQUEST_CACHE);
assertTrue(iCache instanceof OpenSearchOnHeapCache);
}

public void testWithCreateCacheWithInvalidStoreNameAssociatedForCacheType() {
Expand Down

0 comments on commit 0eff4a5

Please sign in to comment.