use of org.apache.activemq.artemis.core.config.Configuration in project activemq-artemis by apache.
the class HeuristicXATest method doHeuristicCompletionWithRestart.
private void doHeuristicCompletionWithRestart(final boolean isCommit) throws Exception {
Configuration configuration = createDefaultInVMConfig().setJMXManagementEnabled(true);
ActiveMQServer server = createServer(true, configuration);
server.setMBeanServer(mbeanServer);
server.start();
Xid xid = newXID();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(true, false, false);
session.createQueue(ADDRESS, ADDRESS, true);
session.start(xid, XAResource.TMNOFLAGS);
ClientProducer producer = session.createProducer(ADDRESS);
ClientMessage msg = session.createMessage(true);
msg.getBodyBuffer().writeString(body);
producer.send(msg);
session.end(xid, XAResource.TMSUCCESS);
session.prepare(xid);
session.close();
ActiveMQServerControl jmxServer = ManagementControlHelper.createActiveMQServerControl(mbeanServer);
String[] preparedTransactions = jmxServer.listPreparedTransactions();
Assert.assertEquals(1, preparedTransactions.length);
System.out.println(preparedTransactions[0]);
if (isCommit) {
jmxServer.commitPreparedTransaction(XidImpl.toBase64String(xid));
} else {
jmxServer.rollbackPreparedTransaction(XidImpl.toBase64String(xid));
}
preparedTransactions = jmxServer.listPreparedTransactions();
Assert.assertEquals(0, preparedTransactions.length);
if (isCommit) {
Assert.assertEquals(1, getMessageCount(((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable())));
session = sf.createSession(false, false, false);
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
msg = consumer.receive(1000);
Assert.assertNotNull(msg);
msg.acknowledge();
Assert.assertEquals(body, msg.getBodyBuffer().readString());
session.commit();
session.close();
}
Assert.assertEquals(0, getMessageCount(((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable())));
server.stop();
server.start();
jmxServer = ManagementControlHelper.createActiveMQServerControl(mbeanServer);
if (isCommit) {
String[] listHeuristicCommittedTransactions = jmxServer.listHeuristicCommittedTransactions();
Assert.assertEquals(1, listHeuristicCommittedTransactions.length);
System.out.println(listHeuristicCommittedTransactions[0]);
} else {
String[] listHeuristicRolledBackTransactions = jmxServer.listHeuristicRolledBackTransactions();
Assert.assertEquals(1, listHeuristicRolledBackTransactions.length);
System.out.println(listHeuristicRolledBackTransactions[0]);
}
}
use of org.apache.activemq.artemis.core.config.Configuration in project activemq-artemis by apache.
the class HeuristicXATest method doForgetHeuristicCompletedTxAndRestart.
private void doForgetHeuristicCompletedTxAndRestart(final boolean heuristicCommit) throws Exception {
Configuration configuration = createDefaultInVMConfig().setJMXManagementEnabled(true);
ActiveMQServer server = createServer(true, configuration);
server.setMBeanServer(mbeanServer);
server.start();
Xid xid = newXID();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(true, false, false);
session.createQueue(ADDRESS, ADDRESS, true);
session.start(xid, XAResource.TMNOFLAGS);
ClientProducer producer = session.createProducer(ADDRESS);
ClientMessage msg = session.createMessage(true);
msg.getBodyBuffer().writeBytes(new byte[123]);
producer.send(msg);
session.end(xid, XAResource.TMSUCCESS);
session.prepare(xid);
ActiveMQServerControl jmxServer = ManagementControlHelper.createActiveMQServerControl(mbeanServer);
String[] preparedTransactions = jmxServer.listPreparedTransactions();
Assert.assertEquals(1, preparedTransactions.length);
System.out.println(preparedTransactions[0]);
if (heuristicCommit) {
jmxServer.commitPreparedTransaction(XidImpl.toBase64String(xid));
} else {
jmxServer.rollbackPreparedTransaction(XidImpl.toBase64String(xid));
}
preparedTransactions = jmxServer.listPreparedTransactions();
Assert.assertEquals(0, preparedTransactions.length);
session.forget(xid);
session.close();
if (heuristicCommit) {
Assert.assertEquals(0, jmxServer.listHeuristicCommittedTransactions().length);
} else {
Assert.assertEquals(0, jmxServer.listHeuristicRolledBackTransactions().length);
}
server.stop();
server.start();
// we need to recreate the sf
sf = createSessionFactory(locator);
session = sf.createSession(true, false, false);
Xid[] recoveredXids = session.recover(XAResource.TMSTARTRSCAN);
Assert.assertEquals(0, recoveredXids.length);
jmxServer = ManagementControlHelper.createActiveMQServerControl(mbeanServer);
if (heuristicCommit) {
Assert.assertEquals(0, jmxServer.listHeuristicCommittedTransactions().length);
} else {
Assert.assertEquals(0, jmxServer.listHeuristicRolledBackTransactions().length);
}
session.close();
}
use of org.apache.activemq.artemis.core.config.Configuration in project activemq-artemis by apache.
the class JournalCrashTest method startServer.
protected void startServer() throws Exception {
Configuration config = createDefaultInVMConfig().setJournalFileSize(ActiveMQDefaultConfiguration.getDefaultJournalFileSize()).setJournalCompactMinFiles(ActiveMQDefaultConfiguration.getDefaultJournalCompactMinFiles()).setJournalCompactPercentage(ActiveMQDefaultConfiguration.getDefaultJournalCompactPercentage()).setJournalMinFiles(2);
server = super.createServer(true, config);
server.start();
locator = createInVMNonHALocator();
factory = createSessionFactory(locator);
}
use of org.apache.activemq.artemis.core.config.Configuration in project activemq-artemis by apache.
the class SaslKrb5LDAPSecurityTest method createArtemisServer.
private void createArtemisServer(String securityConfigScope) {
ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(securityConfigScope);
HashMap<String, Object> params = new HashMap<>();
params.put(TransportConstants.PORT_PROP_NAME, String.valueOf(5672));
params.put(TransportConstants.PROTOCOLS_PROP_NAME, "AMQP");
HashMap<String, Object> amqpParams = new HashMap<>();
amqpParams.put("saslMechanisms", "GSSAPI");
amqpParams.put("saslLoginConfigScope", "amqp-sasl-gssapi");
Configuration configuration = new ConfigurationImpl().setSecurityEnabled(true).addAcceptorConfiguration(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY, params, "netty-amqp", amqpParams)).setJournalDirectory(ActiveMQTestBase.getJournalDir(testDir, 0, false)).setBindingsDirectory(ActiveMQTestBase.getBindingsDir(testDir, 0, false)).setPagingDirectory(ActiveMQTestBase.getPageDir(testDir, 0, false)).setLargeMessagesDirectory(ActiveMQTestBase.getLargeMessagesDir(testDir, 0, false));
server = ActiveMQServers.newActiveMQServer(configuration, ManagementFactory.getPlatformMBeanServer(), securityManager, false);
}
use of org.apache.activemq.artemis.core.config.Configuration in project activemq-artemis by apache.
the class ActiveMQCrashTest method testHang.
@Test
public void testHang() throws Exception {
Configuration configuration = createDefaultInVMConfig().setPersistenceEnabled(false);
server = addServer(ActiveMQServers.newActiveMQServer(configuration));
server.start();
server.getRemotingService().addIncomingInterceptor(new AckInterceptor(server));
// Force an ack at once - this means the send call will block
locator.setConfirmationWindowSize(1);
ClientSessionFactory clientSessionFactory = createSessionFactory(locator);
ClientSession session = clientSessionFactory.createSession();
session.setSendAcknowledgementHandler(new SendAcknowledgementHandler() {
@Override
public void sendAcknowledged(final Message message) {
ackReceived = true;
}
});
ClientProducer producer = session.createProducer("fooQueue");
ClientMessage msg = session.createMessage(false);
msg.putStringProperty("someKey", "someValue");
producer.send(msg);
Thread.sleep(250);
Assert.assertFalse(ackReceived);
session.close();
}
Aggregations