Search in sources :

Example 66 with DataInput

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));
    }
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) TimeUnit(java.util.concurrent.TimeUnit) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 67 with DataInput

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);
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 68 with DataInput

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);
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 69 with DataInput

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));
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 70 with DataInput

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);
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

DataInput (java.io.DataInput)247 Test (org.junit.Test)132 DataOutputStream (java.io.DataOutputStream)117 DataInputStream (java.io.DataInputStream)112 ByteArrayInputStream (java.io.ByteArrayInputStream)106 UnitTest (org.apache.geode.test.junit.categories.UnitTest)96 ByteArrayOutputStream (java.io.ByteArrayOutputStream)29 DataOutput (java.io.DataOutput)23 IOException (java.io.IOException)21 ArrayList (java.util.ArrayList)16 ARecord (org.apache.asterix.om.base.ARecord)14 EOFException (java.io.EOFException)9 File (java.io.File)9 BufferedInputStream (java.io.BufferedInputStream)8 HashMap (java.util.HashMap)7 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)7 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)7 GrowableArray (org.apache.hyracks.data.std.util.GrowableArray)7 FileInputStream (java.io.FileInputStream)6 ByteBuffer (java.nio.ByteBuffer)6