camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/4] camel git commit: CAMEL-8526: Add more EIP as specialized mbeans
Date Sat, 25 Jul 2015 08:11:20 GMT
CAMEL-8526: Add more EIP as specialized mbeans


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

Branch: refs/heads/master
Commit: 7563d570eef6b019a63bfef404ddf61f1f844e8e
Parents: c744d59
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Jul 25 10:14:29 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Jul 25 10:18:17 2015 +0200

----------------------------------------------------------------------
 .../mbean/ManagedRandomLoadBalancerMBean.java   |  3 +++
 .../ManagedRoundRobinLoadBalancerMBean.java     |  3 +++
 .../mbean/ManagedStickyLoadBalancerMBean.java   |  3 +++
 .../mbean/ManagedWeightedBalancerMBean.java     |  3 +++
 .../mbean/ManagedRandomLoadBalancer.java        | 20 ++++++++++++++++++++
 .../mbean/ManagedRoundRobinLoadBalancer.java    | 19 +++++++++++++++++++
 .../mbean/ManagedStickyLoadBalancer.java        | 15 +++++++++++++++
 .../mbean/ManagedWeightedLoadBalancer.java      | 15 +++++++++++++++
 .../loadbalancer/RandomLoadBalancer.java        |  7 ++++++-
 .../loadbalancer/RoundRobinLoadBalancer.java    |  4 ++++
 .../loadbalancer/StickyLoadBalancer.java        | 19 +++++++++----------
 .../loadbalancer/WeightedLoadBalancer.java      |  6 ++++++
 .../WeightedRandomLoadBalancer.java             |  7 ++++---
 .../WeightedRoundRobinLoadBalancer.java         |  2 ++
 .../ManagedRandomLoadBalancerTest.java          |  7 ++++++-
 .../ManagedRoundRobinLoadBalancerTest.java      | 17 ++++++++++++++++-
 .../ManagedStickyLoadBalancerTest.java          | 14 ++++++++++++--
 .../ManagedWeightedLoadBalancerTest.java        | 18 +++++++++++++++++-
 18 files changed, 163 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRandomLoadBalancerMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRandomLoadBalancerMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRandomLoadBalancerMBean.java
index 5242e89..da2e90b 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRandomLoadBalancerMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRandomLoadBalancerMBean.java
@@ -23,4 +23,7 @@ public interface ManagedRandomLoadBalancerMBean extends ManagedProcessorMBean
{
     @ManagedAttribute(description = "Number of processors in the load balancer")
     Integer getSize();
 
+    @ManagedAttribute(description = "Processor id of the last chosen processor")
+    String getLastChosenProcessorId();
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRoundRobinLoadBalancerMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRoundRobinLoadBalancerMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRoundRobinLoadBalancerMBean.java
index 1d57ea4..e7877b2 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRoundRobinLoadBalancerMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRoundRobinLoadBalancerMBean.java
@@ -23,4 +23,7 @@ public interface ManagedRoundRobinLoadBalancerMBean extends ManagedProcessorMBea
     @ManagedAttribute(description = "Number of processors in the load balancer")
     Integer getSize();
 
+    @ManagedAttribute(description = "Processor id of the last chosen processor")
+    String getLastChosenProcessorId();
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedStickyLoadBalancerMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedStickyLoadBalancerMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedStickyLoadBalancerMBean.java
index b2bff85..b0d6c7a 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedStickyLoadBalancerMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedStickyLoadBalancerMBean.java
@@ -29,4 +29,7 @@ public interface ManagedStickyLoadBalancerMBean extends ManagedProcessorMBean
{
     @ManagedAttribute(description = "Number of processors in the load balancer")
     Integer getSize();
 
+    @ManagedAttribute(description = "Processor id of the last chosen processor")
+    String getLastChosenProcessorId();
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedWeightedBalancerMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedWeightedBalancerMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedWeightedBalancerMBean.java
index 2671126..b34530c 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedWeightedBalancerMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedWeightedBalancerMBean.java
@@ -32,4 +32,7 @@ public interface ManagedWeightedBalancerMBean extends ManagedProcessorMBean
{
     @ManagedAttribute(description = "The delimiter")
     String getDistributionRatioDelimiter();
 
+    @ManagedAttribute(description = "Processor id of the last chosen processor")
+    String getLastChosenProcessorId();
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRandomLoadBalancer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRandomLoadBalancer.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRandomLoadBalancer.java
index a5f6d98..17f3c66 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRandomLoadBalancer.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRandomLoadBalancer.java
@@ -20,6 +20,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.api.management.mbean.ManagedRandomLoadBalancerMBean;
 import org.apache.camel.model.LoadBalanceDefinition;
+import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.processor.loadbalancer.RandomLoadBalancer;
 
 /**
@@ -35,7 +36,26 @@ public class ManagedRandomLoadBalancer extends ManagedProcessor implements
Manag
     }
 
     @Override
+    public LoadBalanceDefinition getDefinition() {
+        return (LoadBalanceDefinition) super.getDefinition();
+    }
+
+    @Override
     public Integer getSize() {
         return processor.getProcessors().size();
     }
+
+    @Override
+    public String getLastChosenProcessorId() {
+        int idx = processor.getLastChosenProcessorIndex();
+        if (idx != -1) {
+            LoadBalanceDefinition def = getDefinition();
+            ProcessorDefinition<?> output = def.getOutputs().get(idx);
+            if (output != null) {
+                return output.getId();
+            }
+        }
+        return null;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoundRobinLoadBalancer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoundRobinLoadBalancer.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoundRobinLoadBalancer.java
index c8de3fe..369c782 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoundRobinLoadBalancer.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoundRobinLoadBalancer.java
@@ -20,6 +20,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.api.management.mbean.ManagedRoundRobinLoadBalancerMBean;
 import org.apache.camel.model.LoadBalanceDefinition;
+import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.processor.loadbalancer.RoundRobinLoadBalancer;
 
 /**
@@ -35,7 +36,25 @@ public class ManagedRoundRobinLoadBalancer extends ManagedProcessor implements
M
     }
 
     @Override
+    public LoadBalanceDefinition getDefinition() {
+        return (LoadBalanceDefinition) super.getDefinition();
+    }
+
+    @Override
     public Integer getSize() {
         return processor.getProcessors().size();
     }
+
+    @Override
+    public String getLastChosenProcessorId() {
+        int idx = processor.getLastChosenProcessorIndex();
+        if (idx != -1) {
+            LoadBalanceDefinition def = getDefinition();
+            ProcessorDefinition<?> output = def.getOutputs().get(idx);
+            if (output != null) {
+                return output.getId();
+            }
+        }
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedStickyLoadBalancer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedStickyLoadBalancer.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedStickyLoadBalancer.java
index 0835aa7..a073165 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedStickyLoadBalancer.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedStickyLoadBalancer.java
@@ -20,6 +20,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.api.management.mbean.ManagedStickyLoadBalancerMBean;
 import org.apache.camel.model.LoadBalanceDefinition;
+import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.model.loadbalancer.StickyLoadBalancerDefinition;
 import org.apache.camel.processor.loadbalancer.StickyLoadBalancer;
 
@@ -56,4 +57,18 @@ public class ManagedStickyLoadBalancer extends ManagedProcessor implements
Manag
     public Integer getSize() {
         return processor.getProcessors().size();
     }
+
+    @Override
+    public String getLastChosenProcessorId() {
+        int idx = processor.getLastChosenProcessorIndex();
+        if (idx != -1) {
+            LoadBalanceDefinition def = getDefinition();
+            ProcessorDefinition<?> output = def.getOutputs().get(idx);
+            if (output != null) {
+                return output.getId();
+            }
+        }
+        return null;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedWeightedLoadBalancer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedWeightedLoadBalancer.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedWeightedLoadBalancer.java
index 1420be9..ca0bb69 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedWeightedLoadBalancer.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedWeightedLoadBalancer.java
@@ -20,6 +20,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.api.management.mbean.ManagedWeightedBalancerMBean;
 import org.apache.camel.model.LoadBalanceDefinition;
+import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.model.loadbalancer.WeightedLoadBalancerDefinition;
 import org.apache.camel.processor.loadbalancer.WeightedLoadBalancer;
 
@@ -74,4 +75,18 @@ public class ManagedWeightedLoadBalancer extends ManagedProcessor implements
Man
             return null;
         }
     }
+
+    @Override
+    public String getLastChosenProcessorId() {
+        int idx = processor.getLastChosenProcessorIndex();
+        if (idx != -1) {
+            LoadBalanceDefinition def = getDefinition();
+            ProcessorDefinition<?> output = def.getOutputs().get(idx);
+            if (output != null) {
+                return output.getId();
+            }
+        }
+        return null;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/RandomLoadBalancer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/RandomLoadBalancer.java
b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/RandomLoadBalancer.java
index 9771c67..2dbb729 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/RandomLoadBalancer.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/RandomLoadBalancer.java
@@ -30,6 +30,7 @@ import org.apache.camel.Processor;
 public class RandomLoadBalancer extends QueueLoadBalancer {
 
     private static final Random RANDOM = new Random();
+    private transient int index;
 
     protected synchronized Processor chooseProcessor(List<Processor> processors, Exchange
exchange) {
         int size = processors.size();
@@ -41,10 +42,14 @@ public class RandomLoadBalancer extends QueueLoadBalancer {
         }
 
         // pick a random
-        int index = RANDOM.nextInt(size);
+        index = RANDOM.nextInt(size);
         return processors.get(index);
     }
 
+    public int getLastChosenProcessorIndex() {
+        return index;
+    }
+
     public String toString() {
         return "RandomLoadBalancer";
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/RoundRobinLoadBalancer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/RoundRobinLoadBalancer.java
b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/RoundRobinLoadBalancer.java
index b20f434..644f371 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/RoundRobinLoadBalancer.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/RoundRobinLoadBalancer.java
@@ -37,6 +37,10 @@ public class RoundRobinLoadBalancer extends QueueLoadBalancer {
         return processors.get(counter);
     }
 
+    public int getLastChosenProcessorIndex() {
+        return counter;
+    }
+
     public String toString() {
         return "RoundRobinLoadBalancer";
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/StickyLoadBalancer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/StickyLoadBalancer.java
b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/StickyLoadBalancer.java
index cea84d5..5389185 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/StickyLoadBalancer.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/StickyLoadBalancer.java
@@ -34,21 +34,13 @@ import org.apache.camel.Processor;
  */
 public class StickyLoadBalancer extends QueueLoadBalancer {
     private Expression correlationExpression;
-    private QueueLoadBalancer loadBalancer;
+    private RoundRobinLoadBalancer loadBalancer;
     private int numberOfHashGroups = 64 * 1024;
     private final Map<Object, Processor> stickyMap = new HashMap<Object, Processor>();
 
     public StickyLoadBalancer(Expression correlationExpression) {
-        this(correlationExpression, new RoundRobinLoadBalancer());
-    }
-
-    public StickyLoadBalancer(Expression correlationExpression, QueueLoadBalancer loadBalancer)
{
         this.correlationExpression = correlationExpression;
-        this.loadBalancer = loadBalancer;
-    }
-    
-    public Expression getCorrelationExpression() {
-        return correlationExpression;
+        this.loadBalancer = new RoundRobinLoadBalancer();
     }
 
     protected synchronized Processor chooseProcessor(List<Processor> processors, Exchange
exchange) {
@@ -80,6 +72,13 @@ public class StickyLoadBalancer extends QueueLoadBalancer {
         super.removeProcessor(processor);
     }
 
+    public int getLastChosenProcessorIndex() {
+        return loadBalancer.getLastChosenProcessorIndex();
+    }
+
+    public Expression getCorrelationExpression() {
+        return correlationExpression;
+    }
 
     // Properties
     //-------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedLoadBalancer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedLoadBalancer.java
b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedLoadBalancer.java
index e997503..4626100 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedLoadBalancer.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedLoadBalancer.java
@@ -22,6 +22,8 @@ import java.util.List;
 public abstract class WeightedLoadBalancer extends QueueLoadBalancer {
     private List<Integer> distributionRatioList = new ArrayList<Integer>();
     private List<DistributionRatio> runtimeRatios = new ArrayList<DistributionRatio>();
+
+    transient int lastIndex;
     
     public WeightedLoadBalancer(List<Integer> distributionRatios) {
         deepCloneDistributionRatios(distributionRatios);
@@ -34,6 +36,10 @@ public abstract class WeightedLoadBalancer extends QueueLoadBalancer {
         }
     }
 
+    public int getLastChosenProcessorIndex() {
+        return lastIndex;
+    }
+
     @Override
     protected void doStart() throws Exception {
         super.doStart();

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedRandomLoadBalancer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedRandomLoadBalancer.java
b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedRandomLoadBalancer.java
index d566a8a..e453d57 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedRandomLoadBalancer.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedRandomLoadBalancer.java
@@ -26,7 +26,7 @@ public class WeightedRandomLoadBalancer extends WeightedLoadBalancer {
     private final Random rnd = new Random();
     private final int distributionRatioSum;
     private int runtimeRatioSum;
-    
+
     public WeightedRandomLoadBalancer(List<Integer> distributionRatioList) {
         super(distributionRatioList);
         int sum = 0;
@@ -39,8 +39,9 @@ public class WeightedRandomLoadBalancer extends WeightedLoadBalancer {
     
     @Override
     protected Processor chooseProcessor(List<Processor> processors, Exchange exchange)
{        
-        int selectedProcessorIndex = selectProcessIndex();
-        return processors.get(selectedProcessorIndex);
+        int index = selectProcessIndex();
+        lastIndex = index;
+        return processors.get(index);
     }
     
     public int selectProcessIndex() {

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedRoundRobinLoadBalancer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedRoundRobinLoadBalancer.java
b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedRoundRobinLoadBalancer.java
index 41be294..ee9246b 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedRoundRobinLoadBalancer.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/WeightedRoundRobinLoadBalancer.java
@@ -48,6 +48,8 @@ public class WeightedRoundRobinLoadBalancer extends WeightedLoadBalancer
{
                 counter++;
             }
         }
+
+        lastIndex = counter;
        
         return processors.get(counter++);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/test/java/org/apache/camel/management/ManagedRandomLoadBalancerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRandomLoadBalancerTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedRandomLoadBalancerTest.java
index 9967740..21c8b7a 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedRandomLoadBalancerTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRandomLoadBalancerTest.java
@@ -34,6 +34,8 @@ public class ManagedRandomLoadBalancerTest extends ManagementTestSupport
{
             return;
         }
 
+        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
+
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
 
@@ -53,6 +55,9 @@ public class ManagedRandomLoadBalancerTest extends ManagementTestSupport
{
         Integer size = (Integer) mbeanServer.getAttribute(on, "Size");
         assertEquals(2, size.intValue());
 
+        String last = (String) mbeanServer.getAttribute(on, "LastChosenProcessorId");
+        assertTrue("foo".equals(last) || "bar".equals(last));
+
         TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new Object[]{false},
new String[]{"boolean"});
         assertNotNull(data);
         assertEquals(2, data.size());
@@ -73,7 +78,7 @@ public class ManagedRandomLoadBalancerTest extends ManagementTestSupport
{
             public void configure() throws Exception {
                 from("direct:start")
                     .loadBalance().random().id("mysend")
-                        .to("mock:foo", "mock:bar");
+                        .to("mock:foo").id("foo").to("mock:bar").id("bar");
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/test/java/org/apache/camel/management/ManagedRoundRobinLoadBalancerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRoundRobinLoadBalancerTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedRoundRobinLoadBalancerTest.java
index 1a53f18..1dd1354 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedRoundRobinLoadBalancerTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRoundRobinLoadBalancerTest.java
@@ -22,6 +22,7 @@ import javax.management.openmbean.TabularData;
 
 import org.apache.camel.ServiceStatus;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version 
@@ -34,6 +35,17 @@ public class ManagedRoundRobinLoadBalancerTest extends ManagementTestSupport
{
             return;
         }
 
+        MockEndpoint foo = getMockEndpoint("mock:foo");
+        foo.expectedMessageCount(1);
+
+        MockEndpoint bar = getMockEndpoint("mock:bar");
+        bar.expectedMessageCount(1);
+
+        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
+        template.sendBodyAndHeader("direct:start", "Bye World", "foo", "123");
+
+        assertMockEndpointsSatisfied();
+
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
 
@@ -53,6 +65,9 @@ public class ManagedRoundRobinLoadBalancerTest extends ManagementTestSupport
{
         Integer size = (Integer) mbeanServer.getAttribute(on, "Size");
         assertEquals(2, size.intValue());
 
+        String last = (String) mbeanServer.getAttribute(on, "LastChosenProcessorId");
+        assertEquals("bar", last);
+
         TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new Object[]{false},
new String[]{"boolean"});
         assertNotNull(data);
         assertEquals(2, data.size());
@@ -73,7 +88,7 @@ public class ManagedRoundRobinLoadBalancerTest extends ManagementTestSupport
{
             public void configure() throws Exception {
                 from("direct:start")
                     .loadBalance().roundRobin().id("mysend")
-                        .to("mock:foo", "mock:bar");
+                        .to("mock:foo").id("foo").to("mock:bar").id("bar");
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/test/java/org/apache/camel/management/ManagedStickyLoadBalancerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedStickyLoadBalancerTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedStickyLoadBalancerTest.java
index 4f6a9ff..e52e371 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedStickyLoadBalancerTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedStickyLoadBalancerTest.java
@@ -28,12 +28,14 @@ import org.apache.camel.builder.RouteBuilder;
  */
 public class ManagedStickyLoadBalancerTest extends ManagementTestSupport {
 
-    public void testManageRandomLoadBalancer() throws Exception {
+    public void testManageStickyLoadBalancer() throws Exception {
         // JMX tests dont work well on AIX CI servers (hangs them)
         if (isPlatform("aix")) {
             return;
         }
 
+        template.sendBodyAndHeader("direct:start", "Hello World", "num", "123");
+
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
 
@@ -59,6 +61,14 @@ public class ManagedStickyLoadBalancerTest extends ManagementTestSupport
{
         String uri = (String) mbeanServer.getAttribute(on, "Expression");
         assertEquals("num", uri);
 
+        String last = (String) mbeanServer.getAttribute(on, "LastChosenProcessorId");
+        assertTrue("foo".equals(last) || "bar".equals(last));
+
+        template.sendBodyAndHeader("direct:start", "Bye World", "num", "123");
+
+        String last2 = (String) mbeanServer.getAttribute(on, "LastChosenProcessorId");
+        assertEquals("Should be sticky", last, last2);
+
         TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new Object[]{false},
new String[]{"boolean"});
         assertNotNull(data);
         assertEquals(2, data.size());
@@ -79,7 +89,7 @@ public class ManagedStickyLoadBalancerTest extends ManagementTestSupport
{
             public void configure() throws Exception {
                 from("direct:start")
                     .loadBalance().sticky(header("num")).id("mysend")
-                        .to("mock:foo", "mock:bar");
+                        .to("mock:foo").id("foo").to("mock:bar").id("bar");
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7563d570/camel-core/src/test/java/org/apache/camel/management/ManagedWeightedLoadBalancerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedWeightedLoadBalancerTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedWeightedLoadBalancerTest.java
index 6292f48..88b4c2a 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedWeightedLoadBalancerTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedWeightedLoadBalancerTest.java
@@ -22,6 +22,7 @@ import javax.management.openmbean.TabularData;
 
 import org.apache.camel.ServiceStatus;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version 
@@ -34,6 +35,18 @@ public class ManagedWeightedLoadBalancerTest extends ManagementTestSupport
{
             return;
         }
 
+        MockEndpoint foo = getMockEndpoint("mock:foo");
+        foo.expectedMessageCount(1);
+
+        MockEndpoint bar = getMockEndpoint("mock:bar");
+        bar.expectedMessageCount(2);
+
+        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
+        template.sendBodyAndHeader("direct:start", "Bye World", "foo", "123");
+        template.sendBodyAndHeader("direct:start", "Hi World", "foo", "123");
+
+        assertMockEndpointsSatisfied();
+
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
 
@@ -62,6 +75,9 @@ public class ManagedWeightedLoadBalancerTest extends ManagementTestSupport
{
         String delim = (String) mbeanServer.getAttribute(on, "DistributionRatioDelimiter");
         assertEquals(",", delim);
 
+        String last = (String) mbeanServer.getAttribute(on, "LastChosenProcessorId");
+        assertEquals("bar", last);
+
         TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new Object[]{false},
new String[]{"boolean"});
         assertNotNull(data);
         assertEquals(2, data.size());
@@ -82,7 +98,7 @@ public class ManagedWeightedLoadBalancerTest extends ManagementTestSupport
{
             public void configure() throws Exception {
                 from("direct:start")
                     .loadBalance().weighted(true, "1,2").id("mysend")
-                        .to("mock:foo", "mock:bar");
+                        .to("mock:foo").id("foo").to("mock:bar").id("bar");
             }
         };
     }


Mime
View raw message