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);
}
}
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());
}
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());
}
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);
}
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);
}
Aggregations