Search in sources :

Example 46 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class ClientUserCodeDeploymentExceptionTest method testUserCodeDeploymentIsDisabledByDefaultOnClient.

@Test
public void testUserCodeDeploymentIsDisabledByDefaultOnClient() {
    // this test also validate the EP is filtered locally and has to be loaded from the other member
    ClientConfig clientConfig = new ClientConfig();
    Config config = createNodeConfig();
    config.getUserCodeDeploymentConfig().setEnabled(true);
    IncrementingEntryProcessor incrementingEntryProcessor = new IncrementingEntryProcessor();
    factory.newHazelcastInstance(config);
    HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    IMap<Integer, Integer> map = client.getMap(randomName());
    try {
        map.executeOnEntries(incrementingEntryProcessor);
        fail();
    } catch (HazelcastSerializationException e) {
        assertEquals(ClassNotFoundException.class, e.getCause().getClass());
    }
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientUserCodeDeploymentConfig(com.hazelcast.client.config.ClientUserCodeDeploymentConfig) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) IncrementingEntryProcessor(usercodedeployment.IncrementingEntryProcessor) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 47 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class ClientDeserializationProtectionTest method testDefaultDeserializationFilter_readOnClient.

/**
 * <pre>
 * When: An untrusted serialized object is stored by member and read from client, the default Whitelist is used.
 * Then: Deserialization fails.
 * </pre>
 */
@Test
public void testDefaultDeserializationFilter_readOnClient() {
    JavaSerializationFilterConfig filterConfig = new JavaSerializationFilterConfig();
    Config config = new Config();
    config.getSerializationConfig().setJavaSerializationFilterConfig(filterConfig);
    HazelcastInstance member = hazelcastFactory.newInstances(config, 1)[0];
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getSerializationConfig().setJavaSerializationFilterConfig(filterConfig);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    member.getMap("test").put("key", new TestDeserialized());
    try {
        client.getMap("test").get("key");
        fail("Deserialization should have failed");
    } catch (HazelcastSerializationException e) {
        assertFalse(TestDeserialized.isDeserialized);
    }
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestDeserialized(example.serialization.TestDeserialized) Config(com.hazelcast.config.Config) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 48 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class ClientDeserializationProtectionTest method testDefaultDeserializationFilter_readOnMember.

/**
 * <pre>
 * When: An untrusted serialized object is stored from client and read from member, the default Whitelist is used.
 * Then: Deserialization fails.
 * </pre>
 */
@Test
public void testDefaultDeserializationFilter_readOnMember() {
    JavaSerializationFilterConfig filterConfig = new JavaSerializationFilterConfig();
    Config config = new Config();
    config.getSerializationConfig().setJavaSerializationFilterConfig(filterConfig);
    HazelcastInstance member = hazelcastFactory.newInstances(config, 1)[0];
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getSerializationConfig().setJavaSerializationFilterConfig(filterConfig);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    client.getMap("test").put("key", new TestDeserialized());
    try {
        member.getMap("test").get("key");
        fail("Deserialization should have failed");
    } catch (HazelcastSerializationException e) {
        assertFalse(TestDeserialized.isDeserialized);
    }
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestDeserialized(example.serialization.TestDeserialized) Config(com.hazelcast.config.Config) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class AbstractNearCacheSerializationCountTest method getStackTrace.

private static String getStackTrace(String message) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    new HazelcastSerializationException(message).printStackTrace(pw);
    return sw.toString();
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 50 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class DataSerializableSerializationTest method testClarifiedExceptionsForUnsupportedClassTypes.

@Test
public void testClarifiedExceptionsForUnsupportedClassTypes() {
    class LocalClass implements DataSerializable {

        @Override
        public void writeData(ObjectDataOutput out) {
        }

        @Override
        public void readData(ObjectDataInput in) {
        }
    }
    DataSerializable anonymousInstance = new DataSerializable() {

        @Override
        public void writeData(ObjectDataOutput out) {
        }

        @Override
        public void readData(ObjectDataInput in) {
        }
    };
    DataSerializable[] throwingInstances = { new LocalClass(), anonymousInstance, new NonStaticMemberClass() };
    for (DataSerializable throwingInstance : throwingInstances) {
        try {
            ss.toObject(ss.toData(throwingInstance));
        } catch (HazelcastSerializationException e) {
            assertInstanceOf(NoSuchMethodException.class, e.getCause());
            assertContains(e.getCause().getMessage(), "can't conform to DataSerializable");
            assertInstanceOf(NoSuchMethodException.class, e.getCause().getCause());
            continue;
        }
        fail("deserialization of '" + throwingInstance.getClass() + "' is expected to fail");
    }
    for (DataSerializable throwingInstance : throwingInstances) {
        try {
            ss.toObject(ss.toData(throwingInstance), throwingInstance.getClass());
        } catch (HazelcastSerializationException e) {
            assertInstanceOf(InstantiationException.class, e.getCause());
            assertContains(e.getCause().getMessage(), "can't conform to DataSerializable");
            assertInstanceOf(InstantiationException.class, e.getCause().getCause());
            continue;
        }
        fail("deserialization of '" + throwingInstance.getClass() + "' is expected to fail");
    }
}
Also used : ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) DataSerializable(com.hazelcast.nio.serialization.DataSerializable) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)50 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)10 FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)10 IOException (java.io.IOException)9 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 Config (com.hazelcast.config.Config)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)5 ClientConfig (com.hazelcast.client.config.ClientConfig)4 JavaSerializationFilterConfig (com.hazelcast.config.JavaSerializationFilterConfig)4 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)4 Portable (com.hazelcast.nio.serialization.Portable)4 TestDeserialized (example.serialization.TestDeserialized)4 Map (java.util.Map)4 HazelcastException (com.hazelcast.core.HazelcastException)3 FieldKind (com.hazelcast.nio.serialization.FieldKind)3 HashMap (java.util.HashMap)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)2