Search in sources :

Example 1 with PersonEntryProcessor

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);
    }
}
Also used : RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) HazelcastInstance(com.hazelcast.core.HazelcastInstance) PersonCacheLoaderFactory(classloading.domain.PersonCacheLoaderFactory) CacheProxy(com.hazelcast.cache.impl.CacheProxy) CacheManager(javax.cache.CacheManager) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) Person(classloading.domain.Person) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) CacheService(com.hazelcast.cache.impl.CacheService) PersonEntryProcessor(classloading.domain.PersonEntryProcessor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with PersonEntryProcessor

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));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) Person(classloading.domain.Person) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) PersonEntryProcessor(classloading.domain.PersonEntryProcessor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with PersonEntryProcessor

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PersonExpiryPolicyFactory(classloading.domain.PersonExpiryPolicyFactory) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) Person(classloading.domain.Person) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) PersonEntryProcessor(classloading.domain.PersonEntryProcessor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with 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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PersonCacheLoaderFactory(classloading.domain.PersonCacheLoaderFactory) CacheManager(javax.cache.CacheManager) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) CacheConfig(com.hazelcast.config.CacheConfig) Person(classloading.domain.Person) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) PersonEntryProcessor(classloading.domain.PersonEntryProcessor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with 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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) Person(classloading.domain.Person) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) PersonEntryProcessor(classloading.domain.PersonEntryProcessor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Person (classloading.domain.Person)5 PersonEntryProcessor (classloading.domain.PersonEntryProcessor)5 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 CachingProvider (javax.cache.spi.CachingProvider)5 Test (org.junit.Test)5 RootCauseMatcher (com.hazelcast.internal.util.RootCauseMatcher)4 PersonCacheLoaderFactory (classloading.domain.PersonCacheLoaderFactory)2 CacheConfig (com.hazelcast.config.CacheConfig)2 CacheManager (javax.cache.CacheManager)2 PersonExpiryPolicyFactory (classloading.domain.PersonExpiryPolicyFactory)1 CacheProxy (com.hazelcast.cache.impl.CacheProxy)1 CacheService (com.hazelcast.cache.impl.CacheService)1 Config (com.hazelcast.config.Config)1 UserCodeDeploymentConfig (com.hazelcast.config.UserCodeDeploymentConfig)1 FilteringClassLoader (com.hazelcast.internal.util.FilteringClassLoader)1