Search in sources :

Example 56 with DataInput

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

the class DataSerializableJUnitTest method testVectorObject.

/**
   * Tests data serializing an {@link Vector} using {@link DataSerializer#writeObject}.
   */
@Test
public void testVectorObject() 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.writeObject(list, out);
    out.flush();
    DataInput in = getDataInput();
    Vector list2 = (Vector) 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 57 with DataInput

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

the class DataSerializableJUnitTest method testWriteObjectAsByteArray.

@Test
public void testWriteObjectAsByteArray() throws Exception {
    // make sure recursive calls to WriteObjectAsByteArray work to test bug 38194
    Object v = new WOABA();
    DataOutputStream out = getDataOutput();
    DataSerializer.writeObjectAsByteArray(v, out);
    out.flush();
    DataInput in = getDataInput();
    byte[] b2 = DataSerializer.readByteArray(in);
    // todo should we deserislize the byte[] and make sure it is equal to v?
    ByteArrayInputStream bais = new ByteArrayInputStream(b2);
    DataInputStream dis = new DataInputStream(bais);
    Object v2 = DataSerializer.readObject(dis);
    if (!(v2 instanceof WOABA)) {
        fail("expected instance of WOABA but found " + v2.getClass());
    }
}
Also used : DataInput(java.io.DataInput) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) DataInputStream(java.io.DataInputStream) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 58 with DataInput

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

the class DataSerializableJUnitTest method testBigInteger.

@Test
public void testBigInteger() throws Exception {
    BigInteger o = new BigInteger("12345678901234567890");
    DataOutputStream out = getDataOutput();
    DataSerializer.writeObject(o, out, false);
    out.flush();
    DataInput in = getDataInput();
    BigInteger o2 = (BigInteger) DataSerializer.readObject(in);
    assertEquals(o, o2);
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) BigInteger(java.math.BigInteger) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 59 with DataInput

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

the class DataSerializableJUnitTest method testProperties.

@Test
public void testProperties() throws Exception {
    DataOutputStream out = getDataOutput();
    DataSerializer.writeProperties(new Properties(), out);
    DataSerializer.writeProperties(null, out);
    Properties p1 = new Properties();
    p1.setProperty("aKey1", "aValue1");
    p1.setProperty("aKey2", "aValue2");
    DataSerializer.writeProperties(p1, out);
    Properties p2 = new Properties();
    p2.put("aKey1", new Integer(1));
    p2.put("aKey2", new Integer(2));
    DataSerializer.writeProperties(p2, out);
    out.flush();
    DataInput in = getDataInput();
    assertEquals(new Properties(), DataSerializer.readProperties(in));
    assertEquals(null, DataSerializer.readProperties(in));
    assertEquals(p1, DataSerializer.readProperties(in));
    assertEquals(p2, DataSerializer.readProperties(in));
}
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 60 with DataInput

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

the class DataSerializableJUnitTest method testDoubleObject.

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