Search in sources :

Example 36 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class AbstractSerializationServiceTest method testToObject_ServiceInactive.

@Test
public void testToObject_ServiceInactive() throws Exception {
    expectedException.expect(HazelcastSerializationException.class);
    expectedException.expectCause(Is.is(IsInstanceOf.<Throwable>instanceOf(HazelcastInstanceNotActiveException.class)));
    abstractSerializationService.register(StringBuffer.class, new StringBufferSerializer(false));
    Data data = abstractSerializationService.toData(new StringBuffer());
    abstractSerializationService.dispose();
    abstractSerializationService.toObject(data);
}
Also used : Data(com.hazelcast.nio.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) CustomSerializationTest(com.hazelcast.nio.serialization.CustomSerializationTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 37 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class AbstractSerializationServiceTest method testDeserializationForSpecificType.

@Test
public void testDeserializationForSpecificType() {
    BaseClass baseObject = new BaseClass(5, "abc");
    ExtendedClass extendedObject = new ExtendedClass(baseObject, 378);
    Data extendedData = abstractSerializationService.toData(extendedObject);
    Object deserializedObject = abstractSerializationService.toObject(extendedData);
    assertEquals(extendedObject, deserializedObject);
    deserializedObject = abstractSerializationService.toObject(extendedObject, BaseClass.class);
    assertEquals(baseObject, deserializedObject);
}
Also used : Data(com.hazelcast.nio.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) CustomSerializationTest(com.hazelcast.nio.serialization.CustomSerializationTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 38 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class ByteArrayObjectDataInputTest method testReadData.

@Test
public void testReadData() throws Exception {
    byte[] bytesBE = { 0, 0, 0, 0, 0, 0, 0, 8, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, -1, -1, -1, -1 };
    byte[] bytesLE = { 0, 0, 0, 0, 8, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, -1, -1, -1, -1 };
    in.init((byteOrder == BIG_ENDIAN ? bytesBE : bytesLE), 0);
    in.position(bytesLE.length - 4);
    Data nullData = in.readData();
    in.position(0);
    Data theZeroLenghtArray = in.readData();
    in.position(4);
    Data data = in.readData();
    assertNull(nullData);
    assertEquals(0, theZeroLenghtArray.getType());
    assertArrayEquals(new byte[0], theZeroLenghtArray.toByteArray());
    assertArrayEquals(new byte[] { -1, -1, -1, -1, 0, 0, 0, 0 }, data.toByteArray());
}
Also used : Data(com.hazelcast.nio.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 39 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class AbstractSerializationServiceTest method testExternalizable.

@Test
public void testExternalizable() {
    ExternalizableValue original = new ExternalizableValue(100);
    Data data = abstractSerializationService.toData(original);
    ExternalizableValue found = abstractSerializationService.toObject(data);
    assertNotNull(found);
    assertEquals(original.value, found.value);
}
Also used : Data(com.hazelcast.nio.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) CustomSerializationTest(com.hazelcast.nio.serialization.CustomSerializationTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 40 with Data

use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.

the class LiteMemberMapNearCacheBasicTest method createContext.

@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext() {
    HazelcastInstance member = hazelcastFactory.newHazelcastInstance(createConfig(nearCacheConfig, false));
    HazelcastInstance liteMember = hazelcastFactory.newHazelcastInstance(createConfig(nearCacheConfig, true));
    IMap<K, V> memberMap = member.getMap(DEFAULT_NEAR_CACHE_NAME);
    IMap<K, V> liteMemberMap = liteMember.getMap(DEFAULT_NEAR_CACHE_NAME);
    NearCacheManager nearCacheManager = getMapNearCacheManager(liteMember);
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
    return new NearCacheTestContext<K, V, Data, String>(getSerializationService(member), liteMember, member, new IMapDataStructureAdapter<K, V>(liteMemberMap), new IMapDataStructureAdapter<K, V>(memberMap), 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) Data(com.hazelcast.nio.serialization.Data)

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