Search in sources :

Example 31 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class RingbufferTestUtil method getBackupRingbuffer.

/**
 * Returns all backup items of a {@link Ringbuffer} by a given ringbuffer name.
 * <p>
 * Note: You have to provide the {@link HazelcastInstance} you want to retrieve the backups from.
 * Use {@link getBackupInstance} to retrieve the backup instance for a given replica index.
 *
 * @param backupInstance the {@link HazelcastInstance} to retrieve the backups from
 * @param partitionId    the partition ID of the ringbuffer
 * @param ringbufferName the ringbuffer name
 * @return a {@link Collection} with the backup items
 */
static Collection<Object> getBackupRingbuffer(HazelcastInstance backupInstance, int partitionId, String ringbufferName) {
    NodeEngineImpl nodeEngine = getNodeEngineImpl(backupInstance);
    RingbufferService service = nodeEngine.getService(RingbufferService.SERVICE_NAME);
    RingbufferContainer container = service.getContainerOrNull(partitionId, getRingbufferNamespace(ringbufferName));
    if (container == null) {
        return emptyList();
    }
    SerializationService serializationService = nodeEngine.getSerializationService();
    List<Object> backupRingbuffer = new ArrayList<Object>((int) container.size());
    for (long sequence = container.headSequence(); sequence <= container.tailSequence(); sequence++) {
        backupRingbuffer.add(serializationService.toObject(container.readAsData(sequence)));
    }
    return backupRingbuffer;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) RingbufferContainer(com.hazelcast.ringbuffer.impl.RingbufferContainer) ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.internal.serialization.SerializationService) RingbufferService(com.hazelcast.ringbuffer.impl.RingbufferService)

Example 32 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class PartitionPredicateTest method testSerialization.

@Test
public void testSerialization() {
    SerializationService serializationService = getSerializationService(local);
    Data serialized = serializationService.toData(predicate);
    PartitionPredicate deserialized = serializationService.toObject(serialized);
    assertEquals(partitionKey, deserialized.getPartitionKey());
    assertEquals(Predicates.alwaysTrue(), deserialized.getTarget());
}
Also used : PartitionPredicate(com.hazelcast.query.PartitionPredicate) Accessors.getSerializationService(com.hazelcast.test.Accessors.getSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 33 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class DataAwareEntryEventConstructorTest method testConstructor.

@Test
public void testConstructor() {
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    String key = "key";
    String newValue = "newValue";
    String oldValue = "oldValue";
    String mergingValue = "mergingValue";
    Member from = mock(Member.class);
    int eventType = EntryEventType.MERGED.getType();
    String source = UuidUtil.newUnsecureUuidString();
    Data dataKey = serializationService.toData(key);
    Data dataNewValue = serializationService.toData(newValue);
    Data dataOldValue = serializationService.toData(oldValue);
    Data dataMergingValue = serializationService.toData(mergingValue);
    DataAwareEntryEvent dataAwareEntryEvent = new DataAwareEntryEvent(from, eventType, source, dataKey, dataNewValue, dataOldValue, dataMergingValue, serializationService);
    DataAwareEntryEventConstructor constructor = new DataAwareEntryEventConstructor(DataAwareEntryEvent.class);
    DataAwareEntryEvent clonedDataAwareEntryEvent = (DataAwareEntryEvent) constructor.createNew(dataAwareEntryEvent);
    assertEquals(dataAwareEntryEvent.getName(), clonedDataAwareEntryEvent.getName());
    assertEquals(dataAwareEntryEvent.getMember(), clonedDataAwareEntryEvent.getMember());
    assertEquals(dataAwareEntryEvent.getEventType(), clonedDataAwareEntryEvent.getEventType());
    assertEquals(dataAwareEntryEvent.getSource(), clonedDataAwareEntryEvent.getSource());
    assertEquals(dataAwareEntryEvent.getKey(), clonedDataAwareEntryEvent.getKey());
    assertEquals(dataAwareEntryEvent.getKeyData(), clonedDataAwareEntryEvent.getKeyData());
    assertEquals(dataAwareEntryEvent.getValue(), clonedDataAwareEntryEvent.getValue());
    assertEquals(dataAwareEntryEvent.getNewValueData(), clonedDataAwareEntryEvent.getNewValueData());
    assertEquals(dataAwareEntryEvent.getOldValue(), clonedDataAwareEntryEvent.getOldValue());
    assertEquals(dataAwareEntryEvent.getOldValueData(), clonedDataAwareEntryEvent.getOldValueData());
    assertEquals(dataAwareEntryEvent.getMergingValue(), clonedDataAwareEntryEvent.getMergingValue());
    assertEquals(dataAwareEntryEvent.getMergingValueData(), clonedDataAwareEntryEvent.getMergingValueData());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) DataAwareEntryEventConstructor(com.hazelcast.test.starter.constructor.DataAwareEntryEventConstructor) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) DataAwareEntryEvent(com.hazelcast.map.impl.DataAwareEntryEvent) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 34 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class BinaryCompatibilityFileGenerator method generateBinaryFile.

private static void generateBinaryFile(DataOutputStream outputStream, Object object, ByteOrder byteOrder) throws IOException {
    SerializationService serializationService = createSerializationService(byteOrder);
    Data data = serializationService.toData(object);
    outputStream.writeUTF(createObjectKey(object, byteOrder));
    if (data == null) {
        outputStream.writeInt(NULL_OBJECT);
        return;
    }
    byte[] bytes = data.toByteArray();
    outputStream.writeInt(bytes.length);
    outputStream.write(bytes);
}
Also used : SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data)

Example 35 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class BinaryCompatibilityTest method basicSerializeDeserialize.

@Test
public void basicSerializeDeserialize() {
    SerializationService serializationService = createSerializationService();
    Data data = serializationService.toData(object);
    Object readObject = serializationService.toObject(data);
    assertTrue(equals(object, readObject));
}
Also used : InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

SerializationService (com.hazelcast.internal.serialization.SerializationService)170 Data (com.hazelcast.internal.serialization.Data)117 Test (org.junit.Test)100 QuickTest (com.hazelcast.test.annotation.QuickTest)99 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)59 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)50 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)43 ArrayList (java.util.ArrayList)15 SerializationConfig (com.hazelcast.config.SerializationConfig)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 Node (com.hazelcast.instance.impl.Node)12 CustomSerializationTest (com.hazelcast.internal.serialization.impl.CustomSerializationTest)12 Accessors.getNode (com.hazelcast.test.Accessors.getNode)12 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)11 EmployeeDTO (example.serialization.EmployeeDTO)11 ExternalizableEmployeeDTO (example.serialization.ExternalizableEmployeeDTO)11 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)8 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8