use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class PagingOrderTest method testOrder1.
@Test
public void testOrder1() throws Throwable {
boolean persistentMessages = true;
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
server.start();
final int messageSize = 1024;
final int numberOfMessages = 500;
ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(1024 * 1024);
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false, false);
server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, null, true, false);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
byte[] body = new byte[messageSize];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= messageSize; j++) {
bb.put(getSamplebyte(j));
}
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage message = session.createMessage(persistentMessages);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
if (i % 1000 == 0) {
session.commit();
}
}
session.commit();
session.close();
session = sf.createSession(true, true, 0);
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
for (int i = 0; i < numberOfMessages / 2; i++) {
ClientMessage message = consumer.receive(5000);
assertNotNull(message);
assertEquals(i, message.getIntProperty("id").intValue());
if (i < 100) {
// Do not consume the last one so we could restart
message.acknowledge();
}
}
session.close();
sf.close();
sf = createSessionFactory(locator);
session = sf.createSession(true, true, 0);
session.start();
consumer = session.createConsumer(ADDRESS);
for (int i = 100; i < numberOfMessages; i++) {
ClientMessage message = consumer.receive(5000);
assertNotNull(message);
assertEquals(i, message.getIntProperty("id").intValue());
message.acknowledge();
}
session.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class PagingOrderTest method testOrderOverRollback.
@Test
public void testOrderOverRollback() throws Throwable {
boolean persistentMessages = true;
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
server.start();
final int messageSize = 1024;
final int numberOfMessages = 3000;
ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(1024 * 1024);
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false, false);
server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, null, true, false);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
byte[] body = new byte[messageSize];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= messageSize; j++) {
bb.put(getSamplebyte(j));
}
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage message = session.createMessage(persistentMessages);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
if (i % 1000 == 0) {
session.commit();
}
}
session.commit();
session.close();
session = sf.createSession(false, false, 0);
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
for (int i = 0; i < numberOfMessages / 2; i++) {
ClientMessage message = consumer.receive(5000);
assertNotNull(message);
assertEquals(i, message.getIntProperty("id").intValue());
message.acknowledge();
}
session.rollback();
session.close();
session = sf.createSession(false, false, 0);
session.start();
consumer = session.createConsumer(ADDRESS);
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage message = consumer.receive(5000);
assertNotNull(message);
assertEquals(i, message.getIntProperty("id").intValue());
message.acknowledge();
}
session.commit();
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class PagingOrderTest method testOrderOverRollback2.
@Test
public void testOrderOverRollback2() throws Throwable {
boolean persistentMessages = true;
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
server.start();
final int messageSize = 1024;
final int numberOfMessages = 200;
ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(0);
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false, false);
server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
QueueImpl queue = (QueueImpl) server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, null, true, false);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
byte[] body = new byte[messageSize];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= messageSize; j++) {
bb.put(getSamplebyte(j));
}
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage message = session.createMessage(persistentMessages);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
if (i % 1000 == 0) {
session.commit();
}
}
session.commit();
session.close();
session = sf.createSession(false, false, 0);
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
// number of references without paging
int numberOfRefs = queue.getNumberOfReferences();
// consume all non-paged references
for (int ref = 0; ref < numberOfRefs; ref++) {
ClientMessage msg = consumer.receive(5000);
assertNotNull(msg);
msg.acknowledge();
}
session.commit();
session.close();
session = sf.createSession(false, false, 0);
session.start();
consumer = session.createConsumer(ADDRESS);
ClientMessage msg = consumer.receive(5000);
assertNotNull(msg);
int msgIDRolledBack = msg.getIntProperty("id").intValue();
msg.acknowledge();
session.rollback();
msg = consumer.receive(5000);
assertNotNull(msg);
assertEquals(msgIDRolledBack, msg.getIntProperty("id").intValue());
session.rollback();
session.close();
sf.close();
locator.close();
server.stop();
server.start();
locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(0);
sf = createSessionFactory(locator);
session = sf.createSession(false, false, 0);
session.start();
consumer = session.createConsumer(ADDRESS);
for (int i = msgIDRolledBack; i < numberOfMessages; i++) {
ClientMessage message = consumer.receive(5000);
assertNotNull(message);
assertEquals(i, message.getIntProperty("id").intValue());
message.acknowledge();
}
session.commit();
session.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class ClientProducerImpl method largeMessageSendServer.
/**
* Used to send serverMessages through the bridges. No need to validate compression here since
* the message is only compressed at the client
*
* @param sendBlocking
* @param msgI
* @param handler
* @throws ActiveMQException
*/
private void largeMessageSendServer(final boolean sendBlocking, final ICoreMessage msgI, final ClientProducerCredits credits, SendAcknowledgementHandler handler) throws ActiveMQException {
sendInitialLargeMessageHeader(msgI, credits);
LargeBodyEncoder context = msgI.getBodyEncoder();
final long bodySize = context.getLargeBodySize();
context.open();
try {
for (long pos = 0; pos < bodySize; ) {
final boolean lastChunk;
final int chunkLength = (int) Math.min((bodySize - pos), minLargeMessageSize);
final ActiveMQBuffer bodyBuffer = ActiveMQBuffers.fixedBuffer(chunkLength);
context.encode(bodyBuffer, chunkLength);
pos += chunkLength;
lastChunk = pos >= bodySize;
SendAcknowledgementHandler messageHandler = lastChunk ? handler : null;
int creditsUsed = sessionContext.sendServerLargeMessageChunk(msgI, -1, sendBlocking, lastChunk, bodyBuffer.toByteBuffer().array(), messageHandler);
credits.acquireCredits(creditsUsed);
}
} finally {
context.close();
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class ActiveMQSessionContext method sendPacketWithoutLock.
private void sendPacketWithoutLock(final Channel parameterChannel, final Packet packet) {
packet.setChannelID(parameterChannel.getID());
Connection conn = parameterChannel.getConnection().getTransportConnection();
ActiveMQBuffer buffer = packet.encode(this.getCoreConnection());
conn.write(buffer, false, false);
}
Aggregations