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;
}
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;
}
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());
}
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);
}
}
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();
}
Aggregations