Search in sources :

Example 1 with PersonCacheLoaderFactory

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);
    }
}
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 PersonCacheLoaderFactory

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);
}
Also used : PersonCacheLoaderFactory(classloading.domain.PersonCacheLoaderFactory) Data(com.hazelcast.internal.serialization.Data) Person(classloading.domain.Person) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) CacheConfigTest(com.hazelcast.config.CacheConfigTest) Test(org.junit.Test)

Example 3 with 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());
}
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)

Aggregations

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