Search in sources :

Example 71 with DataInput

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

Example 72 with DataInput

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

Example 73 with DataInput

use of java.io.DataInput in project geode by apache.

the class DataSerializableJUnitTest method testDateObject.

/**
   * Tests data serializing a {@link Date} using {@link DataSerializer#writeObject}.
   */
@Test
public void testDateObject() throws Exception {
    Date date = new Date();
    DataOutputStream out = getDataOutput();
    DataSerializer.writeObject(date, out);
    out.flush();
    DataInput in = getDataInput();
    Date date2 = (Date) DataSerializer.readObject(in);
    assertEquals(date, date2);
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 74 with DataInput

use of java.io.DataInput in project geode by apache.

the class DataSerializableJUnitTest method testByteArrayObject.

/**
   * Tests data serializing a <code>byte</code> array using {@link DataSerializer#writeObject}.
   */
@Test
public void testByteArrayObject() throws Exception {
    byte[] array = new byte[] { (byte) 4, (byte) 5, (byte) 6 };
    DataOutputStream out = getDataOutput();
    DataSerializer.writeObject(array, out);
    out.flush();
    DataInput in = getDataInput();
    byte[] array2 = (byte[]) DataSerializer.readObject(in);
    assertEquals(array.length, array2.length);
    for (int i = 0; i < array.length; i++) {
        assertEquals(array[i], array2[i]);
    }
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 75 with DataInput

use of java.io.DataInput in project geode by apache.

the class DataSerializableJUnitTest method testTreeMap.

/**
   * Tests data serializing an {@link TreeMap}
   */
@Test
public void testTreeMap() throws Exception {
    Random random = getRandom();
    TreeMap map = new TreeMap();
    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.writeTreeMap(null, out);
    DataSerializer.writeTreeMap(new TreeMap(), out);
    DataSerializer.writeTreeMap(map, out);
    out.flush();
    DataInput in = getDataInput();
    assertEquals(null, DataSerializer.readTreeMap(in));
    assertEquals(new TreeMap(), DataSerializer.readTreeMap(in));
    TreeMap map2 = DataSerializer.readTreeMap(in);
    assertEquals(map, map2);
}
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