public void testCommitPreparedTransactions() throws Exception { SimpleString recQueue = new SimpleString("BasicXaTestqRec"); SimpleString sendQueue = new SimpleString("BasicXaTestqSend"); byte[] globalTransactionId = UUIDGenerator.getInstance().generateStringUUID().getBytes(); Xid xid = new XidImpl("xa1".getBytes(), 1, globalTransactionId); Xid xid2 = new XidImpl("xa2".getBytes(), 1, globalTransactionId); ServerLocator locator = HornetQClient.createServerLocatorWithoutHA( new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY)); ClientSessionFactory csf = locator.createSessionFactory(); ClientSession clientSession = csf.createSession(true, false, false); clientSession.createQueue(recQueue, recQueue, null, true); clientSession.createQueue(sendQueue, sendQueue, null, true); ClientMessage m1 = createTextMessage(clientSession, ""); m1.putStringProperty("m1", "m1"); ClientProducer clientProducer = clientSession.createProducer(recQueue); clientProducer.send(m1); locator.close(); ServerLocator receiveLocator = HornetQClient.createServerLocatorWithoutHA( new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY)); ClientSessionFactory receiveCsf = receiveLocator.createSessionFactory(); ClientSession receiveClientSession = receiveCsf.createSession(true, false, false); ClientConsumer consumer = receiveClientSession.createConsumer(recQueue); ServerLocator sendLocator = HornetQClient.createServerLocatorWithoutHA( new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY)); ClientSessionFactory sendCsf = sendLocator.createSessionFactory(); ClientSession sendClientSession = sendCsf.createSession(true, false, false); ClientProducer producer = sendClientSession.createProducer(sendQueue); receiveClientSession.start(xid, XAResource.TMNOFLAGS); receiveClientSession.start(); sendClientSession.start(xid2, XAResource.TMNOFLAGS); ClientMessage m = consumer.receive(5000); assertNotNull(m); producer.send(m); receiveClientSession.end(xid, XAResource.TMSUCCESS); sendClientSession.end(xid2, XAResource.TMSUCCESS); receiveClientSession.prepare(xid); sendClientSession.prepare(xid2); HornetQServerControl serverControl = createManagementControl(); sendLocator.close(); receiveLocator.close(); boolean success = serverControl.commitPreparedTransaction(XidImpl.toBase64String(xid)); success = serverControl.commitPreparedTransaction(XidImpl.toBase64String(xid)); System.out.println("HornetQServerControlTest.testCommitPreparedTransactions"); }
public void testListPreparedTransactionDetails() throws Exception { SimpleString atestq = new SimpleString("BasicXaTestq"); Xid xid = newXID(); ServerLocator locator = HornetQClient.createServerLocatorWithoutHA( new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY)); ClientSessionFactory csf = locator.createSessionFactory(); 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", "m1"); m2.putStringProperty("m2", "m2"); m3.putStringProperty("m3", "m3"); m4.putStringProperty("m4", "m4"); 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); HornetQServerControl serverControl = createManagementControl(); JSONArray jsonArray = new JSONArray(serverControl.listProducersInfoAsJSON()); assertEquals(1, jsonArray.length()); assertEquals(4, ((JSONObject) jsonArray.get(0)).getInt("msgSent")); clientSession.close(); locator.close(); String txDetails = serverControl.listPreparedTransactionDetailsAsJSON(); Assert.assertTrue(txDetails.matches(".*m1.*")); Assert.assertTrue(txDetails.matches(".*m2.*")); Assert.assertTrue(txDetails.matches(".*m3.*")); Assert.assertTrue(txDetails.matches(".*m4.*")); }
@Test public void testMultipleMessagesAfterRecovery() throws Exception { Xid xid = new XidImpl("bq1".getBytes(), 4, "gtid1".getBytes()); ClientProducer producer = clientSessionXa.createProducer(address); SimpleString messageId1 = new SimpleString("SMID1"); SimpleString messageId2 = new SimpleString("SMID2"); clientSessionXa.start(xid, XAResource.TMNOFLAGS); ClientMessage m1 = createTextMessage(clientSession, "m1"); m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId1); ClientMessage m2 = createTextMessage(clientSession, "m2"); m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId2); ClientMessage m3 = createTextMessage(clientSession, "m3"); m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId1); ClientMessage m4 = createTextMessage(clientSession, "m4"); m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId2); producer.send(m1); producer.send(m2); producer.send(m3); producer.send(m4); clientSessionXa.end(xid, XAResource.TMSUCCESS); clientSessionXa.prepare(xid); clientSession.close(); clientSessionXa.close(); restartServer(); clientSessionXa.commit(xid, false); ClientConsumer consumer = clientSession.createConsumer(qName1); clientSession.start(); ClientMessage m = consumer.receive(1000); Assert.assertNotNull(m); m.acknowledge(); Assert.assertEquals(m.getBodyBuffer().readString(), "m3"); m = consumer.receive(1000); Assert.assertNotNull(m); m.acknowledge(); Assert.assertEquals(m.getBodyBuffer().readString(), "m4"); }
protected void callPrepare() throws Exception { session.prepare(activeXid); }
@Test public void testManyMessagesReceivedWithRollback() throws Exception { Xid xid = new XidImpl("bq1".getBytes(), 4, "gtid1".getBytes()); ClientProducer producer = clientSession.createProducer(address); ClientConsumer consumer = clientSessionXa.createConsumer(qName1); SimpleString rh = new SimpleString("SMID1"); ClientMessage m1 = createTextMessage(clientSession, "m1"); m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); m1.setDurable(true); ClientMessage m2 = createTextMessage(clientSession, "m2"); m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); m2.setDurable(true); ClientMessage m3 = createTextMessage(clientSession, "m3"); m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); m3.setDurable(true); ClientMessage m4 = createTextMessage(clientSession, "m4"); m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); m4.setDurable(true); ClientMessage m5 = createTextMessage(clientSession, "m5"); m5.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); m5.setDurable(true); ClientMessage m6 = createTextMessage(clientSession, "m6"); m6.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh); m6.setDurable(true); clientSessionXa.start(xid, XAResource.TMNOFLAGS); clientSessionXa.start(); producer.send(m1); ClientMessage m = consumer.receive(1000); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "m1"); producer.send(m2); m = consumer.receive(1000); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "m2"); producer.send(m3); m = consumer.receive(1000); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "m3"); producer.send(m4); m = consumer.receive(1000); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "m4"); producer.send(m5); m = consumer.receive(1000); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "m5"); producer.send(m6); m = consumer.receive(1000); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "m6"); clientSessionXa.end(xid, XAResource.TMSUCCESS); clientSessionXa.prepare(xid); clientSession.close(); clientSessionXa.close(); restartServer(); clientSessionXa.rollback(xid); consumer = clientSession.createConsumer(qName1); clientSession.start(); m = consumer.receive(1000); Assert.assertNotNull(m); m.acknowledge(); Assert.assertEquals(m.getBodyBuffer().readString(), "m6"); m = consumer.receiveImmediate(); Assert.assertNull(m); }