Search in sources :

Example 1 with CacheManagerCallable

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

the class CacheMBeanTest method testAvoidLeakOfCacheMBeanWhenCacheStatisticsDisabled.

public void testAvoidLeakOfCacheMBeanWhenCacheStatisticsDisabled(Method m) {
    String otherJmxDomain = "jmx_" + m.getName();
    GlobalConfigurationBuilder gc = new GlobalConfigurationBuilder();
    gc.jmx().enabled(true).domain(otherJmxDomain).mBeanServerLookup(mBeanServerLookup);
    ConfigurationBuilder c = new ConfigurationBuilder();
    c.statistics().available(false);
    withCacheManager(new CacheManagerCallable(TestCacheManagerFactory.createCacheManager(gc, c)) {

        @Override
        public void call() {
            cm.getCache();
            MBeanServer server = mBeanServerLookup.getMBeanServer();
            ObjectName cacheObjectName = getCacheObjectName(otherJmxDomain, getDefaultCacheName() + "(local)");
            assertTrue(cacheObjectName + " should be registered", server.isRegistered(cacheObjectName));
            TestingUtil.killCacheManagers(cm);
            assertFalse(cacheObjectName + " should NOT be registered", server.isRegistered(cacheObjectName));
        }
    });
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) CacheManagerCallable(org.infinispan.test.CacheManagerCallable) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TestingUtil.getCacheObjectName(org.infinispan.test.TestingUtil.getCacheObjectName) TestingUtil.getCacheManagerObjectName(org.infinispan.test.TestingUtil.getCacheManagerObjectName)

Example 2 with CacheManagerCallable

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

the class CustomInterceptorTest method testCustomInterceptorProperties.

public void testCustomInterceptorProperties() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.customInterceptors().addInterceptor().interceptor(new FooInterceptor()).position(Position.FIRST).addProperty("foo", "bar");
    withCacheManager(new CacheManagerCallable(TestCacheManagerFactory.createCacheManager(builder)) {

        @Override
        public void call() {
            final Cache<Object, Object> cache = cm.getCache();
            AsyncInterceptor i = cache.getAdvancedCache().getAsyncInterceptorChain().getInterceptors().get(0);
            assertTrue("Expecting FooInterceptor in the interceptor chain", i instanceof FooInterceptor);
            assertEquals("bar", ((FooInterceptor) i).getFoo());
        }
    });
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) CacheManagerCallable(org.infinispan.test.CacheManagerCallable) Cache(org.infinispan.Cache)

Example 3 with CacheManagerCallable

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

the class CustomInterceptorTest method testOtherThanFirstOrLastInterceptor.

public void testOtherThanFirstOrLastInterceptor() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.customInterceptors().addInterceptor().position(Position.OTHER_THAN_FIRST_OR_LAST).interceptor(new FooInterceptor());
    final EmbeddedCacheManager cacheManager = TestCacheManagerFactory.createCacheManager();
    cacheManager.defineConfiguration("interceptors", builder.build());
    withCacheManager(new CacheManagerCallable(cacheManager) {

        @Override
        public void call() {
            AsyncInterceptorChain interceptorChain = cacheManager.getCache("interceptors").getAdvancedCache().getAsyncInterceptorChain();
            assertEquals(interceptorChain.getInterceptors().get(1).getClass(), FooInterceptor.class);
        }
    });
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) CacheManagerCallable(org.infinispan.test.CacheManagerCallable) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 4 with CacheManagerCallable

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

the class DataConversionTest method testConversionWithListeners.

@Test
public void testConversionWithListeners() {
    ConfigurationBuilder cfg = new ConfigurationBuilder();
    withCacheManager(new CacheManagerCallable(createCacheManager(TestDataSCI.INSTANCE, cfg)) {

        @Override
        public void call() {
            Cache<String, Person> cache = cm.getCache();
            cm.getClassAllowList().addClasses(Person.class);
            // Obtain cache with custom valueEncoder
            Cache storeMarshalled = cache.getAdvancedCache().withEncoding(JavaSerializationEncoder.class);
            // Add a listener
            SimpleListener simpleListener = new SimpleListener();
            storeMarshalled.addListener(simpleListener);
            Person value = new Person();
            storeMarshalled.put("1", value);
            // Assert values returned are passed through the valueEncoder
            assertEquals(simpleListener.events.size(), 1);
            assertEquals(simpleListener.events.get(0).getKey(), "1");
            assertEquals(simpleListener.events.get(0).getValue(), value);
        }
    });
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) CacheManagerCallable(org.infinispan.test.CacheManagerCallable) Person(org.infinispan.test.data.Person) Cache(org.infinispan.Cache) AdvancedCache(org.infinispan.AdvancedCache) JavaSerializationEncoder(org.infinispan.commons.dataconversion.JavaSerializationEncoder) Test(org.testng.annotations.Test) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest)

Example 5 with CacheManagerCallable

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

the class DataConversionTest method testReadUnencoded.

@Test
public void testReadUnencoded() {
    ConfigurationBuilder cfg = new ConfigurationBuilder();
    cfg.memory().storage(StorageType.OFF_HEAP);
    withCacheManager(new CacheManagerCallable(createCacheManager(TestDataSCI.INSTANCE, cfg)) {

        private final EncoderRegistry registry = TestingUtil.extractGlobalComponent(cm, EncoderRegistry.class);

        public Object asStored(Object object) {
            return registry.convert(object, APPLICATION_OBJECT, APPLICATION_PROTOSTREAM);
        }

        @Override
        public void call() {
            cm.getClassAllowList().addClasses(Person.class);
            Cache<String, Person> cache = cm.getCache();
            Person value = new Person();
            cache.put("1", value);
            // Read using default valueEncoder
            assertEquals(cache.get("1"), value);
            // Read unencoded
            Cache<?, ?> unencodedCache = cache.getAdvancedCache().withStorageMediaType();
            assertEquals(unencodedCache.get(asStored("1")), asStored(value));
        }
    });
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) CacheManagerCallable(org.infinispan.test.CacheManagerCallable) EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) Person(org.infinispan.test.data.Person) Cache(org.infinispan.Cache) AdvancedCache(org.infinispan.AdvancedCache) Test(org.testng.annotations.Test) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest)

Aggregations

CacheManagerCallable (org.infinispan.test.CacheManagerCallable)54 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)38 Cache (org.infinispan.Cache)26 Test (org.testng.annotations.Test)20 AbstractInfinispanTest (org.infinispan.test.AbstractInfinispanTest)19 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)18 AdvancedCache (org.infinispan.AdvancedCache)10 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)10 Configuration (org.infinispan.configuration.cache.Configuration)8 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)6 InputStream (java.io.InputStream)4 MultiCacheManagerCallable (org.infinispan.test.MultiCacheManagerCallable)4 Cache (javax.cache.Cache)3 MutableConfiguration (javax.cache.configuration.MutableConfiguration)3 JCacheManager (org.infinispan.jcache.embedded.JCacheManager)3 InMemoryJCacheLoader (org.infinispan.jcache.util.InMemoryJCacheLoader)3 EncoderRegistry (org.infinispan.marshall.core.EncoderRegistry)3 InfinispanDefaultCacheFactoryBean (org.infinispan.spring.embedded.InfinispanDefaultCacheFactoryBean)3 Person (org.infinispan.test.data.Person)3 File (java.io.File)2