From 9e8943fe11ca5f04136aba5940fa0cbd754f0542 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 | 5 +-- .../test/EmbeddedStorageManagerTest.java | 42 +++++-------------- 2 files changed, 12 insertions(+), 35 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 d03cf43797f..892ad14a062 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 @@ -79,8 +79,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 +115,7 @@ public void close() { @Override public void removeStorage(String storageName) { if (embeddedCacheManager.cacheExists(storageName)) { - cacheContainerAdmin.removeCache(storageName); + embeddedCacheManager.administration().removeCache(storageName); } } @@ -180,6 +178,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 5e8f5b52d92..60fd4949e76 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()); } } }