Search in sources :

Example 61 with DataInput

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

the class DataSerializableJUnitTest method testTreeSetWithComparator.

/**
   * Tests data serializing an {@link TreeSet}
   */
@Test
public void testTreeSetWithComparator() throws Exception {
    Random random = getRandom();
    int size = random.nextInt(50);
    TreeSet set = new TreeSet(new MyComparator(size));
    for (int i = 0; i < size; i++) {
        set.add(new Long(random.nextLong()));
    }
    DataOutputStream out = getDataOutput();
    DataSerializer.writeTreeSet(new TreeSet(new MyComparator(0)), out);
    DataSerializer.writeTreeSet(set, out);
    out.flush();
    DataInput in = getDataInput();
    TreeSet emptySet = DataSerializer.readTreeSet(in);
    assertEquals(new TreeSet(new MyComparator(0)), emptySet);
    assertEquals(new MyComparator(0), emptySet.comparator());
    TreeSet set2 = DataSerializer.readTreeSet(in);
    assertEquals(set, set2);
    assertEquals(set.comparator(), set2.comparator());
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 62 with DataInput

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

the class DataSerializableJUnitTest method testTreeSet.

/**
   * Tests data serializing an {@link TreeSet}
   */
@Test
public void testTreeSet() 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.writeTreeSet(null, out);
    DataSerializer.writeTreeSet(new TreeSet(), out);
    DataSerializer.writeTreeSet(set, out);
    out.flush();
    DataInput in = getDataInput();
    assertEquals(null, DataSerializer.readTreeSet(in));
    assertEquals(new TreeSet(), DataSerializer.readTreeSet(in));
    TreeSet set2 = DataSerializer.readTreeSet(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 63 with DataInput

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

the class DataSerializableJUnitTest method testByteArray.

/**
   * Tests data serializing a <code>byte</code> array
   */
@Test
public void testByteArray() throws Exception {
    byte[] array = new byte[] { (byte) 4, (byte) 5, (byte) 6 };
    DataOutputStream out = getDataOutput();
    DataSerializer.writeByteArray(array, out);
    DataSerializer.writeObject(array, out);
    out.flush();
    DataInput in = getDataInput();
    for (int idx = 0; idx < 2; idx++) {
        byte[] array2 = (idx == 0) ? DataSerializer.readByteArray(in) : (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 64 with DataInput

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

the class DataSerializableJUnitTest method testDouble.

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

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

the class DataSerializableJUnitTest method testLinkedHashSetObject.

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