NO-JIRA Test improvement

This commit is contained in:
Clebert Suconic 2019-05-07 20:06:29 -04:00
parent 25ce319647
commit f7b3dd46d7
2 changed files with 38 additions and 45 deletions

View File

@ -165,7 +165,7 @@ public class GlobalPagingTest extends PagingTest {
session.start(); session.start();
assertEquals(numberOfMessages * 2, getMessageCount(queue)); Wait.assertEquals(numberOfMessages * 2, queue::getMessageCount);
// The consumer has to be created after the getMessageCount(queue) assertion // The consumer has to be created after the getMessageCount(queue) assertion
// otherwise delivery could alter the messagecount and give us a false failure // otherwise delivery could alter the messagecount and give us a false failure
@ -182,7 +182,7 @@ public class GlobalPagingTest extends PagingTest {
} }
session.commit(); session.commit();
assertEquals(0, getMessageCount(queue)); Wait.assertEquals(0, queue::getMessageCount);
} }
protected void sendFewMessages(int numberOfMessages, protected void sendFewMessages(int numberOfMessages,

View File

@ -453,7 +453,7 @@ public class PagingTest extends ActiveMQTestBase {
session.start(); session.start();
assertEquals(numberOfMessages * 2, getMessageCount(queue)); Wait.assertEquals(numberOfMessages * 2, queue::getMessageCount);
// The consumer has to be created after the getMessageCount(queue) assertion // The consumer has to be created after the getMessageCount(queue) assertion
// otherwise delivery could alter the messagecount and give us a false failure // otherwise delivery could alter the messagecount and give us a false failure
@ -476,7 +476,7 @@ public class PagingTest extends ActiveMQTestBase {
locator.close(); locator.close();
assertEquals(0, getMessageCount(queue)); Wait.assertEquals(0, queue::getMessageCount);
waitForNotPaging(queue); waitForNotPaging(queue);
@ -520,7 +520,7 @@ public class PagingTest extends ActiveMQTestBase {
Wait.assertEquals(0, purgeQueue::getMessageCount); Wait.assertEquals(0, purgeQueue::getMessageCount);
Assert.assertEquals(0, purgeQueue.getPageSubscription().getPagingStore().getAddressSize()); Wait.assertEquals(0, purgeQueue.getPageSubscription().getPagingStore()::getAddressSize);
MessageConsumer consumer = session.createConsumer(jmsQueue); MessageConsumer consumer = session.createConsumer(jmsQueue);
@ -583,7 +583,7 @@ public class PagingTest extends ActiveMQTestBase {
server.stop(); server.stop();
server.start(); server.start();
Assert.assertEquals(0, server.getPagingManager().getTransactions().size()); Wait.assertEquals(0, ()->server.getPagingManager().getTransactions().size());
} }
// First page is complete but it wasn't deleted // First page is complete but it wasn't deleted
@ -1133,7 +1133,7 @@ public class PagingTest extends ActiveMQTestBase {
queue = server.locateQueue(PagingTest.ADDRESS); queue = server.locateQueue(PagingTest.ADDRESS);
assertEquals(0, getMessageCount(queue)); Wait.assertEquals(0, queue::getMessageCount);
timeout = System.currentTimeMillis() + 10000; timeout = System.currentTimeMillis() + 10000;
while (timeout > System.currentTimeMillis() && queue.getPageSubscription().getPagingStore().isPaging()) { while (timeout > System.currentTimeMillis() && queue.getPageSubscription().getPagingStore().isPaging()) {
@ -1154,7 +1154,7 @@ public class PagingTest extends ActiveMQTestBase {
server.start(); server.start();
final int numberOfMessages = 5000; final int numberOfMessages = 500;
final int numberOfTX = 10; final int numberOfTX = 10;
@ -1162,7 +1162,7 @@ public class PagingTest extends ActiveMQTestBase {
locator = createInVMNonHALocator(); locator = createInVMNonHALocator();
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true); locator.setBlockOnNonDurableSend(false).setBlockOnDurableSend(false).setBlockOnAcknowledge(false);
sf = createSessionFactory(locator); sf = createSessionFactory(locator);
@ -1213,7 +1213,7 @@ public class PagingTest extends ActiveMQTestBase {
Queue queue = server.locateQueue(ADDRESS); Queue queue = server.locateQueue(ADDRESS);
assertEquals(numberOfMessages, getMessageCount(queue)); Wait.assertEquals(numberOfMessages, queue::getMessageCount);
LinkedList<Xid> xids = new LinkedList<>(); LinkedList<Xid> xids = new LinkedList<>();
@ -1247,7 +1247,7 @@ public class PagingTest extends ActiveMQTestBase {
sessionCheck.close(); sessionCheck.close();
assertEquals(numberOfMessages, getMessageCount(queue)); Wait.assertEquals(numberOfMessages, queue::getMessageCount);
sf.close(); sf.close();
locator.close(); locator.close();
@ -1270,7 +1270,7 @@ public class PagingTest extends ActiveMQTestBase {
session.start(); session.start();
assertEquals(numberOfMessages, getMessageCount(queue)); Wait.assertEquals(numberOfMessages, queue::getMessageCount);
ClientMessage msg = consumer.receive(5000); ClientMessage msg = consumer.receive(5000);
if (msg != null) { if (msg != null) {
@ -1318,7 +1318,7 @@ public class PagingTest extends ActiveMQTestBase {
locator.close(); locator.close();
assertEquals(0, getMessageCount(queue)); Wait.assertEquals(0, queue::getMessageCount);
waitForNotPaging(queue); waitForNotPaging(queue);
} }
@ -1457,7 +1457,7 @@ public class PagingTest extends ActiveMQTestBase {
Queue queue = server.locateQueue(ADDRESS); Queue queue = server.locateQueue(ADDRESS);
assertEquals(numberOfMessages, getMessageCount(queue)); Wait.assertEquals(numberOfMessages, queue::getMessageCount);
int msgReceived = 0; int msgReceived = 0;
ClientSession sessionConsumer = sf.createSession(false, false, false); ClientSession sessionConsumer = sf.createSession(false, false, false);
@ -1488,7 +1488,7 @@ public class PagingTest extends ActiveMQTestBase {
locator.close(); locator.close();
assertEquals(0, getMessageCount(queue)); Wait.assertEquals(0, queue::getMessageCount);
long timeout = System.currentTimeMillis() + 5000; long timeout = System.currentTimeMillis() + 5000;
while (timeout > System.currentTimeMillis() && queue.getPageSubscription().getPagingStore().isPaging()) { while (timeout > System.currentTimeMillis() && queue.getPageSubscription().getPagingStore().isPaging()) {
@ -1623,7 +1623,7 @@ public class PagingTest extends ActiveMQTestBase {
Queue queue = server.locateQueue(ADDRESS); Queue queue = server.locateQueue(ADDRESS);
assertEquals(numberOfMessages, getMessageCount(queue)); Wait.assertEquals(numberOfMessages, queue::getMessageCount);
int msgReceived = 0; int msgReceived = 0;
ClientSession sessionConsumer = sf.createSession(false, false, false); ClientSession sessionConsumer = sf.createSession(false, false, false);
@ -1654,7 +1654,7 @@ public class PagingTest extends ActiveMQTestBase {
locator.close(); locator.close();
assertEquals(0, getMessageCount(queue)); Wait.assertEquals(0, queue::getMessageCount);
long timeout = System.currentTimeMillis() + 5000; long timeout = System.currentTimeMillis() + 5000;
while (timeout > System.currentTimeMillis() && queue.getPageSubscription().getPagingStore().isPaging()) { while (timeout > System.currentTimeMillis() && queue.getPageSubscription().getPagingStore().isPaging()) {
@ -1707,10 +1707,6 @@ public class PagingTest extends ActiveMQTestBase {
locator = createInVMNonHALocator(); locator = createInVMNonHALocator();
sf = createSessionFactory(locator); sf = createSessionFactory(locator);
queue = server.locateQueue(ADDRESS);
// assertEquals(numberOfMessages, getMessageCount(queue));
msgReceived = 0; msgReceived = 0;
sessionConsumer = sf.createSession(false, false, false); sessionConsumer = sf.createSession(false, false, false);
sessionConsumer.start(); sessionConsumer.start();
@ -1825,7 +1821,7 @@ public class PagingTest extends ActiveMQTestBase {
} }
Assert.assertEquals(3, queue.getPageSubscription().getPagingStore().getCurrentWritingPage()); Wait.assertEquals(3, queue.getPageSubscription().getPagingStore()::getCurrentWritingPage);
ClientConsumer consumer = session.createConsumer(ADDRESS); ClientConsumer consumer = session.createConsumer(ADDRESS);
session.start(); session.start();
@ -2427,7 +2423,7 @@ public class PagingTest extends ActiveMQTestBase {
} }
} }
assertEquals(0, server.getPagingManager().getTransactions().size()); Wait.assertEquals(0, ()->server.getPagingManager().getTransactions().size());
} finally { } finally {
running.set(false); running.set(false);
@ -2584,7 +2580,7 @@ public class PagingTest extends ActiveMQTestBase {
Thread.sleep(500); Thread.sleep(500);
} }
assertEquals(0, server.getPagingManager().getTransactions().size()); Wait.assertEquals(0, ()->server.getPagingManager().getTransactions().size());
} }
@ -3496,9 +3492,9 @@ public class PagingTest extends ActiveMQTestBase {
ClientSession session = sf.createSession(true, true, 0); ClientSession session = sf.createSession(true, true, 0);
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true); session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
Queue queue = server.locateQueue(ADDRESS); final Queue queue1 = server.locateQueue(ADDRESS);
queue.getPageSubscription().getPagingStore().startPaging(); queue1.getPageSubscription().getPagingStore().startPaging();
ClientProducer producer = session.createProducer(PagingTest.ADDRESS); ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
@ -3516,19 +3512,19 @@ public class PagingTest extends ActiveMQTestBase {
producer.send(message); producer.send(message);
session.commit(); session.commit();
if (i < 19) { if (i < 19) {
queue.getPageSubscription().getPagingStore().forceAnotherPage(); queue1.getPageSubscription().getPagingStore().forceAnotherPage();
} }
} }
Assert.assertEquals(20, queue.getPageSubscription().getPagingStore().getCurrentWritingPage()); Wait.assertEquals(20, ()->queue1.getPageSubscription().getPagingStore().getCurrentWritingPage());
// This will force a scenario where the pages are cleaned up. When restarting we need to check if the current page is complete // This will force a scenario where the pages are cleaned up. When restarting we need to check if the current page is complete
// if it is complete we must move to another page avoiding races on cleanup // if it is complete we must move to another page avoiding races on cleanup
// which could happen during a crash / restart // which could happen during a crash / restart
long tx = server.getStorageManager().generateID(); long tx = server.getStorageManager().generateID();
for (int i = 1; i <= 20; i++) { for (int i = 1; i <= 20; i++) {
server.getStorageManager().storePageCompleteTransactional(tx, queue.getID(), new PagePositionImpl(i, 1)); server.getStorageManager().storePageCompleteTransactional(tx, queue1.getID(), new PagePositionImpl(i, 1));
} }
server.getStorageManager().commit(tx); server.getStorageManager().commit(tx);
@ -3543,7 +3539,7 @@ public class PagingTest extends ActiveMQTestBase {
server.start(); server.start();
queue = server.locateQueue(ADDRESS); Queue queue = server.locateQueue(ADDRESS);
locator = createInVMNonHALocator(); locator = createInVMNonHALocator();
sf = createSessionFactory(locator); sf = createSessionFactory(locator);
@ -3825,7 +3821,7 @@ public class PagingTest extends ActiveMQTestBase {
Assert.assertNull(consumer.receiveImmediate()); Assert.assertNull(consumer.receiveImmediate());
Assert.assertEquals(0, server.getPagingManager().getPageStore(PagingTest.ADDRESS).getAddressSize()); Wait.assertEquals(0, ()->server.getPagingManager().getPageStore(PagingTest.ADDRESS).getAddressSize());
for (int i = 0; i < numberOfMessages; i++) { for (int i = 0; i < numberOfMessages; i++) {
byte[] body = new byte[2048]; byte[] body = new byte[2048];
@ -3881,7 +3877,7 @@ public class PagingTest extends ActiveMQTestBase {
session.close(); session.close();
Assert.assertEquals(0, server.getPagingManager().getPageStore(PagingTest.ADDRESS).getAddressSize()); Wait.assertEquals(0, ()->server.getPagingManager().getPageStore(PagingTest.ADDRESS).getAddressSize());
} }
@Test @Test
@ -4397,7 +4393,7 @@ public class PagingTest extends ActiveMQTestBase {
// It's async, so need to wait a bit for it happening // It's async, so need to wait a bit for it happening
assertFalse(server.getPagingManager().getPageStore(ADDRESS).isPaging()); assertFalse(server.getPagingManager().getPageStore(ADDRESS).isPaging());
assertEquals(1, server.getPagingManager().getPageStore(ADDRESS).getNumberOfPages()); Wait.assertEquals(1, ()->server.getPagingManager().getPageStore(ADDRESS).getNumberOfPages());
} }
@Test @Test
@ -4541,8 +4537,6 @@ public class PagingTest extends ActiveMQTestBase {
assertNotNull(message); assertNotNull(message);
message.acknowledge(); message.acknowledge();
// assertEquals(msg, message.getIntProperty("propTest").intValue());
System.out.println("i = " + i + " msg = " + message.getIntProperty("propTest")); System.out.println("i = " + i + " msg = " + message.getIntProperty("propTest"));
} }
@ -5298,8 +5292,7 @@ public class PagingTest extends ActiveMQTestBase {
producer.send(message); producer.send(message);
Queue q = (Queue) server.getPostOffice().getBinding(ADDRESS).getBindable(); Queue q = (Queue) server.getPostOffice().getBinding(ADDRESS).getBindable();
Wait.waitFor(() -> 3 == getMessageCount(q)); Wait.assertEquals(3, q::getMessageCount);
Assert.assertEquals(3, getMessageCount(q));
// send a message with a dup ID that should fail b/c the address is full // send a message with a dup ID that should fail b/c the address is full
SimpleString dupID1 = new SimpleString("abcdefg"); SimpleString dupID1 = new SimpleString("abcdefg");
@ -5308,7 +5301,7 @@ public class PagingTest extends ActiveMQTestBase {
validateExceptionOnSending(producer, message); validateExceptionOnSending(producer, message);
Assert.assertEquals(3, getMessageCount(q)); Wait.assertEquals(3, q::getMessageCount);
ClientConsumer consumer = session.createConsumer(ADDRESS); ClientConsumer consumer = session.createConsumer(ADDRESS);
@ -5321,11 +5314,11 @@ public class PagingTest extends ActiveMQTestBase {
session.commit(); // to make sure it's on the server (roundtrip) session.commit(); // to make sure it's on the server (roundtrip)
consumer.close(); consumer.close();
Assert.assertEquals(2, getMessageCount(q)); Wait.assertEquals(2, q::getMessageCount);
producer.send(message); producer.send(message);
Assert.assertEquals(3, getMessageCount(q)); Wait.assertEquals(3, q::getMessageCount);
consumer = session.createConsumer(ADDRESS); consumer = session.createConsumer(ADDRESS);
@ -5743,7 +5736,7 @@ public class PagingTest extends ActiveMQTestBase {
session.commit(); session.commit();
Queue queue = server.locateQueue(PagingTest.ADDRESS); Queue queue = server.locateQueue(PagingTest.ADDRESS);
Assert.assertEquals(numberOfMessages, queue.getMessageCount()); Wait.assertEquals(numberOfMessages, queue::getMessageCount);
store.forceAnotherPage(); store.forceAnotherPage();
@ -5765,7 +5758,7 @@ public class PagingTest extends ActiveMQTestBase {
store.getCursorProvider().cleanup(); store.getCursorProvider().cleanup();
Assert.assertEquals(0, queue.getMessageCount()); Wait.assertEquals(0, queue::getMessageCount);
long timeout = System.currentTimeMillis() + 5000; long timeout = System.currentTimeMillis() + 5000;
while (store.isPaging() && timeout > System.currentTimeMillis()) { while (store.isPaging() && timeout > System.currentTimeMillis()) {
@ -5778,7 +5771,7 @@ public class PagingTest extends ActiveMQTestBase {
locator.close(); locator.close();
Assert.assertEquals(1, store.getNumberOfPages()); Wait.assertEquals(1, store::getNumberOfPages);
} finally { } finally {
try { try {
@ -6265,8 +6258,8 @@ public class PagingTest extends ActiveMQTestBase {
session.close(); session.close();
Queue queue = server.locateQueue(PagingTest.ADDRESS); Queue queue = server.locateQueue(PagingTest.ADDRESS);
assertEquals(numberOfMessages, getMessageCount(queue)); Wait.assertEquals(numberOfMessages, queue::getMessageCount);
assertEquals(1, server.getPagingManager().getPageStore(ADDRESS).getNumberOfPages()); Wait.assertEquals(1, ()->server.getPagingManager().getPageStore(ADDRESS).getNumberOfPages());
sf.close(); sf.close();