Search in sources :

Example 1 with ProtonBufferInputStream

use of org.apache.qpid.protonj2.buffer.ProtonBufferInputStream in project qpid-protonj2 by apache.

the class AcceptedTypeCodecTest method testEncodeDecodeArray.

private void testEncodeDecodeArray(boolean fromStream) throws IOException {
    ProtonBuffer buffer = ProtonByteBufferAllocator.DEFAULT.allocate();
    InputStream stream = new ProtonBufferInputStream(buffer);
    Accepted[] array = new Accepted[3];
    array[0] = Accepted.getInstance();
    array[1] = Accepted.getInstance();
    array[2] = Accepted.getInstance();
    encoder.writeObject(buffer, encoderState, array);
    final Object result;
    if (fromStream) {
        result = streamDecoder.readObject(stream, streamDecoderState);
    } else {
        result = decoder.readObject(buffer, decoderState);
    }
    assertTrue(result.getClass().isArray());
    assertEquals(Accepted.class, result.getClass().getComponentType());
    Accepted[] resultArray = (Accepted[]) result;
    for (int i = 0; i < resultArray.length; ++i) {
        assertNotNull(resultArray[i]);
        assertTrue(resultArray[i] instanceof Accepted);
    }
}
Also used : ProtonBuffer(org.apache.qpid.protonj2.buffer.ProtonBuffer) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream) InputStream(java.io.InputStream) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream) Accepted(org.apache.qpid.protonj2.types.messaging.Accepted)

Example 2 with ProtonBufferInputStream

use of org.apache.qpid.protonj2.buffer.ProtonBufferInputStream in project qpid-protonj2 by apache.

the class AmqpSequenceTypeCodecTest method doTestSkipValue.

private void doTestSkipValue(boolean fromStream) throws IOException {
    ProtonBuffer buffer = ProtonByteBufferAllocator.DEFAULT.allocate();
    InputStream stream = new ProtonBufferInputStream(buffer);
    List<Object> list = new ArrayList<>();
    list.add("one");
    list.add("two");
    list.add("three");
    for (int i = 0; i < 10; ++i) {
        encoder.writeObject(buffer, encoderState, new AmqpSequence<>(list));
    }
    encoder.writeObject(buffer, encoderState, new Modified());
    for (int i = 0; i < 10; ++i) {
        if (fromStream) {
            StreamTypeDecoder<?> typeDecoder = streamDecoder.readNextTypeDecoder(stream, streamDecoderState);
            assertEquals(AmqpSequence.class, typeDecoder.getTypeClass());
            typeDecoder.skipValue(stream, streamDecoderState);
        } else {
            TypeDecoder<?> typeDecoder = decoder.readNextTypeDecoder(buffer, decoderState);
            assertEquals(AmqpSequence.class, typeDecoder.getTypeClass());
            typeDecoder.skipValue(buffer, decoderState);
        }
    }
    final Object result;
    if (fromStream) {
        result = streamDecoder.readObject(stream, streamDecoderState);
    } else {
        result = decoder.readObject(buffer, decoderState);
    }
    assertNotNull(result);
    assertTrue(result instanceof Modified);
    Modified modified = (Modified) result;
    assertFalse(modified.isUndeliverableHere());
    assertFalse(modified.isDeliveryFailed());
}
Also used : ProtonBuffer(org.apache.qpid.protonj2.buffer.ProtonBuffer) Modified(org.apache.qpid.protonj2.types.messaging.Modified) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream)

Example 3 with ProtonBufferInputStream

use of org.apache.qpid.protonj2.buffer.ProtonBufferInputStream in project qpid-protonj2 by apache.

the class AmqpSequenceTypeCodecTest method doTestDecodeWithInvalidMapType.

private void doTestDecodeWithInvalidMapType(byte mapType, boolean fromStream) throws IOException {
    ProtonBuffer buffer = ProtonByteBufferAllocator.DEFAULT.allocate();
    InputStream stream = new ProtonBufferInputStream(buffer);
    // Described Type Indicator
    buffer.writeByte((byte) 0);
    buffer.writeByte(EncodingCodes.SMALLULONG);
    buffer.writeByte(AmqpSequence.DESCRIPTOR_CODE.byteValue());
    if (mapType == EncodingCodes.MAP32) {
        buffer.writeByte(EncodingCodes.MAP32);
        // Size
        buffer.writeInt((byte) 0);
        // Count
        buffer.writeInt((byte) 0);
    } else {
        buffer.writeByte(EncodingCodes.MAP8);
        // Size
        buffer.writeByte((byte) 0);
        // Count
        buffer.writeByte((byte) 0);
    }
    if (fromStream) {
        try {
            streamDecoder.readObject(stream, streamDecoderState);
            fail("Should not decode type with invalid encoding");
        } catch (DecodeException ex) {
        }
    } else {
        try {
            decoder.readObject(buffer, decoderState);
            fail("Should not decode type with invalid encoding");
        } catch (DecodeException ex) {
        }
    }
}
Also used : ProtonBuffer(org.apache.qpid.protonj2.buffer.ProtonBuffer) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream) InputStream(java.io.InputStream) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream) DecodeException(org.apache.qpid.protonj2.codec.DecodeException)

Example 4 with ProtonBufferInputStream

use of org.apache.qpid.protonj2.buffer.ProtonBufferInputStream in project qpid-protonj2 by apache.

the class AmqpSequenceTypeCodecTest method doTestSkipValueWithInvalidMapType.

private void doTestSkipValueWithInvalidMapType(byte mapType, boolean fromStream) throws IOException {
    ProtonBuffer buffer = ProtonByteBufferAllocator.DEFAULT.allocate();
    InputStream stream = new ProtonBufferInputStream(buffer);
    // Described Type Indicator
    buffer.writeByte((byte) 0);
    buffer.writeByte(EncodingCodes.SMALLULONG);
    buffer.writeByte(AmqpSequence.DESCRIPTOR_CODE.byteValue());
    if (mapType == EncodingCodes.MAP32) {
        buffer.writeByte(EncodingCodes.MAP32);
        // Size
        buffer.writeInt((byte) 0);
        // Count
        buffer.writeInt((byte) 0);
    } else {
        buffer.writeByte(EncodingCodes.MAP8);
        // Size
        buffer.writeByte((byte) 0);
        // Count
        buffer.writeByte((byte) 0);
    }
    if (fromStream) {
        StreamTypeDecoder<?> typeDecoder = streamDecoder.readNextTypeDecoder(stream, streamDecoderState);
        assertEquals(AmqpSequence.class, typeDecoder.getTypeClass());
        try {
            typeDecoder.skipValue(stream, streamDecoderState);
            fail("Should not be able to skip type with invalid encoding");
        } catch (DecodeException ex) {
        }
    } else {
        TypeDecoder<?> typeDecoder = decoder.readNextTypeDecoder(buffer, decoderState);
        assertEquals(AmqpSequence.class, typeDecoder.getTypeClass());
        try {
            typeDecoder.skipValue(buffer, decoderState);
            fail("Should not be able to skip type with invalid encoding");
        } catch (DecodeException ex) {
        }
    }
}
Also used : ProtonBuffer(org.apache.qpid.protonj2.buffer.ProtonBuffer) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream) InputStream(java.io.InputStream) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream) DecodeException(org.apache.qpid.protonj2.codec.DecodeException)

Example 5 with ProtonBufferInputStream

use of org.apache.qpid.protonj2.buffer.ProtonBufferInputStream in project qpid-protonj2 by apache.

the class ApplicationPropertiesTypeCodecTest method doTestSkipValue.

private void doTestSkipValue(boolean fromStream) throws IOException {
    ProtonBuffer buffer = ProtonByteBufferAllocator.DEFAULT.allocate();
    InputStream stream = new ProtonBufferInputStream(buffer);
    Map<String, Object> map = new HashMap<>();
    map.put("one", 1);
    map.put("two", Boolean.TRUE);
    map.put("three", "test");
    for (int i = 0; i < 10; ++i) {
        encoder.writeObject(buffer, encoderState, new ApplicationProperties(map));
    }
    encoder.writeObject(buffer, encoderState, new Modified());
    for (int i = 0; i < 10; ++i) {
        if (fromStream) {
            StreamTypeDecoder<?> typeDecoder = streamDecoder.readNextTypeDecoder(stream, streamDecoderState);
            assertEquals(ApplicationProperties.class, typeDecoder.getTypeClass());
            typeDecoder.skipValue(stream, streamDecoderState);
        } else {
            TypeDecoder<?> typeDecoder = decoder.readNextTypeDecoder(buffer, decoderState);
            assertEquals(ApplicationProperties.class, typeDecoder.getTypeClass());
            typeDecoder.skipValue(buffer, decoderState);
        }
    }
    final Object result;
    if (fromStream) {
        result = streamDecoder.readObject(stream, streamDecoderState);
    } else {
        result = decoder.readObject(buffer, decoderState);
    }
    assertNotNull(result);
    assertTrue(result instanceof Modified);
    Modified modified = (Modified) result;
    assertFalse(modified.isUndeliverableHere());
    assertFalse(modified.isDeliveryFailed());
}
Also used : ProtonBuffer(org.apache.qpid.protonj2.buffer.ProtonBuffer) Modified(org.apache.qpid.protonj2.types.messaging.Modified) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream) InputStream(java.io.InputStream) ApplicationProperties(org.apache.qpid.protonj2.types.messaging.ApplicationProperties) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream)

Aggregations

InputStream (java.io.InputStream)572 ProtonBuffer (org.apache.qpid.protonj2.buffer.ProtonBuffer)572 ProtonBufferInputStream (org.apache.qpid.protonj2.buffer.ProtonBufferInputStream)572 DecodeException (org.apache.qpid.protonj2.codec.DecodeException)168 Binary (org.apache.qpid.protonj2.types.Binary)43 Test (org.junit.jupiter.api.Test)39 Symbol (org.apache.qpid.protonj2.types.Symbol)33 UUID (java.util.UUID)28 Modified (org.apache.qpid.protonj2.types.messaging.Modified)26 Random (java.util.Random)23 LinkedHashMap (java.util.LinkedHashMap)22 HashMap (java.util.HashMap)20 ErrorCondition (org.apache.qpid.protonj2.types.transport.ErrorCondition)16 PrimitiveTypeDecoder (org.apache.qpid.protonj2.codec.decoders.PrimitiveTypeDecoder)15 ArrayList (java.util.ArrayList)13 UnsignedInteger (org.apache.qpid.protonj2.types.UnsignedInteger)11 UnsignedLong (org.apache.qpid.protonj2.types.UnsignedLong)9 UnsignedByte (org.apache.qpid.protonj2.types.UnsignedByte)8 UnsignedShort (org.apache.qpid.protonj2.types.UnsignedShort)8 List (java.util.List)7