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()));
}
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) } });
}
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());
}
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);
}
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());
}
Aggregations