use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class OffHeapWriteObjectAsByteArrayJUnitTest method testStringChunk.
@Test
public void testStringChunk() throws IOException, ClassNotFoundException {
byte[] expected = EntryEventImpl.serialize("1234567890");
StoredObject so = createStoredObject(expected, true, false);
assertTrue(so instanceof OffHeapStoredObject);
HeapDataOutputStream hdos = new HeapDataOutputStream(new byte[1024]);
DataSerializer.writeObjectAsByteArray(so, hdos);
DataInputStream in = createInput(hdos);
byte[] actual = DataSerializer.readByteArray(in);
assertArrayEquals(expected, actual);
assertNoMoreInput(in);
}
use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class OffHeapStoredObjectJUnitTest method sendToShouldWriteSerializedValueToDataOutputIfValueIsSerialized.
@Test
public void sendToShouldWriteSerializedValueToDataOutputIfValueIsSerialized() throws IOException {
OffHeapStoredObject chunk = createValueAsSerializedStoredObject(getValue());
OffHeapStoredObject spyChunk = spy(chunk);
HeapDataOutputStream dataOutput = mock(HeapDataOutputStream.class);
ByteBuffer directByteBuffer = ByteBuffer.allocate(1024);
doReturn(directByteBuffer).when(spyChunk).createDirectByteBuffer();
doNothing().when(dataOutput).write(directByteBuffer);
spyChunk.sendTo(dataOutput);
verify(dataOutput, times(1)).write(directByteBuffer);
chunk.release();
}
use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class OffHeapStoredObjectJUnitTest method sendAsByteArrayShouldWriteValueToDataOutput.
@Test
public void sendAsByteArrayShouldWriteValueToDataOutput() throws IOException {
byte[] regionEntryValue = getValueAsByteArray();
OffHeapStoredObject chunk = createValueAsUnserializedStoredObject(regionEntryValue);
// writeByte is a final method and cannot be mocked, so creating a real one
HeapDataOutputStream dataOutput = new HeapDataOutputStream(Version.CURRENT);
chunk.sendAsByteArray(dataOutput);
byte[] actual = dataOutput.toByteArray();
byte[] expected = new byte[regionEntryValue.length + 1];
expected[0] = (byte) regionEntryValue.length;
System.arraycopy(regionEntryValue, 0, expected, 1, regionEntryValue.length);
assertNotNull(dataOutput);
assertThat(actual).isEqualTo(expected);
chunk.release();
}
use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class OffHeapStoredObjectJUnitTest method sendToShouldWriteUnserializedValueToDataOutputIfValueIsUnserialized.
@Test
public void sendToShouldWriteUnserializedValueToDataOutputIfValueIsUnserialized() throws IOException {
byte[] regionEntryValue = getValueAsByteArray();
OffHeapStoredObject chunk = createValueAsUnserializedStoredObject(regionEntryValue);
// writeByte is a final method and cannot be mocked, so creating a real one
HeapDataOutputStream dataOutput = new HeapDataOutputStream(Version.CURRENT);
chunk.sendTo(dataOutput);
byte[] actual = dataOutput.toByteArray();
byte[] expected = new byte[regionEntryValue.length + 2];
expected[0] = DSCODE.BYTE_ARRAY;
expected[1] = (byte) regionEntryValue.length;
System.arraycopy(regionEntryValue, 0, expected, 2, regionEntryValue.length);
assertNotNull(dataOutput);
assertThat(actual).isEqualTo(expected);
chunk.release();
}
use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class OffHeapValidationJUnitTest method putCompressedString.
private void putCompressedString(Region<Object, Object> region, List<ExpectedValues> expected) throws IOException {
String key = "keyString";
String value = "this is a string";
region.put(key, value);
HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
DataSerializer.writeObject(value, hdos);
byte[] uncompressedBytes = hdos.toByteArray();
byte[] expectedValue = SnappyCompressor.getDefaultInstance().compress(uncompressedBytes);
expected.add(new ExpectedValues(expectedValue, 32, "compressed object of size " + expectedValue.length, -1, getMemoryAddress(region, key), 1, 0, true, true));
}
Aggregations