camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-11446: Use awaitility in camel-core for testing where we otherwise use thred sleep which can be speeded up.
Date Thu, 06 Jul 2017 14:19:15 GMT
Repository: camel
Updated Branches:
  refs/heads/master 2253ebb59 -> 183abd872


CAMEL-11446: Use awaitility in camel-core for testing where we otherwise use thred sleep which
can be speeded up.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/183abd87
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/183abd87
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/183abd87

Branch: refs/heads/master
Commit: 183abd872fe0647d64e6f4735ebc38523bb85065
Parents: 2253ebb
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Jul 6 16:17:11 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Jul 6 16:19:10 2017 +0200

----------------------------------------------------------------------
 .../file/FileBatchConsumerMemoryLeakTest.java   |  4 +-
 .../file/FileConsumePollEnrichFileTest.java     |  4 +-
 ...rPollStrategyRollbackThrowExceptionTest.java | 11 ++-
 ...lerConsumerShouldSkipDoneFileSuffixTest.java |  4 +-
 .../component/seda/SedaNoConsumerTest.java      | 16 -----
 .../camel/management/ManagedThrottlerTest.java  |  2 -
 .../processor/ShutdownCompleteAllTasksTest.java | 10 ++-
 .../AggregateNewExchangeAndConfirmTest.java     |  6 +-
 .../org/apache/camel/util/StopWatchTest.java    | 74 --------------------
 9 files changed, 28 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/183abd87/camel-core/src/test/java/org/apache/camel/component/file/FileBatchConsumerMemoryLeakTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileBatchConsumerMemoryLeakTest.java
b/camel-core/src/test/java/org/apache/camel/component/file/FileBatchConsumerMemoryLeakTest.java
index 6cec367..5c40d8e 100644
--- a/camel-core/src/test/java/org/apache/camel/component/file/FileBatchConsumerMemoryLeakTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FileBatchConsumerMemoryLeakTest.java
@@ -20,12 +20,14 @@ import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
+import org.junit.Ignore;
 
 /**
  * Unit test to test CAMEL-1652
  *
  * @version 
  */
+@Ignore("Manual test")
 public class FileBatchConsumerMemoryLeakTest extends ContextTestSupport {
 
     private String fileUrl = "file://target/filesorter/";
@@ -56,7 +58,7 @@ public class FileBatchConsumerMemoryLeakTest extends ContextTestSupport
{
      * The test is not really a good integration test as it simply waits and does not fail
      * or succeed fast
      */
-    public void xxxtestMemoryLeak() throws Exception {
+    public void testMemoryLeak() throws Exception {
         // run this manually and browse the memory usage, eg in IDEA there is a Statistics
tab
 
         deleteDirectory("target/filesorter/archiv");

http://git-wip-us.apache.org/repos/asf/camel/blob/183abd87/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
index d9dcaac..17536a8 100644
--- a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumePollEnrichFileTest.java
@@ -40,8 +40,8 @@ public class FileConsumePollEnrichFileTest extends ContextTestSupport {
 
         template.sendBodyAndHeader("file://target/enrich", "Start", Exchange.FILE_NAME, "AAA.fin");
 
-        log.info("Sleeping for 1 sec before writing enrichdata file");
-        Thread.sleep(1000);
+        log.info("Sleeping for 0.5 sec before writing enrichdata file");
+        Thread.sleep(500);
         template.sendBodyAndHeader("file://target/enrichdata", "Big file", Exchange.FILE_NAME,
"AAA.dat");
         log.info("... write done");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/183abd87/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyRollbackThrowExceptionTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyRollbackThrowExceptionTest.java
b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyRollbackThrowExceptionTest.java
index 25ffa9c..9f146b6 100644
--- a/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyRollbackThrowExceptionTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyRollbackThrowExceptionTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.component.file;
 
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.Consumer;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Endpoint;
@@ -24,6 +27,8 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.spi.PollingConsumerPollStrategy;
 
+import static org.awaitility.Awaitility.await;
+
 /**
  * Unit test for poll strategy
  */
@@ -31,6 +36,8 @@ public class FileConsumerPollStrategyRollbackThrowExceptionTest extends
ContextT
 
     private static volatile String event = "";
 
+    private static final CountDownLatch LATCH = new CountDownLatch(1);
+
     private String fileUrl = "file://target/pollstrategy/?pollStrategy=#myPoll&initialDelay=0&delay=10";
 
     @Override
@@ -48,8 +55,7 @@ public class FileConsumerPollStrategyRollbackThrowExceptionTest extends
ContextT
     }
 
     public void testRollbackThrowException() throws Exception {
-        // let it run for a little, but it fails all the time
-        Thread.sleep(200);
+        await().atMost(2, TimeUnit.SECONDS).until(() -> LATCH.getCount() == 0);
 
         // and we should rollback X number of times
         assertTrue(event.startsWith("rollback"));
@@ -76,6 +82,7 @@ public class FileConsumerPollStrategyRollbackThrowExceptionTest extends
ContextT
 
         public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception
cause) throws Exception {
             event += "rollback";
+            LATCH.countDown();
             throw cause;
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/183abd87/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileSuffixTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileSuffixTest.java
b/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileSuffixTest.java
index 258b98a..faf82a3 100644
--- a/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileSuffixTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FilerConsumerShouldSkipDoneFileSuffixTest.java
@@ -40,7 +40,7 @@ public class FilerConsumerShouldSkipDoneFileSuffixTest extends ContextTestSuppor
         template.sendBodyAndHeader("file:target/done", "", Exchange.FILE_NAME, "hello.txt.ready");
 
         // wait a bit and it should not pickup the written file as there are no target file
-        Thread.sleep(250);
+        Thread.sleep(100);
 
         assertMockEndpointsSatisfied();
         resetMocks();
@@ -67,7 +67,7 @@ public class FilerConsumerShouldSkipDoneFileSuffixTest extends ContextTestSuppor
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("file:target/done?doneFileName=${file:name}.ready&initialDelay=0")
+                from("file:target/done?doneFileName=${file:name}.ready&initialDelay=0&delay=50")
                     .convertBodyTo(String.class)
                     .to("mock:result");
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/183abd87/camel-core/src/test/java/org/apache/camel/component/seda/SedaNoConsumerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/seda/SedaNoConsumerTest.java
b/camel-core/src/test/java/org/apache/camel/component/seda/SedaNoConsumerTest.java
index 8a89baa..0b40bb8 100644
--- a/camel-core/src/test/java/org/apache/camel/component/seda/SedaNoConsumerTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/seda/SedaNoConsumerTest.java
@@ -163,20 +163,4 @@ public class SedaNoConsumerTest extends ContextTestSupport {
 
     }
 
-    @Test
-    public void testConfigOnAConsumer() throws Exception {
-        context.addRoutes(new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                // these are the same!
-                from("seda:foo?failIfNoConsumers=true").to("log:test");
-                from("seda:foo").to("log:test2");
-
-            }
-        });
-
-        context.start();
-        Thread.sleep(2 * 1000);
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/183abd87/camel-core/src/test/java/org/apache/camel/management/ManagedThrottlerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedThrottlerTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedThrottlerTest.java
index 1f2cc18..1a06721 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedThrottlerTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedThrottlerTest.java
@@ -192,8 +192,6 @@ public class ManagedThrottlerTest extends ManagementTestSupport {
 
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
-        // get the object name for the delayer
-        ObjectName throttlerName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mythrottler4\"");
 
         // use route to get the total time
         ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route4\"");

http://git-wip-us.apache.org/repos/asf/camel/blob/183abd87/camel-core/src/test/java/org/apache/camel/processor/ShutdownCompleteAllTasksTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/ShutdownCompleteAllTasksTest.java
b/camel-core/src/test/java/org/apache/camel/processor/ShutdownCompleteAllTasksTest.java
index 792600b..2535fc6 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/ShutdownCompleteAllTasksTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/ShutdownCompleteAllTasksTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.processor;
 
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -33,6 +34,7 @@ public class ShutdownCompleteAllTasksTest extends ContextTestSupport {
 
     private static String url = "file:target/pending";
     private static AtomicInteger counter = new AtomicInteger();
+    private static CountDownLatch latch = new CountDownLatch(2);
 
     @Override
     protected void setUp() throws Exception {
@@ -56,11 +58,13 @@ public class ShutdownCompleteAllTasksTest extends ContextTestSupport {
         MockEndpoint bar = getMockEndpoint("mock:bar");
         bar.expectedMinimumMessageCount(1);
 
-        // wait 20 seconds to give more time for slow servers
-        bar.await(20, TimeUnit.SECONDS);
+        assertMockEndpointsSatisfied();
 
         int batch = bar.getReceivedExchanges().get(0).getProperty(Exchange.BATCH_SIZE, int.class);
 
+        // wait for latch
+        latch.await(10, TimeUnit.SECONDS);
+
         // shutdown during processing
         context.stop();
 
@@ -87,8 +91,8 @@ public class ShutdownCompleteAllTasksTest extends ContextTestSupport {
     public static class MyProcessor implements Processor {
 
         public void process(Exchange exchange) throws Exception {
-            Thread.sleep(500);
             counter.incrementAndGet();
+            latch.countDown();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/183abd87/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateNewExchangeAndConfirmTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateNewExchangeAndConfirmTest.java
b/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateNewExchangeAndConfirmTest.java
index 2d2b9d3..3f95260 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateNewExchangeAndConfirmTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateNewExchangeAndConfirmTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.processor.aggregator;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
@@ -24,6 +26,8 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.processor.aggregate.AggregationStrategy;
 import org.apache.camel.processor.aggregate.MemoryAggregationRepository;
 
+import static org.awaitility.Awaitility.await;
+
 /**
  * Testing CAMEL-3139
  * 
@@ -44,7 +48,7 @@ public class AggregateNewExchangeAndConfirmTest extends ContextTestSupport
{
         assertMockEndpointsSatisfied();
 
         // give UoW time to complete and confirm
-        Thread.sleep(500);
+        await().atMost(1, TimeUnit.SECONDS).until(() -> repo.getId() != null);
 
         // must have confirmed
         assertEquals(mock.getReceivedExchanges().get(0).getExchangeId(), repo.getId());

http://git-wip-us.apache.org/repos/asf/camel/blob/183abd87/camel-core/src/test/java/org/apache/camel/util/StopWatchTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/StopWatchTest.java b/camel-core/src/test/java/org/apache/camel/util/StopWatchTest.java
deleted file mode 100644
index 212bb40..0000000
--- a/camel-core/src/test/java/org/apache/camel/util/StopWatchTest.java
+++ /dev/null
@@ -1,74 +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.camel.util;
-
-import junit.framework.TestCase;
-
-/**
- * @version 
- */
-public class StopWatchTest extends TestCase {
-
-    public void testStopWatch() throws Exception {
-        StopWatch watch = new StopWatch();
-        Thread.sleep(200);
-        long taken = watch.stop();
-
-        assertEquals(taken, watch.taken());
-        assertTrue("Should take approx 200 millis, was: " + taken, taken > 150);
-    }
-
-    public void testStopWatchNotStarted() throws Exception {
-        StopWatch watch = new StopWatch(false);
-        long taken = watch.stop();
-        assertEquals(0, taken);
-
-        watch.restart();
-        Thread.sleep(200);
-        taken = watch.stop();
-
-        assertEquals(taken, watch.taken());
-        assertTrue("Should take approx 200 millis, was: " + taken, taken > 150);
-    }
-
-    public void testStopWatchRestart() throws Exception {
-        StopWatch watch = new StopWatch();
-        Thread.sleep(200);
-        long taken = watch.stop();
-
-        assertEquals(taken, watch.taken());
-        assertTrue("Should take approx 200 millis, was: " + taken, taken > 150);
-
-        watch.restart();
-        Thread.sleep(100);
-        taken = watch.stop();
-
-        assertEquals(taken, watch.taken());
-        assertTrue("Should take approx 100 millis, was: " + taken, taken > 50);
-    }
-
-    public void testStopWatchTaken() throws Exception {
-        StopWatch watch = new StopWatch();
-        Thread.sleep(100);
-        long taken = watch.taken();
-        Thread.sleep(100);
-        long taken2 = watch.taken();
-        assertNotSame(taken, taken2);
-        assertTrue(taken2 > taken);
-    }
-
-}


Mime
View raw message