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));
}
});
}
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());
}
});
}
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);
}
});
}
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);
}
});
}
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));
}
});
}
Aggregations