Search in sources :

Example 1 with PdxReaderImpl

use of org.apache.geode.pdx.internal.PdxReaderImpl in project geode by apache.

the class InternalDataSerializer method readPdxSerializable.

private static Object readPdxSerializable(final DataInput in) throws IOException, ClassNotFoundException {
    int len = in.readInt();
    int typeId = in.readInt();
    InternalCache internalCache = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.");
    PdxType pdxType = internalCache.getPdxRegistry().getType(typeId);
    if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
        logger.trace(LogMarker.SERIALIZER, "readPdxSerializable pdxType={}", pdxType);
    }
    if (pdxType == null) {
        throw new IllegalStateException("Unknown pdx type=" + typeId);
    }
    DMStats dmStats = getDMStats(internalCache);
    dmStats.incPdxDeserialization(len + 9);
    // check if PdxInstance needs to be returned.
    if (pdxType.getNoDomainClass() || internalCache.getPdxReadSerializedByAnyGemFireServices()) {
        dmStats.incPdxInstanceCreations();
        return new PdxInstanceImpl(pdxType, in, len);
    } else {
        PdxReaderImpl pdxReader = new PdxReaderImpl(pdxType, in, len);
        return pdxReader.getObject();
    }
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) PdxReaderImpl(org.apache.geode.pdx.internal.PdxReaderImpl) PdxType(org.apache.geode.pdx.internal.PdxType) PdxInstanceImpl(org.apache.geode.pdx.internal.PdxInstanceImpl) InternalCache(org.apache.geode.internal.cache.InternalCache)

Example 2 with PdxReaderImpl

use of org.apache.geode.pdx.internal.PdxReaderImpl in project geode by apache.

the class PdxSerializableJUnitTest method testByteFormatForLongStrings.

@Test
public void testByteFormatForLongStrings() throws Exception {
    boolean myFlag = true;
    short myShort = 25;
    String myString1 = "A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1." + "A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1." + "A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1." + "A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1." + "A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1." + "A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1." + "A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1." + "A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1." + "A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1." + "A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.A very long string1.";
    long myLong = 15654;
    String myString2 = "Class4_myString2";
    String myString3 = "Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. " + "Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. " + "Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. " + "Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. " + "Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. " + "Even longer string3. Even longer string3. Even longer string3. Even longer string3. Even longer string3. ";
    int myInt = 1420;
    float myFloat = 123.023f;
    HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
    SimpleClass1 pdx = new SimpleClass1(myFlag, myShort, myString1, myLong, myString2, myString3, myInt, myFloat);
    DataSerializer.writeObject(pdx, out);
    int typeId = getPdxTypeIdForClass(SimpleClass1.class);
    HeapDataOutputStream hdos1 = new HeapDataOutputStream(Version.CURRENT);
    DataSerializer.writeString(myString1, hdos1);
    byte[] str1Bytes = hdos1.toByteArray();
    HeapDataOutputStream hdos2 = new HeapDataOutputStream(Version.CURRENT);
    DataSerializer.writeString(myString2, hdos2);
    byte[] str2Bytes = hdos2.toByteArray();
    HeapDataOutputStream hdos3 = new HeapDataOutputStream(Version.CURRENT);
    DataSerializer.writeString(myString3, hdos3);
    byte[] str3Bytes = hdos3.toByteArray();
    int length = 1 + /* myFlag */
    2 + /* myShort */
    8 + /* myLong */
    4 + /* myInt */
    4 + /* myFloat */
    str1Bytes.length + str2Bytes.length + str3Bytes.length + (2 * 2);
    int offset1 = 1 + 2;
    int offset2 = offset1 + 8 + str1Bytes.length;
    int offset3 = offset1 + 8 + str1Bytes.length + str2Bytes.length;
    byte[] actual = out.toByteArray();
    int floatBytes = Float.floatToRawIntBits(myFloat);
    Byte[] expected = new Byte[] { // byte
    DSCODE.PDX, // int -
    (byte) (length >> 24), // int -
    (byte) (length >> 16), // int -
    (byte) (length >> 8), // int -
    (byte) length, // int -
    (byte) (typeId >> 24), // int -
    (byte) (typeId >> 16), // int -
    (byte) (typeId >> 8), // int -
    (byte) typeId, // boolean - myFlag = true
    1, // short - myShort
    (byte) (myShort >> 8), // short - myShort
    (byte) myShort, (byte) (myLong >> 56), (byte) (myLong >> 48), (byte) (myLong >> 40), (byte) (myLong >> 32), // long -
    (byte) (myLong >> 24), // long -
    (byte) (myLong >> 16), // long -
    (byte) (myLong >> 8), // long -
    (byte) myLong, // int -
    (byte) (myInt >> 24), // int -
    (byte) (myInt >> 16), // int -
    (byte) (myInt >> 8), // int -
    (byte) myInt, // myInt
    (byte) (floatBytes >> 24), (byte) (floatBytes >> 16), (byte) (floatBytes >> 8), // float - myFloat
    (byte) floatBytes, // offset of myString3
    (byte) (offset3 >> 8), // offset of myString3
    (byte) offset3, // offset of myString2
    (byte) (offset2 >> 8), // offset of myString2
    (byte) offset2 };
    for (int i = (str1Bytes.length - 1); i >= 0; i--) {
        expected = // +
        (Byte[]) ArrayUtils.insert(expected, offset1 + PdxWriterImpl.HEADER_SIZE, str1Bytes[i]);
    // 5
    // for:
    // 1
    // for
    // DSCODE.PDX
    // and
    // 4
    // for
    // byte
    // stream
    // length
    }
    for (int i = (str2Bytes.length - 1); i >= 0; i--) {
        expected = (Byte[]) ArrayUtils.insert(expected, offset2 + PdxWriterImpl.HEADER_SIZE, str2Bytes[i]);
    }
    for (int i = (str3Bytes.length - 1); i >= 0; i--) {
        expected = (Byte[]) ArrayUtils.insert(expected, offset3 + PdxWriterImpl.HEADER_SIZE, str3Bytes[i]);
    }
    StringBuffer msg = new StringBuffer("Actual output: ");
    for (byte val : actual) {
        msg.append(val + ", ");
    }
    msg.append("\nExpected output: ");
    for (byte val : expected) {
        msg.append(val + ", ");
    }
    if (actual.length != expected.length) {
        System.out.println(msg.toString());
    }
    assertTrue("Mismatch in length, actual.length: " + actual.length + " and expected length: " + expected.length, actual.length == expected.length);
    for (int i = 0; i < actual.length; i++) {
        if (actual[i] != expected[i]) {
            System.out.println(msg.toString());
        }
        assertTrue("Mismatch at index " + i, actual[i] == expected[i]);
    }
    System.out.println("\n");
    DataInput in = new DataInputStream(new ByteArrayInputStream(actual));
    SimpleClass1 actualVal = (SimpleClass1) DataSerializer.readObject(in);
    // System.out.println("actualVal..."+actualVal);
    assertTrue("Mismatch in write and read value: Value Write..." + pdx + " Value Read..." + actualVal, pdx.equals(actualVal));
    c.setReadSerialized(true);
    try {
        in = new DataInputStream(new ByteArrayInputStream(actual));
        PdxInstance pi = (PdxInstance) DataSerializer.readObject(in);
        actualVal = (SimpleClass1) pi.getObject();
        assertTrue("Mismatch in write and read value: Value Write..." + pdx + " Value Read..." + actualVal, pdx.equals(actualVal));
        assertTrue(pi.hasField("myFlag"));
        assertTrue(pi.hasField("myShort"));
        assertTrue(pi.hasField("myString1"));
        assertTrue(pi.hasField("myLong"));
        assertTrue(pi.hasField("myString2"));
        assertTrue(pi.hasField("myString3"));
        assertTrue(pi.hasField("myInt"));
        assertTrue(pi.hasField("myFloat"));
        assertEquals(pdx.isMyFlag(), pi.getField("myFlag"));
        assertEquals(pdx.getMyShort(), pi.getField("myShort"));
        assertEquals(pdx.getMyString1(), pi.getField("myString1"));
        assertEquals(pdx.getMyLong(), pi.getField("myLong"));
        assertEquals(pdx.getMyString2(), pi.getField("myString2"));
        assertEquals(pdx.getMyString3(), pi.getField("myString3"));
        assertEquals(pdx.getMyInt(), pi.getField("myInt"));
        assertEquals(pdx.getMyFloat(), pi.getField("myFloat"));
        PdxReaderImpl reader = (PdxReaderImpl) pi;
        PdxType type = reader.getPdxType();
        assertEquals(SimpleClass1.class.getName(), type.getClassName());
        assertEquals(8, type.getFieldCount());
        assertEquals(2, type.getVariableLengthFieldCount());
        assertEquals(0, type.getPdxField("myFlag").getFieldIndex());
        assertEquals(1, type.getPdxField("myShort").getFieldIndex());
        assertEquals(2, type.getPdxField("myString1").getFieldIndex());
        assertEquals(3, type.getPdxField("myLong").getFieldIndex());
        assertEquals(4, type.getPdxField("myString2").getFieldIndex());
        assertEquals(5, type.getPdxField("myString3").getFieldIndex());
        assertEquals(6, type.getPdxField("myInt").getFieldIndex());
        assertEquals(7, type.getPdxField("myFloat").getFieldIndex());
        assertEquals(FieldType.BOOLEAN, type.getPdxField("myFlag").getFieldType());
        assertEquals(FieldType.SHORT, type.getPdxField("myShort").getFieldType());
        assertEquals(FieldType.STRING, type.getPdxField("myString1").getFieldType());
        assertEquals(FieldType.LONG, type.getPdxField("myLong").getFieldType());
        assertEquals(FieldType.STRING, type.getPdxField("myString2").getFieldType());
        assertEquals(FieldType.STRING, type.getPdxField("myString3").getFieldType());
        assertEquals(FieldType.INT, type.getPdxField("myInt").getFieldType());
        assertEquals(FieldType.FLOAT, type.getPdxField("myFloat").getFieldType());
        assertEquals("myFlag", type.getPdxField("myFlag").getFieldName());
        assertEquals("myShort", type.getPdxField("myShort").getFieldName());
        assertEquals("myString1", type.getPdxField("myString1").getFieldName());
        assertEquals("myLong", type.getPdxField("myLong").getFieldName());
        assertEquals("myString2", type.getPdxField("myString2").getFieldName());
        assertEquals("myString3", type.getPdxField("myString3").getFieldName());
        assertEquals("myInt", type.getPdxField("myInt").getFieldName());
        assertEquals("myFloat", type.getPdxField("myFloat").getFieldName());
        assertEquals(0, type.getPdxField("myFlag").getVarLenFieldSeqId());
        assertEquals(0, type.getPdxField("myShort").getVarLenFieldSeqId());
        assertEquals(0, type.getPdxField("myString1").getVarLenFieldSeqId());
        assertEquals(0, type.getPdxField("myLong").getVarLenFieldSeqId());
        assertEquals(1, type.getPdxField("myString2").getVarLenFieldSeqId());
        assertEquals(2, type.getPdxField("myString3").getVarLenFieldSeqId());
        assertEquals(2, type.getPdxField("myInt").getVarLenFieldSeqId());
        assertEquals(2, type.getPdxField("myFloat").getVarLenFieldSeqId());
        assertEquals(false, type.getPdxField("myFlag").isVariableLengthType());
        assertEquals(false, type.getPdxField("myShort").isVariableLengthType());
        assertEquals(true, type.getPdxField("myString1").isVariableLengthType());
        assertEquals(false, type.getPdxField("myLong").isVariableLengthType());
        assertEquals(true, type.getPdxField("myString2").isVariableLengthType());
        assertEquals(true, type.getPdxField("myString3").isVariableLengthType());
        assertEquals(false, type.getPdxField("myInt").isVariableLengthType());
        assertEquals(false, type.getPdxField("myFloat").isVariableLengthType());
        assertEquals(ByteSourceFactory.wrap(new byte[] { (byte) (pdx.isMyFlag() ? 1 : 0) }), reader.getRaw(0));
        assertEquals(ByteSourceFactory.wrap(new byte[] { (byte) (pdx.getMyShort() >> 8), (byte) pdx.getMyShort() }), reader.getRaw(1));
        assertEquals(ByteSourceFactory.wrap(str1Bytes), reader.getRaw(2));
        assertEquals(ByteSourceFactory.wrap(new byte[] { (byte) (pdx.getMyLong() >> 56), (byte) (pdx.getMyLong() >> 48), (byte) (pdx.getMyLong() >> 40), (byte) (pdx.getMyLong() >> 32), (byte) (pdx.getMyLong() >> 24), (byte) (pdx.getMyLong() >> 16), (byte) (pdx.getMyLong() >> 8), (byte) pdx.getMyLong() }), reader.getRaw(3));
        assertEquals(ByteSourceFactory.wrap(str2Bytes), reader.getRaw(4));
        assertEquals(ByteSourceFactory.wrap(str3Bytes), reader.getRaw(5));
        assertEquals(ByteSourceFactory.wrap(new byte[] { (byte) (pdx.getMyInt() >> 24), (byte) (pdx.getMyInt() >> 16), (byte) (pdx.getMyInt() >> 8), (byte) pdx.getMyInt() }), reader.getRaw(6));
        assertEquals(ByteSourceFactory.wrap(new byte[] { (byte) (floatBytes >> 24), (byte) (floatBytes >> 16), (byte) (floatBytes >> 8), (byte) floatBytes }), reader.getRaw(7));
    } finally {
        c.setReadSerialized(false);
    }
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) DataInputStream(java.io.DataInputStream) DataInput(java.io.DataInput) PdxReaderImpl(org.apache.geode.pdx.internal.PdxReaderImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with PdxReaderImpl

use of org.apache.geode.pdx.internal.PdxReaderImpl in project geode by apache.

the class PdxSerializableJUnitTest method testByteFormatForStrings.

@Test
public void testByteFormatForStrings() throws Exception {
    boolean myFlag = true;
    short myShort = 25;
    String myString1 = "Class4_myString1";
    long myLong = 15654;
    String myString2 = "Class4_myString2";
    String myString3 = "Class4_myString3";
    int myInt = 1420;
    float myFloat = 123.023f;
    HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
    SimpleClass1 pdx = new SimpleClass1(myFlag, myShort, myString1, myLong, myString2, myString3, myInt, myFloat);
    DataSerializer.writeObject(pdx, out);
    int typeId = getPdxTypeIdForClass(SimpleClass1.class);
    HeapDataOutputStream hdos1 = new HeapDataOutputStream(Version.CURRENT);
    DataSerializer.writeString(myString1, hdos1);
    byte[] str1Bytes = hdos1.toByteArray();
    HeapDataOutputStream hdos2 = new HeapDataOutputStream(Version.CURRENT);
    DataSerializer.writeString(myString2, hdos2);
    byte[] str2Bytes = hdos2.toByteArray();
    HeapDataOutputStream hdos3 = new HeapDataOutputStream(Version.CURRENT);
    DataSerializer.writeString(myString3, hdos3);
    byte[] str3Bytes = hdos3.toByteArray();
    int length = 1 + /* myFlag */
    2 + /* myShort */
    8 + /* myLong */
    4 + /* myInt */
    4 + /* myFloat */
    str1Bytes.length + str2Bytes.length + str3Bytes.length + 2;
    int offset1 = 1 + 2;
    int offset2 = offset1 + 8 + str1Bytes.length;
    int offset3 = offset1 + 8 + str1Bytes.length + str2Bytes.length;
    byte[] actual = out.toByteArray();
    int floatBytes = Float.floatToRawIntBits(myFloat);
    Byte[] expected = new Byte[] { // byte
    DSCODE.PDX, // int -
    (byte) (length >> 24), // int -
    (byte) (length >> 16), // int -
    (byte) (length >> 8), // int -
    (byte) length, // int -
    (byte) (typeId >> 24), // int -
    (byte) (typeId >> 16), // int -
    (byte) (typeId >> 8), // int -
    (byte) typeId, // boolean - myFlag = true
    1, // short - myShort
    (byte) (myShort >> 8), // short - myShort
    (byte) myShort, (byte) (myLong >> 56), (byte) (myLong >> 48), (byte) (myLong >> 40), (byte) (myLong >> 32), // long -
    (byte) (myLong >> 24), // long -
    (byte) (myLong >> 16), // long -
    (byte) (myLong >> 8), // long -
    (byte) myLong, // int -
    (byte) (myInt >> 24), // int -
    (byte) (myInt >> 16), // int -
    (byte) (myInt >> 8), // int -
    (byte) myInt, // myInt
    (byte) (floatBytes >> 24), (byte) (floatBytes >> 16), (byte) (floatBytes >> 8), // float - myFloat
    (byte) floatBytes, // offset of myString3
    (byte) offset3, // offset of myString2
    (byte) offset2 };
    for (int i = (str1Bytes.length - 1); i >= 0; i--) {
        expected = // +
        (Byte[]) ArrayUtils.insert(expected, offset1 + PdxWriterImpl.HEADER_SIZE, str1Bytes[i]);
    // 5
    // for:
    // 1
    // for
    // DSCODE.PDX
    // and
    // 4
    // for
    // byte
    // stream
    // length
    }
    for (int i = (str2Bytes.length - 1); i >= 0; i--) {
        expected = (Byte[]) ArrayUtils.insert(expected, offset2 + PdxWriterImpl.HEADER_SIZE, str2Bytes[i]);
    }
    for (int i = (str3Bytes.length - 1); i >= 0; i--) {
        expected = (Byte[]) ArrayUtils.insert(expected, offset3 + PdxWriterImpl.HEADER_SIZE, str3Bytes[i]);
    }
    StringBuffer msg = new StringBuffer("Actual output: ");
    for (byte val : actual) {
        msg.append(val + ", ");
    }
    msg.append("\nExpected output: ");
    for (byte val : expected) {
        msg.append(val + ", ");
    }
    if (actual.length != expected.length) {
        System.out.println(msg.toString());
    }
    assertTrue("Mismatch in length, actual.length: " + actual.length + " and expected length: " + expected.length, actual.length == expected.length);
    for (int i = 0; i < actual.length; i++) {
        if (actual[i] != expected[i]) {
            System.out.println(msg.toString());
        }
        assertTrue("Mismatch at index " + i, actual[i] == expected[i]);
    }
    System.out.println("\n");
    DataInput in = new DataInputStream(new ByteArrayInputStream(actual));
    SimpleClass1 actualVal = (SimpleClass1) DataSerializer.readObject(in);
    // System.out.println("actualVal..."+actualVal);
    assertTrue("Mismatch in write and read value: Value Write..." + pdx + " Value Read..." + actualVal, pdx.equals(actualVal));
    c.setReadSerialized(true);
    try {
        in = new DataInputStream(new ByteArrayInputStream(actual));
        PdxInstance pi = (PdxInstance) DataSerializer.readObject(in);
        actualVal = (SimpleClass1) pi.getObject();
        assertTrue("Mismatch in write and read value: Value Write..." + pdx + " Value Read..." + actualVal, pdx.equals(actualVal));
        assertTrue(pi.hasField("myFlag"));
        assertTrue(pi.hasField("myShort"));
        assertTrue(pi.hasField("myString1"));
        assertTrue(pi.hasField("myLong"));
        assertTrue(pi.hasField("myString2"));
        assertTrue(pi.hasField("myString3"));
        assertTrue(pi.hasField("myInt"));
        assertTrue(pi.hasField("myFloat"));
        assertEquals(pdx.isMyFlag(), pi.getField("myFlag"));
        assertEquals(pdx.getMyShort(), pi.getField("myShort"));
        assertEquals(pdx.getMyString1(), pi.getField("myString1"));
        assertEquals(pdx.getMyLong(), pi.getField("myLong"));
        assertEquals(pdx.getMyString2(), pi.getField("myString2"));
        assertEquals(pdx.getMyString3(), pi.getField("myString3"));
        assertEquals(pdx.getMyInt(), pi.getField("myInt"));
        assertEquals(pdx.getMyFloat(), pi.getField("myFloat"));
        PdxReaderImpl reader = (PdxReaderImpl) pi;
        PdxType type = reader.getPdxType();
        assertEquals(SimpleClass1.class.getName(), type.getClassName());
        assertEquals(8, type.getFieldCount());
        assertEquals(2, type.getVariableLengthFieldCount());
        assertEquals(0, type.getPdxField("myFlag").getFieldIndex());
        assertEquals(1, type.getPdxField("myShort").getFieldIndex());
        assertEquals(2, type.getPdxField("myString1").getFieldIndex());
        assertEquals(3, type.getPdxField("myLong").getFieldIndex());
        assertEquals(4, type.getPdxField("myString2").getFieldIndex());
        assertEquals(5, type.getPdxField("myString3").getFieldIndex());
        assertEquals(6, type.getPdxField("myInt").getFieldIndex());
        assertEquals(7, type.getPdxField("myFloat").getFieldIndex());
        assertEquals(FieldType.BOOLEAN, type.getPdxField("myFlag").getFieldType());
        assertEquals(FieldType.SHORT, type.getPdxField("myShort").getFieldType());
        assertEquals(FieldType.STRING, type.getPdxField("myString1").getFieldType());
        assertEquals(FieldType.LONG, type.getPdxField("myLong").getFieldType());
        assertEquals(FieldType.STRING, type.getPdxField("myString2").getFieldType());
        assertEquals(FieldType.STRING, type.getPdxField("myString3").getFieldType());
        assertEquals(FieldType.INT, type.getPdxField("myInt").getFieldType());
        assertEquals(FieldType.FLOAT, type.getPdxField("myFloat").getFieldType());
        assertEquals("myFlag", type.getPdxField("myFlag").getFieldName());
        assertEquals("myShort", type.getPdxField("myShort").getFieldName());
        assertEquals("myString1", type.getPdxField("myString1").getFieldName());
        assertEquals("myLong", type.getPdxField("myLong").getFieldName());
        assertEquals("myString2", type.getPdxField("myString2").getFieldName());
        assertEquals("myString3", type.getPdxField("myString3").getFieldName());
        assertEquals("myInt", type.getPdxField("myInt").getFieldName());
        assertEquals("myFloat", type.getPdxField("myFloat").getFieldName());
        assertEquals(0, type.getPdxField("myFlag").getVarLenFieldSeqId());
        assertEquals(0, type.getPdxField("myShort").getVarLenFieldSeqId());
        assertEquals(0, type.getPdxField("myString1").getVarLenFieldSeqId());
        assertEquals(0, type.getPdxField("myLong").getVarLenFieldSeqId());
        assertEquals(1, type.getPdxField("myString2").getVarLenFieldSeqId());
        assertEquals(2, type.getPdxField("myString3").getVarLenFieldSeqId());
        assertEquals(2, type.getPdxField("myInt").getVarLenFieldSeqId());
        assertEquals(2, type.getPdxField("myFloat").getVarLenFieldSeqId());
        assertEquals(false, type.getPdxField("myFlag").isVariableLengthType());
        assertEquals(false, type.getPdxField("myShort").isVariableLengthType());
        assertEquals(true, type.getPdxField("myString1").isVariableLengthType());
        assertEquals(false, type.getPdxField("myLong").isVariableLengthType());
        assertEquals(true, type.getPdxField("myString2").isVariableLengthType());
        assertEquals(true, type.getPdxField("myString3").isVariableLengthType());
        assertEquals(false, type.getPdxField("myInt").isVariableLengthType());
        assertEquals(false, type.getPdxField("myFloat").isVariableLengthType());
        assertEquals(ByteSourceFactory.wrap(new byte[] { (byte) (pdx.isMyFlag() ? 1 : 0) }), reader.getRaw(0));
        assertEquals(ByteSourceFactory.wrap(new byte[] { (byte) (pdx.getMyShort() >> 8), (byte) pdx.getMyShort() }), reader.getRaw(1));
        assertEquals(ByteSourceFactory.wrap(str1Bytes), reader.getRaw(2));
        assertEquals(ByteSourceFactory.wrap(new byte[] { (byte) (pdx.getMyLong() >> 56), (byte) (pdx.getMyLong() >> 48), (byte) (pdx.getMyLong() >> 40), (byte) (pdx.getMyLong() >> 32), (byte) (pdx.getMyLong() >> 24), (byte) (pdx.getMyLong() >> 16), (byte) (pdx.getMyLong() >> 8), (byte) pdx.getMyLong() }), reader.getRaw(3));
        assertEquals(ByteSourceFactory.wrap(str2Bytes), reader.getRaw(4));
        assertEquals(ByteSourceFactory.wrap(str3Bytes), reader.getRaw(5));
        assertEquals(ByteSourceFactory.wrap(new byte[] { (byte) (pdx.getMyInt() >> 24), (byte) (pdx.getMyInt() >> 16), (byte) (pdx.getMyInt() >> 8), (byte) pdx.getMyInt() }), reader.getRaw(6));
        assertEquals(ByteSourceFactory.wrap(new byte[] { (byte) (floatBytes >> 24), (byte) (floatBytes >> 16), (byte) (floatBytes >> 8), (byte) floatBytes }), reader.getRaw(7));
    } finally {
        c.setReadSerialized(false);
    }
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) DataInputStream(java.io.DataInputStream) DataInput(java.io.DataInput) PdxReaderImpl(org.apache.geode.pdx.internal.PdxReaderImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

PdxReaderImpl (org.apache.geode.pdx.internal.PdxReaderImpl)3 PdxType (org.apache.geode.pdx.internal.PdxType)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInput (java.io.DataInput)2 DataInputStream (java.io.DataInputStream)2 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)2 Test (org.junit.Test)2 DMStats (org.apache.geode.distributed.internal.DMStats)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 PdxInstanceImpl (org.apache.geode.pdx.internal.PdxInstanceImpl)1