Search in sources :

Example 6 with HeapData

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

the class OutboundResponseHandlerTest method testToNormalResponsePacket.

private void testToNormalResponsePacket(Object value, int callId, int backupAcks, boolean urgent) {
    Packet packet = handler.toNormalResponsePacket(callId, backupAcks, urgent, value);
    HeapData expected = serializationService.toData(new NormalResponse(value, callId, backupAcks, urgent));
    assertEquals(expected, new HeapData(packet.toByteArray()));
}
Also used : Packet(com.hazelcast.internal.nio.Packet) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) HeapData(com.hazelcast.internal.serialization.impl.HeapData)

Example 7 with HeapData

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

the class EntryEventDataCacheTest method parameters.

@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> parameters() {
    // setup mock MapServiceContext & NodeEngine, required by FilteringStrategy's
    MapServiceContext mapServiceContext = mock(MapServiceContext.class);
    NodeEngine mockNodeEngine = mock(NodeEngine.class);
    when(mockNodeEngine.getThisAddress()).thenReturn(ADDRESS);
    when(mapServiceContext.toData(anyObject())).thenReturn(new HeapData());
    when(mapServiceContext.getNodeEngine()).thenReturn(mockNodeEngine);
    return Arrays.asList(new Object[][] { { new DefaultEntryEventFilteringStrategy(null, mapServiceContext) }, { new QueryCacheNaturalFilteringStrategy(null, mapServiceContext) } });
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) HeapData(com.hazelcast.internal.serialization.impl.HeapData) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 8 with HeapData

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

the class EntryEventDataCacheTest method eventDataExcludingValues_whenValueIsCached.

@Test
public void eventDataExcludingValues_whenValueIsCached() 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: the cache is not empty & eventDataExcludingValues returns the cached entry
    assertFalse(instance.isEmpty());
    assertSame(eed, instance.eventDataExcludingValues().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)

Example 9 with HeapData

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

the class EntryEventDataCacheTest method getOrCreateEventDataExcludingValues_whenAlreadyCached.

@Test
public void getOrCreateEventDataExcludingValues_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(), false);
    EntryEventData shouldBeCached = instance.getOrCreateEventData("test", ADDRESS, new HeapData(), new Object(), new Object(), new Object(), EntryEventType.ADDED.getType(), false);
    // 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 10 with HeapData

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

the class AsyncSnapshotWriterImplTest method test_serializeAndDeserialize.

@Test
public void test_serializeAndDeserialize() throws Exception {
    // This is the way we serialize and deserialize objects into the snapshot. We depend on some internals of IMDG:
    // - using the HeapData.toByteArray() from offset 4
    // - concatenate them into one array
    // - read that array with createObjectDataInput(byte[])
    // Purpose of this test is to check that they didn't change anything...
    Data serialized1 = serializationService.toData("foo");
    Data serialized2 = serializationService.toData("bar");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    Stream.of(serialized1, serialized2).forEach(serialized -> {
        Assert.assertTrue("unexpected class: " + serialized.getClass(), serialized instanceof HeapData);
        byte[] bytes = serialized.toByteArray();
        os.write(bytes, HeapData.TYPE_OFFSET, bytes.length - HeapData.TYPE_OFFSET);
    });
    BufferObjectDataInput in = serializationService.createObjectDataInput(os.toByteArray());
    Assert.assertEquals("foo", in.readObject());
    Assert.assertEquals("bar", in.readObject());
}
Also used : HeapData(com.hazelcast.internal.serialization.impl.HeapData) Data(com.hazelcast.internal.serialization.Data) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CustomByteArrayOutputStream(com.hazelcast.jet.impl.util.AsyncSnapshotWriterImpl.CustomByteArrayOutputStream) 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)

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