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