use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testInteger.
/**
* Tests data serializing a {@link Integer}
*/
@Test
public void testInteger() throws Exception {
Integer value = new Integer(getRandom().nextInt());
DataOutputStream out = getDataOutput();
DataSerializer.writeInteger(value, out);
out.flush();
DataInput in = getDataInput();
Integer value2 = DataSerializer.readInteger(in);
assertEquals(value, value2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testBooleanObject.
/**
* Tests data serializing a {@link Boolean} using {@link DataSerializer#writeObject}.
*/
@Test
public void testBooleanObject() throws Exception {
Boolean value = new Boolean(getRandom().nextInt() % 2 == 0);
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(value, out);
out.flush();
DataInput in = getDataInput();
Boolean value2 = (Boolean) DataSerializer.readObject(in);
assertEquals(value, value2);
}
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);
}
Aggregations