Search in sources :

Example 16 with FilteringClassLoader

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

the class UserCodeDeploymentBasicTest method givenSomeMemberCanAccessTheEP_whenTheEPIsFilteredLocally_thenItWillBeLoadedOverNetwork_anonymousInnerClasses.

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

Example 17 with FilteringClassLoader

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

the class UserCodeDeploymentBasicTest method testUserCodeDeploymentIsDisabledByDefault.

@Test
public void testUserCodeDeploymentIsDisabledByDefault() {
    // this test also validate the EP is filtered locally and has to be loaded from the other member
    Config i1Config = new Config();
    Config i2Config = new Config();
    FilteringClassLoader filteringCL = new FilteringClassLoader(singletonList("usercodedeployment"), null);
    i2Config.setClassLoader(filteringCL);
    IncrementingEntryProcessor incrementingEntryProcessor = new IncrementingEntryProcessor();
    try {
        executeSimpleTestScenario(i1Config, i2Config, incrementingEntryProcessor);
        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 18 with FilteringClassLoader

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

the class DynamicConfigAdvancedTest method test_userCustomizations_withUserCodeDeployment.

@Test
public void test_userCustomizations_withUserCodeDeployment() {
    factory = new TestHazelcastInstanceFactory();
    // first member is aware of MapLoader class
    HazelcastInstance member1 = factory.newHazelcastInstance(newConfigWithUserCodeDeployment());
    member1.getConfig().addMapConfig(mapConfigWithMapLoader());
    IMap<Integer, Integer> intMap = member1.getMap(MAP_NAME);
    assertEquals(1, (long) intMap.get(1));
    // start another member which is not aware of map loader
    Config config = newConfigWithUserCodeDeployment();
    FilteringClassLoader cl = new FilteringClassLoader(singletonList("classloading"), null);
    config.setClassLoader(cl);
    factory.newHazelcastInstance(config);
    for (int i = 0; i < 1000; i++) {
        assertEquals(i, (long) intMap.get(i));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with FilteringClassLoader

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

the class GenericRecordTest method testGenericRecordToStringValidJson.

@Test
public void testGenericRecordToStringValidJson() throws IOException {
    CompactSerializationConfig compactSerializationConfig = new CompactSerializationConfig();
    compactSerializationConfig.setEnabled(true);
    InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setConfig(new SerializationConfig().setCompactSerializationConfig(compactSerializationConfig)).build();
    MainDTO expectedDTO = createMainDTO();
    expectedDTO.nullableBool = null;
    expectedDTO.p.localDateTimes[0] = null;
    Data data = serializationService.toData(expectedDTO);
    assertTrue(data.isCompact());
    // internal generic record created on the servers on query
    InternalGenericRecord internalGenericRecord = serializationService.readAsInternalGenericRecord(data);
    String string = internalGenericRecord.toString();
    Json.parse(string);
    // generic record read from a remote instance without classes on the classpath
    List<String> excludes = Collections.singletonList("example.serialization");
    FilteringClassLoader classLoader = new FilteringClassLoader(excludes, null);
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(classLoader);
        InternalSerializationService ss2 = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setClassLoader(classLoader).setConfig(new SerializationConfig().setCompactSerializationConfig(new CompactSerializationConfig())).build();
        GenericRecord genericRecord = ss2.toObject(data);
        Json.parse(genericRecord.toString());
        // generic record build by API
        GenericRecord apiGenericRecord = createCompactGenericRecord(expectedDTO);
        Json.parse(apiGenericRecord.toString());
    } finally {
        Thread.currentThread().setContextClassLoader(contextClassLoader);
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) MainDTO(example.serialization.MainDTO) CompactTestUtil.createMainDTO(com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createMainDTO) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) CompactTestUtil.createCompactGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createCompactGenericRecord) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with FilteringClassLoader

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

the class ClientDeploymentTest method beforeClass.

@BeforeClass
public static void beforeClass() {
    Config config = smallInstanceConfig();
    config.getJetConfig().setResourceUploadEnabled(true);
    FilteringClassLoader filteringClassLoader = new FilteringClassLoader(singletonList("deployment"), null);
    config.setClassLoader(filteringClassLoader);
    initializeWithClient(MEMBER_COUNT, config, null);
}
Also used : Config(com.hazelcast.config.Config) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) BeforeClass(org.junit.BeforeClass)

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