use of classloading.domain.PersonCacheLoaderFactory in project hazelcast by hazelcast.
the class CacheTypesConfigTest method cacheConfigShouldBeAddedOnJoiningMember_whenCacheLoaderFactoryNotResolvableWithClassLoaderSet.
// tests deferred resolution of factories, with context class loader set correctly
@Test
public void cacheConfigShouldBeAddedOnJoiningMember_whenCacheLoaderFactoryNotResolvableWithClassLoaderSet() throws InterruptedException {
HazelcastInstance hz1 = factory.newHazelcastInstance(getConfig());
CachingProvider cachingProvider = createServerCachingProvider(hz1);
CacheManager cacheManager1 = cachingProvider.getCacheManager(null, null, propertiesByInstanceItself(hz1));
CacheConfig<String, Person> cacheConfig = createCacheConfig();
cacheConfig.setCacheLoaderFactory(new PersonCacheLoaderFactory());
cacheManager1.createCache(cacheName, cacheConfig);
// joining member cannot resolve PersonCacheLoaderFactory class
HazelcastInstance hz2 = factory.newHazelcastInstance(getClassFilteringConfig());
assertClusterSize(2, hz1, hz2);
ICache<String, Person> cache = hz2.getCacheManager().getCache(cacheName);
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(hz2.getConfig().getClassLoader());
CacheProxy<String, Person> cacheProxy = (CacheProxy<String, Person>) cache;
CacheService cacheService = (CacheService) cacheProxy.getService();
expect.expectCause(new RootCauseMatcher(ClassNotFoundException.class, "classloading.domain.PersonCacheLoaderFactory - " + "Package excluded explicitly"));
cacheService.getCacheConfig(cache.getPrefixedName()).getCacheLoaderFactory();
String key = generateKeyOwnedBy(hz2);
cache.invoke(key, new PersonEntryProcessor());
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
use of classloading.domain.PersonCacheLoaderFactory in project hazelcast by hazelcast.
the class PreJoinCacheConfigTest method serializationSucceeds_cacheLoaderFactory.
@Test
public void serializationSucceeds_cacheLoaderFactory() {
CacheConfig<String, Person> cacheConfig = newDefaultCacheConfig("test");
cacheConfig.setCacheLoaderFactory(new PersonCacheLoaderFactory());
PreJoinCacheConfig preJoinCacheConfig = new PreJoinCacheConfig(cacheConfig);
Data data = serializationService.toData(preJoinCacheConfig);
PreJoinCacheConfig deserialized = serializationService.toObject(data);
assertEquals(preJoinCacheConfig, deserialized);
assertEquals(cacheConfig, deserialized.asCacheConfig());
assertTrue("Invalid Factory Class", deserialized.getCacheLoaderFactory() instanceof PersonCacheLoaderFactory);
}
use of classloading.domain.PersonCacheLoaderFactory in project hazelcast by hazelcast.
the class CacheTypesConfigTest method cacheConfigShouldBeAddedOnJoiningMember_whenCacheLoaderFactoryNotResolvable.
// tests deferred resolution of factories
@Test
public void cacheConfigShouldBeAddedOnJoiningMember_whenCacheLoaderFactoryNotResolvable() throws InterruptedException {
HazelcastInstance hz1 = factory.newHazelcastInstance(getConfig());
CachingProvider cachingProvider = createServerCachingProvider(hz1);
CacheManager cacheManager1 = cachingProvider.getCacheManager(null, null, propertiesByInstanceItself(hz1));
CacheConfig cacheConfig = createCacheConfig();
cacheConfig.setCacheLoaderFactory(new PersonCacheLoaderFactory());
cacheManager1.createCache(cacheName, cacheConfig);
// joining member cannot resolve PersonCacheLoaderFactory class
HazelcastInstance hz2 = factory.newHazelcastInstance(getClassFilteringConfig());
assertClusterSize(2, hz1, hz2);
ICache<String, Person> cache = hz2.getCacheManager().getCache(cacheName);
String key = generateKeyOwnedBy(hz2);
expect.expectCause(new RootCauseMatcher(ClassNotFoundException.class, "classloading.domain.PersonCacheLoaderFactory - " + "Package excluded explicitly"));
cache.invoke(key, new PersonEntryProcessor());
}
Aggregations