use of org.apache.activemq.command.Response 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.");
}
}
use of org.apache.activemq.command.Response in project activemq-artemis by apache.
the class UdpTestSupport method sendResponse.
protected void sendResponse(Command command) {
Response response = new Response();
response.setCorrelationId(command.getCommandId());
try {
consumer.oneway(response);
} catch (IOException e) {
LOG.info("Caught: " + e);
e.printStackTrace();
throw new RuntimeException(e);
}
}
use of org.apache.activemq.command.Response in project activemq-artemis by apache.
the class NetworkRouteTest method addAndRemoveSameOrder.
@Test
public void addAndRemoveSameOrder() throws Exception {
// from (1)
localBroker.request(EasyMock.isA(ConsumerInfo.class));
ArgHolder localConsumer = ArgHolder.holdArgsForLastObjectCall();
// from (2a)
remoteBroker.asyncRequest(EasyMock.isA(ActiveMQMessage.class), EasyMock.isA(ResponseCallback.class));
ArgHolder firstMessageFuture = ArgHolder.holdArgsForLastFutureRequestCall();
localBroker.oneway(EasyMock.isA(MessageAck.class));
// from (2b)
remoteBroker.asyncRequest(EasyMock.isA(ActiveMQMessage.class), EasyMock.isA(ResponseCallback.class));
ArgHolder secondMessageFuture = ArgHolder.holdArgsForLastFutureRequestCall();
localBroker.oneway(EasyMock.isA(MessageAck.class));
// from (3)
localBroker.oneway(EasyMock.isA(RemoveInfo.class));
ExpectationWaiter waitForRemove = ExpectationWaiter.waiterForLastVoidCall();
control.replay();
// (1) send advisory of path 1
remoteListener.onCommand(path1Msg);
msgDispatch.setConsumerId(((ConsumerInfo) localConsumer.arguments[0]).getConsumerId());
// send advisory of path 2, doesn't send a ConsumerInfo to localBroker
remoteListener.onCommand(path2Msg);
// (2a) send a message
localListener.onCommand(msgDispatch);
ResponseCallback callback = (ResponseCallback) firstMessageFuture.arguments[1];
FutureResponse response = new FutureResponse(callback);
response.set(new Response());
// send advisory of path 1 remove, shouldn't send a RemoveInfo to localBroker
remoteListener.onCommand(removePath1Msg);
// (2b) send a message, should send the message as in 2a
localListener.onCommand(msgDispatch);
callback = (ResponseCallback) secondMessageFuture.arguments[1];
response = new FutureResponse(callback);
response.set(new Response());
// (3) send advisory of path 1 remove, should send a RemoveInfo to localBroker
remoteListener.onCommand(removePath2Msg);
waitForRemove.assertHappens(5, TimeUnit.SECONDS);
// send a message, does not send message as in 2a
localListener.onCommand(msgDispatch);
control.verify();
}
use of org.apache.activemq.command.Response in project activemq-artemis by apache.
the class XARecoveryBrokerTest method testPreparedJmxView.
public void testPreparedJmxView() 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);
ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
connection.send(consumerInfo);
// Prepare 4 message sends.
for (int i = 0; i < 4; i++) {
// Begin the transaction.
XATransactionId txid = createXATransaction(sessionInfo);
connection.send(createBeginTransaction(connectionInfo, txid));
Message message = createMessage(producerInfo, destination);
message.setPersistent(true);
message.setTransactionId(txid);
connection.send(message);
// Prepare
connection.send(createPrepareTransaction(connectionInfo, txid));
}
Response response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
assertNotNull(response);
DataArrayResponse dar = (DataArrayResponse) response;
assertEquals(4, dar.getData().length);
// view prepared in kahadb view
if (broker.getPersistenceAdapter() instanceof KahaDBPersistenceAdapter) {
PersistenceAdapterViewMBean kahadbView = getProxyToPersistenceAdapter(broker.getPersistenceAdapter().toString());
String txFromView = kahadbView.getTransactions();
LOG.info("Tx view fromm PA:" + txFromView);
assertTrue("xid with our dud format in transaction string " + txFromView, txFromView.contains("XID:[55,"));
}
// restart the broker.
restartBroker();
connection = createConnection();
connectionInfo = createConnectionInfo();
connection.send(connectionInfo);
response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
assertNotNull(response);
dar = (DataArrayResponse) response;
assertEquals(4, dar.getData().length);
// validate destination depth via jmx
DestinationViewMBean destinationView = getProxyToDestination(destinationList(destination)[0]);
assertEquals("enqueue count does not see prepared", 0, destinationView.getQueueSize());
TransactionId first = (TransactionId) dar.getData()[0];
int commitCount = 0;
// via jmx, force outcome
for (int i = 0; i < 4; i++) {
RecoveredXATransactionViewMBean mbean = getProxyToPreparedTransactionViewMBean((TransactionId) dar.getData()[i]);
if (i % 2 == 0) {
mbean.heuristicCommit();
commitCount++;
} else {
mbean.heuristicRollback();
}
}
// verify all completed
response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
assertNotNull(response);
dar = (DataArrayResponse) response;
assertEquals(0, dar.getData().length);
// verify messages available
assertEquals("enqueue count reflects outcome", commitCount, destinationView.getQueueSize());
// verify mbeans gone
try {
RecoveredXATransactionViewMBean gone = getProxyToPreparedTransactionViewMBean(first);
gone.heuristicRollback();
fail("Excepted not found");
} catch (InstanceNotFoundException expectedNotfound) {
}
}
use of org.apache.activemq.command.Response in project activemq-artemis by apache.
the class XARecoveryBrokerTest method testTopicPreparedTransactionRecoveredOnRestart.
public void testTopicPreparedTransactionRecoveredOnRestart() throws Exception {
ActiveMQDestination destination = new ActiveMQTopic("TryTopic");
StubConnection connection = createConnection();
ConnectionInfo connectionInfo = createConnectionInfo();
connectionInfo.setClientId("durable");
SessionInfo sessionInfo = createSessionInfo(connectionInfo);
ProducerInfo producerInfo = createProducerInfo(sessionInfo);
connection.send(connectionInfo);
connection.send(sessionInfo);
connection.send(producerInfo);
ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
consumerInfo.setSubscriptionName("durable");
connection.send(consumerInfo);
// Prepare 4 message sends.
for (int i = 0; i < 4; i++) {
// Begin the transaction.
XATransactionId txid = createXATransaction(sessionInfo);
connection.send(createBeginTransaction(connectionInfo, txid));
Message message = createMessage(producerInfo, destination);
message.setPersistent(true);
message.setTransactionId(txid);
connection.send(message);
// Prepare
connection.send(createPrepareTransaction(connectionInfo, txid));
}
// Since prepared but not committed.. they should not get delivered.
assertNull(receiveMessage(connection));
assertNoMessagesLeft(connection);
connection.request(closeConnectionInfo(connectionInfo));
// restart the broker.
restartBroker();
// Setup the consumer and try receive the message.
connection = createConnection();
connectionInfo = createConnectionInfo();
connectionInfo.setClientId("durable");
sessionInfo = createSessionInfo(connectionInfo);
connection.send(connectionInfo);
connection.send(sessionInfo);
consumerInfo = createConsumerInfo(sessionInfo, destination);
consumerInfo.setSubscriptionName("durable");
connection.send(consumerInfo);
// Since prepared but not committed.. they should not get delivered.
assertNull(receiveMessage(connection));
assertNoMessagesLeft(connection);
Response response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
assertNotNull(response);
DataArrayResponse dar = (DataArrayResponse) response;
assertEquals(4, dar.getData().length);
// ensure we can close a connection with prepared transactions
connection.request(closeConnectionInfo(connectionInfo));
// open again to deliver outcome
connection = createConnection();
connectionInfo = createConnectionInfo();
connectionInfo.setClientId("durable");
sessionInfo = createSessionInfo(connectionInfo);
connection.send(connectionInfo);
connection.send(sessionInfo);
consumerInfo = createConsumerInfo(sessionInfo, destination);
consumerInfo.setSubscriptionName("durable");
connection.send(consumerInfo);
// Commit the prepared transactions.
for (int i = 0; i < dar.getData().length; i++) {
connection.request(createCommitTransaction2Phase(connectionInfo, (TransactionId) dar.getData()[i]));
}
// We should get the committed transactions.
for (int i = 0; i < expectedMessageCount(4, destination); i++) {
Message m = receiveMessage(connection, TimeUnit.SECONDS.toMillis(10));
assertNotNull(m);
}
assertNoMessagesLeft(connection);
}
Aggregations