activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [3/4] activemq-artemis git commit: NO-JIRA use lambdas in tests for readability
Date Mon, 25 Sep 2017 15:02:27 GMT
NO-JIRA use lambdas in tests for readability


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/956c4c64
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/956c4c64
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/956c4c64

Branch: refs/heads/master
Commit: 956c4c64935ae08a3f37be37f10a132f8071c23a
Parents: dac6251
Author: Justin Bertram <jbertram@apache.org>
Authored: Fri Sep 15 11:16:44 2017 -0500
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Mon Sep 25 11:00:56 2017 -0400

----------------------------------------------------------------------
 .../integration/mqtt/imported/MQTTTest.java     | 104 +++----------------
 .../activemq/artemis/tests/util/Wait.java       |   4 +-
 2 files changed, 16 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/956c4c64/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt/imported/MQTTTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt/imported/MQTTTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt/imported/MQTTTest.java
index 8a1eea2..9338384 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt/imported/MQTTTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt/imported/MQTTTest.java
@@ -842,26 +842,14 @@ public class MQTTTest extends MQTTTestSupport {
       // publish non-retained message
       connection.publish(TOPIC, TOPIC.getBytes(), QoS.EXACTLY_ONCE, false);
 
-      Wait.waitFor(new Wait.Condition() {
-         @Override
-         public boolean isSatisfied() throws Exception {
-            return publishList.size() == 2;
-         }
-      }, 5000);
-      assertEquals(2, publishList.size());
+      assertTrue(Wait.waitFor(() -> publishList.size() == 2, 5000));
 
       connection.disconnect();
 
       connection = mqtt.blockingConnection();
       connection.connect();
 
-      Wait.waitFor(new Wait.Condition() {
-         @Override
-         public boolean isSatisfied() throws Exception {
-            return publishList.size() == 4;
-         }
-      }, 5000);
-      assertEquals(4, publishList.size());
+      assertTrue(Wait.waitFor(() -> publishList.size() == 4, 5000));
 
       // TODO Investigate if receiving the same ID for overlapping subscriptions is actually
spec compliant.
       // In Artemis we send a new ID for every copy of the message.
@@ -1018,12 +1006,7 @@ public class MQTTTest extends MQTTTestSupport {
 
       final BlockingConnection connection = mqtt.blockingConnection();
       connection.connect();
-      Wait.waitFor(new Wait.Condition() {
-         @Override
-         public boolean isSatisfied() throws Exception {
-            return connection.isConnected();
-         }
-      });
+      Wait.waitFor(() -> connection.isConnected());
 
       final String TOPIC = "TopicA";
       final byte[] qos = connection.subscribe(new Topic[]{new Topic(TOPIC, QoS.EXACTLY_ONCE)});
@@ -1037,12 +1020,7 @@ public class MQTTTest extends MQTTTestSupport {
 
       final BlockingConnection newConnection = mqtt.blockingConnection();
       newConnection.connect();
-      Wait.waitFor(new Wait.Condition() {
-         @Override
-         public boolean isSatisfied() throws Exception {
-            return newConnection.isConnected();
-         }
-      });
+      Wait.waitFor(() -> newConnection.isConnected());
 
       assertEquals(QoS.EXACTLY_ONCE.ordinal(), qos[0]);
       Message msg = newConnection.receive(1000, TimeUnit.MILLISECONDS);
@@ -1064,12 +1042,7 @@ public class MQTTTest extends MQTTTestSupport {
 
       final BlockingConnection connection = mqtt.blockingConnection();
       connection.connect();
-      Wait.waitFor(new Wait.Condition() {
-         @Override
-         public boolean isSatisfied() throws Exception {
-            return connection.isConnected();
-         }
-      });
+      Wait.waitFor(() -> connection.isConnected());
 
       MQTT mqtt2 = createMQTTConnection("2", false);
       BlockingConnection connection2 = mqtt2.blockingConnection();
@@ -1098,12 +1071,7 @@ public class MQTTTest extends MQTTTestSupport {
 
       final BlockingConnection connection = mqtt.blockingConnection();
       connection.connect();
-      Wait.waitFor(new Wait.Condition() {
-         @Override
-         public boolean isSatisfied() throws Exception {
-            return connection.isConnected();
-         }
-      });
+      Wait.waitFor(() -> connection.isConnected());
 
       // kill transport
       connection.kill();
@@ -1276,13 +1244,7 @@ public class MQTTTest extends MQTTTestSupport {
       final BlockingConnection connection = mqtt.blockingConnection();
       connection.connect();
 
-      assertTrue("KeepAlive didn't work properly", Wait.waitFor(new Wait.Condition() {
-
-         @Override
-         public boolean isSatisfied() throws Exception {
-            return connection.isConnected();
-         }
-      }));
+      assertTrue("KeepAlive didn't work properly", Wait.waitFor(() -> connection.isConnected()));
 
       connection.disconnect();
    }
@@ -1299,13 +1261,7 @@ public class MQTTTest extends MQTTTestSupport {
       final BlockingConnection connection = mqtt.blockingConnection();
       connection.connect();
 
-      assertTrue("KeepAlive didn't work properly", Wait.waitFor(new Wait.Condition() {
-
-         @Override
-         public boolean isSatisfied() throws Exception {
-            return connection.isConnected();
-         }
-      }));
+      assertTrue("KeepAlive didn't work properly", Wait.waitFor(() -> connection.isConnected()));
 
       connection.disconnect();
    }
@@ -1365,19 +1321,9 @@ public class MQTTTest extends MQTTTestSupport {
       final BlockingConnection connection1 = mqtt1.blockingConnection();
       connection1.connect();
 
-      assertTrue("Duplicate client disconnected", Wait.waitFor(new Wait.Condition() {
-         @Override
-         public boolean isSatisfied() throws Exception {
-            return connection1.isConnected();
-         }
-      }));
+      assertTrue("Duplicate client disconnected", Wait.waitFor(() -> connection1.isConnected()));
 
-      assertTrue("Old client still connected", Wait.waitFor(new Wait.Condition() {
-         @Override
-         public boolean isSatisfied() throws Exception {
-            return !connection.isConnected();
-         }
-      }));
+      assertTrue("Old client still connected", Wait.waitFor(() -> !connection.isConnected()));
 
       connection1.publish(TOPICA, TOPICA.getBytes(), QoS.EXACTLY_ONCE, true);
       connection1.disconnect();
@@ -1399,20 +1345,10 @@ public class MQTTTest extends MQTTTestSupport {
          connection.connect();
          connection.publish(TOPICA, TOPICA.getBytes(), QoS.EXACTLY_ONCE, true);
 
-         assertTrue("Client connect failed for attempt: " + i, Wait.waitFor(new Wait.Condition()
{
-            @Override
-            public boolean isSatisfied() throws Exception {
-               return connection.isConnected();
-            }
-         }, TimeUnit.SECONDS.toMillis(3), TimeUnit.MILLISECONDS.toMillis(200)));
+         assertTrue("Client connect failed for attempt: " + i, Wait.waitFor(() -> connection.isConnected(),
3000, 200));
 
          if (oldConnection.get() != null) {
-            assertTrue("Old client still connected on attempt: " + i, Wait.waitFor(new Wait.Condition()
{
-               @Override
-               public boolean isSatisfied() throws Exception {
-                  return !oldConnection.get().isConnected();
-               }
-            }, TimeUnit.SECONDS.toMillis(3), TimeUnit.MILLISECONDS.toMillis(200)));
+            assertTrue("Old client still connected on attempt: " + i, Wait.waitFor(() ->
!oldConnection.get().isConnected(), 3000, 200));
          }
 
          oldConnection.set(connection);
@@ -1575,13 +1511,7 @@ public class MQTTTest extends MQTTTestSupport {
       final BlockingConnection connection = mqtt.blockingConnection();
       connection.connect();
 
-      assertTrue("KeepAlive didn't work properly", Wait.waitFor(new Wait.Condition() {
-
-         @Override
-         public boolean isSatisfied() throws Exception {
-            return connection.isConnected();
-         }
-      }));
+      assertTrue("KeepAlive didn't work properly", Wait.waitFor(() -> connection.isConnected()));
    }
 
    @Test(timeout = 60 * 1000)
@@ -1773,13 +1703,7 @@ public class MQTTTest extends MQTTTestSupport {
       mqtt.setKeepAlive((short) 2);
       final BlockingConnection connection = mqtt.blockingConnection();
       connection.connect();
-      assertTrue("KeepAlive didn't work properly", Wait.waitFor(new Wait.Condition() {
-
-         @Override
-         public boolean isSatisfied() throws Exception {
-            return connection.isConnected();
-         }
-      }));
+      assertTrue("KeepAlive didn't work properly", Wait.waitFor(() -> connection.isConnected()));
 
       connection.disconnect();
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/956c4c64/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/util/Wait.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/util/Wait.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/util/Wait.java
index 795a478..2f3772a 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/util/Wait.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/util/Wait.java
@@ -40,10 +40,10 @@ public class Wait {
    }
 
    public static boolean waitFor(final Condition condition,
-                                 final long duration,
+                                 final long durationMillis,
                                  final long sleepMillis) throws Exception {
 
-      final long expiry = System.currentTimeMillis() + duration;
+      final long expiry = System.currentTimeMillis() + durationMillis;
       boolean conditionSatisified = condition.isSatisfied();
       while (!conditionSatisified && System.currentTimeMillis() < expiry) {
          TimeUnit.MILLISECONDS.sleep(sleepMillis);


Mime
View raw message