use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testVector.
/**
* Tests data serializing an {@link Vector}
*/
@Test
public void testVector() throws Exception {
Random random = getRandom();
Vector list = new Vector();
int size = random.nextInt(50);
for (int i = 0; i < size; i++) {
list.add(new Long(random.nextLong()));
}
DataOutputStream out = getDataOutput();
DataSerializer.writeVector(list, out);
out.flush();
DataInput in = getDataInput();
Vector list2 = DataSerializer.readVector(in);
assertEquals(list, list2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testShortArray.
/**
* Tests data serializing a <code>short</code> array
*/
@Test
public void testShortArray() throws Exception {
short[] array = new short[] { (short) 4, (short) 5, (short) 6 };
DataOutputStream out = getDataOutput();
DataSerializer.writeShortArray(array, out);
out.flush();
DataInput in = getDataInput();
short[] array2 = DataSerializer.readShortArray(in);
assertEquals(array.length, array2.length);
for (int i = 0; i < array.length; i++) {
assertEquals(array[i], array2[i]);
}
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testHashSetObject.
/**
* Tests data serializing an {@link HashSet} using {@link DataSerializer#writeObject}.
*/
@Test
public void testHashSetObject() throws Exception {
Random random = getRandom();
HashSet set = new HashSet();
int size = random.nextInt(50);
for (int i = 0; i < size; i++) {
set.add(new Long(random.nextLong()));
}
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(set, out);
out.flush();
DataInput in = getDataInput();
HashSet set2 = (HashSet) DataSerializer.readObject(in);
assertEquals(set, set2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testVectorObject.
/**
* Tests data serializing an {@link Vector} using {@link DataSerializer#writeObject}.
*/
@Test
public void testVectorObject() throws Exception {
Random random = getRandom();
Vector list = new Vector();
int size = random.nextInt(50);
for (int i = 0; i < size; i++) {
list.add(new Long(random.nextLong()));
}
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(list, out);
out.flush();
DataInput in = getDataInput();
Vector list2 = (Vector) DataSerializer.readObject(in);
assertEquals(list, list2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testWriteObjectAsByteArray.
@Test
public void testWriteObjectAsByteArray() throws Exception {
// make sure recursive calls to WriteObjectAsByteArray work to test bug 38194
Object v = new WOABA();
DataOutputStream out = getDataOutput();
DataSerializer.writeObjectAsByteArray(v, out);
out.flush();
DataInput in = getDataInput();
byte[] b2 = DataSerializer.readByteArray(in);
// todo should we deserislize the byte[] and make sure it is equal to v?
ByteArrayInputStream bais = new ByteArrayInputStream(b2);
DataInputStream dis = new DataInputStream(bais);
Object v2 = DataSerializer.readObject(dis);
if (!(v2 instanceof WOABA)) {
fail("expected instance of WOABA but found " + v2.getClass());
}
}
Aggregations