You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/12/09 07:48:34 UTC
svn commit: r1043846 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/util/DefaultTimeoutMap.java
test/java/org/apache/camel/util/DefaultTimeoutMapTest.java
Author: davsclaus
Date: Thu Dec 9 06:48:34 2010
New Revision: 1043846
URL: http://svn.apache.org/viewvc?rev=1043846&view=rev
Log:
CAMEL-3411: Optimized test time.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/util/DefaultTimeoutMap.java
camel/trunk/camel-core/src/test/java/org/apache/camel/util/DefaultTimeoutMapTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/DefaultTimeoutMap.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/DefaultTimeoutMap.java?rev=1043846&r1=1043845&r2=1043846&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/DefaultTimeoutMap.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/DefaultTimeoutMap.java Thu Dec 9 06:48:34 2010
@@ -52,7 +52,6 @@ public class DefaultTimeoutMap<K, V> ext
private final ConcurrentMap<K, TimeoutMapEntry<K, V>> map = new ConcurrentHashMap<K, TimeoutMapEntry<K, V>>();
private final ScheduledExecutorService executor;
private final long purgePollTime;
- private final long initialDelay = 1000L;
private final Lock lock = new ReentrantLock();
private boolean useLock = true;
@@ -242,7 +241,7 @@ public class DefaultTimeoutMap<K, V> ext
* lets schedule each time to allow folks to change the time at runtime
*/
protected void schedulePoll() {
- executor.scheduleWithFixedDelay(this, initialDelay, purgePollTime, TimeUnit.MILLISECONDS);
+ executor.scheduleWithFixedDelay(this, 0, purgePollTime, TimeUnit.MILLISECONDS);
}
/**
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/DefaultTimeoutMapTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/DefaultTimeoutMapTest.java?rev=1043846&r1=1043845&r2=1043846&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/DefaultTimeoutMapTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/DefaultTimeoutMapTest.java Thu Dec 9 06:48:34 2010
@@ -39,29 +39,29 @@ public class DefaultTimeoutMapTest exten
}
public void testDefaultTimeoutMapPurge() throws Exception {
- DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(executor);
+ DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(executor, 100);
assertTrue(map.currentTime() > 0);
assertEquals(0, map.size());
- map.put("A", 123, 500);
+ map.put("A", 123, 50);
assertEquals(1, map.size());
- Thread.sleep(1500);
+ Thread.sleep(250);
assertEquals(0, map.size());
}
public void testDefaultTimeoutMapForcePurge() throws Exception {
- DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(executor);
+ DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(executor, 100);
assertTrue(map.currentTime() > 0);
assertEquals(0, map.size());
- map.put("A", 123, 500);
+ map.put("A", 123, 50);
assertEquals(1, map.size());
- Thread.sleep(1500);
+ Thread.sleep(250);
// will purge and remove old entries
map.purge();
@@ -70,12 +70,12 @@ public class DefaultTimeoutMapTest exten
}
public void testDefaultTimeoutMapGetRemove() throws Exception {
- DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(executor);
+ DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(executor, 100);
assertTrue(map.currentTime() > 0);
assertEquals(0, map.size());
- map.put("A", 123, 500);
+ map.put("A", 123, 50);
assertEquals(1, map.size());
assertEquals(123, (int)map.get("A"));
@@ -87,13 +87,13 @@ public class DefaultTimeoutMapTest exten
}
public void testDefaultTimeoutMapGetKeys() throws Exception {
- DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(executor);
+ DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(executor, 100);
assertTrue(map.currentTime() > 0);
assertEquals(0, map.size());
- map.put("A", 123, 500);
- map.put("B", 456, 500);
+ map.put("A", 123, 50);
+ map.put("B", 456, 50);
assertEquals(2, map.size());
Object[] keys = map.getKeys();
@@ -104,13 +104,13 @@ public class DefaultTimeoutMapTest exten
public void testExecutor() throws Exception {
ScheduledExecutorService e = ExecutorServiceHelper.newScheduledThreadPool(2, null, "foo", true);
- DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(e, 500);
- assertEquals(500, map.getPurgePollTime());
+ DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(e, 50);
+ assertEquals(50, map.getPurgePollTime());
- map.put("A", 123, 1000);
+ map.put("A", 123, 100);
assertEquals(1, map.size());
- Thread.sleep(2000);
+ Thread.sleep(250);
// should have been timed out now
assertEquals(0, map.size());
@@ -122,7 +122,7 @@ public class DefaultTimeoutMapTest exten
final List<String> keys = new ArrayList<String>();
final List<Integer> values = new ArrayList<Integer>();
- DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(executor) {
+ DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(executor, 100) {
@Override
public boolean onEviction(String key, Integer value) {
keys.add(key);
@@ -132,15 +132,15 @@ public class DefaultTimeoutMapTest exten
};
assertEquals(0, map.size());
- map.put("A", 1, 500);
- map.put("B", 2, 300);
- map.put("C", 3, 400);
- map.put("D", 4, 200);
- map.put("E", 5, 400);
+ map.put("A", 1, 50);
+ map.put("B", 2, 30);
+ map.put("C", 3, 40);
+ map.put("D", 4, 20);
+ map.put("E", 5, 40);
// is not expired
- map.put("F", 6, 8000);
+ map.put("F", 6, 800);
- Thread.sleep(1500);
+ Thread.sleep(250);
// force purge
map.purge();
@@ -163,7 +163,7 @@ public class DefaultTimeoutMapTest exten
final List<String> keys = new ArrayList<String>();
final List<Integer> values = new ArrayList<Integer>();
- DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(executor) {
+ DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(executor, 100) {
@Override
public boolean onEviction(String key, Integer value) {
// do not evict special key
@@ -177,12 +177,12 @@ public class DefaultTimeoutMapTest exten
};
assertEquals(0, map.size());
- map.put("A", 1, 900);
- map.put("B", 2, 1000);
- map.put("gold", 9, 1100);
- map.put("C", 3, 1200);
+ map.put("A", 1, 90);
+ map.put("B", 2, 100);
+ map.put("gold", 9, 110);
+ map.put("C", 3, 120);
- Thread.sleep(2000);
+ Thread.sleep(250);
// force purge
map.purge();
@@ -200,25 +200,24 @@ public class DefaultTimeoutMapTest exten
}
public void testDefaultTimeoutMapStopStart() throws Exception {
- DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(executor);
- map.put("A", 1, 5000);
+ DefaultTimeoutMap<String, Integer> map = new DefaultTimeoutMap<String, Integer>(executor, 100);
+ map.put("A", 1, 500);
assertEquals(1, map.size());
map.stop();
assertEquals(0, map.size());
- map.put("A", 1, 500);
+ map.put("A", 1, 50);
// should not timeout as the scheduler doesn't run
-
- Thread.sleep(1000);
+ Thread.sleep(250);
assertEquals(1, map.size());
// start
map.start();
// start and wait for scheduler to purge
- Thread.sleep(2000);
+ Thread.sleep(250);
// now it should be gone
assertEquals(0, map.size());
}