Skip to content

Commit

Permalink
Fixing infinispan upgrade test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
RishiRajAnand committed Nov 28, 2024
1 parent fdd9122 commit f81509f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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";
Expand All @@ -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)
Expand Down Expand Up @@ -117,7 +109,7 @@ public void close() {
@Override
public void removeStorage(String storageName) {
if (embeddedCacheManager.cacheExists(storageName)) {
cacheContainerAdmin.removeCache(storageName);
embeddedCacheManager.administration().removeCache(storageName);
}
}

Expand Down Expand Up @@ -180,6 +172,7 @@ public void setEmbeddedCacheManager(DefaultCacheManager embeddedCacheManager) {
this.embeddedCacheManager.stop();
}
this.embeddedCacheManager = embeddedCacheManager;

}

// test purpose to remove GlobalState and FileStore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Object> 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<String> 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());
}
}
}

0 comments on commit f81509f

Please sign in to comment.