Search in sources :

Example 36 with ActiveMQConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class GroupingTest method testGroupingRollbackOnClose.

@Test
@BMRules(rules = { @BMRule(name = "trace clientsessionimpl commit", targetClass = "org.apache.activemq.artemis.core.server.impl.ServerSessionImpl", targetMethod = "rollback", targetLocation = "EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.GroupingTest.pause();") })
public void testGroupingRollbackOnClose() throws Exception {
    Connection sendConnection = null;
    Connection connection = null;
    Connection connection2 = null;
    try {
        ActiveMQConnectionFactory fact = (ActiveMQConnectionFactory) getCF();
        fact.setReconnectAttempts(0);
        // fact.setConsumerWindowSize(1000);
        // fact.setTransactionBatchSize(0);
        connection = fact.createConnection();
        RemotingConnection rc = server.getRemotingService().getConnections().iterator().next();
        connection2 = fact.createConnection();
        sendConnection = fact.createConnection();
        final Session sendSession = sendConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
        Session session2 = connection2.createSession(true, Session.SESSION_TRANSACTED);
        final MessageProducer producer = sendSession.createProducer(queue);
        MessageConsumer consumer1 = session.createConsumer(queue);
        MessageConsumer consumer2 = session2.createConsumer(queue);
        connection.start();
        connection2.start();
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    for (int j = 0; j < 10000; j++) {
                        TextMessage message = sendSession.createTextMessage();
                        message.setText("Message" + j);
                        message.setStringProperty("JMSXGroupID", "foo");
                        producer.send(message);
                    }
                } catch (JMSException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();
        // consume 5 msgs from 1st first consumer
        for (int j = 0; j < 5; j++) {
            TextMessage tm = (TextMessage) consumer1.receive(10000);
            assertNotNull(tm);
            assertEquals("Message" + j, tm.getText());
            assertEquals(tm.getStringProperty("JMSXGroupID"), "foo");
        }
        pause = true;
        rc.fail(new ActiveMQNotConnectedException());
        pause = false;
        for (int j = 0; j < 10000; j++) {
            TextMessage tm = (TextMessage) consumer2.receive(5000);
            assertNotNull(tm);
            assertEquals("Message" + j, tm.getText());
            assertEquals(tm.getStringProperty("JMSXGroupID"), "foo");
        }
    } finally {
        if (sendConnection != null) {
            sendConnection.close();
        }
        if (connection2 != null) {
            connection2.close();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) JMSException(javax.jms.JMSException) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 37 with ActiveMQConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class FailureXATest method doTestCrashServerAfterXACommit.

private void doTestCrashServerAfterXACommit(boolean onePhase) throws Exception {
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
    XAConnection connection = connectionFactory.createXAConnection();
    try {
        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
        Queue queue = session.createQueue("Queue1");
        final XASession xaSession = connection.createXASession();
        MessageConsumer consumer = xaSession.createConsumer(queue);
        MessageProducer producer = session.createProducer(queue);
        producer.send(session.createTextMessage("hello " + 1));
        session.commit();
        XAResource xaResource = xaSession.getXAResource();
        final Xid xid = newXID();
        xaResource.start(xid, XAResource.TMNOFLAGS);
        connection.start();
        Assert.assertNotNull(consumer.receive(5000));
        xaResource.end(xid, XAResource.TMSUCCESS);
        try {
            xaResource.commit(xid, onePhase);
            Assert.fail("didn't get expected exception!");
        } catch (XAException xae) {
            if (onePhase) {
                // expected error code is XAER_RMFAIL
                Assert.assertEquals(XAException.XAER_RMFAIL, xae.errorCode);
            } else {
                // expected error code is XA_RETRY
                Assert.assertEquals(XAException.XA_RETRY, xae.errorCode);
            }
        }
    } finally {
        connection.close();
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) XASession(javax.jms.XASession) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) XAConnection(javax.jms.XAConnection) XASession(javax.jms.XASession) Session(javax.jms.Session)

Example 38 with ActiveMQConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class SimpleJNDIClientTest method testRemoteCFWithTCPandHA.

@Test
public void testRemoteCFWithTCPandHA() throws NamingException, JMSException {
    Hashtable<String, String> props = new Hashtable<>();
    props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
    props.put("connectionFactory.myConnectionFactory", "tcp://127.0.0.1:61616?ha=true");
    Context ctx = new InitialContext(props);
    ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
    Assert.assertEquals(true, cf.isHA());
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) Hashtable(java.util.Hashtable) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 39 with ActiveMQConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class SimpleJNDIClientTest method testRemoteCFWithUDPWithTransportConfig.

@Test
public void testRemoteCFWithUDPWithTransportConfig() throws NamingException, JMSException {
    Hashtable<String, String> props = new Hashtable<>();
    props.put(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getCanonicalName());
    props.put("connectionFactory.myConnectionFactory", "udp://" + getUDPDiscoveryAddress() + ":" + getUDPDiscoveryPort() + "?" + TransportConstants.LOCAL_ADDRESS_PROP_NAME + "=Server1&" + TransportConstants.LOCAL_PORT_PROP_NAME + "=1198&" + ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" + ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000");
    Context ctx = new InitialContext(props);
    ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
    DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration();
    Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout());
    Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout());
    UDPBroadcastEndpointFactory udpBroadcastEndpointFactory = (UDPBroadcastEndpointFactory) discoveryGroupConfiguration.getBroadcastEndpointFactory();
    // these 2 are transient so are ignored
    Assert.assertNotEquals("Server1", udpBroadcastEndpointFactory.getLocalBindAddress());
    Assert.assertNotEquals(1198, udpBroadcastEndpointFactory.getLocalBindPort());
    Assert.assertEquals(getUDPDiscoveryAddress(), udpBroadcastEndpointFactory.getGroupAddress());
    Assert.assertEquals(getUDPDiscoveryPort(), udpBroadcastEndpointFactory.getGroupPort());
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) Hashtable(java.util.Hashtable) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) ActiveMQInitialContextFactory(org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 40 with ActiveMQConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class SimpleJNDIClientTest method testRemoteCFWithJgroupsWithTransportConfigNullProps.

@Test
public void testRemoteCFWithJgroupsWithTransportConfigNullProps() throws Exception {
    Hashtable<String, String> props = new Hashtable<>();
    props.put(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getCanonicalName());
    props.put("connectionFactory.ConnectionFactory", "jgroups://testChannelName?" + ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" + ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000");
    Context ctx = new InitialContext(props);
    ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("ConnectionFactory");
    DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration();
    Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout());
    Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout());
    BroadcastEndpointFactory broadcastEndpointFactory = cf.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory();
    Assert.assertTrue(broadcastEndpointFactory instanceof JGroupsPropertiesBroadcastEndpointFactory);
    JGroupsPropertiesBroadcastEndpointFactory endpointFactory = (JGroupsPropertiesBroadcastEndpointFactory) broadcastEndpointFactory;
    Assert.assertEquals(endpointFactory.getProperties(), null);
    Assert.assertEquals(endpointFactory.getChannelName(), "testChannelName");
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) Hashtable(java.util.Hashtable) JGroupsPropertiesBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsPropertiesBroadcastEndpointFactory) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) ActiveMQInitialContextFactory(org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory) InitialContext(javax.naming.InitialContext) JGroupsPropertiesBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsPropertiesBroadcastEndpointFactory) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory) Test(org.junit.Test)

Aggregations

ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)221 Test (org.junit.Test)141 Connection (javax.jms.Connection)84 Session (javax.jms.Session)84 MessageProducer (javax.jms.MessageProducer)63 MessageConsumer (javax.jms.MessageConsumer)60 TextMessage (javax.jms.TextMessage)49 Queue (javax.jms.Queue)48 ConnectionFactory (javax.jms.ConnectionFactory)35 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)27 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)26 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)24 ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)24 URI (java.net.URI)22 JMSException (javax.jms.JMSException)20 Message (javax.jms.Message)19 DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)19 InitialContext (javax.naming.InitialContext)16 Context (javax.naming.Context)15 Hashtable (java.util.Hashtable)14