Search in sources :

Example 31 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class GIIDeltaDUnitTest method getDiskRVV.

protected RegionVersionVector getDiskRVV(VM vm) throws IOException, ClassNotFoundException {
    SerializableCallable createData = new SerializableCallable("getRVV") {

        public Object call() throws Exception {
            Cache cache = getCache();
            LocalRegion region = (LocalRegion) cache.getRegion(REGION_NAME);
            RegionVersionVector rvv = region.getDiskRegion().getRegionVersionVector();
            rvv = rvv.getCloneForTransmission();
            HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
            // Using gemfire serialization because
            // RegionVersionVector is not java serializable
            DataSerializer.writeObject(rvv, hdos);
            return hdos.toByteArray();
        }
    };
    byte[] result = (byte[]) vm.invoke(createData);
    ByteArrayInputStream bais = new ByteArrayInputStream(result);
    return DataSerializer.readObject(new DataInputStream(bais));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) DataInputStream(java.io.DataInputStream)

Example 32 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class FetchEntriesMessageJUnitTest method testProcessChunk.

@Test
public void testProcessChunk() throws Exception {
    cache = Fakes.cache();
    PartitionedRegion pr = mock(PartitionedRegion.class);
    InternalDistributedSystem system = cache.getInternalDistributedSystem();
    FetchEntriesResponse response = new FetchEntriesResponse(system, pr, null, 0);
    HeapDataOutputStream chunkStream = createDummyChunk();
    FetchEntriesReplyMessage reply = new FetchEntriesReplyMessage(null, 0, 0, chunkStream, 0, 0, 0, false, false);
    reply.chunk = chunkStream.toByteArray();
    response.processChunk(reply);
    assertNull(response.returnRVV);
    assertEquals(2, response.returnValue.size());
    assertTrue(response.returnValue.get("keyWithOutVersionTag").equals("valueWithOutVersionTag"));
    assertTrue(response.returnValue.get("keyWithVersionTag").equals("valueWithVersionTag"));
    assertNull(response.returnVersions.get("keyWithOutVersionTag"));
    assertNotNull(response.returnVersions.get("keyWithVersionTag"));
}
Also used : FetchEntriesResponse(org.apache.geode.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesResponse) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) FetchEntriesReplyMessage(org.apache.geode.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesReplyMessage) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 33 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class BlobHelperTest method serializeNullToStreamWritesNullAsBytes.

@Test
public void serializeNullToStreamWritesNullAsBytes() throws Exception {
    HeapDataOutputStream hdos = createHeapDataOutputStream();
    serializeTo(null, hdos);
    assertThat(hdos.toByteArray()).isNotNull().isEqualTo(this.bytesOfNull);
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 34 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class BlobHelperTest method serializeUnserializableToStreamThrowsNotSerializableException.

@Test
public void serializeUnserializableToStreamThrowsNotSerializableException() throws Exception {
    HeapDataOutputStream hdos = createHeapDataOutputStream();
    assertThatThrownBy(() -> serializeTo(new Object(), hdos)).isExactlyInstanceOf(NotSerializableException.class).hasMessage(Object.class.getName());
}
Also used : NotSerializableException(java.io.NotSerializableException) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) StoredObject(org.apache.geode.internal.offheap.StoredObject) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 35 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class BlobHelperTest method serializeMapToStreamWritesMapAsBytes.

@Test
public void serializeMapToStreamWritesMapAsBytes() throws Exception {
    HeapDataOutputStream hdos = createHeapDataOutputStream();
    serializeTo(this.mapWithTwoEntries, hdos);
    assertThat(hdos.toByteArray()).isNotNull().isEqualTo(bytesOfMap);
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)134 Test (org.junit.Test)55 IOException (java.io.IOException)40 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)36 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)33 DataInputStream (java.io.DataInputStream)29 ByteArrayInputStream (java.io.ByteArrayInputStream)23 UnitTest (org.apache.geode.test.junit.categories.UnitTest)15 DiskAccessException (org.apache.geode.cache.DiskAccessException)12 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)11 PdxSerializerObject (org.apache.geode.internal.PdxSerializerObject)10 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)8 Version (org.apache.geode.internal.Version)8 DataInput (java.io.DataInput)7 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)7 OutputStream (java.io.OutputStream)6 Properties (java.util.Properties)6 ByteBuffer (java.nio.ByteBuffer)5 HashMap (java.util.HashMap)5 InternalGemFireException (org.apache.geode.InternalGemFireException)5