Search in sources :

Example 11 with FilteringClassLoader

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

the class CacheTypesConfigTest method getClassFilteringConfig.

private Config getClassFilteringConfig() {
    List<String> excludes = Arrays.asList("classloading");
    ClassLoader classLoader = new FilteringClassLoader(excludes, null);
    return getConfig().setClassLoader(classLoader);
}
Also used : FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader)

Example 12 with FilteringClassLoader

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

the class ClientUserCodeDeploymentTest method createNodeConfig.

private Config createNodeConfig() {
    Config config = new Config();
    FilteringClassLoader filteringCL = new FilteringClassLoader(singletonList("usercodedeployment"), null);
    config.setClassLoader(filteringCL);
    config.getUserCodeDeploymentConfig().setEnabled(true).setClassCacheMode(classCacheMode).setProviderMode(providerMode);
    return config;
}
Also used : AttributeConfig(com.hazelcast.config.AttributeConfig) UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientUserCodeDeploymentConfig(com.hazelcast.client.config.ClientUserCodeDeploymentConfig) Config(com.hazelcast.config.Config) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader)

Example 13 with FilteringClassLoader

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

the class UserCodeDeploymentBasicTest method givenTheEPButItIsBlacklisted_whenTheEPIsFilteredLocally_thenItWillFailToLoadIt.

@Test
public void givenTheEPButItIsBlacklisted_whenTheEPIsFilteredLocally_thenItWillFailToLoadIt() {
    Config i1Config = new Config();
    i1Config.getUserCodeDeploymentConfig().setEnabled(true).setClassCacheMode(classCacheMode);
    Config i2Config = new Config();
    FilteringClassLoader filteringCL = new FilteringClassLoader(singletonList("usercodedeployment"), null);
    i2Config.setClassLoader(filteringCL);
    i2Config.getUserCodeDeploymentConfig().setEnabled(true).setBlacklistedPrefixes("usercodedeployment.blacklisted").setClassCacheMode(classCacheMode);
    EntryProcessor<Integer, Integer, Integer> myEP = new BlacklistedEP();
    try {
        executeSimpleTestScenario(i1Config, i2Config, myEP);
        fail();
    } catch (Exception e) {
        assertInstanceOfByClassName(HazelcastSerializationException.class.getName(), e);
    }
}
Also used : UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) Config(com.hazelcast.config.Config) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) BlacklistedEP(usercodedeployment.blacklisted.BlacklistedEP) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with FilteringClassLoader

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

the class UserCodeDeploymentBasicTest method givenInnerClassOneIsCachedInServer1_whenInnerClassTwoIsRequested_thenServer1RespondsNull.

@Test
public void givenInnerClassOneIsCachedInServer1_whenInnerClassTwoIsRequested_thenServer1RespondsNull() {
    Config config = new Config();
    config.getUserCodeDeploymentConfig().setEnabled(true);
    Config configWithoutEnclosingClass = new Config();
    FilteringClassLoader filteringCL = new FilteringClassLoader(asList("usercodedeployment"), null);
    configWithoutEnclosingClass.setClassLoader(filteringCL);
    configWithoutEnclosingClass.getUserCodeDeploymentConfig().setEnabled(true);
    ClassWithTwoInnerClasses.StaticNestedIncrementingEntryProcessor<String> ep = new ClassWithTwoInnerClasses.StaticNestedIncrementingEntryProcessor<String>();
    HazelcastInstance instance1WithoutEp = factory.newHazelcastInstance(configWithoutEnclosingClass);
    HazelcastInstance instance2WithoutEp = factory.newHazelcastInstance(configWithoutEnclosingClass);
    // instance with ep
    factory.newHazelcastInstance(config);
    String mapName = randomName();
    IMap<String, Integer> map = instance1WithoutEp.getMap(mapName);
    String key = generateKeyOwnedBy(instance2WithoutEp);
    map.put(key, 0);
    map.executeOnEntries(ep);
    assertEquals(1, (int) map.get(key));
    ClassWithTwoInnerClasses.StaticNestedDecrementingEntryProcessor ep2 = new ClassWithTwoInnerClasses.StaticNestedDecrementingEntryProcessor();
    // executing ep on instance without that ep
    map.executeOnKey(key, ep2);
    assertEquals(0, (int) map.get(key));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) Config(com.hazelcast.config.Config) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) ClassWithTwoInnerClasses(usercodedeployment.ClassWithTwoInnerClasses) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with FilteringClassLoader

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

the class UserCodeDeploymentBasicTest method givenTheEPButItIsNotOnTheWhitelist_whenTheEPIsFilteredLocally_thenItWillFailToLoadIt.

@Test
public void givenTheEPButItIsNotOnTheWhitelist_whenTheEPIsFilteredLocally_thenItWillFailToLoadIt() {
    Config i1Config = new Config();
    i1Config.getUserCodeDeploymentConfig().setEnabled(true).setClassCacheMode(classCacheMode);
    Config i2Config = new Config();
    FilteringClassLoader filteringCL = new FilteringClassLoader(singletonList("usercodedeployment"), null);
    i2Config.setClassLoader(filteringCL);
    i2Config.getUserCodeDeploymentConfig().setEnabled(true).setWhitelistedPrefixes("usercodedeployment.whitelisted").setClassCacheMode(classCacheMode);
    EntryProcessor<Integer, Integer, Integer> myEP = new IncrementingEntryProcessor();
    try {
        executeSimpleTestScenario(i1Config, i2Config, myEP);
        fail();
    } catch (Exception e) {
        assertInstanceOfByClassName(HazelcastSerializationException.class.getName(), e);
    }
}
Also used : UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) Config(com.hazelcast.config.Config) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) IncrementingEntryProcessor(usercodedeployment.IncrementingEntryProcessor) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

FilteringClassLoader (com.hazelcast.internal.util.FilteringClassLoader)21 Config (com.hazelcast.config.Config)18 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)13 QuickTest (com.hazelcast.test.annotation.QuickTest)13 Test (org.junit.Test)13 UserCodeDeploymentConfig (com.hazelcast.config.UserCodeDeploymentConfig)12 IncrementingEntryProcessor (usercodedeployment.IncrementingEntryProcessor)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 ClientUserCodeDeploymentConfig (com.hazelcast.client.config.ClientUserCodeDeploymentConfig)2 MapConfig (com.hazelcast.config.MapConfig)2 BeforeClass (org.junit.BeforeClass)2 DomainClassWithInnerClass (usercodedeployment.DomainClassWithInnerClass)2 AttributeConfig (com.hazelcast.config.AttributeConfig)1 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)1 SerializationConfig (com.hazelcast.config.SerializationConfig)1 Data (com.hazelcast.internal.serialization.Data)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)1