use of classloading.domain.PersonEntryProcessor 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.PersonEntryProcessor in project hazelcast by hazelcast.
the class CacheTypesConfigTest method cacheConfigShouldBeAddedOnJoiningMember_whenKVTypesAvailableViaUserCodeDeployment.
// When the joining member is not aware of key or value class but it is later resolvable via user code deployment, then
// all Cache features should work
@Test
public void cacheConfigShouldBeAddedOnJoiningMember_whenKVTypesAvailableViaUserCodeDeployment() {
// create a HazelcastInstance with a CacheConfig referring to a Class resolvable via user code deployment
Config config = getConfig();
UserCodeDeploymentConfig codeDeploymentConfig = new UserCodeDeploymentConfig().setEnabled(true).setClassCacheMode(OFF).setWhitelistedPrefixes("classloading");
config.setUserCodeDeploymentConfig(codeDeploymentConfig);
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
CachingProvider cachingProvider = createServerCachingProvider(hz1);
cachingProvider.getCacheManager().createCache(cacheName, createCacheConfig());
// joining member cannot resolve Person class but it is resolvable on other member via user code deployment
Config joiningMemberConfig = getClassFilteringConfig();
joiningMemberConfig.setUserCodeDeploymentConfig(codeDeploymentConfig);
HazelcastInstance hz2 = factory.newHazelcastInstance(joiningMemberConfig);
assertClusterSize(2, hz1, hz2);
ICache<String, Person> testCache = hz1.getCacheManager().getCache(cacheName);
String key = generateKeyOwnedBy(hz2);
testCache.put(key, new Person());
testCache.invoke(key, new PersonEntryProcessor());
assertNotNull(testCache.get(key));
}
use of classloading.domain.PersonEntryProcessor in project hazelcast by hazelcast.
the class CacheTypesConfigTest method cacheConfigShouldBeAddedOnJoiningMember_whenExpiryPolicyFactoryNotResolvable.
// tests deferred resolution of expiry policy factory
@Test
public void cacheConfigShouldBeAddedOnJoiningMember_whenExpiryPolicyFactoryNotResolvable() throws InterruptedException {
HazelcastInstance hz1 = factory.newHazelcastInstance(getConfig());
CachingProvider cachingProvider = createServerCachingProvider(hz1);
cachingProvider.getCacheManager().createCache(cacheName, createCacheConfig().setExpiryPolicyFactory(new PersonExpiryPolicyFactory()));
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.PersonExpiryPolicyFactory - " + "Package excluded explicitly"));
cache.invoke(key, new PersonEntryProcessor());
}
use of classloading.domain.PersonEntryProcessor 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());
}
use of classloading.domain.PersonEntryProcessor in project hazelcast by hazelcast.
the class CacheTypesConfigTest method cacheConfigShouldBeAddedOnJoiningMember_whenClassNotResolvable.
// Even when the key or value class is not present in the classpath of the target member, a joining member will join.
// Some Cache operations that require deserialization on the member will fail (eg entry processors)
@Test
public void cacheConfigShouldBeAddedOnJoiningMember_whenClassNotResolvable() {
// create a HazelcastInstance with a CacheConfig referring to a Class not resolvable on the joining member
HazelcastInstance hz1 = factory.newHazelcastInstance(getConfig());
CachingProvider cachingProvider = createServerCachingProvider(hz1);
cachingProvider.getCacheManager().createCache(cacheName, createCacheConfig());
// joining member cannot resolve Person class
HazelcastInstance hz2 = factory.newHazelcastInstance(getClassFilteringConfig());
assertClusterSize(2, hz1, hz2);
ICache<String, Person> cache = hz1.getCacheManager().getCache(cacheName);
String key = generateKeyOwnedBy(hz2);
// a simple put will work as hz2 will just receive a Data value blob
cache.put(key, new Person());
expect.expectCause(new RootCauseMatcher(ClassNotFoundException.class, "classloading.domain.PersonEntryProcessor - " + "Package excluded explicitly"));
cache.invoke(key, new PersonEntryProcessor());
}
Aggregations