Search in sources :

Example 21 with HeapData

use of com.hazelcast.internal.serialization.impl.HeapData in project hazelcast by hazelcast.

the class BufferPoolTest method takeInputBuffer_whenPooledInstanceWithVersionSetIsReturned.

@Test
public void takeInputBuffer_whenPooledInstanceWithVersionSetIsReturned() {
    Data data = new HeapData(new byte[] {});
    BufferObjectDataInput found1 = bufferPool.takeInputBuffer(data);
    assertEquals(Version.UNKNOWN, found1.getVersion());
    found1.setVersion(Versions.CURRENT_CLUSTER_VERSION);
    bufferPool.returnInputBuffer(found1);
    BufferObjectDataInput found2 = bufferPool.takeInputBuffer(data);
    assertEquals(Version.UNKNOWN, found2.getVersion());
}
Also used : Data(com.hazelcast.internal.serialization.Data) HeapData(com.hazelcast.internal.serialization.impl.HeapData) HeapData(com.hazelcast.internal.serialization.impl.HeapData) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with HeapData

use of com.hazelcast.internal.serialization.impl.HeapData in project hazelcast by hazelcast.

the class BinaryCompatibilityTest method init.

@BeforeClass
public static void init() throws IOException {
    for (byte version : versions) {
        InputStream input = BinaryCompatibilityTest.class.getResourceAsStream("/" + createFileName(version));
        if (input == null) {
            fail("Could not locate file " + createFileName(version) + ". Follow the instructions in " + "BinaryCompatibilityFileGenerator to generate the file.");
        }
        DataInputStream inputStream = new DataInputStream(input);
        while (input.available() != 0) {
            String objectKey = inputStream.readUTF();
            int length = inputStream.readInt();
            if (length != NULL_OBJECT) {
                byte[] bytes = new byte[length];
                inputStream.read(bytes);
                dataMap.put(objectKey, new HeapData(bytes));
            }
        }
        inputStream.close();
    }
}
Also used : DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) DataInputStream(java.io.DataInputStream) HeapData(com.hazelcast.internal.serialization.impl.HeapData) BeforeClass(org.junit.BeforeClass)

Example 23 with HeapData

use of com.hazelcast.internal.serialization.impl.HeapData in project hazelcast by hazelcast.

the class EntryEventDataCacheTest method getOrCreateEventDataIncludingValues_whenAlreadyCached.

@Test
public void getOrCreateEventDataIncludingValues_whenAlreadyCached() throws Exception {
    // when: creating EntryEventData including values with same arguments
    EntryEventData eed = instance.getOrCreateEventData("test", ADDRESS, new HeapData(), new Object(), new Object(), new Object(), EntryEventType.ADDED.getType(), true);
    EntryEventData shouldBeCached = instance.getOrCreateEventData("test", ADDRESS, new HeapData(), new Object(), new Object(), new Object(), EntryEventType.ADDED.getType(), true);
    // then: returned instances are the same
    assertSame(eed, shouldBeCached);
}
Also used : Matchers.anyObject(org.mockito.Matchers.anyObject) HeapData(com.hazelcast.internal.serialization.impl.HeapData) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with HeapData

use of com.hazelcast.internal.serialization.impl.HeapData in project hazelcast by hazelcast.

the class EntryEventDataCacheTest method eventDataIncludingValues_whenDataExcludingValuesAreCached.

@Test
public void eventDataIncludingValues_whenDataExcludingValuesAreCached() throws Exception {
    // when: EntryEventData excluding values have been created
    EntryEventData eed = instance.getOrCreateEventData("test", ADDRESS, new HeapData(), new Object(), new Object(), new Object(), EntryEventType.ADDED.getType(), false);
    // then: eventDataIncludingValues returns null or empty collection
    assertTrue(instance.eventDataIncludingValues() == null || instance.eventDataIncludingValues().isEmpty());
}
Also used : Matchers.anyObject(org.mockito.Matchers.anyObject) HeapData(com.hazelcast.internal.serialization.impl.HeapData) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with HeapData

use of com.hazelcast.internal.serialization.impl.HeapData in project hazelcast by hazelcast.

the class EntryEventDataCacheTest method eventDataIncludingValues_whenValueIsCached.

@Test
public void eventDataIncludingValues_whenValueIsCached() throws Exception {
    // when: EntryEventData including values have been created
    EntryEventData eed = instance.getOrCreateEventData("test", ADDRESS, new HeapData(), new Object(), new Object(), new Object(), EntryEventType.ADDED.getType(), true);
    // then: the cache is not empty & eventDataIncludingValues returns the cached entry
    assertFalse(instance.isEmpty());
    assertSame(eed, instance.eventDataIncludingValues().iterator().next());
}
Also used : Matchers.anyObject(org.mockito.Matchers.anyObject) HeapData(com.hazelcast.internal.serialization.impl.HeapData) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HeapData (com.hazelcast.internal.serialization.impl.HeapData)28 QuickTest (com.hazelcast.test.annotation.QuickTest)18 Test (org.junit.Test)18 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)13 Matchers.anyObject (org.mockito.Matchers.anyObject)7 Data (com.hazelcast.internal.serialization.Data)6 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)4 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)2 HandlerStatus (com.hazelcast.internal.networking.HandlerStatus)2 Packet (com.hazelcast.internal.nio.Packet)2 SerializationService (com.hazelcast.spi.serialization.SerializationService)2 ByteBuffer (java.nio.ByteBuffer)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Before (org.junit.Before)2 MapPutCodec (com.hazelcast.client.impl.protocol.codec.MapPutCodec)1 PartitioningStrategy (com.hazelcast.core.PartitioningStrategy)1 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)1 MapUtil.createHashMap (com.hazelcast.internal.util.MapUtil.createHashMap)1 CustomByteArrayOutputStream (com.hazelcast.jet.impl.util.AsyncSnapshotWriterImpl.CustomByteArrayOutputStream)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1