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);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testEnum.
/**
* Tests Dataserializing an Enum
*/
@Test
public void testEnum() throws Exception {
DAY_OF_WEEK e = DAY_OF_WEEK.SUN;
MONTH m = MONTH.FEB;
DataOutputStream out = getDataOutput();
DataSerializer.writeEnum(e, out);
DataSerializer.writeEnum(m, out);
try {
DataSerializer.writeEnum(null, out);
fail("Expected exception not thrown");
} catch (NullPointerException ex) {
}
out.flush();
DataInput in = getDataInput();
Class c = null;
try {
DataSerializer.readEnum(c, in);
fail("Expected exception not thrown");
} catch (NullPointerException ex) {
}
c = Foo.class;
try {
DataSerializer.readEnum(c, in);
fail("Expected exception not thrown");
} catch (IllegalArgumentException ex) {
}
DAY_OF_WEEK e2 = DataSerializer.readEnum(DAY_OF_WEEK.class, in);
MONTH m2 = DataSerializer.readEnum(MONTH.class, in);
assertEquals(e, e2);
assertEquals(m, m2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testByteObject.
/**
* Tests data serializing a {@link Byte} using {@link DataSerializer#writeObject}.
*/
@Test
public void testByteObject() throws Exception {
Byte value = new Byte((byte) getRandom().nextInt());
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(value, out);
out.flush();
DataInput in = getDataInput();
Byte value2 = (Byte) DataSerializer.readObject(in);
assertEquals(value, value2);
}
Aggregations