Search in sources :

Example 26 with ClientSessionFactoryInternal

use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.

the class ServerLocatorConnectTest method testMultipleConnectorSingleServerNoConnect.

@Test
public void testMultipleConnectorSingleServerNoConnect() throws Exception {
    ServerLocatorInternal locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false, generateParams(1, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(2, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(3, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(4, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(5, isNetty())));
    ClientSessionFactoryInternal csf = null;
    try {
        csf = locator.connect();
    } catch (ActiveMQNotConnectedException nce) {
    // ok
    } catch (Exception e) {
        assertTrue(e instanceof ActiveMQException);
        fail("Invalid Exception type:" + ((ActiveMQException) e).getType());
    }
    assertNull(csf);
    locator.close();
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ServerLocatorInternal(org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Test(org.junit.Test)

Example 27 with ClientSessionFactoryInternal

use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.

the class FailoverTest method testTimeoutOnFailoverTransactionCommit.

// https://issues.jboss.org/browse/HORNETQ-685
@Test(timeout = 120000)
public void testTimeoutOnFailoverTransactionCommit() throws Exception {
    locator.setCallTimeout(5000).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setAckBatchSize(0).setReconnectAttempts(300).setRetryInterval(100);
    if (nodeManager instanceof InVMNodeManager) {
        ((InVMNodeManager) nodeManager).failoverPause = 5000L;
    }
    ClientSessionFactoryInternal sf1 = (ClientSessionFactoryInternal) createSessionFactory(locator);
    final ClientSession session = createSession(sf1, true, false, false);
    session.createQueue(FailoverTestBase.ADDRESS, RoutingType.MULTICAST, FailoverTestBase.ADDRESS, null, true);
    final CountDownLatch connectionFailed = new CountDownLatch(1);
    session.addFailureListener(new SessionFailureListener() {

        @Override
        public void beforeReconnect(ActiveMQException exception) {
        }

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver) {
        }

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver, String scaleDownTargetNodeID) {
            connectionFailed.countDown();
        }
    });
    final ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
    Xid xid = new XidImpl("uhuhuhu".getBytes(), 126512, "auhsduashd".getBytes());
    session.start(xid, XAResource.TMNOFLAGS);
    for (int i = 0; i < 500; i++) {
        ClientMessage message = session.createMessage(true);
        message.putIntProperty("counter", i);
        producer.send(message);
    }
    session.end(xid, XAResource.TMSUCCESS);
    session.prepare(xid);
    crash(true, session);
    try {
        session.commit(xid, false);
    } catch (XAException e) {
        // there is still an edge condition that we must deal with
        Assert.assertTrue(connectionFailed.await(10, TimeUnit.SECONDS));
        session.commit(xid, false);
    }
    ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
    session.start();
    for (int i = 0; i < 500; i++) {
        ClientMessage m = consumer.receive(1000);
        Assert.assertNotNull(m);
        Assert.assertEquals(i, m.getIntProperty("counter").intValue());
    }
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) XAException(javax.transaction.xa.XAException) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) XidImpl(org.apache.activemq.artemis.core.transaction.impl.XidImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) CountDownLatch(java.util.concurrent.CountDownLatch) SessionFailureListener(org.apache.activemq.artemis.api.core.client.SessionFailureListener) CountDownSessionFailureListener(org.apache.activemq.artemis.tests.util.CountDownSessionFailureListener) Xid(javax.transaction.xa.Xid) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 28 with ClientSessionFactoryInternal

use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.

the class LiveToLiveFailoverTest method createSessionFactoryAndWaitForTopology.

protected final ClientSessionFactoryInternal createSessionFactoryAndWaitForTopology(ServerLocator locator, TransportConfiguration transportConfiguration, int topologyMembers) throws Exception {
    CountDownLatch countDownLatch = new CountDownLatch(topologyMembers * 2);
    locator.addClusterTopologyListener(new LatchClusterTopologyListener(countDownLatch));
    ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) locator.createSessionFactory(transportConfiguration);
    addSessionFactory(sf);
    assertTrue("topology members expected " + topologyMembers, countDownLatch.await(5, TimeUnit.SECONDS));
    closeSessionFactory(sf);
    sf = (ClientSessionFactoryInternal) locator.createSessionFactory(liveServer.getServer().getNodeID().toString());
    addSessionFactory(sf);
    if (sf2 == null) {
        sf2 = (ClientSessionFactoryInternal) locator.createSessionFactory(backupServer.getServer().getNodeID().toString());
        ClientSession session2 = createSession(sf2, false, false);
        session2.createQueue(ADDRESS, ADDRESS, null, true);
        addSessionFactory(sf2);
    }
    return sf;
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 29 with ClientSessionFactoryInternal

use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.

the class LiveToLiveFailoverTest method createSessionFactoryAndWaitForTopology.

@Override
protected final ClientSessionFactoryInternal createSessionFactoryAndWaitForTopology(ServerLocator locator, int topologyMembers) throws Exception {
    CountDownLatch countDownLatch = new CountDownLatch(topologyMembers * 2);
    locator.addClusterTopologyListener(new LatchClusterTopologyListener(countDownLatch));
    ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) locator.createSessionFactory();
    addSessionFactory(sf);
    assertTrue("topology members expected " + topologyMembers, countDownLatch.await(5, TimeUnit.SECONDS));
    closeSessionFactory(sf);
    sf = (ClientSessionFactoryInternal) locator.createSessionFactory(liveServer.getServer().getNodeID().toString());
    addSessionFactory(sf);
    if (sf2 == null) {
        sf2 = (ClientSessionFactoryInternal) locator.createSessionFactory(backupServer.getServer().getNodeID().toString());
        ClientSession session2 = createSession(sf2, false, false);
        session2.createQueue(ADDRESS, ADDRESS, null, true);
        addSessionFactory(sf2);
    }
    return sf;
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 30 with ClientSessionFactoryInternal

use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal in project activemq-artemis by apache.

the class MultiThreadReattachSupportTestBase method runMultipleThreadsFailoverTest.

protected void runMultipleThreadsFailoverTest(final RunnableT runnable, final int numThreads, final int numIts, final boolean failOnCreateConnection, final long failDelay) throws Exception {
    for (int its = 0; its < numIts; its++) {
        log.info("Beginning iteration " + its);
        start();
        final ServerLocator locator = createLocator();
        final ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
        final ClientSession session = addClientSession(sf.createSession(false, true, true));
        Failer failer = startFailer(failDelay, session, failOnCreateConnection);
        class Runner extends Thread {

            private volatile Throwable throwable;

            private final RunnableT test;

            private final int threadNum;

            Runner(final RunnableT test, final int threadNum) {
                this.test = test;
                this.threadNum = threadNum;
            }

            @Override
            public void run() {
                try {
                    test.run(sf, threadNum);
                } catch (Throwable t) {
                    throwable = t;
                    log.error("Failed to run test", t);
                    // Case a failure happened here, it should print the Thread dump
                    // Sending it to System.out, as it would show on the Tests report
                    System.out.println(ActiveMQTestBase.threadDump(" - fired by MultiThreadRandomReattachTestBase::runTestMultipleThreads (" + t.getLocalizedMessage() + ")"));
                }
            }
        }
        do {
            List<Runner> threads = new ArrayList<>();
            for (int i = 0; i < numThreads; i++) {
                Runner runner = new Runner(runnable, i);
                threads.add(runner);
                runner.start();
            }
            for (Runner thread : threads) {
                thread.join();
                if (thread.throwable != null) {
                    throw new Exception("Exception on thread " + thread, thread.throwable);
                }
            }
            runnable.checkFail();
        } while (!failer.isExecuted());
        InVMConnector.resetFailures();
        session.close();
        locator.close();
        Assert.assertEquals(0, sf.numSessions());
        Assert.assertEquals(0, sf.numConnections());
        sf.close();
        stop();
    }
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ArrayList(java.util.ArrayList) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)

Aggregations

ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)43 Test (org.junit.Test)30 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)28 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)20 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)19 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)17 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)16 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)14 CountDownLatch (java.util.concurrent.CountDownLatch)13 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)12 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)12 ClientSessionInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionInternal)11 InVMNodeManager (org.apache.activemq.artemis.core.server.impl.InVMNodeManager)8 ActiveMQObjectClosedException (org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException)6 SessionFailureListener (org.apache.activemq.artemis.api.core.client.SessionFailureListener)6 ServerLocatorInternal (org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal)6 XAException (javax.transaction.xa.XAException)5 ActiveMQDuplicateIdException (org.apache.activemq.artemis.api.core.ActiveMQDuplicateIdException)4 ActiveMQTransactionOutcomeUnknownException (org.apache.activemq.artemis.api.core.ActiveMQTransactionOutcomeUnknownException)4 ActiveMQTransactionRolledBackException (org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException)4