camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [1/2] camel git commit: Speed up InfinispanProducerTest
Date Thu, 24 Mar 2016 09:35:33 GMT
Repository: camel
Updated Branches:
  refs/heads/master 7e12832b8 -> 8a03f0e40


Speed up InfinispanProducerTest


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

Branch: refs/heads/master
Commit: 551142974c117449cd95add196d36b048231f9a9
Parents: 7e12832
Author: Martin Gencur <mgencur@redhat.com>
Authored: Tue Mar 22 09:45:26 2016 +0100
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Mar 24 10:23:05 2016 +0100

----------------------------------------------------------------------
 .../infinispan/InfinispanContinuousQueryIT.java |   4 +-
 .../infinispan/InfinispanProducerTest.java      | 401 ++++++-------------
 .../InfinispanRemoteQueryProducerIT.java        |   7 +-
 .../camel/component/infinispan/UserUtils.java   |  81 ----
 .../component/infinispan/util/Condition.java    |   8 +
 .../component/infinispan/util/UserUtils.java    |  81 ++++
 .../camel/component/infinispan/util/Wait.java   |  39 ++
 7 files changed, 263 insertions(+), 358 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/55114297/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanContinuousQueryIT.java
----------------------------------------------------------------------
diff --git a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanContinuousQueryIT.java
b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanContinuousQueryIT.java
index b591555..82888b0 100644
--- a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanContinuousQueryIT.java
+++ b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanContinuousQueryIT.java
@@ -38,8 +38,8 @@ import org.infinispan.query.remote.client.MarshallerRegistration;
 import org.infinispan.query.remote.client.ProtobufMetadataManagerConstants;
 import org.junit.Test;
 
-import static org.apache.camel.component.infinispan.UserUtils.CQ_USERS;
-import static org.apache.camel.component.infinispan.UserUtils.createKey;
+import static org.apache.camel.component.infinispan.util.UserUtils.CQ_USERS;
+import static org.apache.camel.component.infinispan.util.UserUtils.createKey;
 
 public class InfinispanContinuousQueryIT extends CamelTestSupport {
 

http://git-wip-us.apache.org/repos/asf/camel/blob/55114297/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanProducerTest.java
b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanProducerTest.java
index c4cd561..b3f227d 100644
--- a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanProducerTest.java
+++ b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanProducerTest.java
@@ -23,16 +23,20 @@ import java.util.concurrent.TimeUnit;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.infinispan.util.Condition;
 import org.infinispan.commons.util.concurrent.NotifyingFuture;
 import org.junit.Test;
 
+import static org.apache.camel.component.infinispan.util.Wait.waitFor;
+
+
 public class InfinispanProducerTest extends InfinispanTestSupport {
 
     private static final String COMMAND_VALUE = "commandValue";
     private static final String COMMAND_KEY = "commandKey1";
-    private static final long LIFESPAN_TIME = 5;
+    private static final long LIFESPAN_TIME = 100;
     private static final long LIFESPAN_FOR_MAX_IDLE = -1;
-    private static final long MAX_IDLE_TIME = 3;
+    private static final long MAX_IDLE_TIME = 200;
 
     @Test
     public void keyAndValueArePublishedWithDefaultOperation() throws Exception {
@@ -81,7 +85,7 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
 
     @Test
     public void publishKeyAndValueAsync() throws Exception {
-        Exchange exchange = template.send("direct:putasync", new Processor() {
+        final Exchange exchange = template.send("direct:putasync", new Processor() {
             @Override
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
@@ -89,74 +93,64 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
             }
         });
 
-        Thread.sleep(10000);
-        NotifyingFuture resultPutAsync = exchange.getIn().getHeader(InfinispanConstants.RESULT,
NotifyingFuture.class);
-        assertEquals(Boolean.TRUE, resultPutAsync.isDone());
-
-        Object value = currentCache().get(KEY_ONE);
-        assertEquals(VALUE_ONE, value.toString());
+        waitFor(new Condition() {
+            @Override
+            public boolean isSatisfied() throws Exception {
+                NotifyingFuture resultPutAsync = exchange.getIn().getHeader(InfinispanConstants.RESULT,
NotifyingFuture.class);
+                Object value = currentCache().get(KEY_ONE);
+                return resultPutAsync.isDone() && value.toString().equals(VALUE_ONE);
+            }
+        }, 5000);
     }
 
     @Test
     public void publishKeyAndValueAsyncWithLifespan() throws Exception {
-        Exchange exchange = template.send("direct:putasync", new Processor() {
+        final Exchange exchange = template.send("direct:putasync", new Processor() {
             @Override
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
             }
         });
 
-        Thread.sleep(1000);
-        NotifyingFuture resultPutAsync = exchange.getIn().getHeader(InfinispanConstants.RESULT,
NotifyingFuture.class);
-        assertEquals(Boolean.TRUE, resultPutAsync.isDone());
-
-        Object value = currentCache().get(KEY_ONE);
-        assertEquals(value.toString(), VALUE_ONE);
-
-        Thread.sleep(6000);
-        exchange = template.send("direct:get", new Processor() {
+        waitFor(new Condition() {
             @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
+            public boolean isSatisfied() throws Exception {
+                NotifyingFuture resultPutAsync = exchange.getIn().getHeader(InfinispanConstants.RESULT,
NotifyingFuture.class);
+                Object value = currentCache().get(KEY_ONE);
+                return resultPutAsync.isDone() && value.equals(VALUE_ONE);
             }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        }, 1000);
+
+        waitForNullValue(KEY_ONE);
     }
 
     @Test
     public void publishKeyAndValueAsyncWithLifespanAndMaxIdle() throws Exception {
-        Exchange exchange = template.send("direct:putasync", new Processor() {
+        final Exchange exchange = template.send("direct:putasync", new Processor() {
             @Override
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_FOR_MAX_IDLE));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
                 exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME, new Long(MAX_IDLE_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
             }
         });
 
-        Thread.sleep(1000);
-        NotifyingFuture resultPutAsync = exchange.getIn().getHeader(InfinispanConstants.RESULT,
NotifyingFuture.class);
-        assertEquals(Boolean.TRUE, resultPutAsync.isDone());
-
-        Object value = currentCache().get(KEY_ONE);
-        assertEquals(VALUE_ONE, value.toString());
-
-        Thread.sleep(10000);
-        exchange = template.send("direct:get", new Processor() {
+        waitFor(new Condition() {
             @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
+            public boolean isSatisfied() throws Exception {
+                NotifyingFuture resultPutAsync = exchange.getIn().getHeader(InfinispanConstants.RESULT,
NotifyingFuture.class);
+                return resultPutAsync.isDone() && currentCache().get(KEY_ONE).toString().equals(VALUE_ONE);
             }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        }, 1000);
+
+        Thread.sleep(300);
+        waitForNullValue(KEY_ONE);
     }
 
     @Test
@@ -190,7 +184,7 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
                 exchange.getIn().setHeader(InfinispanConstants.MAP, map);
                 exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.PUT_ALL);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
             }
         });
 
@@ -200,25 +194,7 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
         value = currentCache().get(KEY_TWO);
         assertEquals(VALUE_TWO, value.toString());
 
-        Thread.sleep(LIFESPAN_TIME * 1000);
-
-        Exchange exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
-            }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
-
-        exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_TWO);
-            }
-        });
-        resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        waitForNullValue(KEY_ONE);
     }
 
     @Test
@@ -232,33 +208,16 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
                 exchange.getIn().setHeader(InfinispanConstants.MAP, map);
                 exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.PUT_ALL);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_FOR_MAX_IDLE));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
                 exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME, new Long(MAX_IDLE_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
             }
         });
 
         assertEquals(2, currentCache().size());
 
-        Thread.sleep(10000);
-
-        Exchange exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
-            }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
-
-        exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_TWO);
-            }
-        });
-        resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(null);
+        Thread.sleep(300);
+        waitForNullValue(KEY_TWO);
     }
 
     @Test
@@ -292,36 +251,20 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
                 exchange.getIn().setHeader(InfinispanConstants.MAP, map);
                 exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.PUT_ALL);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
             }
         });
 
-        Thread.sleep(100);
-        assertEquals(2, currentCache().size());
-        Object value = currentCache().get(KEY_ONE);
-        assertEquals(VALUE_ONE, value.toString());
-        value = currentCache().get(KEY_TWO);
-        assertEquals(VALUE_TWO, value.toString());
-
-        Thread.sleep(LIFESPAN_TIME * 1000);
-
-        Exchange exchange = template.send("direct:get", new Processor() {
+        waitFor(new Condition() {
             @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
+            public boolean isSatisfied() throws Exception {
+                Object valueOne = currentCache().get(KEY_ONE);
+                Object valueTwo = currentCache().get(KEY_TWO);
+                return valueOne.equals(VALUE_ONE) && valueTwo.equals(VALUE_TWO) &&
currentCache().size() == 2;
             }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        }, 100);
 
-        exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_TWO);
-            }
-        });
-        resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        waitForNullValue(KEY_ONE);
     }
 
     @Test
@@ -335,34 +278,23 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
                 exchange.getIn().setHeader(InfinispanConstants.MAP, map);
                 exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.PUT_ALL);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_FOR_MAX_IDLE));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
                 exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME, new Long(MAX_IDLE_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
             }
         });
 
-        Thread.sleep(100);
-        assertEquals(2, currentCache().size());
-
-        Thread.sleep(10000);
-
-        Exchange exchange = template.send("direct:get", new Processor() {
+        waitFor(new Condition() {
             @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
+            public boolean isSatisfied() throws Exception {
+                return currentCache().size() == 2;
             }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        }, 100);
 
-        exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_TWO);
-            }
-        });
-        resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        Thread.sleep(300);
+
+        waitForNullValue(KEY_ONE);
+        waitForNullValue(KEY_TWO);
     }
 
     @Test
@@ -403,82 +335,69 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
 
     @Test
     public void putIfAbsentKeyAndValueAsync() throws Exception {
-        Exchange exchange = template.send("direct:putifabsentasync", new Processor() {
+        final Exchange exchange = template.send("direct:putifabsentasync", new Processor()
{
             @Override
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_ONE);
             }
         });
-
-        Thread.sleep(10000);
-        NotifyingFuture resultPutAsync = exchange.getIn().getHeader(InfinispanConstants.RESULT,
NotifyingFuture.class);
-        assertEquals(Boolean.TRUE, resultPutAsync.isDone());
-
-        Object value = currentCache().get(KEY_ONE);
-        assertEquals(VALUE_ONE, value.toString());
+        waitFor(new Condition() {
+            @Override
+            public boolean isSatisfied() throws Exception {
+                NotifyingFuture resultPutAsync = exchange.getIn().getHeader(InfinispanConstants.RESULT,
NotifyingFuture.class);
+                return resultPutAsync.isDone() && currentCache().get(KEY_ONE).equals(VALUE_ONE);
+            }
+        }, 2000);
     }
 
     @Test
     public void putIfAbsentKeyAndValueAsyncWithLifespan() throws Exception {
-        Exchange exchange = template.send("direct:putifabsentasync", new Processor() {
+        final Exchange exchange = template.send("direct:putifabsentasync", new Processor()
{
             @Override
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
             }
         });
 
-        Thread.sleep(1000);
-        NotifyingFuture resultPutAsync = exchange.getIn().getHeader(InfinispanConstants.RESULT,
NotifyingFuture.class);
-        assertEquals(Boolean.TRUE, resultPutAsync.isDone());
-
-        Object value = currentCache().get(KEY_ONE);
-        assertEquals(VALUE_ONE, value.toString());
-
-        Thread.sleep(6000);
-        exchange = template.send("direct:get", new Processor() {
+        waitFor(new Condition() {
             @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
+            public boolean isSatisfied() throws Exception {
+                NotifyingFuture resultPutAsync = exchange.getIn().getHeader(InfinispanConstants.RESULT,
NotifyingFuture.class);
+                return resultPutAsync.isDone() && currentCache().get(KEY_ONE).equals(VALUE_ONE);
             }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        }, 100);
+
+        waitForNullValue(KEY_ONE);
     }
 
     @Test
     public void putIfAbsentKeyAndValueAsyncWithLifespanAndMaxIdle() throws Exception {
-        Exchange exchange = template.send("direct:putifabsentasync", new Processor() {
+        final Exchange exchange = template.send("direct:putifabsentasync", new Processor()
{
             @Override
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_FOR_MAX_IDLE));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
                 exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME, new Long(MAX_IDLE_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
             }
         });
 
-        Thread.sleep(1000);
-        NotifyingFuture resultPutAsync = exchange.getIn().getHeader(InfinispanConstants.RESULT,
NotifyingFuture.class);
-        assertEquals(Boolean.TRUE, resultPutAsync.isDone());
-
-        Object value = currentCache().get(KEY_ONE);
-        assertEquals(VALUE_ONE, value.toString());
-
-        Thread.sleep(10000);
-        exchange = template.send("direct:get", new Processor() {
+        waitFor(new Condition() {
             @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
+            public boolean isSatisfied() throws Exception {
+                NotifyingFuture resultPutAsync = exchange.getIn().getHeader(InfinispanConstants.RESULT,
NotifyingFuture.class);
+                return resultPutAsync.isDone() && currentCache().get(KEY_ONE).equals(VALUE_ONE);
             }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        }, 500);
+
+        Thread.sleep(300);
+        waitForNullValue(KEY_ONE);
     }
 
     @Test
@@ -553,7 +472,7 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
                 exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
                 exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.PUT);
             }
         });
@@ -571,16 +490,7 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
         String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
         assertEquals(VALUE_ONE, resultGet);
 
-        Thread.sleep(LIFESPAN_TIME * 1000);
-
-        exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
-            }
-        });
-        resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        waitForNullValue(KEY_ONE);
     }
 
     @Test
@@ -642,7 +552,7 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
                 exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_TWO);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
                 exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.REPLACE);
             }
         });
@@ -650,16 +560,7 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
         assertEquals(VALUE_ONE, exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class));
         assertEquals(VALUE_TWO, currentCache().get(KEY_ONE));
 
-        Thread.sleep(LIFESPAN_TIME * 1000);
-
-        exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
-            }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        waitForNullValue(KEY_ONE);
     }
 
     @Test
@@ -672,9 +573,9 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
                 exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_TWO);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_FOR_MAX_IDLE));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
                 exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME, new Long(MAX_IDLE_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
                 exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.REPLACE);
             }
         });
@@ -682,16 +583,8 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
         assertEquals(VALUE_ONE, exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class));
         assertEquals(VALUE_TWO, currentCache().get(KEY_ONE));
 
-        Thread.sleep(10000);
-
-        exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
-            }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        Thread.sleep(300);
+        waitForNullValue(KEY_ONE);
     }
 
     @Test
@@ -723,7 +616,7 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
                 exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_TWO);
                 exchange.getIn().setHeader(InfinispanConstants.OLD_VALUE, VALUE_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
                 exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.REPLACE);
             }
         });
@@ -731,16 +624,7 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
         assertTrue(exchange.getIn().getHeader(InfinispanConstants.RESULT, Boolean.class));
         assertEquals(VALUE_TWO, currentCache().get(KEY_ONE));
 
-        Thread.sleep(LIFESPAN_TIME * 1100);
-
-        exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
-            }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        waitForNullValue(KEY_ONE);
     }
 
     @Test
@@ -754,9 +638,9 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
                 exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_TWO);
                 exchange.getIn().setHeader(InfinispanConstants.OLD_VALUE, VALUE_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_FOR_MAX_IDLE));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
                 exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME, new Long(MAX_IDLE_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
                 exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.REPLACE);
             }
         });
@@ -764,16 +648,8 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
         assertTrue(exchange.getIn().getHeader(InfinispanConstants.RESULT, Boolean.class));
         assertEquals(VALUE_TWO, currentCache().get(KEY_ONE));
 
-        Thread.sleep(10000);
-
-        exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
-            }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        Thread.sleep(300);
+        waitForNullValue(KEY_ONE);
     }
 
 
@@ -803,23 +679,14 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
                 exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_TWO);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
             }
         });
 
         assertEquals(exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class),
VALUE_ONE);
         assertEquals(currentCache().get(KEY_ONE), VALUE_TWO);
 
-        TimeUnit.SECONDS.sleep(LIFESPAN_TIME + 1);
-
-        exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
-            }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertEquals(null, resultGet);
+        waitForNullValue(KEY_ONE);
     }
 
 
@@ -833,25 +700,17 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
                 exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_TWO);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_FOR_MAX_IDLE));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
                 exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME, new Long(MAX_IDLE_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
             }
         });
 
         assertEquals(VALUE_ONE, exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class));
         assertEquals(VALUE_TWO, currentCache().get(KEY_ONE));
 
-        Thread.sleep(10000);
-
-        exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
-            }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        Thread.sleep(300);
+        waitForNullValue(KEY_ONE);
     }
 
     @Test
@@ -882,23 +741,14 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
                 exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_TWO);
                 exchange.getIn().setHeader(InfinispanConstants.OLD_VALUE, VALUE_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
             }
         });
 
         assertTrue(exchange.getIn().getHeader(InfinispanConstants.RESULT, Boolean.class));
         assertEquals(VALUE_TWO, currentCache().get(KEY_ONE));
 
-        Thread.sleep(LIFESPAN_TIME * 1100);
-
-        exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
-            }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        waitForNullValue(KEY_ONE);
     }
 
     @Test
@@ -912,25 +762,17 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
                 exchange.getIn().setHeader(InfinispanConstants.VALUE, VALUE_TWO);
                 exchange.getIn().setHeader(InfinispanConstants.OLD_VALUE, VALUE_ONE);
                 exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_FOR_MAX_IDLE));
-                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
                 exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME, new Long(MAX_IDLE_TIME));
-                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.SECONDS.toString());
+                exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
             }
         });
 
         assertTrue(exchange.getIn().getHeader(InfinispanConstants.RESULT, Boolean.class));
         assertEquals(VALUE_TWO, currentCache().get(KEY_ONE));
 
-        Thread.sleep(10000);
-
-        exchange = template.send("direct:get", new Processor() {
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(InfinispanConstants.KEY, KEY_ONE);
-            }
-        });
-        String resultGet = exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class);
-        assertNull(resultGet);
+        Thread.sleep(300);
+        waitForNullValue(KEY_ONE);
     }
 
     @Test
@@ -1129,4 +971,19 @@ public class InfinispanProducerTest extends InfinispanTestSupport {
             }
         };
     }
+
+    private void waitForNullValue(final String key) {
+        waitFor(new Condition() {
+            @Override
+            public boolean isSatisfied() throws Exception {
+                Exchange exchange = template.send("direct:get", new Processor() {
+                    @Override
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.getIn().setHeader(InfinispanConstants.KEY, key);
+                    }
+                });
+                return exchange.getIn().getHeader(InfinispanConstants.RESULT, String.class)
== null;
+            }
+        }, 1000);
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/55114297/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanRemoteQueryProducerIT.java
----------------------------------------------------------------------
diff --git a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanRemoteQueryProducerIT.java
b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanRemoteQueryProducerIT.java
index 77fea92..b3715c9 100644
--- a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanRemoteQueryProducerIT.java
+++ b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/InfinispanRemoteQueryProducerIT.java
@@ -44,9 +44,10 @@ import static org.apache.camel.component.infinispan.InfinispanConstants.OPERATIO
 import static org.apache.camel.component.infinispan.InfinispanConstants.QUERY;
 import static org.apache.camel.component.infinispan.InfinispanConstants.QUERY_BUILDER;
 import static org.apache.camel.component.infinispan.InfinispanConstants.RESULT;
-import static org.apache.camel.component.infinispan.UserUtils.USERS;
-import static org.apache.camel.component.infinispan.UserUtils.createKey;
-import static org.apache.camel.component.infinispan.UserUtils.hasUser;
+import static org.apache.camel.component.infinispan.InfinispanConstants.VALUE;
+import static org.apache.camel.component.infinispan.util.UserUtils.USERS;
+import static org.apache.camel.component.infinispan.util.UserUtils.createKey;
+import static org.apache.camel.component.infinispan.util.UserUtils.hasUser;
 
 public class InfinispanRemoteQueryProducerIT extends CamelTestSupport {
 

http://git-wip-us.apache.org/repos/asf/camel/blob/55114297/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/UserUtils.java
----------------------------------------------------------------------
diff --git a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/UserUtils.java
b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/UserUtils.java
deleted file mode 100644
index df2ba65..0000000
--- a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/UserUtils.java
+++ /dev/null
@@ -1,81 +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.component.infinispan;
-
-import java.util.List;
-import org.infinispan.protostream.sampledomain.User;
-
-public final class UserUtils {
-    public static final User[] USERS = new User[]{
-            createUser("nameA", "surnameA"),
-            createUser("nameA", "surnameB"),
-            createUser("nameB", "surnameB")};
-
-    public static final User[] CQ_USERS = new User[]{
-        createUser("CQ01", "surname01"),
-        createUser("CQ02", "surname01"),
-        createUser("NQ03", "surname03"),
-        createUser("NQ04", "surname04")
-    };
-
-    private UserUtils() {
-    }
-
-    public static String createKey(User user) {
-        return String.format("%s+%s", user.getName(), user.getSurname());
-    }
-
-    public static User createUser(String name, String surname) {
-        User user = new User();
-        user.setName(name);
-        user.setSurname(surname);
-        return user;
-    }
-
-    public static boolean eq(String str1, String str2) {
-        if (str1 == null) {
-            return str2 == null;
-        } else {
-            return str1.equals(str2);
-        }
-    }
-
-    public static boolean eq(User user, String name, String surname) {
-        if (user == null) {
-            return false;
-        }
-        if (!eq(user.getName(), name)) {
-            return false;
-        }
-        if (!eq(user.getSurname(), surname)) {
-            return false;
-        }
-        return true;
-    }
-
-    public static boolean hasUser(List<User> users, String name, String surname) {
-        if (users == null) {
-            return false;
-        }
-        for (User user : users) {
-            if (eq(user, name, surname)) {
-                return true;
-            }
-        }
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/55114297/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/util/Condition.java
----------------------------------------------------------------------
diff --git a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/util/Condition.java
b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/util/Condition.java
new file mode 100644
index 0000000..917c6e9
--- /dev/null
+++ b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/util/Condition.java
@@ -0,0 +1,8 @@
+package org.apache.camel.component.infinispan.util;
+
+/**
+ * @author Martin Gencur
+ */
+public interface Condition {
+    boolean isSatisfied() throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/55114297/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/util/UserUtils.java
----------------------------------------------------------------------
diff --git a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/util/UserUtils.java
b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/util/UserUtils.java
new file mode 100644
index 0000000..85cd20b
--- /dev/null
+++ b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/util/UserUtils.java
@@ -0,0 +1,81 @@
+/**
+ * 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.component.infinispan.util;
+
+import java.util.List;
+import org.infinispan.protostream.sampledomain.User;
+
+public final class UserUtils {
+    public static final User[] USERS = new User[]{
+            createUser("nameA", "surnameA"),
+            createUser("nameA", "surnameB"),
+            createUser("nameB", "surnameB")};
+
+    public static final User[] CQ_USERS = new User[]{
+        createUser("CQ01", "surname01"),
+        createUser("CQ02", "surname01"),
+        createUser("NQ03", "surname03"),
+        createUser("NQ04", "surname04")
+    };
+
+    private UserUtils() {
+    }
+
+    public static String createKey(User user) {
+        return String.format("%s+%s", user.getName(), user.getSurname());
+    }
+
+    public static User createUser(String name, String surname) {
+        User user = new User();
+        user.setName(name);
+        user.setSurname(surname);
+        return user;
+    }
+
+    public static boolean eq(String str1, String str2) {
+        if (str1 == null) {
+            return str2 == null;
+        } else {
+            return str1.equals(str2);
+        }
+    }
+
+    public static boolean eq(User user, String name, String surname) {
+        if (user == null) {
+            return false;
+        }
+        if (!eq(user.getName(), name)) {
+            return false;
+        }
+        if (!eq(user.getSurname(), surname)) {
+            return false;
+        }
+        return true;
+    }
+
+    public static boolean hasUser(List<User> users, String name, String surname) {
+        if (users == null) {
+            return false;
+        }
+        for (User user : users) {
+            if (eq(user, name, surname)) {
+                return true;
+            }
+        }
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/55114297/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/util/Wait.java
----------------------------------------------------------------------
diff --git a/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/util/Wait.java
b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/util/Wait.java
new file mode 100644
index 0000000..6806548
--- /dev/null
+++ b/components/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/util/Wait.java
@@ -0,0 +1,39 @@
+package org.apache.camel.component.infinispan.util;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Martin Gencur
+ */
+public class Wait {
+
+    public static void waitFor(Condition ec, long timeout) {
+        waitFor(ec, timeout, 10);
+    }
+
+    /**
+     * @param ec Condition that has to be met after the timeout
+     * @param timeout Overall timeout - how long to wait for the condition
+     * @param loops How many times to check the condition before the timeout expires.
+     */
+    public static void waitFor(Condition ec, long timeout, int loops) {
+        if (loops <= 0) {
+            throw new IllegalArgumentException("Number of loops must be positive");
+        }
+        long sleepDuration = timeout / loops;
+        if (sleepDuration == 0) {
+            sleepDuration = 1;
+        }
+        try {
+            for (int i = 0; i < loops; i++) {
+                if (ec.isSatisfied()) {
+                    return;
+                }
+                Thread.sleep(sleepDuration);
+            }
+            assertTrue("The condition was not satisfied after " + timeout + " ms", ec.isSatisfied());
+        } catch (Exception e) {
+            throw new RuntimeException("Unexpected!", e);
+        }
+    }
+}
\ No newline at end of file


Mime
View raw message