Search in sources :

Example 76 with SerializationService

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

the class WanReplicationRefTest method testSerialization.

@Test
public void testSerialization() {
    ref.setName("myWanReplicationRef");
    ref.setMergePolicy("myMergePolicy");
    ref.setRepublishingEnabled(true);
    ref.addFilter("myFilter");
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    Data serialized = serializationService.toData(ref);
    WanReplicationRef deserialized = serializationService.toObject(serialized);
    assertEquals(ref.getName(), deserialized.getName());
    assertEquals(ref.getMergePolicy(), deserialized.getMergePolicy());
    assertEquals(ref.isRepublishingEnabled(), deserialized.isRepublishingEnabled());
    assertEquals(ref.getFilters(), deserialized.getFilters());
    assertEquals(ref.toString(), deserialized.toString());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 77 with SerializationService

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

the class ClientListenersTest method testEntryMergeListener_withPortableNotRegisteredInNode.

@Test
public void testEntryMergeListener_withPortableNotRegisteredInNode() throws Exception {
    final IMap<Object, Object> map = client.getMap(randomMapName());
    final CountDownLatch latch = new CountDownLatch(1);
    map.addEntryListener(new EntryMergedListener<Object, Object>() {

        @Override
        public void entryMerged(EntryEvent<Object, Object> event) {
            latch.countDown();
        }
    }, true);
    Node node = getNode(server);
    NodeEngineImpl nodeEngine = node.nodeEngine;
    OperationServiceImpl operationService = (OperationServiceImpl) nodeEngine.getOperationService();
    SerializationService serializationService = getSerializationService(server);
    Data key = serializationService.toData(1);
    Data value = serializationService.toData(new ClientRegressionWithMockNetworkTest.SamplePortable(1));
    EntryView entryView = EntryViews.createSimpleEntryView(key, value, Mockito.mock(Record.class));
    MergeOperation op = new MergeOperation(map.getName(), key, entryView, new PassThroughMergePolicy());
    int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    operationService.invokeOnPartition(MapService.SERVICE_NAME, op, partitionId);
    assertOpenEventually(latch);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MergeOperation(com.hazelcast.map.impl.operation.MergeOperation) PassThroughMergePolicy(com.hazelcast.map.merge.PassThroughMergePolicy) Node(com.hazelcast.instance.Node) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) CountDownLatch(java.util.concurrent.CountDownLatch) EntryView(com.hazelcast.core.EntryView) Record(com.hazelcast.map.impl.record.Record) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 78 with SerializationService

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

the class DurableExecutorServiceProxy method submitToPartition.

private <T> DurableExecutorServiceFuture<T> submitToPartition(Callable<T> task, int partitionId, T defaultValue) {
    checkNotNull(task, "task can't be null");
    SerializationService serializationService = getNodeEngine().getSerializationService();
    Data taskData = serializationService.toData(task);
    TaskOperation operation = new TaskOperation(name, taskData);
    operation.setPartitionId(partitionId);
    InternalCompletableFuture<Integer> future = invokeOnPartition(operation);
    int sequence;
    try {
        sequence = future.get();
    } catch (Throwable t) {
        CompletedFuture<T> completedFuture = new CompletedFuture<T>(serializationService, t, getAsyncExecutor());
        return new DurableExecutorServiceDelegateFuture<T>(completedFuture, serializationService, null, -1);
    }
    Operation op = new RetrieveResultOperation(name, sequence).setPartitionId(partitionId);
    InternalCompletableFuture<T> internalCompletableFuture = invokeOnPartition(op);
    long taskId = Bits.combineToLong(partitionId, sequence);
    return new DurableExecutorServiceDelegateFuture<T>(internalCompletableFuture, serializationService, defaultValue, taskId);
}
Also used : SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) TaskOperation(com.hazelcast.durableexecutor.impl.operations.TaskOperation) ShutdownOperation(com.hazelcast.durableexecutor.impl.operations.ShutdownOperation) TaskOperation(com.hazelcast.durableexecutor.impl.operations.TaskOperation) Operation(com.hazelcast.spi.Operation) DisposeResultOperation(com.hazelcast.durableexecutor.impl.operations.DisposeResultOperation) RetrieveAndDisposeResultOperation(com.hazelcast.durableexecutor.impl.operations.RetrieveAndDisposeResultOperation) RetrieveResultOperation(com.hazelcast.durableexecutor.impl.operations.RetrieveResultOperation) RetrieveResultOperation(com.hazelcast.durableexecutor.impl.operations.RetrieveResultOperation) CompletedFuture(com.hazelcast.util.executor.CompletedFuture)

Example 79 with SerializationService

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

the class MultipleEntryBackupOperation method run.

@Override
public void run() throws Exception {
    boolean shouldClone = mapContainer.shouldCloneOnEntryProcessing();
    SerializationService serializationService = getNodeEngine().getSerializationService();
    for (Data key : keys) {
        if (!isKeyProcessable(key)) {
            continue;
        }
        Object oldValue = recordStore.get(key, true);
        Object value = shouldClone ? serializationService.toObject(serializationService.toData(oldValue)) : oldValue;
        Map.Entry entry = createMapEntry(key, value);
        if (!isEntryProcessable(entry)) {
            continue;
        }
        processBackup(entry);
        if (noOp(entry, oldValue)) {
            continue;
        }
        if (entryRemovedBackup(entry, key)) {
            continue;
        }
        entryAddedOrUpdatedBackup(entry, key);
        evict(key);
    }
}
Also used : SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) Map(java.util.Map)

Example 80 with SerializationService

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

the class MultipleEntryOperation method innerBeforeRun.

@Override
public void innerBeforeRun() throws Exception {
    super.innerBeforeRun();
    final SerializationService serializationService = getNodeEngine().getSerializationService();
    final ManagedContext managedContext = serializationService.getManagedContext();
    managedContext.initialize(entryProcessor);
}
Also used : SerializationService(com.hazelcast.spi.serialization.SerializationService) ManagedContext(com.hazelcast.core.ManagedContext)

Aggregations

SerializationService (com.hazelcast.spi.serialization.SerializationService)120 Test (org.junit.Test)59 QuickTest (com.hazelcast.test.annotation.QuickTest)56 Data (com.hazelcast.nio.serialization.Data)54 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)46 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)28 ParallelTest (com.hazelcast.test.annotation.ParallelTest)22 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)18 HeapData (com.hazelcast.internal.serialization.impl.HeapData)17 Map (java.util.Map)15 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)10 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)9 ClientDelegatingFuture (com.hazelcast.client.util.ClientDelegatingFuture)8 Node (com.hazelcast.instance.Node)7 SerializationConfig (com.hazelcast.config.SerializationConfig)6 ICacheService (com.hazelcast.cache.impl.ICacheService)5 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)5 Record (com.hazelcast.map.impl.record.Record)5 ICacheRecordStore (com.hazelcast.cache.impl.ICacheRecordStore)3