Search in sources :

Example 1 with ByteArrayData

use of org.apache.geode.internal.ByteArrayData 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 2 with ByteArrayData

use of org.apache.geode.internal.ByteArrayData in project geode by apache.

the class StartupMessageDataJUnitTest method testToDataWithThreeHostedLocators.

@Test
public void testToDataWithThreeHostedLocators() throws Exception {
    String[] locatorStrings = createManyLocatorStrings(3);
    List<String> hostedLocators = new ArrayList<String>();
    for (int i = 0; i < 3; i++) {
        hostedLocators.add(locatorStrings[i]);
    }
    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);
    assertNotNull(props);
    String hostedLocatorsString = props.getProperty(StartupMessageData.HOSTED_LOCATORS);
    assertNotNull(hostedLocatorsString);
    Collection<String> actualLocatorStrings = new ArrayList<String>(1);
    StringTokenizer st = new StringTokenizer(hostedLocatorsString, StartupMessageData.COMMA_DELIMITER);
    while (st.hasMoreTokens()) {
        actualLocatorStrings.add(st.nextToken());
    }
    assertEquals(3, actualLocatorStrings.size());
    int i = 0;
    for (String actualLocatorString : actualLocatorStrings) {
        assertEquals(locatorStrings[i], actualLocatorString);
        i++;
    }
}
Also used : DataInput(java.io.DataInput) StringTokenizer(java.util.StringTokenizer) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) 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 3 with ByteArrayData

use of org.apache.geode.internal.ByteArrayData in project geode by apache.

the class StartupMessageDataJUnitTest method testToDataWithEmptyHostedLocators.

@Test
public void testToDataWithEmptyHostedLocators() throws Exception {
    Collection<String> hostedLocators = new ArrayList<String>();
    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) ArrayList(java.util.ArrayList) 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 4 with ByteArrayData

use of org.apache.geode.internal.ByteArrayData in project geode by apache.

the class StartupMessageDataJUnitTest method testToDataWithOneHostedLocator.

@Test
public void testToDataWithOneHostedLocator() throws Exception {
    String locatorString = createOneLocatorString();
    List<String> hostedLocators = new ArrayList<String>();
    hostedLocators.add(locatorString);
    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);
    assertNotNull(props);
    String hostedLocatorsString = props.getProperty(StartupMessageData.HOSTED_LOCATORS);
    assertNotNull(hostedLocatorsString);
    assertEquals(locatorString, hostedLocatorsString);
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) 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 5 with ByteArrayData

use of org.apache.geode.internal.ByteArrayData in project geode by apache.

the class StartupMessageDataJUnitTest method getDataInputWithOneHostedLocator.

private DataInput getDataInputWithOneHostedLocator(String locatorString) throws Exception {
    List<String> hostedLocators = new ArrayList<String>();
    if (locatorString != null) {
        hostedLocators.add(locatorString);
    }
    StartupMessageData dataToWrite = new StartupMessageData();
    dataToWrite.writeHostedLocators(hostedLocators);
    ByteArrayData testStream = new ByteArrayData();
    assertTrue(testStream.isEmpty());
    DataOutputStream out = testStream.getDataOutput();
    dataToWrite.writeTo(out);
    assertTrue(testStream.size() > 0);
    DataInput in = testStream.getDataInput();
    assertNotNull(in);
    return in;
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) ByteArrayData(org.apache.geode.internal.ByteArrayData)

Aggregations

DataInput (java.io.DataInput)5 DataOutputStream (java.io.DataOutputStream)5 ByteArrayData (org.apache.geode.internal.ByteArrayData)5 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)4 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)4 UnitTest (org.apache.geode.test.junit.categories.UnitTest)4 Test (org.junit.Test)4 StringTokenizer (java.util.StringTokenizer)1