Search in sources :

Example 61 with RootCauseMatcher

use of com.hazelcast.internal.util.RootCauseMatcher in project hazelcast by hazelcast.

the class AbstractJavaXCacheDependencyTest method createHazelcastInstance.

private void createHazelcastInstance(boolean testGetCacheManager, boolean testGetCache) throws Exception {
    Thread thread = Thread.currentThread();
    ClassLoader tccl = thread.getContextClassLoader();
    thread.setContextClassLoader(CLASS_LOADER);
    try {
        Class<?> configClazz = CLASS_LOADER.loadClass(getConfigClass());
        Class<?> hazelcastClazz = CLASS_LOADER.loadClass(getHazelcastClass());
        Class<?> hazelcastInstanceClazz = CLASS_LOADER.loadClass("com.hazelcast.core.HazelcastInstance");
        Class<?> cacheManagerClazz = CLASS_LOADER.loadClass("com.hazelcast.core.ICacheManager");
        try {
            Object config = configClazz.newInstance();
            Method setClassLoader = configClazz.getDeclaredMethod("setClassLoader", ClassLoader.class);
            setClassLoader.invoke(config, CLASS_LOADER);
            Method newHazelcastInstance = hazelcastClazz.getDeclaredMethod(getNewInstanceMethod(), configClazz);
            Object hazelcastInstance = newHazelcastInstance.invoke(hazelcastClazz, config);
            if (testGetCacheManager) {
                Method getCacheManager = hazelcastInstanceClazz.getDeclaredMethod("getCacheManager");
                getCacheManager.invoke(hazelcastInstance);
            }
            if (testGetCache) {
                expectedException.expect(new RootCauseMatcher(ClassNotFoundException.class, EXPECTED_CAUSE));
                cacheManagerClazz.getDeclaredMethod("getCache", String.class);
            }
        } finally {
            Method shutdownAll = hazelcastClazz.getDeclaredMethod("shutdownAll");
            shutdownAll.invoke(hazelcastClazz);
        }
    } finally {
        thread.setContextClassLoader(tccl);
    }
}
Also used : FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) Method(java.lang.reflect.Method) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher)

Example 62 with RootCauseMatcher

use of com.hazelcast.internal.util.RootCauseMatcher 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 63 with RootCauseMatcher

use of com.hazelcast.internal.util.RootCauseMatcher 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)

Example 64 with RootCauseMatcher

use of com.hazelcast.internal.util.RootCauseMatcher in project hazelcast by hazelcast.

the class YamlClientConfigBuilderTest method testNullInMapThrows.

@Test
public void testNullInMapThrows() {
    String yaml = "" + "hazelcast-client:\n" + "  group:\n" + "  name: instanceName";
    expected.expect(new RootCauseMatcher(InvalidConfigurationException.class, "hazelcast-client/group"));
    buildConfig(yaml);
}
Also used : RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) QuickTest(com.hazelcast.test.annotation.QuickTest) YamlConfigBuilderTest(com.hazelcast.config.YamlConfigBuilderTest) Test(org.junit.Test)

Example 65 with RootCauseMatcher

use of com.hazelcast.internal.util.RootCauseMatcher in project hazelcast by hazelcast.

the class YamlClientConfigBuilderTest method testNullInSequenceThrows.

@Test
public void testNullInSequenceThrows() {
    String yaml = "" + "hazelcast-client:\n" + "  client-labels:\n" + "    - admin\n" + "    -\n";
    expected.expect(new RootCauseMatcher(InvalidConfigurationException.class, "hazelcast-client/client-labels"));
    buildConfig(yaml);
}
Also used : RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) QuickTest(com.hazelcast.test.annotation.QuickTest) YamlConfigBuilderTest(com.hazelcast.config.YamlConfigBuilderTest) Test(org.junit.Test)

Aggregations

RootCauseMatcher (com.hazelcast.internal.util.RootCauseMatcher)122 QuickTest (com.hazelcast.test.annotation.QuickTest)118 Test (org.junit.Test)118 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)106 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)64 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)31 CompletableFutureTestUtil (com.hazelcast.spi.impl.operationservice.impl.CompletableFutureTestUtil)26 CancellationException (java.util.concurrent.CancellationException)25 CountDownLatch (java.util.concurrent.CountDownLatch)25 CALLER_RUNS (com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS)24 InternalCompletableFuture.newCompletedFuture (com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture)24 CountingExecutor (com.hazelcast.spi.impl.operationservice.impl.CompletableFutureTestUtil.CountingExecutor)24 CompletableFutureTestUtil.ignore (com.hazelcast.spi.impl.operationservice.impl.CompletableFutureTestUtil.ignore)24 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)24 HazelcastTestSupport.assertInstanceOf (com.hazelcast.test.HazelcastTestSupport.assertInstanceOf)24 HazelcastTestSupport.assertOpenEventually (com.hazelcast.test.HazelcastTestSupport.assertOpenEventually)24 HazelcastTestSupport.assertTrueEventually (com.hazelcast.test.HazelcastTestSupport.assertTrueEventually)24 CompletableFuture (java.util.concurrent.CompletableFuture)24 CompletionException (java.util.concurrent.CompletionException)24 CompletionStage (java.util.concurrent.CompletionStage)24