Author: davsclaus
Date: Fri Dec  5 06:40:57 2008
New Revision: 723743

URL: http://svn.apache.org/viewvc?rev=723743&view=rev
Log:
CAMEL-1099, CAMEL-1144 added more unit tests

Added:
    
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentTrunkStoreTest.java
      - copied, changed from r723657, 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentConsumerTest.java
Modified:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/MemoryIdempotentRepository.java
    
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategyTest.java

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java?rev=723743&r1=723742&r2=723743&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
 Fri Dec  5 06:40:57 2008
@@ -61,7 +61,7 @@
      *
      * @param fileStore  the file store
      */
-    public static IdempotentRepository fileIdempotentRepository(File 
fileStore) {
+    public static IdempotentRepository<String> fileIdempotentRepository(File 
fileStore) {
         return fileIdempotentRepository(fileStore, 1000);
     }
 
@@ -72,7 +72,7 @@
      * @param fileStore  the file store
      * @param cacheSize  the cache size
      */
-    public static IdempotentRepository fileIdempotentRepository(File 
fileStore, int cacheSize) {
+    public static IdempotentRepository<String> fileIdempotentRepository(File 
fileStore, int cacheSize) {
         return fileIdempotentRepository(fileStore, new LRUCache<String, 
Object>(cacheSize));
     }
 
@@ -84,7 +84,7 @@
      * @param cacheSize  the cache size
      * @param maxFileStoreSize  the max size in bytes for the filestore file 
      */
-    public static IdempotentRepository fileIdempotentRepository(File 
fileStore, int cacheSize, long maxFileStoreSize) {
+    public static IdempotentRepository<String> fileIdempotentRepository(File 
fileStore, int cacheSize, long maxFileStoreSize) {
         FileIdempotentRepository repository = new 
FileIdempotentRepository(fileStore, new LRUCache<String, Object>(cacheSize));
         repository.setMaxFileStoreSize(maxFileStoreSize);
         return repository;
@@ -100,7 +100,7 @@
      * @param store  the file store
      * @param cache  the cache to use as 1st level cache
      */
-    public static IdempotentRepository fileIdempotentRepository(File store, 
Map<String, Object> cache) {
+    public static IdempotentRepository<String> fileIdempotentRepository(File 
store, Map<String, Object> cache) {
         return new FileIdempotentRepository(store, cache);
     }
 
@@ -208,8 +208,8 @@
      * to the file store.
      */
     protected void trunkStore() {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Trunking idempotent filestore: " + fileStore);
+        if (LOG.isInfoEnabled()) {
+            LOG.info("Trunking idempotent filestore: " + fileStore);
         }
         FileOutputStream fos = null;
         try {

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/MemoryIdempotentRepository.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/MemoryIdempotentRepository.java?rev=723743&r1=723742&r2=723743&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/MemoryIdempotentRepository.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/idempotent/MemoryIdempotentRepository.java
 Fri Dec  5 06:40:57 2008
@@ -45,7 +45,7 @@
      * Creates a new memory based repository using a [EMAIL PROTECTED] 
LRUCache}
      * with a default of 1000 entries in the cache.
      */
-    public static IdempotentRepository memoryIdempotentRepository() {
+    public static IdempotentRepository<String> memoryIdempotentRepository() {
         return new MemoryIdempotentRepository();
     }
 
@@ -54,7 +54,7 @@
      *
      * @param cacheSize  the cache size
      */
-    public static IdempotentRepository memoryIdempotentRepository(int 
cacheSize) {
+    public static IdempotentRepository<String> memoryIdempotentRepository(int 
cacheSize) {
         return memoryIdempotentRepository(new LRUCache<String, 
Object>(cacheSize));
     }
 
@@ -67,7 +67,7 @@
      *
      * @param cache  the cache
      */
-    public static IdempotentRepository memoryIdempotentRepository(Map<String, 
Object> cache) {
+    public static IdempotentRepository<String> 
memoryIdempotentRepository(Map<String, Object> cache) {
         return new MemoryIdempotentRepository(cache);
     }
 

Copied: 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentTrunkStoreTest.java
 (from r723657, 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentConsumerTest.java)
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentTrunkStoreTest.java?p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentTrunkStoreTest.java&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentConsumerTest.java&r1=723657&r2=723743&rev=723743&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentConsumerTest.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentTrunkStoreTest.java
 Fri Dec  5 06:40:57 2008
@@ -31,34 +31,45 @@
 /**
  * @version $Revision$
  */
-public class FileIdempotentConsumerTest extends ContextTestSupport {
+public class FileIdempotentTrunkStoreTest extends ContextTestSupport {
     protected Endpoint startEndpoint;
     protected MockEndpoint resultEndpoint;
     private File store = new File("target/idempotentfilestore.dat");
-    private IdempotentRepository repo;
+    private IdempotentRepository<String> repo;
 
-    public void testDuplicateMessagesAreFilteredOut() throws Exception {
-        assertFalse(repo.contains("1"));
-        assertFalse(repo.contains("2"));
-        assertFalse(repo.contains("3"));
-        assertTrue(repo.contains("4"));
-
-        resultEndpoint.expectedBodiesReceived("one", "two", "three");
-
-        sendMessage("1", "one");
-        sendMessage("2", "two");
-        sendMessage("1", "one");
-        sendMessage("2", "two");
-        sendMessage("4", "four");
-        sendMessage("1", "one");
-        sendMessage("3", "three");
+    public void testTrunkFileStore() throws Exception {
+        resultEndpoint.expectedBodiesReceived("A", "B", "C", "D", "E");
+
+        sendMessage("AAAAAAAAAA", "A");
+        sendMessage("BBBBBBBBBB", "B");
+        sendMessage("CCCCCCCCCC", "C");
+        sendMessage("AAAAAAAAAA", "A");
+        sendMessage("DDDDDDDDDD", "D");
+        sendMessage("BBBBBBBBBB", "B");
+        sendMessage("EEEEEEEEEE", "E");
 
         resultEndpoint.assertIsSatisfied();
+        resultEndpoint.reset();
+        resultEndpoint.expectedBodiesReceived("Z", "X");
+
+        // should trunk the file store
+        sendMessage("ZZZZZZZZZZ", "Z");
+
+        // load in new store and verify we only have the last 5 elements
+        IdempotentRepository<String> repo2 = 
FileIdempotentRepository.fileIdempotentRepository(store);
+        assertFalse(repo2.contains("AAAAAAAAAA"));
+        assertTrue(repo2.contains("BBBBBBBBBB"));
+        assertTrue(repo2.contains("CCCCCCCCCC"));
+        assertTrue(repo2.contains("DDDDDDDDDD"));
+        assertTrue(repo2.contains("EEEEEEEEEE"));
+        assertTrue(repo2.contains("ZZZZZZZZZZ"));
 
-        assertTrue(repo.contains("1"));
-        assertTrue(repo.contains("2"));
-        assertTrue(repo.contains("3"));
-        assertTrue(repo.contains("4"));
+        // should trunk the file store
+        sendMessage("XXXXXXXXXX", "X");
+
+        resultEndpoint.assertIsSatisfied();
+        assertFalse(repo.contains("BBBBBBBBBB"));
+        assertTrue(repo.contains("XXXXXXXXXX"));
     }
 
     protected void sendMessage(final Object messageId, final Object body) {
@@ -79,10 +90,8 @@
             store.delete();
         }
 
-        repo = FileIdempotentRepository.fileIdempotentRepository(store);
-
-        // let's add 4 to start with
-        repo.add("4");
+        // 5 elements in cache, and 50 bytes as max size limit for when 
trunking should start
+        repo = FileIdempotentRepository.fileIdempotentRepository(store, 5, 50);
 
         super.setUp();
         startEndpoint = resolveMandatoryEndpoint("direct:start");

Modified: 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategyTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategyTest.java?rev=723743&r1=723742&r2=723743&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategyTest.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategyTest.java
 Fri Dec  5 06:40:57 2008
@@ -19,14 +19,15 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.ConnectException;
+import java.net.MalformedURLException;
 import java.net.SocketException;
 import java.util.HashMap;
 
 import junit.framework.TestCase;
-
 import org.apache.camel.AlreadyStoppedException;
 import org.apache.camel.CamelExchangeException;
 import org.apache.camel.ExchangeTimedOutException;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.ValidationException;
 import org.apache.camel.model.ExceptionType;
 
@@ -62,6 +63,17 @@
         policies.put(ExceptionPolicyKey.newInstance(IOException.class), type3);
     }
 
+    private void setupPoliciesCausedBy() {
+        strategy = new DefaultExceptionPolicyStrategy();
+        policies = new HashMap<ExceptionPolicyKey, ExceptionType>();
+        type1 = new ExceptionType(FileNotFoundException.class);
+        type2 = new ExceptionType(ConnectException.class);
+        type3 = new ExceptionType(IOException.class);
+        
policies.put(ExceptionPolicyKey.newInstance(FileNotFoundException.class), 
type1);
+        policies.put(ExceptionPolicyKey.newInstance(IOException.class), type2);
+        policies.put(ExceptionPolicyKey.newInstance(ConnectException.class), 
type3);
+    }
+
     public void testDirectMatch1() {
         setupPolicies();
         ExceptionType result = strategy.getExceptionPolicy(policies, null, new 
CamelExchangeException("", null));
@@ -125,4 +137,40 @@
         assertNull("Should not find an exception policy to use", result);
     }
 
+    public void testCausedBy() {
+        setupPoliciesCausedBy();
+
+        IOException ioe = new IOException("Damm");
+        ioe.initCause(new FileNotFoundException("Somefile not found"));
+        ExceptionType result = strategy.getExceptionPolicy(policies, null, 
ioe);
+        assertEquals(type1, result);
+    }
+
+    public void testCausedByWrapped() {
+        setupPoliciesCausedBy();
+
+        IOException ioe = new IOException("Damm");
+        ioe.initCause(new FileNotFoundException("Somefile not found"));
+        ExceptionType result = strategy.getExceptionPolicy(policies, null, new 
RuntimeCamelException(ioe));
+        assertEquals(type1, result);
+    }
+
+    public void testCausedByNotConnected() {
+        setupPoliciesCausedBy();
+
+        IOException ioe = new IOException("Damm");
+        ioe.initCause(new ConnectException("Not connected"));
+        ExceptionType result = strategy.getExceptionPolicy(policies, null, 
ioe);
+        assertEquals(type3, result);
+    }
+
+    public void testCausedByOtherIO() {
+        setupPoliciesCausedBy();
+
+        IOException ioe = new IOException("Damm");
+        ioe.initCause(new MalformedURLException("Bad url"));
+        ExceptionType result = strategy.getExceptionPolicy(policies, null, 
ioe);
+        assertEquals(type2, result);
+    }
+
 }


Reply via email to