use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testTreeSetWithComparator.
/**
* Tests data serializing an {@link TreeSet}
*/
@Test
public void testTreeSetWithComparator() throws Exception {
Random random = getRandom();
int size = random.nextInt(50);
TreeSet set = new TreeSet(new MyComparator(size));
for (int i = 0; i < size; i++) {
set.add(new Long(random.nextLong()));
}
DataOutputStream out = getDataOutput();
DataSerializer.writeTreeSet(new TreeSet(new MyComparator(0)), out);
DataSerializer.writeTreeSet(set, out);
out.flush();
DataInput in = getDataInput();
TreeSet emptySet = DataSerializer.readTreeSet(in);
assertEquals(new TreeSet(new MyComparator(0)), emptySet);
assertEquals(new MyComparator(0), emptySet.comparator());
TreeSet set2 = DataSerializer.readTreeSet(in);
assertEquals(set, set2);
assertEquals(set.comparator(), set2.comparator());
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testTreeSet.
/**
* Tests data serializing an {@link TreeSet}
*/
@Test
public void testTreeSet() throws Exception {
Random random = getRandom();
TreeSet set = new TreeSet();
int size = random.nextInt(50);
for (int i = 0; i < size; i++) {
set.add(new Long(random.nextLong()));
}
DataOutputStream out = getDataOutput();
DataSerializer.writeTreeSet(null, out);
DataSerializer.writeTreeSet(new TreeSet(), out);
DataSerializer.writeTreeSet(set, out);
out.flush();
DataInput in = getDataInput();
assertEquals(null, DataSerializer.readTreeSet(in));
assertEquals(new TreeSet(), DataSerializer.readTreeSet(in));
TreeSet set2 = DataSerializer.readTreeSet(in);
assertEquals(set, set2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testByteArray.
/**
* Tests data serializing a <code>byte</code> array
*/
@Test
public void testByteArray() throws Exception {
byte[] array = new byte[] { (byte) 4, (byte) 5, (byte) 6 };
DataOutputStream out = getDataOutput();
DataSerializer.writeByteArray(array, out);
DataSerializer.writeObject(array, out);
out.flush();
DataInput in = getDataInput();
for (int idx = 0; idx < 2; idx++) {
byte[] array2 = (idx == 0) ? DataSerializer.readByteArray(in) : (byte[]) DataSerializer.readObject(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 testDouble.
/**
* Tests data serializing a {@link Double}
*/
@Test
public void testDouble() throws Exception {
Double value = new Double(getRandom().nextDouble());
DataOutputStream out = getDataOutput();
DataSerializer.writeDouble(value, out);
out.flush();
DataInput in = getDataInput();
Double value2 = DataSerializer.readDouble(in);
assertEquals(value, value2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testLinkedHashSetObject.
/**
* Tests data serializing an {@link LinkedHashSet} using {@link DataSerializer#writeObject}.
*/
@Test
public void testLinkedHashSetObject() throws Exception {
Random random = getRandom();
LinkedHashSet set = new LinkedHashSet();
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();
LinkedHashSet set2 = (LinkedHashSet) DataSerializer.readObject(in);
assertEquals(set, set2);
}
Aggregations