Search in sources :

Example 76 with DataInput

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

the class StartupMessageDataJUnitTest method testToDataWithNullHostedLocators.

@Test
public void testToDataWithNullHostedLocators() throws Exception {
    Collection<String> hostedLocators = null;
    StartupMessageData data = new StartupMessageData();
    data.writeHostedLocators(hostedLocators);
    ByteArrayData testStream = new ByteArrayData();
    assertTrue(testStream.isEmpty());
    DataOutputStream out = testStream.getDataOutput();
    data.writeTo(out);
    assertTrue(testStream.size() > 0);
    DataInput in = testStream.getDataInput();
    Properties props = (Properties) DataSerializer.readObject(in);
    assertNull(props);
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) Properties(java.util.Properties) ByteArrayData(org.apache.geode.internal.ByteArrayData) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Example 77 with DataInput

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

the class StartupMessageDataJUnitTest method testNullHostedLocator.

@Test
public void testNullHostedLocator() throws Exception {
    String locatorString = null;
    DataInput in = getDataInputWithOneHostedLocator(locatorString);
    StartupMessageData dataToRead = new StartupMessageData();
    dataToRead.readFrom(in);
    Collection<String> readHostedLocators = dataToRead.readHostedLocators();
    assertNull(readHostedLocators);
}
Also used : DataInput(java.io.DataInput) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Example 78 with DataInput

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

the class StartupMessageDataJUnitTest method testOneHostedLocator.

@Test
public void testOneHostedLocator() throws Exception {
    String locatorString = createOneLocatorString();
    DataInput in = getDataInputWithOneHostedLocator(locatorString);
    StartupMessageData dataToRead = new StartupMessageData();
    dataToRead.readFrom(in);
    Collection<String> readHostedLocators = dataToRead.readHostedLocators();
    assertNotNull(readHostedLocators);
    assertEquals(1, readHostedLocators.size());
    assertEquals(locatorString, readHostedLocators.iterator().next());
}
Also used : DataInput(java.io.DataInput) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Example 79 with DataInput

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

the class DataSerializableJUnitTest method testHashtableObject.

/**
   * Tests data serializing an {@link Hashtable} using {@link DataSerializer#writeObject}.
   */
@Test
public void testHashtableObject() throws Exception {
    Random random = getRandom();
    Hashtable map = new Hashtable();
    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.writeObject(map, out);
    out.flush();
    DataInput in = getDataInput();
    Hashtable map2 = (Hashtable) DataSerializer.readObject(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)

Example 80 with DataInput

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

the class RemoteRemoveAllMessageTest method shouldBeMockable.

@Test
public void shouldBeMockable() throws Exception {
    RemoteRemoveAllMessage mockRemoteRemoveAllMessage = mock(RemoteRemoveAllMessage.class);
    DataInput mockDataInput = mock(DataInput.class);
    mockRemoteRemoveAllMessage.fromData(mockDataInput);
    verify(mockRemoteRemoveAllMessage, times(1)).fromData(mockDataInput);
}
Also used : DataInput(java.io.DataInput) 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