ARTEMIS-2183 Fixing RefsOperation on consumers and adding test

This commit is contained in:
Clebert Suconic 2019-02-25 17:23:08 -05:00
parent a1d10c02f9
commit 9f6f36d041
2 changed files with 51 additions and 1 deletions

View File

@ -28,6 +28,7 @@ import java.util.Map;
import org.apache.activemq.artemis.api.core.JsonUtil;
import org.apache.activemq.artemis.api.core.Message;
import org.apache.activemq.artemis.core.server.MessageReference;
import org.apache.activemq.artemis.core.server.impl.RefsOperation;
import org.apache.activemq.artemis.core.transaction.impl.XidImpl;
import org.apache.activemq.artemis.utils.JsonLoader;
@ -83,7 +84,7 @@ public abstract class TransactionDetail {
String opType = null;
if (opClassName.equals("org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl$AddOperation")) {
opType = "(+) send";
} else if (opClassName.equals("org.apache.activemq.artemis.core.server.impl.QueueImpl$RefsOperation")) {
} else if (opClassName.equals(RefsOperation.class.getName())) {
opType = "(-) receive";
}

View File

@ -984,6 +984,55 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
Assert.assertFalse(txDetails.matches(".*m8.*"));
}
@Test
public void testListPreparedTransactionDetailsOnConsumer() throws Exception {
SimpleString atestq = new SimpleString("BasicXaTestq");
Xid xid = newXID();
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession clientSession = csf.createSession(true, false, false);
clientSession.createQueue(atestq, atestq, null, true);
ClientMessage m1 = createTextMessage(clientSession, "");
ClientMessage m2 = createTextMessage(clientSession, "");
ClientMessage m3 = createTextMessage(clientSession, "");
ClientMessage m4 = createTextMessage(clientSession, "");
m1.putStringProperty("m1", "valuem1");
m2.putStringProperty("m2", "valuem2");
m3.putStringProperty("m3", "valuem3");
m4.putStringProperty("m4", "valuem4");
ClientProducer clientProducer = clientSession.createProducer(atestq);
clientSession.start(xid, XAResource.TMNOFLAGS);
clientProducer.send(m1);
clientProducer.send(m2);
clientProducer.send(m3);
clientProducer.send(m4);
clientSession.end(xid, XAResource.TMSUCCESS);
clientSession.prepare(xid);
clientSession.commit(xid, false);
ClientConsumer consumer = clientSession.createConsumer(atestq);
clientSession.start();
xid = newXID();
clientSession.start(xid, XAResource.TMNOFLAGS);
m1 = consumer.receive(1000);
Assert.assertNotNull(m1);
m1.acknowledge();
clientSession.end(xid, XAResource.TMSUCCESS);
clientSession.prepare(xid);
ActiveMQServerControl serverControl = createManagementControl();
String jsonOutput = serverControl.listPreparedTransactionDetailsAsJSON();
// just one message is pending, and it should be listed on the output
Assert.assertTrue(jsonOutput.lastIndexOf("valuem1") > 0);
Assert.assertTrue(jsonOutput.lastIndexOf("valuem2") < 0);
Assert.assertTrue(jsonOutput.lastIndexOf("valuem3") < 0);
Assert.assertTrue(jsonOutput.lastIndexOf("valuem4") < 0);
clientSession.close();
locator.close();
}
@Test
public void testListPreparedTransactionDetailsAsHTML() throws Exception {
SimpleString atestq = new SimpleString("BasicXaTestq");