use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class WriteBehindQueueTest method createDelayedEntryList.
private List<DelayedEntry> createDelayedEntryList(int numberOfEntriesToCreate) {
final List<DelayedEntry> list = new ArrayList<DelayedEntry>(numberOfEntriesToCreate);
SerializationService ss1 = new DefaultSerializationServiceBuilder().build();
final long storeTime = Clock.currentTimeMillis();
for (int i = 0; i < numberOfEntriesToCreate; i++) {
final DelayedEntry<Data, Object> e = DelayedEntries.createWithoutValue(ss1.toData(i), storeTime, i);
list.add(e);
}
return list;
}
use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class MapNearCacheBasicTest method createContext.
@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext() {
Config config = getConfig();
config.getMapConfig(DEFAULT_NEAR_CACHE_NAME).setNearCacheConfig(nearCacheConfig);
HazelcastInstance[] instances = hazelcastFactory.newInstances(config);
HazelcastInstance member = instances[0];
IMap<K, V> map = member.getMap(DEFAULT_NEAR_CACHE_NAME);
NearCacheManager nearCacheManager = getMapNearCacheManager(member);
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
return new NearCacheTestContext<K, V, Data, String>(getSerializationService(member), member, new IMapDataStructureAdapter<K, V>(map), true, nearCache, nearCacheManager);
}
use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class MapTransactionTest method testGetForUpdate_releasesBackupLock.
@Test
public void testGetForUpdate_releasesBackupLock() {
Config config = getConfig();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = factory.newHazelcastInstance(config);
HazelcastInstance instance2 = factory.newHazelcastInstance(config);
final String keyOwnedByInstance2 = generateKeyOwnedBy(instance2);
instance1.executeTransaction(new TransactionalTask<Object>() {
@Override
public Object execute(TransactionalTaskContext context) throws TransactionException {
TransactionalMap<Object, Object> map = context.getMap(randomString());
map.getForUpdate(keyOwnedByInstance2);
return null;
}
});
Node node = TestUtil.getNode(instance1);
Data keyData = node.nodeEngine.toData(keyOwnedByInstance2);
LockService lockService = node.nodeEngine.getService(LockService.SERVICE_NAME);
for (LockResource lockResource : lockService.getAllLocks()) {
if (keyData.equals(lockResource.getKey())) {
assertEquals(0, lockResource.getLockCount());
}
}
}
use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class TxnMapNearCacheBasicTest method createContext.
@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext() {
Config config = getConfig();
config.getMapConfig(DEFAULT_NEAR_CACHE_NAME).setNearCacheConfig(nearCacheConfig);
HazelcastInstance[] instances = hazelcastFactory.newInstances(config);
HazelcastInstance member = instances[0];
// this creates the Near Cache instance
member.getMap(DEFAULT_NEAR_CACHE_NAME);
NearCacheManager nearCacheManager = getMapNearCacheManager(member);
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
return new NearCacheTestContext<K, V, Data, String>(getSerializationService(member), member, new TransactionalMapDataStructureAdapter<K, V>(member, DEFAULT_NEAR_CACHE_NAME), false, nearCache, nearCacheManager);
}
use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class RecordsTest method getValueOrCachedValue_whenRecordIsCachedDataRecord_thenCache.
@Test
public void getValueOrCachedValue_whenRecordIsCachedDataRecord_thenCache() {
String objectPayload = "foo";
Data dataPayload = serializationService.toData(objectPayload);
Record record = new CachedDataRecord(dataPayload);
Object firstDeserializedValue = Records.getValueOrCachedValue(record, serializationService);
assertEquals(objectPayload, firstDeserializedValue);
// we don't need serialization service for the 2nd call
Object secondDeserializedValue = Records.getValueOrCachedValue(record, null);
assertSame(firstDeserializedValue, secondDeserializedValue);
}
Aggregations