Skip to content

Commit

Permalink
NO-JIRA fix testSimpleCursorIteratorLargeMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
jbertram authored and gemmellr committed Jan 30, 2025
1 parent 0aa9c2d commit 29e800f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ public void testSimpleCursorIteratorLargeMessage() throws Exception {

message.getBodyBuffer().writerIndex(0);

message.getBodyBuffer().writeBytes(new byte[numberOfBytes]);

message.putIntProperty("i", i);

producer.send(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@
*/
package org.apache.activemq.artemis.tests.integration.cluster.failover;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.api.core.Pair;
import org.apache.activemq.artemis.api.core.QueueConfiguration;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.TransportConfiguration;
Expand All @@ -45,7 +37,6 @@
import org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal;
import org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal;
import org.apache.activemq.artemis.core.config.Configuration;
import org.apache.activemq.artemis.core.journal.impl.JournalFile;
import org.apache.activemq.artemis.core.journal.impl.JournalImpl;
import org.apache.activemq.artemis.core.paging.PagingStore;
import org.apache.activemq.artemis.core.persistence.impl.journal.DescribeJournal;
Expand All @@ -60,6 +51,11 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class BackupSyncJournalTest extends FailoverTestBase {

protected static final int BACKUP_WAIT_TIME = 60;
Expand Down Expand Up @@ -103,7 +99,7 @@ public void testNodeID() throws Exception {
@Test
public void testReserveFileIdValuesOnBackup() throws Exception {
final int totalRounds = 5;
createProducerSendSomeMessages();
createProducer();
JournalImpl messageJournal = getMessageJournalFromServer(primaryServer);
for (int i = 0; i < totalRounds; i++) {
messageJournal.forceMoveNextFile();
Expand Down Expand Up @@ -143,7 +139,6 @@ public void testReserveFileIdValuesOnBackup() throws Exception {
store.forceAnotherPage();
}

Set<Pair<Long, Integer>> primaryIds = getFileIds(messageJournal);
int size = messageJournal.getFileSize();
PagingStore ps = primaryServer.getServer().getPagingManager().getPageStore(ADDRESS);
if (ps.getPageSizeBytes() == PAGE_SIZE) {
Expand All @@ -153,10 +148,9 @@ public void testReserveFileIdValuesOnBackup() throws Exception {
finishSyncAndFailover();

assertEquals(size, backupMsgJournal.getFileSize(), "file sizes must be the same");
Set<Pair<Long, Integer>> backupIds = getFileIds(backupMsgJournal);

// "+ 2": there two other calls that send N_MSGS.
for (int i = 0; i < totalRounds + 3; i++) {
for (int i = 0; i < totalRounds + 2; i++) {
receiveMsgsInRange(0, n_msgs);
}
assertNoMoreMessages();
Expand Down Expand Up @@ -353,12 +347,16 @@ private void startBackupCrashPrimary() throws Exception {
assertTrue(failoverWaiter.waitFailoverComplete(), "Session didn't failover, the maxRetryAttempts and retryInterval may be too small");
}

protected void createProducerSendSomeMessages() throws ActiveMQException {
protected void createProducer() throws ActiveMQException {
session = addClientSession(sessionFactory.createSession(true, true));
session.createQueue(QueueConfiguration.of(ADDRESS));
if (producer != null)
producer.close();
producer = addClientProducer(session.createProducer(ADDRESS));
}

protected void createProducerSendSomeMessages() throws ActiveMQException {
createProducer();
sendMessages(session, producer, n_msgs);
session.commit();
}
Expand All @@ -371,23 +369,6 @@ protected void receiveMsgsInRange(int start, int end) throws ActiveMQException {
session.commit();
}

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;
}

/**
* @param jf
* @return
*/
private Pair<Long, Integer> getPair(JournalFile jf) {
return new Pair<>(jf.getFileID(), jf.getPosCount());
}

static JournalImpl getMessageJournalFromServer(TestableServer server) {
JournalStorageManager sm = (JournalStorageManager) server.getServer().getStorageManager();
return (JournalImpl) sm.getMessageJournal();
Expand Down

0 comments on commit 29e800f

Please sign in to comment.