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