use of org.apache.activemq.command.Message in project activemq-artemis by apache.
the class XARecoveryBrokerTest method testQueuePersistentCommittedAcksNotLostOnRestart.
public void testQueuePersistentCommittedAcksNotLostOnRestart() throws Exception {
ActiveMQDestination destination = createDestination();
// Setup the producer and send the message.
StubConnection connection = createConnection();
ConnectionInfo connectionInfo = createConnectionInfo();
SessionInfo sessionInfo = createSessionInfo(connectionInfo);
ProducerInfo producerInfo = createProducerInfo(sessionInfo);
connection.send(connectionInfo);
connection.send(sessionInfo);
connection.send(producerInfo);
for (int i = 0; i < 4; i++) {
Message message = createMessage(producerInfo, destination);
message.setPersistent(true);
connection.send(message);
}
// Begin the transaction.
XATransactionId txid = createXATransaction(sessionInfo);
connection.send(createBeginTransaction(connectionInfo, txid));
ConsumerInfo consumerInfo;
Message m = null;
for (ActiveMQDestination dest : destinationList(destination)) {
// Setup the consumer and receive the message.
consumerInfo = createConsumerInfo(sessionInfo, dest);
connection.send(consumerInfo);
for (int i = 0; i < 4; i++) {
m = receiveMessage(connection);
assertNotNull(m);
}
MessageAck ack = createAck(consumerInfo, m, 4, MessageAck.STANDARD_ACK_TYPE);
ack.setTransactionId(txid);
connection.send(ack);
}
// Commit
connection.request(createCommitTransaction1Phase(connectionInfo, txid));
// restart the broker.
restartBroker();
// Setup the consumer and receive the message.
connection = createConnection();
connectionInfo = createConnectionInfo();
sessionInfo = createSessionInfo(connectionInfo);
connection.send(connectionInfo);
connection.send(sessionInfo);
consumerInfo = createConsumerInfo(sessionInfo, destination);
connection.send(consumerInfo);
// No messages should be delivered.
assertNoMessagesLeft(connection);
m = receiveMessage(connection);
assertNull(m);
}
use of org.apache.activemq.command.Message in project activemq-artemis by apache.
the class AdvisoryBrokerTest method testConnectionAdvisories.
public void testConnectionAdvisories() throws Exception {
ActiveMQDestination destination = AdvisorySupport.getConnectionAdvisoryTopic();
// Setup a first connection
StubConnection connection1 = createConnection();
ConnectionInfo connectionInfo1 = createConnectionInfo();
SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
consumerInfo1.setPrefetchSize(100);
connection1.send(connectionInfo1);
connection1.send(sessionInfo1);
connection1.send(consumerInfo1);
// We should get an advisory of our own connection.
Message m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
assertEquals(((ConnectionInfo) m1.getDataStructure()).getConnectionId(), connectionInfo1.getConnectionId());
// Setup a second connection
StubConnection connection2 = createConnection();
ConnectionInfo connectionInfo2 = createConnectionInfo();
connection2.send(connectionInfo2);
// We should get an advisory of the second connection.
m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
assertEquals(((ConnectionInfo) m1.getDataStructure()).getConnectionId(), connectionInfo2.getConnectionId());
// Close the second connection.
connection2.send(closeConnectionInfo(connectionInfo2));
connection2.stop();
// We should get an advisory of the second connection closing
m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
RemoveInfo r = (RemoveInfo) m1.getDataStructure();
assertEquals(r.getObjectId(), connectionInfo2.getConnectionId());
assertNoMessagesLeft(connection1);
}
use of org.apache.activemq.command.Message in project activemq-artemis by apache.
the class AdvisoryBrokerTest method testConsumerAdvisories.
public void testConsumerAdvisories() throws Exception {
ActiveMQDestination queue = new ActiveMQQueue("test");
ActiveMQDestination destination = AdvisorySupport.getConsumerAdvisoryTopic(queue);
// Setup a first connection
StubConnection connection1 = createConnection();
ConnectionInfo connectionInfo1 = createConnectionInfo();
SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
consumerInfo1.setPrefetchSize(100);
connection1.send(connectionInfo1);
connection1.send(sessionInfo1);
connection1.send(consumerInfo1);
// We should not see and advisory for the advisory consumer.
assertNoMessagesLeft(connection1);
// Setup a second consumer.
StubConnection connection2 = createConnection();
ConnectionInfo connectionInfo2 = createConnectionInfo();
SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, queue);
consumerInfo1.setPrefetchSize(100);
connection2.send(connectionInfo2);
connection2.send(sessionInfo2);
connection2.send(consumerInfo2);
// We should get an advisory of the new consumer.
Message m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
assertEquals(((ConsumerInfo) m1.getDataStructure()).getConsumerId(), consumerInfo2.getConsumerId());
// Close the second connection.
connection2.request(closeConnectionInfo(connectionInfo2));
connection2.stop();
// We should get an advisory of the consumer closing
m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
RemoveInfo r = (RemoveInfo) m1.getDataStructure();
assertEquals(r.getObjectId(), consumerInfo2.getConsumerId());
assertNoMessagesLeft(connection2);
}
use of org.apache.activemq.command.Message in project activemq-artemis by apache.
the class AdvisoryBrokerTest method testProducerAdvisories.
public void testProducerAdvisories() throws Exception {
ActiveMQDestination queue = new ActiveMQQueue("test");
ActiveMQDestination destination = AdvisorySupport.getProducerAdvisoryTopic(queue);
// Setup a first connection
StubConnection connection1 = createConnection();
ConnectionInfo connectionInfo1 = createConnectionInfo();
SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
consumerInfo1.setPrefetchSize(100);
connection1.send(connectionInfo1);
connection1.send(sessionInfo1);
connection1.send(consumerInfo1);
assertNoMessagesLeft(connection1);
// Setup a producer.
StubConnection connection2 = createConnection();
ConnectionInfo connectionInfo2 = createConnectionInfo();
SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
producerInfo2.setDestination(queue);
connection2.send(connectionInfo2);
connection2.send(sessionInfo2);
connection2.send(producerInfo2);
// We should get an advisory of the new producer.
Message m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
// Close the second connection.
connection2.request(closeConnectionInfo(connectionInfo2));
connection2.stop();
// We should get an advisory of the producer closing
m1 = receiveMessage(connection1);
assertNotNull(m1);
assertNotNull(m1.getDataStructure());
RemoveInfo r = (RemoveInfo) m1.getDataStructure();
assertEquals(r.getObjectId(), producerInfo2.getProducerId());
assertNoMessagesLeft(connection2);
}
use of org.apache.activemq.command.Message in project activemq-artemis by apache.
the class QueueOptimizedDispatchExceptionTest method TestOptimizedDispatchCME.
@Test
public void TestOptimizedDispatchCME() throws Exception {
final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(destination);
final ConnectionContext contextNotInTx = new ConnectionContext();
contextNotInTx.setConnection(new Connection() {
@Override
public void stop() throws Exception {
}
@Override
public void start() throws Exception {
}
@Override
public void updateClient(ConnectionControl control) {
}
@Override
public void serviceExceptionAsync(IOException e) {
}
@Override
public void serviceException(Throwable error) {
}
@Override
public Response service(Command command) {
return null;
}
@Override
public boolean isSlow() {
return false;
}
@Override
public boolean isNetworkConnection() {
return false;
}
@Override
public boolean isManageable() {
return false;
}
@Override
public boolean isFaultTolerantConnection() {
return false;
}
@Override
public boolean isConnected() {
return true;
}
@Override
public boolean isBlocked() {
return false;
}
@Override
public boolean isActive() {
return false;
}
@Override
public ConnectionStatistics getStatistics() {
return null;
}
@Override
public String getRemoteAddress() {
return null;
}
@Override
public int getDispatchQueueSize() {
return 0;
}
@Override
public Connector getConnector() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getConnectionId() {
return null;
}
@Override
public void dispatchSync(Command message) {
}
@Override
public void dispatchAsync(Command command) {
}
@Override
public int getActiveTransactionCount() {
return 0;
}
@Override
public Long getOldestActiveTransactionDuration() {
return null;
}
});
final DestinationStatistics destinationStatistics = new DestinationStatistics();
final Queue queue = new Queue(broker, destination, queueMessageStore, destinationStatistics, broker.getTaskRunnerFactory());
final MockMemoryUsage usage = new MockMemoryUsage();
queue.setOptimizedDispatch(true);
queue.initialize();
queue.start();
queue.memoryUsage = usage;
ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
ProducerInfo producerInfo = new ProducerInfo();
ProducerState producerState = new ProducerState(producerInfo);
producerExchange.setProducerState(producerState);
producerExchange.setConnectionContext(contextNotInTx);
// populate the queue store, exceed memory limit so that cache is disabled
for (int i = 0; i < count; i++) {
Message message = getMessage(i);
queue.send(producerExchange, message);
}
usage.setFull(false);
try {
queue.wakeup();
} catch (Exception e) {
LOG.error("Queue threw an unexpected exception: " + e.toString());
fail("Should not throw an exception.");
}
}
Aggregations