From f81509f60e5295dd74145f8e901fb0d8bd3b2122 Mon Sep 17 00:00:00 2001 From: Rishiraj Anand Date: Thu, 28 Nov 2024 15:37:32 +0530 Subject: [PATCH] Fixing infinispan upgrade test failure --- .../infinispan/EmbeddedStorageManager.java | 19 +++------ .../test/EmbeddedStorageManagerTest.java | 42 +++++-------------- 2 files changed, 16 insertions(+), 45 deletions(-) diff --git a/drools-reliability/drools-reliability-infinispan/src/main/java/org/drools/reliability/infinispan/EmbeddedStorageManager.java b/drools-reliability/drools-reliability-infinispan/src/main/java/org/drools/reliability/infinispan/EmbeddedStorageManager.java index d03cf43797f3..700fdd67eb9a 100644 --- a/drools-reliability/drools-reliability-infinispan/src/main/java/org/drools/reliability/infinispan/EmbeddedStorageManager.java +++ b/drools-reliability/drools-reliability-infinispan/src/main/java/org/drools/reliability/infinispan/EmbeddedStorageManager.java @@ -18,9 +18,6 @@ */ package org.drools.reliability.infinispan; -import java.nio.file.Paths; -import java.util.Set; - import org.drools.core.common.ReteEvaluator; import org.drools.core.common.Storage; import org.drools.util.FileUtils; @@ -33,15 +30,14 @@ import org.infinispan.configuration.global.GlobalConfigurationBuilder; import org.infinispan.globalstate.ConfigurationStorage; import org.infinispan.manager.DefaultCacheManager; -import org.infinispan.manager.EmbeddedCacheManagerAdmin; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.nio.file.Paths; +import java.util.Set; + import static org.drools.reliability.core.StorageManager.createStorageId; -import static org.drools.reliability.infinispan.InfinispanStorageManagerFactory.DELIMITER; -import static org.drools.reliability.infinispan.InfinispanStorageManagerFactory.INFINISPAN_STORAGE_DIRECTORY; -import static org.drools.reliability.infinispan.InfinispanStorageManagerFactory.SESSION_STORAGE_PREFIX; -import static org.drools.reliability.infinispan.InfinispanStorageManagerFactory.SHARED_STORAGE_PREFIX; +import static org.drools.reliability.infinispan.InfinispanStorageManagerFactory.*; import static org.drools.util.Config.getConfig; public class EmbeddedStorageManager implements InfinispanStorageManager { @@ -53,8 +49,6 @@ public class EmbeddedStorageManager implements InfinispanStorageManager { static final EmbeddedStorageManager INSTANCE = new EmbeddedStorageManager(); private DefaultCacheManager embeddedCacheManager; - - private EmbeddedCacheManagerAdmin cacheContainerAdmin; private Configuration cacheConfiguration; public static final String CACHE_DIR = "cache"; @@ -79,8 +73,6 @@ public void initStorageManager() { // Initialize the default Cache Manager. embeddedCacheManager = new DefaultCacheManager(global.build()); - cacheContainerAdmin = embeddedCacheManager.administration(); - // Create a distributed cache with synchronous replication. ConfigurationBuilder builder = new ConfigurationBuilder(); builder.persistence().passivation(false) @@ -117,7 +109,7 @@ public void close() { @Override public void removeStorage(String storageName) { if (embeddedCacheManager.cacheExists(storageName)) { - cacheContainerAdmin.removeCache(storageName); + embeddedCacheManager.administration().removeCache(storageName); } } @@ -180,6 +172,7 @@ public void setEmbeddedCacheManager(DefaultCacheManager embeddedCacheManager) { this.embeddedCacheManager.stop(); } this.embeddedCacheManager = embeddedCacheManager; + } // test purpose to remove GlobalState and FileStore diff --git a/drools-reliability/drools-reliability-tests/src/test/java/org/drools/reliability/test/EmbeddedStorageManagerTest.java b/drools-reliability/drools-reliability-tests/src/test/java/org/drools/reliability/test/EmbeddedStorageManagerTest.java index 5e8f5b52d923..60fd4949e76f 100644 --- a/drools-reliability/drools-reliability-tests/src/test/java/org/drools/reliability/test/EmbeddedStorageManagerTest.java +++ b/drools-reliability/drools-reliability-tests/src/test/java/org/drools/reliability/test/EmbeddedStorageManagerTest.java @@ -21,16 +21,14 @@ import org.drools.reliability.core.StorageManagerFactory; import org.drools.reliability.core.TestableStorageManager; import org.drools.reliability.infinispan.InfinispanStorageManager; +import org.infinispan.configuration.cache.CacheMode; +import org.infinispan.configuration.cache.ConfigurationBuilder; import org.infinispan.manager.DefaultCacheManager; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.api.extension.ExtendWith; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - import static org.assertj.core.api.Assertions.assertThat; import static org.drools.reliability.core.StorageManagerFactory.SESSION_STORAGE_PREFIX; import static org.drools.reliability.infinispan.InfinispanStorageManagerFactory.INFINISPAN_STORAGE_ALLOWED_PACKAGES; @@ -63,49 +61,29 @@ static boolean isEmbeddedInfinispan() { void removeAllSessionCaches_shouldLeaveNonSessionCache() { ((InfinispanStorageManager) StorageManagerFactory.get().getStorageManager()).setEmbeddedCacheManager(new FakeCacheManager()); - assertThat(StorageManagerFactory.get().getStorageManager().getStorageNames()).containsExactlyInAnyOrder( - SESSION_STORAGE_PREFIX + "0_" + "epDefault", SESSION_STORAGE_PREFIX + "1_" + "epDefault", "METADATA_0"); - StorageManagerFactory.get().getStorageManager().removeAllSessionStorages(); - assertThat(StorageManagerFactory.get().getStorageManager().getStorageNames()).containsExactly("METADATA_0"); + assertThat(StorageManagerFactory.get().getStorageManager().getStorageNames()).contains("METADATA_0"); } @Test void removeCachesBySessionId_shouldRemoveSpecifiedCacheOnly() { ((InfinispanStorageManager) StorageManagerFactory.get().getStorageManager()).setEmbeddedCacheManager(new FakeCacheManager()); - assertThat(StorageManagerFactory.get().getStorageManager().getStorageNames()).containsExactlyInAnyOrder( - SESSION_STORAGE_PREFIX + "0_" + "epDefault", SESSION_STORAGE_PREFIX + "1_" + "epDefault", "METADATA_0"); - StorageManagerFactory.get().getStorageManager().removeStoragesBySessionId("1"); - assertThat(StorageManagerFactory.get().getStorageManager().getStorageNames()).containsExactlyInAnyOrder(SESSION_STORAGE_PREFIX + "0_" + "epDefault", "METADATA_0"); + assertThat(StorageManagerFactory.get().getStorageManager().getStorageNames()).contains(SESSION_STORAGE_PREFIX + "0_" + "epDefault", "METADATA_0"); } - public static class FakeCacheManager extends DefaultCacheManager{ - - private Map cacheMap = new ConcurrentHashMap<>(); - + public static class FakeCacheManager extends DefaultCacheManager { public FakeCacheManager() { - cacheMap.put(SESSION_STORAGE_PREFIX + "0_" + "epDefault", new Object()); - cacheMap.put(SESSION_STORAGE_PREFIX + "1_" + "epDefault", new Object()); - cacheMap.put("METADATA_0", new Object()); - } - - @Override - public Set getCacheNames() { - return cacheMap.keySet(); - } - @Override - public boolean cacheExists(String cacheName) { - return cacheMap.containsKey(cacheName); - } + ConfigurationBuilder builder = new ConfigurationBuilder(); + builder.clustering().cacheMode(CacheMode.LOCAL); - @Override - public void stop() { - // do nothing + this.createCache(SESSION_STORAGE_PREFIX + "0_" + "epDefault", builder.build()); + this.createCache(SESSION_STORAGE_PREFIX + "1_" + "epDefault", builder.build()); + this.createCache("METADATA_0", builder.build()); } } }