Search in sources :

Example 31 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class InVMNonPersistentMessageBufferTest method testCannotReadPastEndOfMessageBody.

@Test
public void testCannotReadPastEndOfMessageBody() throws Exception {
    ClientMessage message = session.createMessage(false);
    final String body = RandomUtil.randomString();
    message.getBodyBuffer().writeString(body);
    ClientMessage received = sendAndReceive(message);
    Assert.assertNotNull(received);
    ActiveMQBuffer buffer = received.getReadOnlyBodyBuffer();
    Assert.assertEquals(body, buffer.readString());
    try {
        buffer.readByte();
        Assert.fail("Should throw exception");
    } catch (IndexOutOfBoundsException e) {
    // OK
    }
    Assert.assertEquals(body, received.getBodyBuffer().readString());
    try {
        received.getBodyBuffer().readByte();
        Assert.fail("Should throw exception");
    } catch (IndexOutOfBoundsException e) {
    // OK
    }
    buffer = received.getReadOnlyBodyBuffer();
    Assert.assertEquals(body, buffer.readString());
    try {
        buffer.readByte();
        Assert.fail("Should throw exception");
    } catch (IndexOutOfBoundsException e) {
    // OK
    }
}
Also used : ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 32 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class UTF8Test method testValidateUTF.

@Test
public void testValidateUTF() throws Exception {
    ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(60 * 1024);
    byte[] bytes = new byte[20000];
    RandomUtil.getRandom().nextBytes(bytes);
    String str = new String(bytes);
    UTF8Util.saveUTF(buffer.byteBuf(), str);
    String newStr = UTF8Util.readUTF(buffer);
    Assert.assertEquals(str, newStr);
}
Also used : ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 33 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class UTF8Test method testValidateUTFWithChars.

private void testValidateUTFWithChars(final int size, final char c) {
    final char[] chars = new char[size];
    Arrays.fill(chars, c);
    final String expectedUtf8String = new String(chars);
    final ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(4 * chars.length);
    UTF8Util.saveUTF(buffer.byteBuf(), expectedUtf8String);
    final byte[] expectedBytes = expectedUtf8String.getBytes(StandardCharsets.UTF_8);
    final int encodedSize = buffer.readUnsignedShort();
    final byte[] realEncodedBytes = new byte[encodedSize];
    buffer.getBytes(buffer.readerIndex(), realEncodedBytes);
    Assert.assertArrayEquals(expectedBytes, realEncodedBytes);
}
Also used : ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 34 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class NettyConnectionTest method testCreateBuffer.

@Test
public void testCreateBuffer() throws Exception {
    EmbeddedChannel channel = createChannel();
    NettyConnection conn = new NettyConnection(emptyMap, channel, new MyListener(), false, false);
    final int size = 1234;
    ActiveMQBuffer buff = conn.createTransportBuffer(size);
    // Netty buffer does lazy initialization.
    buff.writeByte((byte) 0x00);
    Assert.assertEquals(size, buff.capacity());
}
Also used : NettyConnection(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 35 with ActiveMQBuffer

use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.

the class NettyConnectorTest method testBadProtocol.

@Test
public void testBadProtocol() throws Exception {
    BufferHandler handler = new BufferHandler() {

        @Override
        public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
        }
    };
    Map<String, Object> params = new HashMap<>();
    params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
    params.put(TransportConstants.ENABLED_PROTOCOLS_PROP_NAME, "myBadProtocol");
    NettyConnector connector = new NettyConnector(params, handler, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()));
    connector.start();
    Assert.assertTrue(connector.isStarted());
    Assert.assertNull(connector.createConnection());
    connector.close();
    Assert.assertFalse(connector.isStarted());
}
Also used : HashMap(java.util.HashMap) NettyConnector(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector) BufferHandler(org.apache.activemq.artemis.spi.core.remoting.BufferHandler) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)150 Test (org.junit.Test)81 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)49 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)44 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)39 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)38 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)35 ByteBuffer (java.nio.ByteBuffer)34 Configuration (org.apache.activemq.artemis.core.config.Configuration)34 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)27 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)25 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)25 ArrayList (java.util.ArrayList)21 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)21 Queue (org.apache.activemq.artemis.core.server.Queue)18 HashMap (java.util.HashMap)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)15 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)15 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)14