Search in sources :

Example 26 with HazelcastSerializationException

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

the class RingbufferContainer method addAll.

/**
 * Adds all items to the ringbuffer. Sets the expiration time if TTL is
 * configured and also attempts to store the items in the data store if one
 * is configured.
 *
 * @param items items to be stored in the ring buffer and data store
 * @return the sequence ID of the last item stored in the ring buffer
 * @throws HazelcastException              if there was any exception thrown by the data store
 * @throws HazelcastSerializationException if the ring buffer is configured to keep items
 *                                         in object format and the item could not be
 *                                         deserialized
 */
public long addAll(T[] items) {
    long firstSequence = ringbuffer.peekNextTailSequence();
    long lastSequence = ringbuffer.peekNextTailSequence();
    if (store.isEnabled() && items.length != 0) {
        try {
            store.storeAll(firstSequence, convertToData(items));
        } catch (Exception e) {
            throw new HazelcastException(e);
        }
    }
    for (int i = 0; i < items.length; i++) {
        lastSequence = addInternal(items[i]);
    }
    return lastSequence;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException)

Example 27 with HazelcastSerializationException

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

the class RingbufferContainer method add.

/**
 * Adds one item to the ring buffer. Sets the expiration time if TTL is
 * configured and also attempts to store the item in the data store if one
 * is configured. The provided {@code item} can be {@link Data} or the
 * deserialized object.
 * The provided item will be transformed to the configured ringbuffer
 * {@link InMemoryFormat} if necessary.
 *
 * @param item item to be stored in the ring buffer and data store, can be
 *             {@link Data} or an deserialized object
 * @return the sequence ID of the item stored in the ring buffer
 * @throws HazelcastException              if there was any exception thrown by the data store
 * @throws HazelcastSerializationException if the ring buffer is configured to keep items in object format and the
 *                                         item could not be deserialized
 */
public long add(T item) {
    final long nextSequence = ringbuffer.peekNextTailSequence();
    if (store.isEnabled()) {
        try {
            store.store(nextSequence, convertToData(item));
        } catch (Exception e) {
            throw new HazelcastException(e);
        }
    }
    final long storedSequence = addInternal(item);
    if (storedSequence != nextSequence) {
        throw new IllegalStateException("Sequence we stored the item with and Ringbuffer sequence differs. Was the " + "Ringbuffer mutated from multiple threads?");
    }
    return storedSequence;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException)

Example 28 with HazelcastSerializationException

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

the class SmallClusterTest method submitToAllMembers_NonSerializableResponse.

@Test
public void submitToAllMembers_NonSerializableResponse() {
    IExecutorService executorService = instances[0].getExecutorService(randomString());
    NonSerializableResponseCallable nonSerializableResponseCallable = new NonSerializableResponseCallable();
    final AtomicLong exceptionCount = new AtomicLong();
    final AtomicLong responseCount = new AtomicLong();
    final CountDownLatch completedLatch = new CountDownLatch(1);
    executorService.submitToAllMembers(nonSerializableResponseCallable, new MultiExecutionCallback() {

        @Override
        public void onResponse(Member member, Object value) {
            if (value instanceof HazelcastSerializationException) {
                exceptionCount.incrementAndGet();
            } else {
                responseCount.incrementAndGet();
            }
        }

        @Override
        public void onComplete(Map<Member, Object> values) {
            completedLatch.countDown();
        }
    });
    assertOpenEventually(completedLatch);
    // two exceptions from remote nodes
    assertEquals(2, exceptionCount.get());
    // one response from local node since, it does not need to serialize/deserialize the response
    assertEquals(1, responseCount.get());
}
Also used : MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) IAtomicLong(com.hazelcast.cp.IAtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 29 with HazelcastSerializationException

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

the class DeserializationProtectionTest method assertDeserializationFails.

private void assertDeserializationFails(JavaSerializationFilterConfig javaSerializationFilterConfig, boolean keyOwnedByTarget) {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    Config config = new Config();
    config.getSerializationConfig().setJavaSerializationFilterConfig(javaSerializationFilterConfig);
    HazelcastInstance[] instances = factory.newInstances(config);
    String key = generateKeyOwnedBy(instances[keyOwnedByTarget ? 1 : 0]);
    instances[0].getMap("test").put(key, new TestDeserialized());
    try {
        instances[1].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) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 30 with HazelcastSerializationException

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

the class PortableTest method testClassDefinitionConfigWithErrors.

@Test
public void testClassDefinitionConfigWithErrors() throws Exception {
    SerializationConfig serializationConfig = new SerializationConfig();
    serializationConfig.addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory());
    serializationConfig.setPortableVersion(1);
    serializationConfig.addClassDefinition(new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, TestSerializationConstants.RAW_DATA_PORTABLE, 1).addLongField("l").addCharArrayField("c").addPortableField("p", createNamedPortableClassDefinition(1)).build());
    try {
        new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
        fail("Should throw HazelcastSerializationException!");
    } catch (HazelcastSerializationException ignored) {
    }
    new DefaultSerializationServiceBuilder().setConfig(serializationConfig).setCheckClassDefErrors(false).build();
    // -- OR --
    serializationConfig.setCheckClassDefErrors(false);
    new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) SerializationConfig(com.hazelcast.config.SerializationConfig) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) QuickTest(com.hazelcast.test.annotation.QuickTest) CustomSerializationTest(com.hazelcast.internal.serialization.impl.CustomSerializationTest) 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