use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testBigInteger.
@Test
public void testBigInteger() throws Exception {
BigInteger o = new BigInteger("12345678901234567890");
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(o, out, false);
out.flush();
DataInput in = getDataInput();
BigInteger o2 = (BigInteger) DataSerializer.readObject(in);
assertEquals(o, o2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testProperties.
@Test
public void testProperties() throws Exception {
DataOutputStream out = getDataOutput();
DataSerializer.writeProperties(new Properties(), out);
DataSerializer.writeProperties(null, out);
Properties p1 = new Properties();
p1.setProperty("aKey1", "aValue1");
p1.setProperty("aKey2", "aValue2");
DataSerializer.writeProperties(p1, out);
Properties p2 = new Properties();
p2.put("aKey1", new Integer(1));
p2.put("aKey2", new Integer(2));
DataSerializer.writeProperties(p2, out);
out.flush();
DataInput in = getDataInput();
assertEquals(new Properties(), DataSerializer.readProperties(in));
assertEquals(null, DataSerializer.readProperties(in));
assertEquals(p1, DataSerializer.readProperties(in));
assertEquals(p2, DataSerializer.readProperties(in));
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testDoubleObject.
/**
* Tests data serializing a {@link Double} using {@link DataSerializer#writeObject}.
*/
@Test
public void testDoubleObject() throws Exception {
Double value = new Double(getRandom().nextDouble());
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(value, out);
out.flush();
DataInput in = getDataInput();
Double value2 = (Double) DataSerializer.readObject(in);
assertEquals(value, value2);
}
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);
}
Aggregations