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;
}
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();
}
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());
}
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);
}
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;
}
Aggregations