use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testTimeUnitObject.
/**
* Tests data serializing {@link TimeUnit}s using {@link DataSerializer#writeObject}.
*/
@Test
public void testTimeUnitObject() throws Exception {
DataOutputStream out = getDataOutput();
for (TimeUnit v : TimeUnit.values()) {
DataSerializer.writeObject(v, out, false);
}
out.flush();
DataInput in = getDataInput();
for (TimeUnit v : TimeUnit.values()) {
assertEquals(v, DataSerializer.readObject(in));
}
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testTreeSetObject.
/**
* Tests data serializing an {@link TreeSet} using {@link DataSerializer#writeObject}.
*/
@Test
public void testTreeSetObject() 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.writeObject(set, out);
out.flush();
DataInput in = getDataInput();
TreeSet set2 = (TreeSet) DataSerializer.readObject(in);
assertEquals(set, set2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testStackObject.
/**
* Tests data serializing an {@link Stack} using {@link DataSerializer#writeObject}.
*/
@Test
public void testStackObject() throws Exception {
Random random = getRandom();
Stack list = new Stack();
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();
Stack list2 = (Stack) DataSerializer.readObject(in);
assertEquals(list, list2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testIdentityHashMap.
/**
* Tests data serializing an {@link IdentityHashMap}
*/
@Test
public void testIdentityHashMap() throws Exception {
Random random = getRandom();
IdentityHashMap map = new IdentityHashMap();
int size = random.nextInt(50);
for (int i = 0; i < size; i++) {
Object key = new Long(random.nextLong());
Object value = String.valueOf(random.nextLong());
map.put(key, value);
}
DataOutputStream out = getDataOutput();
DataSerializer.writeIdentityHashMap(map, out);
out.flush();
DataInput in = getDataInput();
IdentityHashMap map2 = DataSerializer.readIdentityHashMap(in);
assertEquals(new HashMap(map), new HashMap(map2));
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testStringEncodingLengthCrossesBoundry.
/**
* Tests data serializing a non-<code>null</code> String whose length is > 0xFFFF, but who's utf-8
* encoded length is < 0xFFFF See bug 40932.
*/
@Test
public void testStringEncodingLengthCrossesBoundry() throws Exception {
StringBuffer sb = new StringBuffer(0xFFFF);
for (int i = 0; i < 0xFFFF; i++) {
if (i == 0) {
sb.append(Character.MAX_VALUE);
} else {
sb.append("a");
}
}
String value = sb.toString();
DataOutputStream out = getDataOutput();
DataSerializer.writeString(value, out);
DataSerializer.writeObject(value, out);
out.flush();
DataInput in = getDataInput();
String value2 = DataSerializer.readString(in);
assertEquals(value, value2);
value2 = (String) DataSerializer.readObject(in);
assertEquals(value, value2);
}
Aggregations