Search in sources :

Example 1 with SerializationService

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

the class CollectionTestUtil method getBackupSet.

/**
 * Returns all backup items of an {@link ISet} by a given set 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 setName        the set name
 * @return a {@link Set} with the backup items
 */
public static <E> Set<E> getBackupSet(HazelcastInstance backupInstance, String setName) {
    NodeEngineImpl nodeEngine = getNodeEngineImpl(backupInstance);
    CollectionService service = nodeEngine.getService(SetService.SERVICE_NAME);
    CollectionContainer collectionContainer = service.getContainerMap().get(setName);
    if (collectionContainer == null) {
        return emptySet();
    }
    // the replica items are retrieved via `getMap()`, the primary items via `getCollection()`
    Map<Long, CollectionItem> map = collectionContainer.getMap();
    Set<E> backupSet = new HashSet<E>();
    SerializationService serializationService = nodeEngine.getSerializationService();
    for (CollectionItem collectionItem : map.values()) {
        E value = serializationService.toObject(collectionItem.getValue());
        backupSet.add(value);
    }
    return backupSet;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) CollectionService(com.hazelcast.collection.impl.collection.CollectionService) SerializationService(com.hazelcast.internal.serialization.SerializationService) CollectionContainer(com.hazelcast.collection.impl.collection.CollectionContainer) CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem) HashSet(java.util.HashSet)

Example 2 with SerializationService

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

the class WanReplicationConfigTest method testSerialization.

@Test
public void testSerialization() {
    Map<String, Comparable> properties = new HashMap<>();
    properties.put("key", "value");
    WanConsumerConfig wanConsumerConfig = new WanConsumerConfig();
    wanConsumerConfig.setProperties(properties);
    wanConsumerConfig.setClassName("className");
    wanConsumerConfig.setImplementation(new DummyWanConsumer());
    WanBatchPublisherConfig wanPublisherConfig1 = new WanBatchPublisherConfig();
    WanBatchPublisherConfig wanPublisherConfig2 = new WanBatchPublisherConfig();
    List<WanBatchPublisherConfig> publisherConfigs = new LinkedList<>();
    publisherConfigs.add(wanPublisherConfig1);
    config.setName("name");
    config.setConsumerConfig(wanConsumerConfig);
    config.setBatchPublisherConfigs(publisherConfigs);
    config.addBatchReplicationPublisherConfig(wanPublisherConfig2);
    ArrayList<WanCustomPublisherConfig> customPublishers = new ArrayList<>(1);
    customPublishers.add(new WanCustomPublisherConfig());
    config.setCustomPublisherConfigs(customPublishers);
    config.addCustomPublisherConfig(new WanCustomPublisherConfig());
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    Data serialized = serializationService.toData(config);
    WanReplicationConfig deserialized = serializationService.toObject(serialized);
    assertWanReplicationConfig(config, deserialized);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) LinkedList(java.util.LinkedList) WanConsumerConfigTest.assertWanConsumerConfig(com.hazelcast.config.WanConsumerConfigTest.assertWanConsumerConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with SerializationService

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

the class MergePolicyConfigTest method testSerialization.

@Test
public void testSerialization() {
    config.setPolicy(DiscardMergePolicy.class.getName());
    config.setBatchSize(1234);
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    Data serialized = serializationService.toData(config);
    MergePolicyConfig deserialized = serializationService.toObject(serialized);
    assertEquals(config.getPolicy(), deserialized.getPolicy());
    assertEquals(config.getBatchSize(), deserialized.getBatchSize());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) DiscardMergePolicy(com.hazelcast.spi.merge.DiscardMergePolicy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with SerializationService

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

the class AbstractCollectionProxyImpl method getAll.

private Collection<E> getAll() {
    CollectionGetAllOperation operation = new CollectionGetAllOperation(name);
    SerializableList result = invoke(operation);
    List<Data> collection = result.getCollection();
    SerializationService serializationService = getNodeEngine().getSerializationService();
    return new UnmodifiableLazyList(collection, serializationService);
}
Also used : CollectionGetAllOperation(com.hazelcast.collection.impl.collection.operations.CollectionGetAllOperation) SerializableList(com.hazelcast.spi.impl.SerializableList) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) UnmodifiableLazyList(com.hazelcast.spi.impl.UnmodifiableLazyList)

Example 5 with SerializationService

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

the class MapChunk method writeChunk.

/**
 * This method writes a map's main data, which is key-value
 * pairs, to output stream.
 * <p>
 * If number of written bytes exceeds chunk limit, it stops writing.
 * Next key-values pairs are written in subsequent chunks later.
 */
protected final void writeChunk(ObjectDataOutput out, MapChunkContext context) throws IOException {
    SerializationService ss = context.getSerializationService();
    long recordCount = 0;
    out.writeString(context.getMapName());
    Iterator<Map.Entry<Data, Record>> entries = context.getIterator();
    while (entries.hasNext()) {
        Map.Entry<Data, Record> entry = entries.next();
        Data dataKey = entry.getKey();
        Record record = entry.getValue();
        Data dataValue = ss.toData(record.getValue());
        IOUtil.writeData(out, dataKey);
        Records.writeRecord(out, record, dataValue);
        Records.writeExpiry(out, context.getExpiryMetadata(dataKey));
        recordCount++;
        if (isEndOfChunk.getAsBoolean()) {
            break;
        }
    }
    incrementReplicationRecordCount(recordCount);
    if (!entries.hasNext()) {
        incrementReplicationCount();
    }
    // indicates end of chunk
    IOUtil.writeData(out, null);
}
Also used : DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry) DelayedEntries.newAddedDelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntries.newAddedDelayedEntry) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) Record(com.hazelcast.map.impl.record.Record) Map(java.util.Map) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap)

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