Search in sources :

Example 6 with FilteringClassLoader

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

the class UserCodeDeploymentBasicTest method givenProviderFilterUsesMemberAttribute_whenNoMemberHasMatchingAttribute_thenClassLoadingRequestFails.

@Test
public void givenProviderFilterUsesMemberAttribute_whenNoMemberHasMatchingAttribute_thenClassLoadingRequestFails() {
    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).setProviderFilter("HAS_ATTRIBUTE:foo").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)

Example 7 with FilteringClassLoader

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

the class UserCodeDeploymentBasicTest method givenSomeMemberCanAccessTheEP_whenTheEPIsFilteredLocally_thenItWillBeLoadedOverNetwork.

@Test
public void givenSomeMemberCanAccessTheEP_whenTheEPIsFilteredLocally_thenItWillBeLoadedOverNetwork() {
    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).setClassCacheMode(classCacheMode);
    IncrementingEntryProcessor incrementingEntryProcessor = new IncrementingEntryProcessor();
    executeSimpleTestScenario(i1Config, i2Config, incrementingEntryProcessor);
}
Also used : UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) Config(com.hazelcast.config.Config) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) IncrementingEntryProcessor(usercodedeployment.IncrementingEntryProcessor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with FilteringClassLoader

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

the class UserCodeDeploymentBasicTest method testMainClassFetchedFirst_thenInnerlassFetchedFromRemote.

@Test
public void testMainClassFetchedFirst_thenInnerlassFetchedFromRemote() {
    Config i1Config = new Config();
    i1Config.getUserCodeDeploymentConfig().setEnabled(true).setClassCacheMode(classCacheMode);
    Config filteredConfig = new Config();
    FilteringClassLoader filteringCL = new FilteringClassLoader(singletonList("usercodedeployment"), null);
    filteredConfig.setClassLoader(filteringCL);
    filteredConfig.getUserCodeDeploymentConfig().setEnabled(true).setClassCacheMode(classCacheMode);
    HazelcastInstance instanceWithClasses = factory.newHazelcastInstance(i1Config);
    HazelcastInstance instanceWithoutTheClasses = factory.newHazelcastInstance(filteredConfig);
    IMap<Object, Object> map = instanceWithClasses.getMap("test");
    DomainClassWithInnerClass mainDomainObject = new DomainClassWithInnerClass(new DomainClassWithInnerClass.InnerClass(2));
    map.put("main", mainDomainObject);
    DomainClassWithInnerClass.InnerClass innerObject = new DomainClassWithInnerClass.InnerClass(1);
    map.put("inner", innerObject);
    IMap<Object, Object> map2 = instanceWithoutTheClasses.getMap("test");
    map2.get("main");
    map2.get("inner");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) DomainClassWithInnerClass(usercodedeployment.DomainClassWithInnerClass) UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) Config(com.hazelcast.config.Config) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) DomainClassWithInnerClass(usercodedeployment.DomainClassWithInnerClass) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with FilteringClassLoader

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

the class UserCodeDeploymentBasicTest method givenProviderFilterUsesMemberAttribute_whenSomeMemberHasMatchingAttribute_thenClassLoadingRequestSucceed.

@Test
public void givenProviderFilterUsesMemberAttribute_whenSomeMemberHasMatchingAttribute_thenClassLoadingRequestSucceed() {
    Config i1Config = new Config();
    i1Config.getMemberAttributeConfig().setAttribute("foo", "bar");
    i1Config.getUserCodeDeploymentConfig().setEnabled(true).setClassCacheMode(classCacheMode);
    Config i2Config = new Config();
    FilteringClassLoader filteringCL = new FilteringClassLoader(singletonList("usercodedeployment"), null);
    i2Config.setClassLoader(filteringCL);
    i2Config.getUserCodeDeploymentConfig().setEnabled(true).setProviderFilter("HAS_ATTRIBUTE:foo").setClassCacheMode(classCacheMode);
    EntryProcessor<Integer, Integer, Integer> myEP = new IncrementingEntryProcessor();
    executeSimpleTestScenario(i1Config, i2Config, myEP);
}
Also used : UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) Config(com.hazelcast.config.Config) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) IncrementingEntryProcessor(usercodedeployment.IncrementingEntryProcessor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with FilteringClassLoader

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

the class UserCodeDeploymentBasicTest method givenTheEPIsOnTheWhitelist_whenTheEPIsFilteredLocally_thenItWillLoadIt.

@Test
public void givenTheEPIsOnTheWhitelist_whenTheEPIsFilteredLocally_thenItWillLoadIt() {
    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, usercodedeployment").setClassCacheMode(classCacheMode);
    EntryProcessor<Integer, Integer, Integer> myEP = new WhitelistedEP();
    executeSimpleTestScenario(i1Config, i2Config, myEP);
}
Also used : WhitelistedEP(usercodedeployment.whitelisted.WhitelistedEP) UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) Config(com.hazelcast.config.Config) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) 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