use of org.apache.geode.internal.tcp.ByteBufferInputStream in project geode by apache.
the class DataSerializableJUnitTest method getDataInputStream.
private DataInputStream getDataInputStream() {
ByteBuffer bb = ByteBuffer.wrap(this.baos.toByteArray());
ByteBufferInputStream bbis = new ByteBufferInputStream(bb);
return new DataInputStream(bbis);
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream in project geode by apache.
the class DataSerializableJUnitTest method getDataInput.
/**
* Returns a <code>DataInput</code> to read from
*/
private DataInput getDataInput() {
// changed this to use ByteBufferInputStream to give us better
// test coverage of this class.
ByteBuffer bb = ByteBuffer.wrap(this.baos.toByteArray());
ByteBufferInputStream bbis = new ByteBufferInputStream(bb);
return bbis;
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream in project geode by apache.
the class DataSerializableJUnitTest method testVersionedDataSerializable.
/**
* Tests serializing an object that implements {@link DataSerializable}
*/
@Test
public void testVersionedDataSerializable() throws Exception {
VersionedDataSerializableImpl ds = new VersionedDataSerializableImpl(getRandom());
VersionedDataOutputStream v = new VersionedDataOutputStream(this.baos, Version.GFE_70);
DataSerializer.writeObject(ds, v);
v.flush();
ByteBuffer bb = ByteBuffer.wrap(this.baos.toByteArray());
ByteBufferInputStream bbis = new ByteBufferInputStream(bb);
VersionedDataInputStream vin = new VersionedDataInputStream(bbis, Version.GFE_70);
VersionedDataSerializableImpl ds2 = (VersionedDataSerializableImpl) DataSerializer.readObject(vin);
assertEquals(ds, ds2);
assertTrue(ds.preMethodInvoked());
assertTrue(ds2.preMethodInvoked());
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream in project geode by apache.
the class ByteArrayData method getDataInputStream.
public DataInputStream getDataInputStream() {
ByteBuffer bb = ByteBuffer.wrap(this.baos.toByteArray());
ByteBufferInputStream bbis = new ByteBufferInputStream(bb);
return new DataInputStream(bbis);
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream in project geode by apache.
the class DataSerializableJUnitTest method testStatArchiveCompactValueSerialization.
/**
* Test for {@link StatArchiveWriter#writeCompactValue} and
* {@link StatArchiveWriter#readCompactValue}. Also added test for
* ByteBufferInputStream#readUnsigned* methods (bug #41197).
*/
@Test
public void testStatArchiveCompactValueSerialization() throws Exception {
// test all combos of valueToTest and + and -offsets
long[] valuesToTest = new long[] { 0, Byte.MAX_VALUE, Byte.MIN_VALUE, Short.MAX_VALUE, Short.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Long.MAX_VALUE, Long.MIN_VALUE };
int[] offsets = new int[] { 0, 1, 4, 9, 14, 15, 16, -1, -4, -9, -14, -15, -16 };
// write all combos of longs to the outputstream
HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
DataOutput out = hdos;
for (long valueToTest : valuesToTest) {
for (int offset : offsets) {
long val = valueToTest + offset;
StatArchiveWriter.writeCompactValue(val, out);
}
}
// now read all the combos
byte[] bytes = hdos.toByteArray();
DataInput in = new DataInputStream(new ByteArrayInputStream(bytes));
for (long valueToTest : valuesToTest) {
for (int offset : offsets) {
long expectedVal = valueToTest + offset;
long val = StatArchiveWriter.readCompactValue(in);
assertEquals(expectedVal, val);
}
}
// also test using ByteBufferInputStream (bug #41197)
in = new ByteBufferInputStream(ByteBuffer.wrap(bytes));
for (long valueToTest : valuesToTest) {
for (int offset : offsets) {
long expectedVal = valueToTest + offset;
long val = StatArchiveWriter.readCompactValue(in);
assertEquals(expectedVal, val);
}
}
// now check ByteBufferInputStream#readUnsignedShort explicitly
// readUnsignedByte is already tested in StatArchiveWriter.readCompactValue
// above likely in a more thorough manner than a simple explicit test would
short[] shortValuesToTest = new short[] { 0, Byte.MAX_VALUE, Byte.MIN_VALUE, Short.MAX_VALUE, Short.MIN_VALUE };
ByteBufferOutputStream bos = new ByteBufferOutputStream();
out = new DataOutputStream(bos);
for (short valueToTest : shortValuesToTest) {
for (int offset : offsets) {
short val = (short) (valueToTest + offset);
out.writeShort(val);
}
}
// now read all the combos
in = new ByteBufferInputStream(bos.getContentBuffer());
for (short valueToTest : shortValuesToTest) {
for (int offset : offsets) {
int expectedVal = (valueToTest + offset) & 0xffff;
int val = in.readUnsignedShort();
assertEquals(expectedVal, val);
}
}
}
Aggregations