Search in sources :

Example 51 with DataInput

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

the class DataSerializableJUnitTest method testInteger.

/**
   * Tests data serializing a {@link Integer}
   */
@Test
public void testInteger() throws Exception {
    Integer value = new Integer(getRandom().nextInt());
    DataOutputStream out = getDataOutput();
    DataSerializer.writeInteger(value, out);
    out.flush();
    DataInput in = getDataInput();
    Integer value2 = DataSerializer.readInteger(in);
    assertEquals(value, value2);
}
Also used : BigInteger(java.math.BigInteger) DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 52 with DataInput

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

the class DataSerializableJUnitTest method testBooleanObject.

/**
   * Tests data serializing a {@link Boolean} using {@link DataSerializer#writeObject}.
   */
@Test
public void testBooleanObject() throws Exception {
    Boolean value = new Boolean(getRandom().nextInt() % 2 == 0);
    DataOutputStream out = getDataOutput();
    DataSerializer.writeObject(value, out);
    out.flush();
    DataInput in = getDataInput();
    Boolean value2 = (Boolean) 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 53 with DataInput

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

the class DataSerializableJUnitTest method testVector.

/**
   * Tests data serializing an {@link Vector}
   */
@Test
public void testVector() throws Exception {
    Random random = getRandom();
    Vector list = new Vector();
    int size = random.nextInt(50);
    for (int i = 0; i < size; i++) {
        list.add(new Long(random.nextLong()));
    }
    DataOutputStream out = getDataOutput();
    DataSerializer.writeVector(list, out);
    out.flush();
    DataInput in = getDataInput();
    Vector list2 = DataSerializer.readVector(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 54 with DataInput

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

the class DataSerializableJUnitTest method testShortArray.

/**
   * Tests data serializing a <code>short</code> array
   */
@Test
public void testShortArray() throws Exception {
    short[] array = new short[] { (short) 4, (short) 5, (short) 6 };
    DataOutputStream out = getDataOutput();
    DataSerializer.writeShortArray(array, out);
    out.flush();
    DataInput in = getDataInput();
    short[] array2 = DataSerializer.readShortArray(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 55 with DataInput

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

the class DataSerializableJUnitTest method testHashSetObject.

/**
   * Tests data serializing an {@link HashSet} using {@link DataSerializer#writeObject}.
   */
@Test
public void testHashSetObject() throws Exception {
    Random random = getRandom();
    HashSet set = new HashSet();
    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();
    HashSet set2 = (HashSet) 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)

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