Search in sources :

Example 16 with SerializationService

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

the class RingbufferService method addRingbuffer.

public void addRingbuffer(String name, RingbufferContainer ringbuffer) {
    checkNotNull(name, "name can't be null");
    checkNotNull(ringbuffer, "ringbuffer can't be null");
    final RingbufferConfig config = nodeEngine.getConfig().getRingbufferConfig(name);
    final SerializationService serializationService = nodeEngine.getSerializationService();
    ringbuffer.init(name, config, serializationService, nodeEngine.getConfigClassLoader());
    ringbuffer.getStore().instrument(nodeEngine);
    containers.put(name, ringbuffer);
}
Also used : RingbufferConfig(com.hazelcast.config.RingbufferConfig) SerializationService(com.hazelcast.spi.serialization.SerializationService)

Example 17 with SerializationService

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

the class CacheLoadAllTest method testLoadAll.

@Test
public void testLoadAll() throws InterruptedException {
    ICache<String, String> cache = createCache();
    String cacheName = cache.getName();
    Map<String, String> entries = createAndFillEntries();
    final CountDownLatch latch = new CountDownLatch(1);
    cache.loadAll(entries.keySet(), true, new CompletionListener() {

        @Override
        public void onCompletion() {
            latch.countDown();
        }

        @Override
        public void onException(Exception e) {
            latch.countDown();
        }
    });
    latch.await(60, TimeUnit.SECONDS);
    // Verify that load-all 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 load-all 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);
        }
    }
}
Also used : CompletionListener(javax.cache.integration.CompletionListener) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.Node) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) ICacheRecordStore(com.hazelcast.cache.impl.ICacheRecordStore) CountDownLatch(java.util.concurrent.CountDownLatch) CacheLoaderException(javax.cache.integration.CacheLoaderException) ICacheService(com.hazelcast.cache.impl.ICacheService) 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 18 with SerializationService

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

the class CacheBackupTest method entrySuccessfullyRetrievedFromBackup.

private void entrySuccessfullyRetrievedFromBackup(int backupCount, boolean sync) {
    final String KEY = "key";
    final String VALUE = "value";
    final int nodeCount = backupCount + 1;
    final TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
    for (int i = 0; i < instances.length; i++) {
        instances[i] = instanceFactory.newHazelcastInstance();
    }
    final HazelcastInstance hz = instances[0];
    final CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(hz);
    final CacheManager cacheManager = cachingProvider.getCacheManager();
    final String cacheName = randomName();
    final CacheConfig cacheConfig = new CacheConfig().setName(cacheName);
    if (sync) {
        cacheConfig.setBackupCount(backupCount);
    } else {
        cacheConfig.setAsyncBackupCount(backupCount);
    }
    final Cache cache = cacheManager.createCache(cacheName, cacheConfig);
    warmUpPartitions(instances);
    waitAllForSafeState(instances);
    cache.put(KEY, VALUE);
    final Node node = getNode(hz);
    final InternalPartitionService partitionService = node.getPartitionService();
    final int keyPartitionId = partitionService.getPartitionId(KEY);
    for (int i = 1; i <= backupCount; i++) {
        final Node backupNode = getNode(instances[i]);
        final SerializationService serializationService = backupNode.getSerializationService();
        final ICacheService cacheService = backupNode.getNodeEngine().getService(ICacheService.SERVICE_NAME);
        if (sync) {
            checkSavedRecordOnBackup(KEY, VALUE, cacheName, keyPartitionId, serializationService, cacheService);
        } else {
            assertTrueEventually(new AssertTask() {

                @Override
                public void run() throws Exception {
                    checkSavedRecordOnBackup(KEY, VALUE, cacheName, keyPartitionId, serializationService, cacheService);
                }
            });
        }
    }
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.Node) SerializationService(com.hazelcast.spi.serialization.SerializationService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICacheService(com.hazelcast.cache.impl.ICacheService) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) CacheConfig(com.hazelcast.config.CacheConfig) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache)

Example 19 with SerializationService

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

the class CacheBasicAbstractTest method testInitableIterator.

@Test
public void testInitableIterator() {
    int testSize = 3007;
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    for (int fetchSize = 1; fetchSize < 102; fetchSize++) {
        SampleableConcurrentHashMap<Data, String> map = new SampleableConcurrentHashMap<Data, String>(1000);
        for (int i = 0; i < testSize; i++) {
            Integer key = i;
            Data data = serializationService.toData(key);
            String value1 = "value" + i;
            map.put(data, value1);
        }
        int nextTableIndex = Integer.MAX_VALUE;
        int total = 0;
        int remaining = testSize;
        while (remaining > 0 && nextTableIndex > 0) {
            int size = (remaining > fetchSize ? fetchSize : remaining);
            List<Data> keys = new ArrayList<Data>(size);
            nextTableIndex = map.fetchKeys(nextTableIndex, size, keys);
            remaining -= keys.size();
            total += keys.size();
        }
        assertEquals(testSize, total);
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SampleableConcurrentHashMap(com.hazelcast.util.SampleableConcurrentHashMap) ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) Test(org.junit.Test)

Example 20 with SerializationService

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

the class CachePutAllTest method testPutAll.

@Test
public void testPutAll() {
    ICache<String, String> cache = createCache();
    String cacheName = cache.getName();
    Map<String, String> entries = createAndFillEntries();
    cache.putAll(entries);
    // Verify that put-all 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-all 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);
        }
    }
}
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)

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