Search in sources :

Example 21 with KahaDBPersistenceAdapter

use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.

the class FailoverStaticNetworkTest method doTestRepeatedSendReceiveWithMasterSlaveAlternate.

public void doTestRepeatedSendReceiveWithMasterSlaveAlternate(HashMap<String, String> networkConnectorProps) throws Exception {
    brokerB = createBroker("tcp", "62617", new String[] { "61610", "61611" }, networkConnectorProps);
    brokerB.start();
    final AtomicBoolean done = new AtomicBoolean(false);
    ExecutorService executorService = Executors.newCachedThreadPool();
    executorService.execute(new Runnable() {

        @Override
        public void run() {
            try {
                while (!done.get()) {
                    brokerA = createBroker("tcp", "61610", null);
                    brokerA.setBrokerName("Pair");
                    brokerA.setBrokerObjectName(new ObjectName(brokerA.getManagementContext().getJmxDomainName() + ":" + "BrokerName=" + JMXSupport.encodeObjectNamePart("A") + "," + "Type=Broker"));
                    ((KahaDBPersistenceAdapter) brokerA.getPersistenceAdapter()).getLocker().setLockAcquireSleepInterval(1000);
                    brokerA.start();
                    brokerA.waitUntilStopped();
                    // restart after peer taken over
                    brokerA1.waitUntilStarted();
                }
            } catch (Exception ignored) {
                LOG.info("A create/start, unexpected: " + ignored, ignored);
            }
        }
    });
    // start with brokerA as master
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return brokerA != null && brokerA.waitUntilStarted();
        }
    });
    executorService.execute(new Runnable() {

        @Override
        public void run() {
            try {
                while (!done.get()) {
                    brokerA1 = createBroker("tcp", "61611", null);
                    brokerA1.setBrokerName("Pair");
                    // so they can coexist in local jmx we set the object name b/c the brokername identifies the shared store
                    brokerA1.setBrokerObjectName(new ObjectName(brokerA.getManagementContext().getJmxDomainName() + ":" + "BrokerName=" + JMXSupport.encodeObjectNamePart("A1") + "," + "Type=Broker"));
                    ((KahaDBPersistenceAdapter) brokerA1.getPersistenceAdapter()).getLocker().setLockAcquireSleepInterval(1000);
                    brokerA1.start();
                    brokerA1.waitUntilStopped();
                    // restart after peer taken over
                    brokerA.waitUntilStarted();
                }
            } catch (Exception ignored) {
                LOG.info("A1 create/start, unexpected: " + ignored, ignored);
            }
        }
    });
    for (int i = 0; i < 4; i++) {
        BrokerService currentMaster = (i % 2 == 0 ? brokerA : brokerA1);
        LOG.info("iteration: " + i + ", using: " + currentMaster.getBrokerObjectName().getKeyProperty("BrokerName"));
        currentMaster.waitUntilStarted();
        doTestNetworkSendReceive(brokerB, currentMaster);
        LOG.info("Stopping " + currentMaster.getBrokerObjectName().getKeyProperty("BrokerName"));
        currentMaster.stop();
        currentMaster.waitUntilStopped();
    }
    done.set(true);
    LOG.info("all done");
    executorService.shutdownNow();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutorService(java.util.concurrent.ExecutorService) Wait(org.apache.activemq.util.Wait) BrokerService(org.apache.activemq.broker.BrokerService) JMSException(javax.jms.JMSException) ObjectName(javax.management.ObjectName) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 22 with KahaDBPersistenceAdapter

use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.

the class NetworkBrokerDetachTest method configureBroker.

// variants for each store....
protected void configureBroker(BrokerService broker) throws Exception {
    KahaDBPersistenceAdapter persistenceAdapter = new KahaDBPersistenceAdapter();
    persistenceAdapter.setDirectory(new File("target/activemq-data/kahadb/" + broker.getBrokerName() + "NetworBrokerDetatchTest"));
    broker.setPersistenceAdapter(persistenceAdapter);
}
Also used : File(java.io.File) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 23 with KahaDBPersistenceAdapter

use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.

the class CheckDuplicateMessagesOnDuplexTest method persistenceAdapterFactory_KahaDB.

private PersistenceAdapter persistenceAdapterFactory_KahaDB(String path) {
    KahaDBPersistenceAdapter kahaDBPersistenceAdapter = new KahaDBPersistenceAdapter();
    kahaDBPersistenceAdapter.setDirectory(new File(path));
    kahaDBPersistenceAdapter.setIgnoreMissingJournalfiles(true);
    kahaDBPersistenceAdapter.setCheckForCorruptJournalFiles(true);
    kahaDBPersistenceAdapter.setChecksumJournalFiles(true);
    return kahaDBPersistenceAdapter;
}
Also used : File(java.io.File) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 24 with KahaDBPersistenceAdapter

use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.

the class TestSupport method setPersistenceAdapter.

public static PersistenceAdapter setPersistenceAdapter(BrokerService broker, PersistenceAdapterChoice choice) throws IOException {
    PersistenceAdapter adapter = null;
    switch(choice) {
        case JDBC:
            JDBCPersistenceAdapter jdbcPersistenceAdapter = new JDBCPersistenceAdapter();
            // rollback (at shutdown) on derby can take a long time with file io etc
            jdbcPersistenceAdapter.setUseLock(false);
            adapter = jdbcPersistenceAdapter;
            break;
        case KahaDB:
            adapter = new KahaDBPersistenceAdapter();
            break;
        case LevelDB:
            adapter = new LevelDBPersistenceAdapter();
            break;
        case MEM:
            adapter = new MemoryPersistenceAdapter();
            break;
    }
    broker.setPersistenceAdapter(adapter);
    adapter.setDirectory(new File(broker.getBrokerDataDirectory(), choice.name()));
    return adapter;
}
Also used : JDBCPersistenceAdapter(org.apache.activemq.store.jdbc.JDBCPersistenceAdapter) MemoryPersistenceAdapter(org.apache.activemq.store.memory.MemoryPersistenceAdapter) LevelDBPersistenceAdapter(org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter) File(java.io.File) JDBCPersistenceAdapter(org.apache.activemq.store.jdbc.JDBCPersistenceAdapter) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter) MemoryPersistenceAdapter(org.apache.activemq.store.memory.MemoryPersistenceAdapter) LevelDBPersistenceAdapter(org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 25 with KahaDBPersistenceAdapter

use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.

the class XARecoveryBrokerTest method testPreparedJmxView.

public void testPreparedJmxView() throws Exception {
    ActiveMQDestination destination = createDestination();
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Prepare 4 message sends.
    for (int i = 0; i < 4; i++) {
        // Begin the transaction.
        XATransactionId txid = createXATransaction(sessionInfo);
        connection.send(createBeginTransaction(connectionInfo, txid));
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        message.setTransactionId(txid);
        connection.send(message);
        // Prepare
        connection.send(createPrepareTransaction(connectionInfo, txid));
    }
    Response response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
    assertNotNull(response);
    DataArrayResponse dar = (DataArrayResponse) response;
    assertEquals(4, dar.getData().length);
    // view prepared in kahadb view
    if (broker.getPersistenceAdapter() instanceof KahaDBPersistenceAdapter) {
        PersistenceAdapterViewMBean kahadbView = getProxyToPersistenceAdapter(broker.getPersistenceAdapter().toString());
        String txFromView = kahadbView.getTransactions();
        LOG.info("Tx view fromm PA:" + txFromView);
        assertTrue("xid with our dud format in transaction string " + txFromView, txFromView.contains("XID:[55,"));
    }
    // restart the broker.
    restartBroker();
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    connection.send(connectionInfo);
    response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
    assertNotNull(response);
    dar = (DataArrayResponse) response;
    assertEquals(4, dar.getData().length);
    // validate destination depth via jmx
    DestinationViewMBean destinationView = getProxyToDestination(destinationList(destination)[0]);
    assertEquals("enqueue count does not see prepared", 0, destinationView.getQueueSize());
    TransactionId first = (TransactionId) dar.getData()[0];
    int commitCount = 0;
    // via jmx, force outcome
    for (int i = 0; i < 4; i++) {
        RecoveredXATransactionViewMBean mbean = getProxyToPreparedTransactionViewMBean((TransactionId) dar.getData()[i]);
        if (i % 2 == 0) {
            mbean.heuristicCommit();
            commitCount++;
        } else {
            mbean.heuristicRollback();
        }
    }
    // verify all completed
    response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
    assertNotNull(response);
    dar = (DataArrayResponse) response;
    assertEquals(0, dar.getData().length);
    // verify messages available
    assertEquals("enqueue count reflects outcome", commitCount, destinationView.getQueueSize());
    // verify mbeans gone
    try {
        RecoveredXATransactionViewMBean gone = getProxyToPreparedTransactionViewMBean(first);
        gone.heuristicRollback();
        fail("Excepted not found");
    } catch (InstanceNotFoundException expectedNotfound) {
    }
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) XATransactionId(org.apache.activemq.command.XATransactionId) Message(org.apache.activemq.command.Message) InstanceNotFoundException(javax.management.InstanceNotFoundException) SessionInfo(org.apache.activemq.command.SessionInfo) PersistenceAdapterViewMBean(org.apache.activemq.broker.jmx.PersistenceAdapterViewMBean) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) XATransactionId(org.apache.activemq.command.XATransactionId) TransactionId(org.apache.activemq.command.TransactionId) Response(org.apache.activemq.command.Response) DataArrayResponse(org.apache.activemq.command.DataArrayResponse) TransactionInfo(org.apache.activemq.command.TransactionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) RecoveredXATransactionViewMBean(org.apache.activemq.broker.jmx.RecoveredXATransactionViewMBean) DataArrayResponse(org.apache.activemq.command.DataArrayResponse) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Aggregations

KahaDBPersistenceAdapter (org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)40 File (java.io.File)18 BrokerService (org.apache.activemq.broker.BrokerService)12 Test (org.junit.Test)8 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)5 Connection (javax.jms.Connection)4 Message (javax.jms.Message)4 MessageProducer (javax.jms.MessageProducer)4 Session (javax.jms.Session)4 Wait (org.apache.activemq.util.Wait)4 IOException (java.io.IOException)3 URI (java.net.URI)3 LinkedList (java.util.LinkedList)3 JMSException (javax.jms.JMSException)3 MessageConsumer (javax.jms.MessageConsumer)3 JDBCPersistenceAdapter (org.apache.activemq.store.jdbc.JDBCPersistenceAdapter)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 MessageListener (javax.jms.MessageListener)2 ObjectName (javax.management.ObjectName)2