NO-JIRA Fixing intermittent test failures

This commit is contained in:
Clebert Suconic 2017-11-01 12:16:51 -04:00
parent 5997e21ec7
commit 7f4a79b0c6
3 changed files with 27 additions and 7 deletions

View File

@ -576,22 +576,27 @@ public class ActiveMQServerImpl implements ActiveMQServer {
}
private void initializeCriticalAnalyzer() throws Exception {
// Some tests will play crazy frequenceistop/start
CriticalAnalyzer analyzer = this.getCriticalAnalyzer();
if (analyzer == null) {
if (configuration.isCriticalAnalyzer()) {
// this will have its own ScheduledPool
this.analyzer = new CriticalAnalyzerImpl();
analyzer = new CriticalAnalyzerImpl();
} else {
this.analyzer = EmptyCriticalAnalyzer.getInstance();
analyzer = EmptyCriticalAnalyzer.getInstance();
}
this.analyzer = analyzer;
}
/* Calling this for cases where the server was stopped and now is being restarted... failback, etc...*/
this.analyzer.clear();
analyzer.clear();
this.getCriticalAnalyzer().setCheckTime(configuration.getCriticalAnalyzerCheckPeriod(), TimeUnit.MILLISECONDS).setTimeout(configuration.getCriticalAnalyzerTimeout(), TimeUnit.MILLISECONDS);
analyzer.setCheckTime(configuration.getCriticalAnalyzerCheckPeriod(), TimeUnit.MILLISECONDS).setTimeout(configuration.getCriticalAnalyzerTimeout(), TimeUnit.MILLISECONDS);
if (configuration.isCriticalAnalyzer()) {
this.getCriticalAnalyzer().start();
analyzer.start();
}
CriticalAction criticalAction = null;
@ -645,7 +650,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
break;
}
this.getCriticalAnalyzer().addAction(criticalAction);
analyzer.addAction(criticalAction);
}
private void sendCriticalNotification(final CriticalComponent criticalComponent) {

View File

@ -20,6 +20,7 @@ import org.apache.activemq.artemis.api.core.RoutingType;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.core.server.Queue;
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
import org.apache.activemq.artemis.tests.util.Wait;
import org.apache.activemq.transport.amqp.client.AmqpClient;
import org.apache.activemq.transport.amqp.client.AmqpConnection;
import org.apache.activemq.transport.amqp.client.AmqpMessage;
@ -76,7 +77,7 @@ public class AmqpPurgeOnNoConsumersTest extends AmqpClientTestSupport {
t.join(5000);
assertEquals(0, queueView.getMessageCount());
Wait.assertEquals(0, queueView::getMessageCount);
connection.close();
}

View File

@ -18,6 +18,8 @@ package org.apache.activemq.artemis.tests.util;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
/**
* Utility adapted from: org.apache.activemq.util.Wait
*/
@ -31,10 +33,22 @@ public class Wait {
boolean isSatisfied() throws Exception;
}
public interface LongCondition {
long getCount() throws Exception;
}
public static boolean waitFor(Condition condition) throws Exception {
return waitFor(condition, MAX_WAIT_MILLIS);
}
public static void assertEquals(long size, LongCondition condition) throws Exception {
boolean result = waitFor(() -> condition.getCount() == size);
if (!result) {
Assert.fail(size + " != " + condition);
}
}
public static boolean waitFor(final Condition condition, final long duration) throws Exception {
return waitFor(condition, duration, SLEEP_MILLIS);
}