Search in sources :

Example 16 with Configuration

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]);
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Xid(javax.transaction.xa.Xid) ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) Configuration(org.apache.activemq.artemis.core.config.Configuration) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 17 with Configuration

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();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Xid(javax.transaction.xa.Xid) ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) Configuration(org.apache.activemq.artemis.core.config.Configuration) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 18 with Configuration

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);
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) ActiveMQDefaultConfiguration(org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration)

Example 19 with Configuration

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);
}
Also used : TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) HashMap(java.util.HashMap) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ConfigurationImpl(org.apache.activemq.artemis.core.config.impl.ConfigurationImpl)

Example 20 with Configuration

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();
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) SendAcknowledgementHandler(org.apache.activemq.artemis.api.core.client.SendAcknowledgementHandler) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Aggregations

Configuration (org.apache.activemq.artemis.core.config.Configuration)331 Test (org.junit.Test)143 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)120 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)109 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)108 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)101 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)93 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)90 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)81 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)78 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)78 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)72 Before (org.junit.Before)59 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)58 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)57 HashMap (java.util.HashMap)56 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)52 ActiveMQDefaultConfiguration (org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration)35 SharedStoreMasterPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration)35 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)34