NO-JIRA de-duplicate class

This commit is contained in:
Justin Bertram 2017-01-20 12:07:14 -06:00
parent 5edf940ed0
commit a138a27adb
5 changed files with 21 additions and 73 deletions

View File

@ -82,7 +82,7 @@ import org.apache.activemq.artemis.protocol.amqp.broker.ProtonProtocolManagerFac
import org.apache.activemq.artemis.protocol.amqp.proton.AmqpSupport; import org.apache.activemq.artemis.protocol.amqp.proton.AmqpSupport;
import org.apache.activemq.artemis.protocol.amqp.proton.ProtonServerReceiverContext; import org.apache.activemq.artemis.protocol.amqp.proton.ProtonServerReceiverContext;
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection; import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
import org.apache.activemq.artemis.tests.integration.mqtt.imported.util.Wait; import org.apache.activemq.artemis.tests.util.Wait;
import org.apache.activemq.artemis.utils.ByteUtil; import org.apache.activemq.artemis.utils.ByteUtil;
import org.apache.activemq.artemis.utils.TimeUtils; import org.apache.activemq.artemis.utils.TimeUtils;
import org.apache.activemq.artemis.utils.VersionLoader; import org.apache.activemq.artemis.utils.VersionLoader;
@ -829,7 +829,7 @@ public class ProtonTest extends ProtonTestBase {
Wait.waitFor(new Wait.Condition() { Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return amqpConnection.isClosed(); return amqpConnection.isClosed();
} }
}); });
@ -853,7 +853,7 @@ public class ProtonTest extends ProtonTestBase {
Wait.waitFor(new Wait.Condition() { Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return amqpConnection.isClosed(); return amqpConnection.isClosed();
} }
}); });
@ -1003,7 +1003,7 @@ public class ProtonTest extends ProtonTestBase {
try { try {
Wait.waitFor(new Wait.Condition() { Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return remote.isActive(); return remote.isActive();
} }
}); });
@ -1024,7 +1024,7 @@ public class ProtonTest extends ProtonTestBase {
try { try {
Wait.waitFor(new Wait.Condition() { Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return remote.getConnectionCount() > 0; return remote.getConnectionCount() > 0;
} }
}); });
@ -1033,7 +1033,7 @@ public class ProtonTest extends ProtonTestBase {
lifeCycleListener.stop(); lifeCycleListener.stop();
Wait.waitFor(new Wait.Condition() { Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return remote.getConnectionCount() == 0; return remote.getConnectionCount() == 0;
} }
}); });

View File

@ -30,8 +30,8 @@ import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.Queue; import org.apache.activemq.artemis.core.server.Queue;
import org.apache.activemq.artemis.core.server.RoutingType; import org.apache.activemq.artemis.core.server.RoutingType;
import org.apache.activemq.artemis.tests.integration.mqtt.imported.util.Wait;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.tests.util.Wait;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -151,7 +151,7 @@ public class ReceiveTest extends ActiveMQTestBase {
Wait.waitFor(new Wait.Condition() { Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return queue.getMessageCount() == 3; return queue.getMessageCount() == 3;
} }
}); });

View File

@ -61,8 +61,8 @@ import org.apache.activemq.artemis.jlibaio.LibaioContext;
import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager; import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
import org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule; import org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule;
import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger; import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
import org.apache.activemq.artemis.tests.integration.mqtt.imported.util.Wait;
import org.apache.activemq.artemis.tests.unit.core.config.impl.fakes.FakeConnectorServiceFactory; import org.apache.activemq.artemis.tests.unit.core.config.impl.fakes.FakeConnectorServiceFactory;
import org.apache.activemq.artemis.tests.util.Wait;
import org.apache.activemq.artemis.utils.RandomUtil; import org.apache.activemq.artemis.utils.RandomUtil;
import org.apache.activemq.artemis.utils.UUIDGenerator; import org.apache.activemq.artemis.utils.UUIDGenerator;
import org.junit.Assert; import org.junit.Assert;
@ -312,7 +312,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
serverControl.destroyQueue(name.toString(), true); serverControl.destroyQueue(name.toString(), true);
Wait.waitFor(new Wait.Condition() { Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return consumer.isClosed(); return consumer.isClosed();
} }
}, 1000, 100); }, 1000, 100);

View File

@ -42,7 +42,7 @@ import org.apache.activemq.artemis.core.protocol.mqtt.MQTTConnectionManager;
import org.apache.activemq.artemis.core.protocol.mqtt.MQTTSession; import org.apache.activemq.artemis.core.protocol.mqtt.MQTTSession;
import org.apache.activemq.artemis.core.server.RoutingType; import org.apache.activemq.artemis.core.server.RoutingType;
import org.apache.activemq.artemis.core.server.impl.AddressInfo; import org.apache.activemq.artemis.core.server.impl.AddressInfo;
import org.apache.activemq.artemis.tests.integration.mqtt.imported.util.Wait; import org.apache.activemq.artemis.tests.util.Wait;
import org.fusesource.mqtt.client.BlockingConnection; import org.fusesource.mqtt.client.BlockingConnection;
import org.fusesource.mqtt.client.MQTT; import org.fusesource.mqtt.client.MQTT;
import org.fusesource.mqtt.client.Message; import org.fusesource.mqtt.client.Message;
@ -789,7 +789,7 @@ public class MQTTTest extends MQTTTestSupport {
Wait.waitFor(new Wait.Condition() { Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return publishList.size() == 2; return publishList.size() == 2;
} }
}, 5000); }, 5000);
@ -802,7 +802,7 @@ public class MQTTTest extends MQTTTestSupport {
Wait.waitFor(new Wait.Condition() { Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return publishList.size() == 4; return publishList.size() == 4;
} }
}, 5000); }, 5000);
@ -964,7 +964,7 @@ public class MQTTTest extends MQTTTestSupport {
connection.connect(); connection.connect();
Wait.waitFor(new Wait.Condition() { Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return connection.isConnected(); return connection.isConnected();
} }
}); });
@ -983,7 +983,7 @@ public class MQTTTest extends MQTTTestSupport {
newConnection.connect(); newConnection.connect();
Wait.waitFor(new Wait.Condition() { Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return newConnection.isConnected(); return newConnection.isConnected();
} }
}); });
@ -1125,7 +1125,7 @@ public class MQTTTest extends MQTTTestSupport {
assertTrue("KeepAlive didn't work properly", Wait.waitFor(new Wait.Condition() { assertTrue("KeepAlive didn't work properly", Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return connection.isConnected(); return connection.isConnected();
} }
})); }));
@ -1148,7 +1148,7 @@ public class MQTTTest extends MQTTTestSupport {
assertTrue("KeepAlive didn't work properly", Wait.waitFor(new Wait.Condition() { assertTrue("KeepAlive didn't work properly", Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return connection.isConnected(); return connection.isConnected();
} }
})); }));
@ -1216,14 +1216,14 @@ public class MQTTTest extends MQTTTestSupport {
assertTrue("Duplicate client disconnected", Wait.waitFor(new Wait.Condition() { assertTrue("Duplicate client disconnected", Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return connection1.isConnected(); return connection1.isConnected();
} }
})); }));
assertTrue("Old client still connected", Wait.waitFor(new Wait.Condition() { assertTrue("Old client still connected", Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return !connection.isConnected(); return !connection.isConnected();
} }
})); }));
@ -1413,7 +1413,7 @@ public class MQTTTest extends MQTTTestSupport {
assertTrue("KeepAlive didn't work properly", Wait.waitFor(new Wait.Condition() { assertTrue("KeepAlive didn't work properly", Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return connection.isConnected(); return connection.isConnected();
} }
})); }));
@ -1611,7 +1611,7 @@ public class MQTTTest extends MQTTTestSupport {
assertTrue("KeepAlive didn't work properly", Wait.waitFor(new Wait.Condition() { assertTrue("KeepAlive didn't work properly", Wait.waitFor(new Wait.Condition() {
@Override @Override
public boolean isSatisified() throws Exception { public boolean isSatisfied() throws Exception {
return connection.isConnected(); return connection.isConnected();
} }
})); }));

View File

@ -1,52 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.tests.integration.mqtt.imported.util;
import java.util.concurrent.TimeUnit;
public class Wait {
public static final long MAX_WAIT_MILLIS = 30 * 1000;
public static final int SLEEP_MILLIS = 1000;
public interface Condition {
boolean isSatisified() throws Exception;
}
public static boolean waitFor(Condition condition) throws Exception {
return waitFor(condition, MAX_WAIT_MILLIS);
}
public static boolean waitFor(final Condition condition, final long duration) throws Exception {
return waitFor(condition, duration, SLEEP_MILLIS);
}
public static boolean waitFor(final Condition condition,
final long duration,
final int sleepMillis) throws Exception {
final long expiry = System.currentTimeMillis() + duration;
boolean conditionSatisified = condition.isSatisified();
while (!conditionSatisified && System.currentTimeMillis() < expiry) {
TimeUnit.MILLISECONDS.sleep(sleepMillis);
conditionSatisified = condition.isSatisified();
}
return conditionSatisified;
}
}