camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r563909 - in /activemq/camel/trunk: components/camel-bam/ components/camel-bam/src/main/java/org/apache/camel/bam/model/ components/camel-bam/src/main/java/org/apache/camel/bam/processor/ components/camel-bam/src/main/java/org/apache/camel/...
Date Wed, 08 Aug 2007 15:01:20 GMT
Author: jstrachan
Date: Wed Aug  8 08:01:19 2007
New Revision: 563909

URL: http://svn.apache.org/viewvc?view=rev&rev=563909
Log:
improved the camel-bam module to handle concurrent processing better & dealing with JDBC/JPA
exceptions if concurrent updates to the same process occur at the same time; also added more
better tests

Added:
    activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/MultipleActivitiesConcurrentlyTest.java
  (with props)
    activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/MultipleProcessesTest.java
  (with props)
    activemq/camel/trunk/components/camel-bam/src/test/profiles/derby/
    activemq/camel/trunk/components/camel-bam/src/test/profiles/derby/META-INF/
    activemq/camel/trunk/components/camel-bam/src/test/profiles/derby/META-INF/persistence.xml
      - copied, changed from r563780, activemq/camel/trunk/components/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml
Modified:
    activemq/camel/trunk/components/camel-bam/pom.xml
    activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityState.java
    activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessInstance.java
    activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/BamProcessorSupport.java
    activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessor.java
    activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessorSupport.java
    activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/rules/ActivityRules.java
    activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/BamRouteTest.java
    activemq/camel/trunk/components/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml
    activemq/camel/trunk/components/camel-bam/src/test/resources/log4j.properties
    activemq/camel/trunk/examples/camel-example-bam/src/main/resources/META-INF/persistence.xml

Modified: activemq/camel/trunk/components/camel-bam/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-bam/pom.xml?view=diff&rev=563909&r1=563908&r2=563909
==============================================================================
--- activemq/camel/trunk/components/camel-bam/pom.xml (original)
+++ activemq/camel/trunk/components/camel-bam/pom.xml Wed Aug  8 08:01:19 2007
@@ -42,35 +42,38 @@
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-spring</artifactId>
     </dependency>
-
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>commons-logging</groupId>
-      <artifactId>commons-logging-api</artifactId>
-    </dependency>
-
     <dependency>
       <groupId>javax.persistence</groupId>
       <artifactId>persistence-api</artifactId>
       <version>1.0</version>
     </dependency>
 
+    <!-- testing -->
     <dependency>
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-core</artifactId>
       <type>test-jar</type>
-      <optional>true</optional>
       <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-spring</artifactId>
       <type>test-jar</type>
-      <optional>true</optional>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-juel</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
       <scope>test</scope>
     </dependency>
     <!--
@@ -88,12 +91,6 @@
         </dependency>
     -->
 
-    <dependency>
-      <groupId>mysql</groupId>
-      <artifactId>mysql-connector-java</artifactId>
-      <version>5.0.5</version>
-      <scope>test</scope>
-    </dependency>
 
     <dependency>
       <groupId>junit</groupId>
@@ -110,6 +107,7 @@
         <configuration>
           <childDelegation>false</childDelegation>
           <useFile>true</useFile>
+          <forkMode>pertest</forkMode>
           <includes>
             <include>**/*Test.*</include>
           </includes>
@@ -163,6 +161,41 @@
         </dependency>
       </dependencies>
     </profile>
+    <profile>
+      <id>derby</id>
+      <build>
+        <testResources>
+          <testResource>
+            <directory>${basedir}/src/test/profiles/derby</directory>
+          </testResource>
+          <testResource>
+            <directory>${basedir}/src/test/resources</directory>
+          </testResource>
+        </testResources>
+      </build>
+      <dependencies>
+        <dependency>
+          <groupId>org.hibernate</groupId>
+          <artifactId>hibernate-entitymanager</artifactId>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
+          <groupId>org.hibernate</groupId>
+          <artifactId>hibernate</artifactId>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.derby</groupId>
+          <artifactId>derby</artifactId>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.geronimo.specs</groupId>
+          <artifactId>geronimo-jta_1.0.1B_spec</artifactId>
+          <scope>test</scope>
+        </dependency>
+      </dependencies>
+    </profile>
 
     <profile>
       <id>mysql</id>
@@ -188,8 +221,9 @@
           <scope>test</scope>
         </dependency>
         <dependency>
-          <groupId>hsqldb</groupId>
-          <artifactId>hsqldb</artifactId>
+          <groupId>mysql</groupId>
+          <artifactId>mysql-connector-java</artifactId>
+          <version>5.0.5</version>
           <scope>test</scope>
         </dependency>
         <dependency>

Modified: activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityState.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityState.java?view=diff&rev=563909&r1=563908&r2=563909
==============================================================================
--- activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityState.java
(original)
+++ activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/model/ActivityState.java
Wed Aug  8 08:01:19 2007
@@ -16,7 +16,9 @@
  */
 package org.apache.camel.bam.model;
 
-import java.util.Date;
+import org.apache.camel.bam.processor.ProcessContext;
+import org.apache.camel.bam.rules.ActivityRules;
+import org.apache.camel.util.ObjectHelper;
 
 import javax.persistence.CascadeType;
 import javax.persistence.Entity;
@@ -26,10 +28,8 @@
 import javax.persistence.ManyToOne;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
-
-import org.apache.camel.bam.processor.ProcessContext;
-import org.apache.camel.bam.rules.ActivityRules;
-import org.apache.camel.util.ObjectHelper;
+import javax.persistence.Transient;
+import java.util.Date;
 
 /**
  * The default state for a specific activity within a process
@@ -56,7 +56,7 @@
 
     @Override
     public String toString() {
-        return "ActivityState[" + getId() + " " + getActivityDefinition() + "]";
+        return "ActivityState[" + getId() + " on " + getProcessInstance() + " " + getActivityDefinition()
+ "]";
     }
 
     public synchronized void processExchange(ActivityRules activityRules, ProcessContext
context) throws Exception {
@@ -145,6 +145,15 @@
         if (timeCompleted != null) {
             setEscalationLevel(-1);
         }
+    }
+
+    @Transient
+    public String getCorrelationKey() {
+        ProcessInstance pi = getProcessInstance();
+        if (pi == null) {
+            return null;
+        }
+        return pi.getCorrelationKey();
     }
 
     // Implementation methods

Modified: activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessInstance.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessInstance.java?view=diff&rev=563909&r1=563908&r2=563909
==============================================================================
--- activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessInstance.java
(original)
+++ activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/model/ProcessInstance.java
Wed Aug  8 08:01:19 2007
@@ -19,15 +19,7 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-import javax.persistence.OneToMany;
-import javax.persistence.UniqueConstraint;
+import javax.persistence.*;
 
 import org.apache.camel.bam.rules.ActivityRules;
 import org.apache.commons.logging.Log;
@@ -39,27 +31,29 @@
  * @version $Revision: $
  */
 @Entity
-@UniqueConstraint(columnNames = {"correlationKey" })
-public class ProcessInstance extends TemporalEntity {
+public class ProcessInstance  {
     private static final transient Log LOG = LogFactory.getLog(ProcessInstance.class);
     private ProcessDefinition processDefinition;
     private Collection<ActivityState> activityStates = new HashSet<ActivityState>();
     private String correlationKey;
+    private Date timeStarted;
+    private Date timeCompleted;
 
     public ProcessInstance() {
         setTimeStarted(new Date());
     }
 
     public String toString() {
-        return getClass().getName() + "[id: " + getId() + ", key: " + getCorrelationKey()
+ "]";
+        return "ProcessInstance[" + getCorrelationKey() + "]";
     }
 
-    // This crap is required to work around a bug in hibernate
-    @Override
     @Id
-    @GeneratedValue
-    public Long getId() {
-        return super.getId();
+    public String getCorrelationKey() {
+        return correlationKey;
+    }
+
+    public void setCorrelationKey(String correlationKey) {
+        this.correlationKey = correlationKey;
     }
 
     @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST })
@@ -80,15 +74,34 @@
         this.activityStates = activityStates;
     }
 
-    public String getCorrelationKey() {
-        return correlationKey;
+
+    @Transient
+    public boolean isStarted() {
+        return timeStarted != null;
     }
 
-    public void setCorrelationKey(String correlationKey) {
-        this.correlationKey = correlationKey;
+    @Transient
+    public boolean isCompleted() {
+        return timeCompleted != null;
+    }
+
+    @Temporal(TemporalType.TIME)
+    public Date getTimeStarted() {
+        return timeStarted;
+    }
+
+    public void setTimeStarted(Date timeStarted) {
+        this.timeStarted = timeStarted;
+    }
+
+    @Temporal(TemporalType.TIME)
+    public Date getTimeCompleted() {
+        return timeCompleted;
     }
 
-    // Helper methods
+    public void setTimeCompleted(Date timeCompleted) {
+        this.timeCompleted = timeCompleted;
+    }    // Helper methods
     //-------------------------------------------------------------------------
 
     /**

Modified: activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/BamProcessorSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/BamProcessorSupport.java?view=diff&rev=563909&r1=563908&r2=563909
==============================================================================
--- activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/BamProcessorSupport.java
(original)
+++ activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/BamProcessorSupport.java
Wed Aug  8 08:01:19 2007
@@ -16,25 +16,27 @@
  */
 package org.apache.camel.bam.processor;
 
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.Processor;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.orm.jpa.JpaSystemException;
 import org.springframework.transaction.TransactionStatus;
 import org.springframework.transaction.support.TransactionCallback;
 import org.springframework.transaction.support.TransactionTemplate;
 
+import javax.persistence.EntityExistsException;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
 /**
  * A base {@link Processor} for working on <a
  * href="http://activemq.apache.org/camel/bam.html">BAM</a> which a derived
  * class would do the actual persistence such as the {@link JpaBamProcessor}
- * 
+ *
  * @version $Revision: $
  */
 public abstract class BamProcessorSupport<T> implements Processor {
@@ -42,6 +44,15 @@
     private Class<T> entityType;
     private Expression<Exchange> correlationKeyExpression;
     private TransactionTemplate transactionTemplate;
+    private int maximumRetries = 30;
+
+    public int getMaximumRetries() {
+        return maximumRetries;
+    }
+
+    public void setMaximumRetries(int maximumRetries) {
+        this.maximumRetries = maximumRetries;
+    }
 
     protected BamProcessorSupport(TransactionTemplate transactionTemplate, Expression<Exchange>
correlationKeyExpression) {
         this.transactionTemplate = transactionTemplate;
@@ -49,12 +60,12 @@
 
         Type type = getClass().getGenericSuperclass();
         if (type instanceof ParameterizedType) {
-            ParameterizedType parameterizedType = (ParameterizedType)type;
+            ParameterizedType parameterizedType = (ParameterizedType) type;
             Type[] arguments = parameterizedType.getActualTypeArguments();
             if (arguments.length > 0) {
                 Type argumentType = arguments[0];
                 if (argumentType instanceof Class) {
-                    this.entityType = (Class<T>)argumentType;
+                    this.entityType = (Class<T>) argumentType;
                 }
             }
         }
@@ -70,27 +81,46 @@
     }
 
     public void process(final Exchange exchange) {
-        transactionTemplate.execute(new TransactionCallback() {
-            public Object doInTransaction(TransactionStatus status) {
-                try {
-                    Object key = getCorrelationKey(exchange);
-
-                    T entity = loadEntity(exchange, key);
+        Object entity = null;
+        for (int i = 0; entity == null && i < maximumRetries; i++) {
+            if (i > 0) {
+                LOG.info("Retry attempt due to duplicate row: " + i);
+            }
+            entity = transactionTemplate.execute(new TransactionCallback() {
+                public Object doInTransaction(TransactionStatus status) {
+                    try {
+                        Object key = getCorrelationKey(exchange);
+
+                        T entity = loadEntity(exchange, key);
+
+                        if (LOG.isDebugEnabled()) {
+                            LOG.debug("Correlation key: " + key + " with entity: " + entity);
+                        }
+                        processEntity(exchange, entity);
 
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Correlation key: " + key + " with entity: " + entity);
+                        return entity;
                     }
-                    processEntity(exchange, entity);
-
-                    return entity;
-                } catch (Exception e) {
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Caught: " + e, e);
+                    catch (JpaSystemException e) {
+                        if (LOG.isDebugEnabled()) {
+                            LOG.debug("Likely exception is due to duplicate row in concurrent
setting: " + e, e);
+                        }
+                        LOG.info("Attempt to insert duplicate row due to concurrency issue,
so retrying: " + e);
+                        return retryDueToDuplicate(status);
+                    }
+                    catch (DataIntegrityViolationException e) {
+                        Throwable throwable = e.getCause();
+                        if (throwable instanceof EntityExistsException) {
+                            LOG.info("Attempt to insert duplicate row due to concurrency
issue, so retrying: " + throwable);
+                            return retryDueToDuplicate(status);
+                        }
+                        return onError(status, throwable);
+                    }
+                    catch (Throwable e) {
+                        return onError(status, e);
                     }
-                    throw new RuntimeCamelException(e);
                 }
-            }
-        });
+            });
+        }
     }
 
     // Properties
@@ -115,5 +145,16 @@
             throw new NoCorrelationKeyException(this, exchange);
         }
         return value;
+    }
+
+    protected Object retryDueToDuplicate(TransactionStatus status) {
+        status.setRollbackOnly();
+        return null;
+    }
+
+    protected Object onError(TransactionStatus status, Throwable e) {
+        status.setRollbackOnly();
+        LOG.error("Caught: " + e, e);
+        throw new RuntimeCamelException(e);
     }
 }

Modified: activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessor.java?view=diff&rev=563909&r1=563908&r2=563909
==============================================================================
--- activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessor.java
(original)
+++ activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessor.java
Wed Aug  8 08:01:19 2007
@@ -18,12 +18,12 @@
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
+import org.apache.camel.Processor;
 import org.apache.camel.bam.model.ActivityState;
 import org.apache.camel.bam.model.ProcessInstance;
 import org.apache.camel.bam.rules.ActivityRules;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.springframework.orm.jpa.JpaTemplate;
 import org.springframework.transaction.support.TransactionTemplate;
 

Modified: activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessorSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessorSupport.java?view=diff&rev=563909&r1=563908&r2=563909
==============================================================================
--- activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessorSupport.java
(original)
+++ activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/processor/JpaBamProcessorSupport.java
Wed Aug  8 08:01:19 2007
@@ -16,30 +16,34 @@
  */
 package org.apache.camel.bam.processor;
 
-import java.util.List;
-
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.Processor;
 import org.apache.camel.bam.model.ProcessDefinition;
 import org.apache.camel.bam.rules.ActivityRules;
 import org.apache.camel.util.IntrospectionSupport;
-
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.springframework.orm.jpa.JpaTemplate;
 import org.springframework.transaction.support.TransactionTemplate;
 
+import java.util.List;
+
 /**
  * A base class for JPA based BAM which can use any entity to store the process
  * instance information which allows derived classes to specialise the process
  * instance entity.
- * 
+ *
  * @version $Revision: $
  */
 public class JpaBamProcessorSupport<T> extends BamProcessorSupport<T> {
+    private static final transient Log LOG = LogFactory.getLog(JpaBamProcessorSupport.class);
+    
     private ActivityRules activityRules;
     private JpaTemplate template;
     private String findByKeyQuery;
     private String keyPropertyName = "correlationKey";
+    private boolean correlationKeyIsPrimary = true;
 
     public JpaBamProcessorSupport(TransactionTemplate transactionTemplate, JpaTemplate template,
Expression<Exchange> correlationKeyExpression, ActivityRules activityRules, Class<T>
entitytype) {
         super(transactionTemplate, correlationKeyExpression, entitytype);
@@ -88,24 +92,48 @@
         this.template = template;
     }
 
+    public boolean isCorrelationKeyIsPrimary() {
+        return correlationKeyIsPrimary;
+    }
+
+    public void setCorrelationKeyIsPrimary(boolean correlationKeyIsPrimary) {
+        this.correlationKeyIsPrimary = correlationKeyIsPrimary;
+    }
+
     // Implementatiom methods
     // -----------------------------------------------------------------------
     protected T loadEntity(Exchange exchange, Object key) {
-        List<T> list = template.find(getFindByKeyQuery(), key);
-        T entity = null;
-        if (!list.isEmpty()) {
-            entity = list.get(0);
-        }
+        T entity = findEntityByCorrelationKey(key);
         if (entity == null) {
             entity = createEntity(exchange, key);
             setKeyProperty(entity, key);
             ProcessDefinition definition = ProcessDefinition.getRefreshedProcessDefinition(template,
getActivityRules().getProcessRules().getProcessDefinition());
             setProcessDefinitionProperty(entity, definition);
             template.persist(entity);
+
+            // Now we must flush to avoid concurrent updates clashing trying to insert the
+            // same row
+            LOG.debug("About to flush on entity: " + entity + " with key: " + key);
+            template.flush();
         }
         return entity;
     }
 
+    protected T findEntityByCorrelationKey(Object key) {
+        if (isCorrelationKeyIsPrimary()) {
+            return template.find(getEntityType(), key);
+        }
+        else {
+            List<T> list = template.find(getFindByKeyQuery(), key);
+            if (list.isEmpty()) {
+                return null;
+            }
+            else {
+                return list.get(0);
+            }
+        }
+    }
+
     /**
      * Sets the key property on the new entity
      */
@@ -121,14 +149,15 @@
      * Create a new instance of the entity for the given key
      */
     protected T createEntity(Exchange exchange, Object key) {
-        return (T)exchange.getContext().getInjector().newInstance(getEntityType());
+        return (T) exchange.getContext().getInjector().newInstance(getEntityType());
     }
 
     protected void processEntity(Exchange exchange, T entity) throws Exception {
         if (entity instanceof Processor) {
-            Processor processor = (Processor)entity;
+            Processor processor = (Processor) entity;
             processor.process(exchange);
-        } else {
+        }
+        else {
             // TODO add other extension points - eg. passing in Activity
             throw new IllegalArgumentException("No processor defined for this route");
         }

Modified: activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/rules/ActivityRules.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/rules/ActivityRules.java?view=diff&rev=563909&r1=563908&r2=563909
==============================================================================
--- activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/rules/ActivityRules.java
(original)
+++ activemq/camel/trunk/components/camel-bam/src/main/java/org/apache/camel/bam/rules/ActivityRules.java
Wed Aug  8 08:01:19 2007
@@ -74,16 +74,6 @@
     public ActivityDefinition getActivityDefinition() {
         // lets always query for it, to avoid issues with refreshing before a commit etc
         return builder.findOrCreateActivityDefinition(activityName);
-/*
-        if (activityDefinition == null) {
-            activityDefinition = builder.findOrCreateActivityDefinition(activityName);
-        }
-        else {
-            // lets refresh it
-            builder.getJpaTemplate().refresh(activityDefinition);
-        }
-        return activityDefinition;
-*/
     }
 
     public void setActivityDefinition(ActivityDefinition activityDefinition) {

Modified: activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/BamRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/BamRouteTest.java?view=diff&rev=563909&r1=563908&r2=563909
==============================================================================
--- activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/BamRouteTest.java
(original)
+++ activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/BamRouteTest.java
Wed Aug  8 08:01:19 2007
@@ -17,28 +17,26 @@
 package org.apache.camel.bam;
 
 import org.apache.camel.builder.RouteBuilder;
+import static org.apache.camel.builder.xml.XPathBuilder.xpath;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.spring.SpringTestSupport;
-
+import static org.apache.camel.util.Time.seconds;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.orm.jpa.JpaTemplate;
 import org.springframework.transaction.support.TransactionTemplate;
 
-import static org.apache.camel.builder.xml.XPathBuilder.xpath;
-import static org.apache.camel.util.Time.seconds;
-
 /**
  * @version $Revision: $
  */
 public class BamRouteTest extends SpringTestSupport {
+    protected MockEndpoint overdueEndpoint;
 
-    public void testSendingToFirstActivityOnlyResultsInOverdueMessage() throws Exception
{
-        MockEndpoint overdueEndpoint = resolveMandatoryEndpoint("mock:overdue", MockEndpoint.class);
+    public void testBam() throws Exception {
         overdueEndpoint.expectedMessageCount(1);
 
         template.sendBody("direct:a", "<hello id='123'>world!</hello>");
 
-        overdueEndpoint.assertIsSatisfied(5000);
+        overdueEndpoint.assertIsSatisfied();
     }
 
     protected ClassPathXmlApplicationContext createApplicationContext() {
@@ -48,7 +46,11 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
+
         camelContext.addRoutes(createRouteBuilder());
+
+        overdueEndpoint = resolveMandatoryEndpoint("mock:overdue", MockEndpoint.class);
+        overdueEndpoint.setDefaulResultWaitMillis(8000);
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {

Added: activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/MultipleActivitiesConcurrentlyTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/MultipleActivitiesConcurrentlyTest.java?view=auto&rev=563909
==============================================================================
--- activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/MultipleActivitiesConcurrentlyTest.java
(added)
+++ activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/MultipleActivitiesConcurrentlyTest.java
Wed Aug  8 08:01:19 2007
@@ -0,0 +1,43 @@
+/**
+ *
+ * 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.bam;
+
+import static org.apache.camel.language.juel.JuelExpression.el;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class MultipleActivitiesConcurrentlyTest extends MultipleProcessesTest {
+
+    @Override
+    public void testBam() throws Exception {
+        overdueEndpoint.expectedMessageCount(1);
+        overdueEndpoint.message(0).predicate(el("${in.body.correlationKey == '124'}"));
+
+        Thread thread = new Thread("B sender") {
+            public void run() {
+                sendBMessages();
+            }
+        };
+        thread.start();
+
+        sendAMessages();
+
+        overdueEndpoint.assertIsSatisfied();
+    }
+}

Propchange: activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/MultipleActivitiesConcurrentlyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/MultipleProcessesTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/MultipleProcessesTest.java?view=auto&rev=563909
==============================================================================
--- activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/MultipleProcessesTest.java
(added)
+++ activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/MultipleProcessesTest.java
Wed Aug  8 08:01:19 2007
@@ -0,0 +1,48 @@
+/**
+ *
+ * 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.bam;
+
+import static org.apache.camel.language.juel.JuelExpression.el;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class MultipleProcessesTest extends BamRouteTest {
+
+    @Override
+    public void testBam() throws Exception {
+        overdueEndpoint.expectedMessageCount(1);
+        overdueEndpoint.message(0).predicate(el("${in.body.correlationKey == '124'}"));
+
+        sendAMessages();
+        sendBMessages();
+
+        overdueEndpoint.assertIsSatisfied();
+    }
+
+    protected void sendAMessages() {
+        template.sendBody("direct:a", "<hello id='123'>A</hello>");
+        template.sendBody("direct:a", "<hello id='124'>B</hello>");
+        template.sendBody("direct:a", "<hello id='125'>C</hello>");
+    }
+
+    protected void sendBMessages() {
+        template.sendBody("direct:b", "<hello id='123'>A</hello>");
+        template.sendBody("direct:b", "<hello id='125'>C</hello>");
+    }
+}

Propchange: activemq/camel/trunk/components/camel-bam/src/test/java/org/apache/camel/bam/MultipleProcessesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: activemq/camel/trunk/components/camel-bam/src/test/profiles/derby/META-INF/persistence.xml
(from r563780, activemq/camel/trunk/components/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-bam/src/test/profiles/derby/META-INF/persistence.xml?view=diff&rev=563909&p1=activemq/camel/trunk/components/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml&r1=563780&p2=activemq/camel/trunk/components/camel-bam/src/test/profiles/derby/META-INF/persistence.xml&r2=563909
==============================================================================
--- activemq/camel/trunk/components/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml
(original)
+++ activemq/camel/trunk/components/camel-bam/src/test/profiles/derby/META-INF/persistence.xml
Wed Aug  8 08:01:19 2007
@@ -25,9 +25,9 @@
     <class>org.apache.camel.bam.model.ProcessInstance</class>
 
     <properties>
-      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
-      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
-      <property name="hibernate.connection.url" value="jdbc:mysql://localhost/camel_bam?relaxAutoCommit=true"/>
+      <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
+      <property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver"/>
+      <property name="hibernate.connection.url" value="jdbc:derby:target/test/database;create=true"/>
       <property name="hibernate.hbm2ddl.auto" value="create"/>
     </properties>
 

Modified: activemq/camel/trunk/components/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml?view=diff&rev=563909&r1=563908&r2=563909
==============================================================================
--- activemq/camel/trunk/components/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml
(original)
+++ activemq/camel/trunk/components/camel-bam/src/test/profiles/mysql/META-INF/persistence.xml
Wed Aug  8 08:01:19 2007
@@ -28,6 +28,11 @@
       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
       <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
       <property name="hibernate.connection.url" value="jdbc:mysql://localhost/camel_bam?relaxAutoCommit=true"/>
+
+      <!-- TODO change to correct user -->
+      <property name="hibernate.connection.username" value="jstrachan"/>
+      <!--<property name="hibernate.connection.password" value=""/>-->
+
       <property name="hibernate.hbm2ddl.auto" value="create"/>
     </properties>
 

Modified: activemq/camel/trunk/components/camel-bam/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-bam/src/test/resources/log4j.properties?view=diff&rev=563909&r1=563908&r2=563909
==============================================================================
--- activemq/camel/trunk/components/camel-bam/src/test/resources/log4j.properties (original)
+++ activemq/camel/trunk/components/camel-bam/src/test/resources/log4j.properties Wed Aug
 8 08:01:19 2007
@@ -18,12 +18,13 @@
 #
 # The logging properties used for eclipse testing, We want to see debug output on the console.
 #
-log4j.rootLogger=INFO, out
+log4j.rootLogger=DEBUG, out
 
-#log4j.logger.org.apache.activemq=DEBUG
+# uncomment the next line to debug Camel
 log4j.logger.org.apache.camel=DEBUG
-log4j.logger.org.springframework=WARN
-log4j.logger.org.hibernate=WARN
+
+#log4j.logger.org.springframework=WARN
+#log4j.logger.org.hibernate=WARN
 
 # CONSOLE appender not used by default
 log4j.appender.out=org.apache.log4j.ConsoleAppender

Modified: activemq/camel/trunk/examples/camel-example-bam/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-bam/src/main/resources/META-INF/persistence.xml?view=diff&rev=563909&r1=563908&r2=563909
==============================================================================
--- activemq/camel/trunk/examples/camel-example-bam/src/main/resources/META-INF/persistence.xml
(original)
+++ activemq/camel/trunk/examples/camel-example-bam/src/main/resources/META-INF/persistence.xml
Wed Aug  8 08:01:19 2007
@@ -31,6 +31,12 @@
       <property name="hibernate.connection.password" value=""/>
       <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:camel_bam"/>
       <property name="hibernate.hbm2ddl.auto" value="create"/>
+
+      <!-- debugging flags -->
+<!--
+      <property name="hibernate.show_sql" value="true"/>
+      <property name="hibernate.format_sql" value="true"/>
+-->
     </properties>
 
   </persistence-unit>



Mime
View raw message