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 9e8943f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -117,7 +115,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 +178,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 9e8943f

Please sign in to comment.