Search in sources :

Example 21 with Pair

use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.

the class BackupSyncJournalTest method getFileIds.

private Set<Pair<Long, Integer>> getFileIds(JournalImpl journal) {
    Set<Pair<Long, Integer>> results = new HashSet<>();
    for (JournalFile jf : journal.getDataFiles()) {
        results.add(getPair(jf));
    }
    results.add(getPair(journal.getCurrentFile()));
    return results;
}
Also used : JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) Pair(org.apache.activemq.artemis.api.core.Pair) HashSet(java.util.HashSet)

Example 22 with Pair

use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.

the class BackupSyncJournalTest method testReserveFileIdValuesOnBackup.

@Test
public void testReserveFileIdValuesOnBackup() throws Exception {
    final int totalRounds = 5;
    createProducerSendSomeMessages();
    JournalImpl messageJournal = getMessageJournalFromServer(liveServer);
    for (int i = 0; i < totalRounds; i++) {
        messageJournal.forceMoveNextFile();
        sendMessages(session, producer, n_msgs);
    }
    Queue queue = liveServer.getServer().locateQueue(ADDRESS);
    PagingStore store = queue.getPageSubscription().getPagingStore();
    // what would make the verification on similar journal to fail after the recovery
    if (store.isPaging()) {
        store.forceAnotherPage();
    }
    backupServer.start();
    // Deliver messages with Backup in-sync
    waitForRemoteBackup(sessionFactory, BACKUP_WAIT_TIME, false, backupServer.getServer());
    final JournalImpl backupMsgJournal = getMessageJournalFromServer(backupServer);
    sendMessages(session, producer, n_msgs);
    // what would make the verification on similar journal to fail after the recovery
    if (store.isPaging()) {
        store.forceAnotherPage();
    }
    // Deliver messages with Backup up-to-date
    syncDelay.deliverUpToDateMsg();
    waitForRemoteBackup(sessionFactory, BACKUP_WAIT_TIME, true, backupServer.getServer());
    // SEND more messages, now with the backup replicating
    sendMessages(session, producer, n_msgs);
    // what would make the verification on similar journal to fail after the recovery
    if (store.isPaging()) {
        store.forceAnotherPage();
    }
    Set<Pair<Long, Integer>> liveIds = getFileIds(messageJournal);
    int size = messageJournal.getFileSize();
    PagingStore ps = liveServer.getServer().getPagingManager().getPageStore(ADDRESS);
    if (ps.getPageSizeBytes() == PAGE_SIZE) {
        assertTrue("isStarted", ps.isStarted());
        assertFalse("start paging should return false, because we expect paging to be running", ps.startPaging());
    }
    finishSyncAndFailover();
    assertEquals("file sizes must be the same", size, backupMsgJournal.getFileSize());
    Set<Pair<Long, Integer>> backupIds = getFileIds(backupMsgJournal);
    int total = 0;
    for (Pair<Long, Integer> pair : liveIds) {
        total += pair.getB();
    }
    int totalBackup = 0;
    for (Pair<Long, Integer> pair : backupIds) {
        totalBackup += pair.getB();
    }
    assertEquals("number of records must match ", total, totalBackup);
    // "+ 2": there two other calls that send N_MSGS.
    for (int i = 0; i < totalRounds + 3; i++) {
        receiveMsgsInRange(0, n_msgs);
    }
    assertNoMoreMessages();
}
Also used : Queue(org.apache.activemq.artemis.core.server.Queue) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Pair(org.apache.activemq.artemis.api.core.Pair) Test(org.junit.Test)

Example 23 with Pair

use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.

the class JMSConnectionFactoryConfigurationStorageTest method testSettingsWithConnectorConfigs.

@Test
public void testSettingsWithConnectorConfigs() throws Exception {
    createJMSStorage();
    String[] str = new String[5];
    for (int i = 0; i < 5; i++) {
        str[i] = "str" + i;
    }
    List<String> connectorConfigs = new ArrayList<>();
    Map<String, Object> liveParams = new HashMap<>();
    liveParams.put(TransportConstants.PORT_PROP_NAME, 5665);
    Map<String, Object> backupParams = new HashMap<>();
    backupParams.put(TransportConstants.PORT_PROP_NAME, 5775);
    Map<String, Object> liveParams2 = new HashMap<>();
    liveParams2.put(TransportConstants.PORT_PROP_NAME, 6665);
    ConnectionFactoryConfiguration config = new ConnectionFactoryConfigurationImpl().setName("some-name").setConnectorNames(connectorConfigs).setBindings(str).setCallTimeout(RandomUtil.randomPositiveLong());
    List<Pair<String, String>> connectors = new ArrayList<>();
    connectors.add(new Pair<String, String>(RandomUtil.randomString(), null));
    // config.setConnectorNames(connectors);
    addSetting(new PersistedConnectionFactory(config));
    jmsJournal.stop();
    createJMSStorage();
    List<PersistedConnectionFactory> cfs = jmsJournal.recoverConnectionFactories();
    assertEquals(1, cfs.size());
    assertEquals("some-name", cfs.get(0).getName());
    assertEquals(config.getCallTimeout(), cfs.get(0).getConfig().getCallTimeout());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PersistedConnectionFactory(org.apache.activemq.artemis.jms.persistence.config.PersistedConnectionFactory) ConnectionFactoryConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.ConnectionFactoryConfigurationImpl) ConnectionFactoryConfiguration(org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration) Pair(org.apache.activemq.artemis.api.core.Pair) Test(org.junit.Test)

Example 24 with Pair

use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.

the class JMSJournalStorageManagerImpl method deleteBindings.

@Override
public void deleteBindings(PersistedType type, String name, String address) throws Exception {
    Pair<PersistedType, String> key = new Pair<>(type, name);
    long tx = idGenerator.generateID();
    PersistedBindings currentBindings = mapBindings.get(key);
    if (currentBindings == null) {
        return;
    } else {
        jmsJournal.appendDeleteRecordTransactional(tx, currentBindings.getId());
    }
    currentBindings.deleteBinding(address);
    if (currentBindings.getBindings().size() == 0) {
        mapBindings.remove(key);
    } else {
        long newId = idGenerator.generateID();
        currentBindings.setId(newId);
        jmsJournal.appendAddRecordTransactional(tx, newId, BINDING_RECORD, currentBindings);
    }
    jmsJournal.appendCommitRecord(tx, true);
}
Also used : PersistedType(org.apache.activemq.artemis.jms.persistence.config.PersistedType) PersistedBindings(org.apache.activemq.artemis.jms.persistence.config.PersistedBindings) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 25 with Pair

use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.

the class TransportConfigurationEncodingSupport method decodeConfigs.

public static List<Pair<TransportConfiguration, TransportConfiguration>> decodeConfigs(ActiveMQBuffer buffer) {
    int size = buffer.readInt();
    List<Pair<TransportConfiguration, TransportConfiguration>> configs = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        TransportConfiguration live = decode(buffer);
        boolean hasBackup = buffer.readBoolean();
        TransportConfiguration backup = null;
        if (hasBackup) {
            backup = decode(buffer);
        }
        configs.add(new Pair<>(live, backup));
    }
    return configs;
}
Also used : ArrayList(java.util.ArrayList) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Pair(org.apache.activemq.artemis.api.core.Pair)

Aggregations

Pair (org.apache.activemq.artemis.api.core.Pair)29 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)12 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)12 List (java.util.List)6 Map (java.util.Map)6 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)5 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)5 HashSet (java.util.HashSet)4 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)4 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)4 Test (org.junit.Test)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 Message (org.apache.activemq.artemis.api.core.Message)3 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)3 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)3 LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)3 PersistedBindings (org.apache.activemq.artemis.jms.persistence.config.PersistedBindings)3 PersistedType (org.apache.activemq.artemis.jms.persistence.config.PersistedType)3