Skip to content

Commit

Permalink
ARTEMIS-5232 Tests cleanup and speedup
Browse files Browse the repository at this point in the history
- Avoid unecessary duplications in inheritance (mainly LargeMessage and FailoverTest)
- Fixed some time outs and sleeps between restart of servers
- Fixed some configuration options
- Tweak in a few tests
  • Loading branch information
clebertsuconic committed Jan 10, 2025
1 parent a1e93b5 commit ecf4928
Show file tree
Hide file tree
Showing 41 changed files with 2,786 additions and 3,334 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@
@RunWith(BlockJUnit4ClassRunner.class)
public class ExpiryHogTest extends JmsMultipleClientsTestSupport {

boolean sleep = false;

int numMessages = 4;

@Test(timeout = 2 * 60 * 1000)
public void testImmediateDispatchWhenCacheDisabled() throws Exception {
ConnectionFactory f = createConnectionFactory();
destination = createDestination();
startConsumers(f, destination);
sleep = true;
this.startProducers(f, destination, numMessages);
allMessagesList.assertMessagesReceived(numMessages);
}
Expand All @@ -55,7 +52,7 @@ protected BrokerService createBroker() throws Exception {
bs.setDeleteAllMessagesOnStartup(true);
PolicyMap policyMap = new PolicyMap();
PolicyEntry defaultEntry = new PolicyEntry();
defaultEntry.setExpireMessagesPeriod(5000);
defaultEntry.setExpireMessagesPeriod(500);
defaultEntry.setUseCache(false);
policyMap.setDefaultEntry(defaultEntry);
bs.setDestinationPolicy(policyMap);
Expand All @@ -65,11 +62,8 @@ protected BrokerService createBroker() throws Exception {

@Override
protected TextMessage createTextMessage(Session session, String initText) throws Exception {
if (sleep) {
TimeUnit.SECONDS.sleep(10);
}
TextMessage msg = super.createTextMessage(session, initText);
msg.setJMSExpiration(4000);
msg.setJMSExpiration(500);
return msg;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@
import org.apache.activemq.artemis.core.config.Configuration;
import org.apache.activemq.artemis.core.config.StoreConfiguration;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.LargeServerMessage;
import org.apache.activemq.artemis.core.server.MessageReference;
import org.apache.activemq.artemis.core.server.Queue;
import org.apache.activemq.artemis.tests.extensions.parameterized.ParameterizedTestExtension;
import org.apache.activemq.artemis.tests.extensions.parameterized.Parameters;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.utils.DataConstants;
import org.apache.activemq.artemis.utils.DeflaterReader;
import org.apache.activemq.artemis.utils.Wait;
import org.apache.activemq.artemis.utils.collections.LinkedListIterator;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -65,20 +70,46 @@
@ExtendWith(ParameterizedTestExtension.class)
public abstract class LargeMessageTestBase extends ActiveMQTestBase {


private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

protected final SimpleString ADDRESS = SimpleString.of("SimpleAddress");

protected ServerLocator locator;

protected StoreConfiguration.StoreType storeType;

protected boolean isCompressedTest = false;

public LargeMessageTestBase(StoreConfiguration.StoreType storeType) {
this.storeType = storeType;
}

protected void validateLargeMessageComplete(ActiveMQServer server) throws Exception {
Queue queue = server.locateQueue(ADDRESS);

protected StoreConfiguration.StoreType storeType;
Wait.assertEquals(1, queue::getMessageCount);

public LargeMessageTestBase(StoreConfiguration.StoreType storeType) {
this.storeType = storeType;
LinkedListIterator<MessageReference> browserIterator = queue.browserIterator();

while (browserIterator.hasNext()) {
MessageReference ref = browserIterator.next();
Message message = ref.getMessage();

assertNotNull(message);
assertTrue(message instanceof LargeServerMessage);
}
browserIterator.close();
}

protected boolean isNetty() {
return false;
}

@Override
@BeforeEach
public void setUp() throws Exception {
super.setUp();
locator = createFactory(isNetty());
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ public void tearDown() throws Exception {

factory = null;

ActiveMQTestBase.forceGC();

assertEquals(0, LibaioContext.getTotalMaxIO());

super.tearDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ protected static final ClusterConnectionConfiguration basicClusterConnectionConf
setName("cluster1").setAddress("jms").setConnectorName(connectorName).
setRetryInterval(100).setDuplicateDetection(false).setMaxHops(1).
setConfirmationWindowSize(1).setMessageLoadBalancingType(MessageLoadBalancingType.STRICT).
setStaticConnectors(connectors0);
setStaticConnectors(connectors0).setCallTimeout(1000).setCallFailoverTimeout(1000);

return clusterConnectionConfiguration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.apache.activemq.artemis.api.core.client.ClientProducer;
import org.apache.activemq.artemis.api.core.client.ClientSession;
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.core.config.StoreConfiguration;
import org.apache.activemq.artemis.core.filter.Filter;
import org.apache.activemq.artemis.core.paging.PagingManager;
Expand Down Expand Up @@ -87,8 +86,6 @@ public class InterruptedLargeMessageTest extends LargeMessageTestBase {

private final int LARGE_MESSAGE_SIZE = ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE * 3;

protected ServerLocator locator;

public InterruptedLargeMessageTest(StoreConfiguration.StoreType storeType) {
super(storeType);
}
Expand All @@ -98,9 +95,9 @@ public InterruptedLargeMessageTest(StoreConfiguration.StoreType storeType) {
public void setUp() throws Exception {
super.setUp();
LargeMessageTestInterceptorIgnoreLastPacket.clearInterrupt();
locator = createFactory(isNetty());
}

@Override
protected boolean isNetty() {
return false;
}
Expand Down Expand Up @@ -141,8 +138,6 @@ public void testInterruptLargeMessageSend() throws Exception {

server.fail(false);

ActiveMQTestBase.forceGC();

server.start();

server.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,13 @@
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.apache.activemq.artemis.tests.extensions.parameterized.ParameterizedTestExtension;
import org.apache.activemq.artemis.tests.integration.largemessage.LargeMessageTestBase;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* The test extends the LargeMessageTest and tests
* the functionality of option avoid-large-messages
*
* Parameters set in superclass
*/
@ExtendWith(ParameterizedTestExtension.class)
public class LargeMessageAvoidLargeMessagesTest extends LargeMessageTest {
public class LargeMessageAvoidLargeMessagesTest extends LargeMessageTestBase {

public LargeMessageAvoidLargeMessagesTest(StoreConfiguration.StoreType storeType) {
super(storeType);
Expand All @@ -66,12 +60,6 @@ protected ServerLocator createFactory(final boolean isNetty) throws Exception {
return super.createFactory(isNetty).setMinLargeMessageSize(10240).setCompressLargeMessage(true);
}

@Disabled
@Override
@TestTemplate
public void testDeleteUnreferencedMessage() {
// this test makes no sense as it needs to delete a large message and its record
}

@TestTemplate
public void testSimpleSendOnAvoid() throws Exception {
Expand Down Expand Up @@ -286,7 +274,6 @@ public void testMixedCompressionSendReceive() throws Exception {

//this test won't leave any large messages in the large-messages dir
//because after compression, the messages are regulars at server.
@Override
@TestTemplate
public void testDLALargeMessage() throws Exception {
final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
Expand Down Expand Up @@ -388,11 +375,4 @@ public void testDLALargeMessage() throws Exception {
validateNoFilesOnLargeDir();
}

@Disabled
@Override
@TestTemplate
public void testSendServerMessage() throws Exception {
// doesn't make sense as compressed
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.tests.extensions.parameterized.ParameterizedTestExtension;
import org.apache.activemq.artemis.tests.integration.largemessage.LargeMessageTestBase;
import org.apache.activemq.artemis.utils.RandomUtil;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;

Expand All @@ -70,7 +70,7 @@

//Parameters set in superclass
@ExtendWith(ParameterizedTestExtension.class)
public class LargeMessageCompressTest extends LargeMessageTest {
public class LargeMessageCompressTest extends LargeMessageTestBase {


public LargeMessageCompressTest(StoreConfiguration.StoreType storeType) {
Expand All @@ -92,13 +92,6 @@ protected ServerLocator createFactory(final boolean isNetty) throws Exception {
return super.createFactory(isNetty).setCompressLargeMessage(true);
}

@Override
@TestTemplate
@Disabled
public void testDeleteUnreferencedMessage() {
// this test makes no sense as it needs to delete a large message and its record
}

@TestTemplate
public void testLargeMessageCompressionNotCompressedAndBrowsed() throws Exception {
final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
Expand Down Expand Up @@ -642,14 +635,6 @@ public void testLargeMessageCompressionLevel() throws Exception {

}

@Disabled
@Override
@TestTemplate
public void testSendServerMessage() throws Exception {
// doesn't make sense as compressed
}


// https://issues.apache.org/jira/projects/ARTEMIS/issues/ARTEMIS-3751
@TestTemplate
public void testOverrideSize() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
import org.apache.activemq.artemis.core.paging.PagingStore;
import org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageImpl;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.LargeServerMessage;
import org.apache.activemq.artemis.core.server.MessageReference;
import org.apache.activemq.artemis.core.server.Queue;
import org.apache.activemq.artemis.core.server.RoutingContext;
import org.apache.activemq.artemis.core.server.ServerProducer;
Expand All @@ -84,7 +82,6 @@
import org.apache.activemq.artemis.tests.util.CFUtil;
import org.apache.activemq.artemis.tests.util.RandomUtil;
import org.apache.activemq.artemis.tests.util.Wait;
import org.apache.activemq.artemis.utils.collections.LinkedListIterator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -101,14 +98,8 @@ public class LargeMessageTest extends LargeMessageTestBase {

protected ServerLocator locator;

protected boolean isCompressedTest = false;

private int largeMessageSize;

protected boolean isNetty() {
return false;
}

public LargeMessageTest(StoreConfiguration.StoreType storeType) {
super(storeType);
// The JDBC Large Message store is pretty slow, to speed tests up we only test 5MB large messages
Expand Down Expand Up @@ -482,23 +473,6 @@ public void testPendingRecord() throws Exception {
validateNoFilesOnLargeDir();
}

protected void validateLargeMessageComplete(ActiveMQServer server) throws Exception {
Queue queue = server.locateQueue(ADDRESS);

Wait.assertEquals(1, queue::getMessageCount);

LinkedListIterator<MessageReference> browserIterator = queue.browserIterator();

while (browserIterator.hasNext()) {
MessageReference ref = browserIterator.next();
Message message = ref.getMessage();

assertNotNull(message);
assertTrue(message instanceof LargeServerMessage);
}
browserIterator.close();
}

@TestTemplate
public void testDeleteOnDrop() throws Exception {
fillAddress();
Expand Down Expand Up @@ -2114,13 +2088,13 @@ public void testPageOnLargeMessageMultipleQueues() throws Exception {

final int numberOfBytes = 1024;

final int numberOfBytesBigMessage = 400000;
final int numberOfBytesBigMessage = 4000;

locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setMinLargeMessageSize(1000);

ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));

ClientSession session = sf.createSession(null, null, false, true, true, false, 0);
ClientSession session = sf.createSession(null, null, false, false, true, false, 0);

session.createQueue(QueueConfiguration.of(ADDRESS.concat("-0")).setAddress(ADDRESS));
session.createQueue(QueueConfiguration.of(ADDRESS.concat("-1")).setAddress(ADDRESS));
Expand All @@ -2143,17 +2117,20 @@ public void testPageOnLargeMessageMultipleQueues() throws Exception {
producer.send(message);
}

session.commit();

ClientMessage clientFile = createLargeClientMessageStreaming(session, numberOfBytesBigMessage);
clientFile.putBooleanProperty("TestLarge", true);
producer.send(clientFile);

for (int i = 0; i < 100; i++) {
for (int i = 0; i < 10; i++) {
message = session.createMessage(true);

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

producer.send(message);
}
session.commit();

session.close();

Expand Down Expand Up @@ -2205,7 +2182,7 @@ public void testPageOnLargeMessageMultipleQueues() throws Exception {
session.commit();
}

for (int i = 0; i < 100; i++) {
for (int i = 0; i < 5; i++) {
ClientMessage message2 = consumer.receive(LargeMessageTest.RECEIVE_WAIT_TIME);

assertNotNull(message2);
Expand Down
Loading

0 comments on commit ecf4928

Please sign in to comment.