Author: davsclaus
Date: Fri Apr  1 08:10:22 2011
New Revision: 1087620

URL: http://svn.apache.org/viewvc?rev=1087620&view=rev
Log:
CAMEL-3826: Added test.

Added:
    
camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/BigPayload.java
    
camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBBigPayloadTest.java
Modified:
    
camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBAggregationRepository.java

Modified: 
camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBAggregationRepository.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBAggregationRepository.java?rev=1087620&r1=1087619&r2=1087620&view=diff
==============================================================================
--- 
camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBAggregationRepository.java
 (original)
+++ 
camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBAggregationRepository.java
 Fri Apr  1 08:10:22 2011
@@ -114,7 +114,9 @@ public class HawtDBAggregationRepository
             Buffer rc = hawtDBFile.execute(new Work<Buffer>() {
                 public Buffer execute(Transaction tx) {
                     SortedIndex<Buffer, Buffer> index = 
hawtDBFile.getRepositoryIndex(tx, repositoryName, true);
-                    return index.put(keyBuffer, exchangeBuffer);
+                    Buffer buffer = index.put(keyBuffer, exchangeBuffer);
+                    LOG.trace("Added key index {}", keyBuffer);
+                    return buffer;
                 }
 
                 @Override
@@ -147,7 +149,9 @@ public class HawtDBAggregationRepository
                     if (index == null) {
                         return null;
                     }
-                    return index.get(keyBuffer);
+                    Buffer buffer = index.get(keyBuffer);
+                    LOG.trace("Getting key index {}", keyBuffer);
+                    return buffer;
                 }
 
                 @Override
@@ -180,11 +184,13 @@ public class HawtDBAggregationRepository
                 public Buffer execute(Transaction tx) {
                     SortedIndex<Buffer, Buffer> index = 
hawtDBFile.getRepositoryIndex(tx, repositoryName, true);
                     // remove from the in progress index
-                    index.remove(keyBuffer);
+                    Buffer buffer = index.remove(keyBuffer);
+                    LOG.trace("Removed key index {} -> {}", keyBuffer, buffer);
 
                     // and add it to the confirmed index
                     SortedIndex<Buffer, Buffer> indexCompleted = 
hawtDBFile.getRepositoryIndex(tx, getRepositoryNameCompleted(), true);
                     indexCompleted.put(confirmKeyBuffer, exchangeBuffer);
+                    LOG.trace("Added confirm index {}", confirmKeyBuffer);
                     return null;
                 }
 
@@ -208,7 +214,9 @@ public class HawtDBAggregationRepository
             hawtDBFile.execute(new Work<Buffer>() {
                 public Buffer execute(Transaction tx) {
                     SortedIndex<Buffer, Buffer> indexCompleted = 
hawtDBFile.getRepositoryIndex(tx, getRepositoryNameCompleted(), true);
-                    return indexCompleted.remove(confirmKeyBuffer);
+                    Buffer buffer = indexCompleted.remove(confirmKeyBuffer);
+                    LOG.trace("Removed confirm index {} -> {}", 
confirmKeyBuffer, buffer);
+                    return buffer;
                 }
 
                 @Override

Added: 
camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/BigPayload.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/BigPayload.java?rev=1087620&view=auto
==============================================================================
--- 
camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/BigPayload.java
 (added)
+++ 
camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/BigPayload.java
 Fri Apr  1 08:10:22 2011
@@ -0,0 +1,34 @@
+/**
+ * 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.hawtdb;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Handler;
+
+/**
+ * a 3mb payload
+ */
+public class BigPayload {
+
+    private int bodySize = 3 * 1024 * 1024;
+
+    @Handler
+    public void process(Exchange exchange) {
+        exchange.getIn().setBody(new byte[bodySize]);
+    }
+
+}

Added: 
camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBBigPayloadTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBBigPayloadTest.java?rev=1087620&view=auto
==============================================================================
--- 
camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBBigPayloadTest.java
 (added)
+++ 
camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBBigPayloadTest.java
 Fri Apr  1 08:10:22 2011
@@ -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.hawtdb;
+
+import java.io.File;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Test issue with hawtdb file store not growing large
+ */
+@Ignore("Work in progress")
+public class HawtDBBigPayloadTest extends CamelTestSupport {
+
+    private static final long TIME = 60 * 1000;
+    private static final AtomicLong NUMBER = new AtomicLong();
+    private HawtDBAggregationRepository repo;
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        deleteDirectory("target/data");
+        repo = new HawtDBAggregationRepository("repo1", 
"target/data/hawtdb.dat");
+        super.setUp();
+    }
+
+    @Test
+    public void testBigPayload() throws Exception {
+
+        log.info("Running test for " + TIME + " millis.");
+        Thread.sleep(60 * 1000);
+
+        // assert the file size of the repo is not big < 32mb
+        File file = new File("target/data/hawtdb.dat");
+        assertTrue(file + " should exists", file.exists());
+        long size = file.length();
+        log.info(file + " size is " + size);
+        assertTrue(file + " should not be so big in size, was: " + size, size 
< 32 * 1024 * 1024);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("timer:foo")
+                    .bean(BigPayload.class)
+                    .aggregate(bean(HawtDBBigPayloadTest.class, "number"), new 
UseLatestAggregationStrategy())
+                        .aggregationRepository(repo)
+                        .completionSize(2).completionTimeout(5000)
+                        .log("Aggregated key 
${header.CamelAggregatedCorrelationKey}");
+            }
+        };
+    }
+
+    public static long number() {
+        // return 123; (will not cause hawtdb to grow in size)
+        return NUMBER.incrementAndGet();
+    }
+
+}


Reply via email to