Search in sources :

Example 41 with Data

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;
}
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) DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)

Example 42 with Data

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);
}
Also used : NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) NearCacheTestUtils.getMapNearCacheManager(com.hazelcast.internal.nearcache.NearCacheTestUtils.getMapNearCacheManager) NearCacheTestUtils.createNearCacheConfig(com.hazelcast.internal.nearcache.NearCacheTestUtils.createNearCacheConfig) Config(com.hazelcast.config.Config) Data(com.hazelcast.nio.serialization.Data)

Example 43 with Data

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());
        }
    }
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) LockService(com.hazelcast.concurrent.lock.LockService) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) Data(com.hazelcast.nio.serialization.Data) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) LockResource(com.hazelcast.concurrent.lock.LockResource) Mockito.anyObject(org.mockito.Mockito.anyObject) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 44 with Data

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);
}
Also used : NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) NearCacheTestUtils.getMapNearCacheManager(com.hazelcast.internal.nearcache.NearCacheTestUtils.getMapNearCacheManager) NearCacheTestUtils.createNearCacheConfig(com.hazelcast.internal.nearcache.NearCacheTestUtils.createNearCacheConfig) Config(com.hazelcast.config.Config) Data(com.hazelcast.nio.serialization.Data)

Example 45 with Data

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);
}
Also used : Data(com.hazelcast.nio.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Data (com.hazelcast.nio.serialization.Data)773 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)140 Test (org.junit.Test)121 QuickTest (com.hazelcast.test.annotation.QuickTest)118 ParallelTest (com.hazelcast.test.annotation.ParallelTest)108 ArrayList (java.util.ArrayList)81 Map (java.util.Map)64 SerializationService (com.hazelcast.spi.serialization.SerializationService)54 HashMap (java.util.HashMap)54 NodeEngine (com.hazelcast.spi.NodeEngine)50 HashSet (java.util.HashSet)39 Address (com.hazelcast.nio.Address)28 AbstractMap (java.util.AbstractMap)28 Record (com.hazelcast.map.impl.record.Record)27 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 HeapData (com.hazelcast.internal.serialization.impl.HeapData)26 List (java.util.List)20 Future (java.util.concurrent.Future)20 CacheEventData (com.hazelcast.cache.impl.CacheEventData)19 Operation (com.hazelcast.spi.Operation)18