Search in sources :

Example 1 with MultiCacheManagerCallable

use of org.infinispan.test.MultiCacheManagerCallable in project infinispan by infinispan.

the class CacheManagerTest method testCacheManagerRestartReusingConfigurations.

public void testCacheManagerRestartReusingConfigurations() {
    withCacheManagers(new MultiCacheManagerCallable(createCacheManager(CacheMode.REPL_SYNC, false), createCacheManager(CacheMode.REPL_SYNC, false)) {

        @Override
        public void call() {
            EmbeddedCacheManager cm1 = cms[0];
            EmbeddedCacheManager cm2 = cms[1];
            waitForNoRebalance(cm1.getCache(), cm2.getCache());
            Cache<Object, Object> c1 = cm1.getCache();
            GlobalConfiguration globalCfg = cm1.getCacheManagerConfiguration();
            Configuration cfg = c1.getCacheConfiguration();
            killCacheManagers(cm1);
            ConfigurationBuilderHolder holder = new ConfigurationBuilderHolder();
            holder.getGlobalConfigurationBuilder().read(globalCfg);
            holder.getNamedConfigurationBuilders().put(TestCacheManagerFactory.DEFAULT_CACHE_NAME, new ConfigurationBuilder().read(cfg));
            withCacheManager(new CacheManagerCallable(new DefaultCacheManager(holder, true)) {

                @Override
                public void call() {
                    Cache<Object, Object> c = cm.getCache();
                    c.put(1, "v1");
                    assertEquals("v1", c.get(1));
                }
            });
        }
    });
}
Also used : TestGlobalConfigurationBuilder(org.infinispan.commands.module.TestGlobalConfigurationBuilder) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) AbstractStoreConfigurationBuilder(org.infinispan.configuration.cache.AbstractStoreConfigurationBuilder) DummyInMemoryStoreConfigurationBuilder(org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder) PersistenceConfigurationBuilder(org.infinispan.configuration.cache.PersistenceConfigurationBuilder) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) AsyncStoreConfiguration(org.infinispan.configuration.cache.AsyncStoreConfiguration) InterceptorConfiguration(org.infinispan.configuration.cache.InterceptorConfiguration) AbstractStoreConfiguration(org.infinispan.configuration.cache.AbstractStoreConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) MultiCacheManagerCallable(org.infinispan.test.MultiCacheManagerCallable) CacheManagerCallable(org.infinispan.test.CacheManagerCallable) MultiCacheManagerCallable(org.infinispan.test.MultiCacheManagerCallable) Cache(org.infinispan.Cache)

Example 2 with MultiCacheManagerCallable

use of org.infinispan.test.MultiCacheManagerCallable in project infinispan by infinispan.

the class ServerEventLoggerTest method testClusteredServerEventLogging.

@Test
public void testClusteredServerEventLogging() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.clustering().cacheMode(CacheMode.DIST_SYNC);
    withCacheManagers(new MultiCacheManagerCallable(TestCacheManagerFactory.createClusteredCacheManager(amendGlobalConfiguration(GlobalConfigurationBuilder.defaultClusteredBuilder()), builder), TestCacheManagerFactory.createClusteredCacheManager(amendGlobalConfiguration(GlobalConfigurationBuilder.defaultClusteredBuilder()), builder), TestCacheManagerFactory.createClusteredCacheManager(amendGlobalConfiguration(GlobalConfigurationBuilder.defaultClusteredBuilder()), builder)) {

        @Override
        public void call() {
            int msg = 1;
            blockUntilViewReceived(cms[0].getCache(), 3);
            // Fill all nodes with logs
            for (int i = 0; i < cms.length; i++) {
                EventLogger eventLogger = EventLogManager.getEventLogger(cms[i]);
                assertTrue(eventLogger.getClass().getName(), eventLogger instanceof ServerEventLogger);
                eventLogger.info(EventLogCategory.SECURITY, "message #" + msg++);
                eventLogger.warn(EventLogCategory.SECURITY, "message #" + msg++);
                eventLogger.info(EventLogCategory.TASKS, "message #" + msg++);
                eventLogger.warn(EventLogCategory.TASKS, "message #" + msg++);
            }
            // query all nodes
            for (int i = 0; i < cms.length; i++) {
                log.debugf("Checking logs on %s", cms[i].getAddress());
                EventLogger eventLogger = EventLogManager.getEventLogger(cms[i]);
                List<EventLog> events = waitForEvents(2 * cms.length, eventLogger, EventLogCategory.TASKS, null);
                for (EventLog event : events) {
                    assertEquals(EventLogCategory.TASKS, event.getCategory());
                }
                events = getLatestEvents(eventLogger, null, EventLogLevel.INFO);
                for (EventLog event : events) {
                    assertEquals(EventLogLevel.INFO, event.getLevel());
                }
            }
        }
    });
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) ServerEventLogger(org.infinispan.server.logging.events.ServerEventLogger) EventLogger(org.infinispan.util.logging.events.EventLogger) EventLog(org.infinispan.util.logging.events.EventLog) MultiCacheManagerCallable(org.infinispan.test.MultiCacheManagerCallable) List(java.util.List) ServerEventLogger(org.infinispan.server.logging.events.ServerEventLogger) Test(org.junit.Test)

Example 3 with MultiCacheManagerCallable

use of org.infinispan.test.MultiCacheManagerCallable in project infinispan by infinispan.

the class ProtobufMetadataCacheStartedTest method testMetadataCacheStarted.

public void testMetadataCacheStarted() throws Exception {
    String persistentStateLocation = CommonsTestingUtil.tmpDirectory(getClass());
    Util.recursiveFileRemove(persistentStateLocation);
    final String persistentStateLocation1 = persistentStateLocation + "/1";
    final String persistentStateLocation2 = persistentStateLocation + "/2";
    TestingUtil.withCacheManagers(new MultiCacheManagerCallable(createCacheManager(persistentStateLocation1), createCacheManager(persistentStateLocation2)) {

        @Override
        public void call() {
            assertTrue(cms[0].isRunning(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME));
            assertTrue(cms[1].isRunning(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME));
        }
    });
}
Also used : MultiCacheManagerCallable(org.infinispan.test.MultiCacheManagerCallable)

Example 4 with MultiCacheManagerCallable

use of org.infinispan.test.MultiCacheManagerCallable in project infinispan by infinispan.

the class MultiStoresFunctionalTest method testStartStopOfBackupDoesntRewriteValue.

/**
 * when a node that persisted KEY wakes up, it can't rewrite existing value.
 */
public void testStartStopOfBackupDoesntRewriteValue(Method m) throws Exception {
    final List<ConfigurationBuilder> configs = configs(2, m);
    withCacheManagers(new MultiCacheManagerCallable(TestCacheManagerFactory.createClusteredCacheManager(configs.get(0)), TestCacheManagerFactory.createClusteredCacheManager(configs.get(1))) {

        @Override
        public void call() {
            final EmbeddedCacheManager cacheManager0 = cms[0];
            final EmbeddedCacheManager cacheManager1 = cms[1];
            final Cache<String, String> cache0 = cacheManager0.getCache();
            final Cache<String, String> cache1 = cacheManager1.getCache();
            TestingUtil.blockUntilViewsChanged(TIMEOUT, 2, cache0, cache1);
            cache0.put("KEY", "VALUE V1");
            assertEquals("VALUE V1", cache1.get("KEY"));
            TestingUtil.killCacheManagers(cacheManager1);
            TestingUtil.blockUntilViewsChanged(TIMEOUT, 1, cache0);
            cache0.put("KEY", "VALUE V2");
            assertEquals("VALUE V2", cache0.get("KEY"));
            withCacheManager(new CacheManagerCallable(TestCacheManagerFactory.createClusteredCacheManager(configs.get(1))) {

                @Override
                public void call() {
                    Cache<String, String> newCache = cm.getCache();
                    TestingUtil.blockUntilViewsChanged(TIMEOUT, 2, cache0, newCache);
                    assertEquals("VALUE V2", newCache.get("KEY"));
                }
            });
        }
    });
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) AbstractStoreConfigurationBuilder(org.infinispan.configuration.cache.AbstractStoreConfigurationBuilder) PersistenceConfigurationBuilder(org.infinispan.configuration.cache.PersistenceConfigurationBuilder) MultiCacheManagerCallable(org.infinispan.test.MultiCacheManagerCallable) CacheManagerCallable(org.infinispan.test.CacheManagerCallable) MultiCacheManagerCallable(org.infinispan.test.MultiCacheManagerCallable) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Cache(org.infinispan.Cache)

Example 5 with MultiCacheManagerCallable

use of org.infinispan.test.MultiCacheManagerCallable in project infinispan by infinispan.

the class MultiStoresFunctionalTest method testStartStopOfBackupResurrectsDeletedKey.

/**
 * When node that persisted KEY2 it will resurrect previous value of KEY2.
 */
public void testStartStopOfBackupResurrectsDeletedKey(Method m) throws Exception {
    final List<ConfigurationBuilder> configs = configs(2, m);
    withCacheManagers(new MultiCacheManagerCallable(TestCacheManagerFactory.createClusteredCacheManager(configs.get(0)), TestCacheManagerFactory.createClusteredCacheManager(configs.get(1))) {

        @Override
        public void call() {
            final EmbeddedCacheManager cacheManager0 = cms[0];
            final EmbeddedCacheManager cacheManager1 = cms[1];
            final Cache<String, String> cache0 = cacheManager0.getCache();
            final Cache<String, String> cache1 = cacheManager1.getCache();
            TestingUtil.blockUntilViewsChanged(TIMEOUT, 2, cache0, cache1);
            cache0.put("KEY2", "VALUE2 V1");
            assertEquals("VALUE2 V1", cache1.get("KEY2"));
            TestingUtil.killCacheManagers(cacheManager1);
            TestingUtil.blockUntilViewsChanged(TIMEOUT, 1, cache0);
            cache0.put("KEY2", "VALUE2 V2");
            assertEquals("VALUE2 V2", cache0.get("KEY2"));
            cache0.remove("KEY2");
            assertEquals(null, cache0.get("KEY2"));
            withCacheManager(new CacheManagerCallable(TestCacheManagerFactory.createClusteredCacheManager(configs.get(1))) {

                @Override
                public void call() {
                    Cache<String, String> newCache = cm.getCache();
                    TestingUtil.blockUntilViewsChanged(TIMEOUT, 2, cache0, newCache);
                    assertEquals("VALUE2 V1", newCache.get("KEY2"));
                }
            });
        }
    });
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) AbstractStoreConfigurationBuilder(org.infinispan.configuration.cache.AbstractStoreConfigurationBuilder) PersistenceConfigurationBuilder(org.infinispan.configuration.cache.PersistenceConfigurationBuilder) MultiCacheManagerCallable(org.infinispan.test.MultiCacheManagerCallable) CacheManagerCallable(org.infinispan.test.CacheManagerCallable) MultiCacheManagerCallable(org.infinispan.test.MultiCacheManagerCallable) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Cache(org.infinispan.Cache)

Aggregations

MultiCacheManagerCallable (org.infinispan.test.MultiCacheManagerCallable)8 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)5 Cache (org.infinispan.Cache)4 AbstractStoreConfigurationBuilder (org.infinispan.configuration.cache.AbstractStoreConfigurationBuilder)3 PersistenceConfigurationBuilder (org.infinispan.configuration.cache.PersistenceConfigurationBuilder)3 CacheManagerCallable (org.infinispan.test.CacheManagerCallable)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2 AbstractInfinispanTest (org.infinispan.test.AbstractInfinispanTest)2 Test (org.testng.annotations.Test)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 Exchanger (java.util.concurrent.Exchanger)1 ExecutorService (java.util.concurrent.ExecutorService)1