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
}
}
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);
}
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);
}
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());
}
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());
}
Aggregations