Search in sources :

Example 56 with SerializationService

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

the class CollectionUtilTest method testObjectToDataCollection_size.

@Test
public void testObjectToDataCollection_size() {
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    Collection<Object> list = new ArrayList<Object>();
    list.add(1);
    list.add("foo");
    Collection<Data> dataCollection = objectToDataCollection(list, serializationService);
    assertEquals(list.size(), dataCollection.size());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) ArrayList(java.util.ArrayList) 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 57 with SerializationService

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

the class CallbackAwareClientDelegatingFutureTest method createGetRequest.

private ClientMessage createGetRequest(Integer key) {
    SerializationService serializationService = client.getSerializationService();
    Data keyData = serializationService.toData(key);
    Data expiryPolicyData = serializationService.toData(null);
    String cacheNameWithPrefix = HazelcastCacheManager.CACHE_MANAGER_PREFIX + CACHE_NAME;
    return CacheGetCodec.encodeRequest(cacheNameWithPrefix, keyData, expiryPolicyData);
}
Also used : SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data)

Example 58 with SerializationService

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

the class NodeQueryCacheEventService method canPassFilter.

private boolean canPassFilter(LocalEntryEventData localEntryEventData, EventFilter filter) {
    if (filter == null || filter instanceof TrueEventFilter) {
        return true;
    }
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    SerializationService serializationService = nodeEngine.getSerializationService();
    Data keyData = localEntryEventData.getKeyData();
    Object value = getValueOrOldValue(localEntryEventData);
    QueryableEntry entry = new QueryEntry((InternalSerializationService) serializationService, keyData, value, Extractors.empty());
    return filter.eval(entry);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) QueryEntry(com.hazelcast.query.impl.QueryEntry) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData) EventData(com.hazelcast.map.impl.event.EventData) Data(com.hazelcast.nio.serialization.Data) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 59 with SerializationService

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

the class CacheClearTest method testClear.

@Test
public void testClear() {
    ICache<String, String> cache = createCache();
    String cacheName = cache.getName();
    Map<String, String> entries = createAndFillEntries();
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        cache.put(entry.getKey(), entry.getValue());
    }
    // Verify that put works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String expectedValue = entries.get(key);
        String actualValue = cache.get(key);
        assertEquals(expectedValue, actualValue);
    }
    Node node = getNode(hazelcastInstance);
    InternalPartitionService partitionService = node.getPartitionService();
    SerializationService serializationService = node.getSerializationService();
    // Verify that backup of put works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String expectedValue = entries.get(key);
        Data keyData = serializationService.toData(key);
        int keyPartitionId = partitionService.getPartitionId(keyData);
        for (int i = 0; i < INSTANCE_COUNT; i++) {
            Node n = getNode(hazelcastInstances[i]);
            ICacheService cacheService = n.getNodeEngine().getService(ICacheService.SERVICE_NAME);
            ICacheRecordStore recordStore = cacheService.getRecordStore("/hz/" + cacheName, keyPartitionId);
            assertNotNull(recordStore);
            String actualValue = serializationService.toObject(recordStore.get(keyData, null));
            assertEquals(expectedValue, actualValue);
        }
    }
    cache.clear();
    // Verify that clear works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String actualValue = cache.get(key);
        assertNull(actualValue);
    }
    // Verify that backup of clear works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        Data keyData = serializationService.toData(key);
        int keyPartitionId = partitionService.getPartitionId(keyData);
        for (int i = 0; i < INSTANCE_COUNT; i++) {
            Node n = getNode(hazelcastInstances[i]);
            ICacheService cacheService = n.getNodeEngine().getService(ICacheService.SERVICE_NAME);
            ICacheRecordStore recordStore = cacheService.getRecordStore("/hz/" + cacheName, keyPartitionId);
            assertNotNull(recordStore);
            String actualValue = serializationService.toObject(recordStore.get(keyData, null));
            assertNull(actualValue);
        }
    }
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) ICacheService(com.hazelcast.cache.impl.ICacheService) Node(com.hazelcast.instance.Node) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) ICacheRecordStore(com.hazelcast.cache.impl.ICacheRecordStore) HashMap(java.util.HashMap) Map(java.util.Map) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 60 with SerializationService

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

the class SetEqualsHashTest method testCollectionItem_equalsAndHash.

@Test
public void testCollectionItem_equalsAndHash() {
    SerializationServiceBuilder serializationServiceBuilder = new DefaultSerializationServiceBuilder();
    SerializationService build = serializationServiceBuilder.build();
    Data value = build.toData(randomString());
    CollectionItem firstItem = new CollectionItem(1, value);
    CollectionItem secondItem = new CollectionItem(2, value);
    assertTrue(firstItem.equals(secondItem));
    assertEquals(firstItem.hashCode(), secondItem.hashCode());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationServiceBuilder(com.hazelcast.internal.serialization.SerializationServiceBuilder) DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

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