camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: CAMEL-10872: camel-jgroups : upgrade to JGroups 4.0
Date Wed, 08 Mar 2017 10:22:25 GMT
Repository: camel
Updated Branches:
  refs/heads/master a6f109538 -> b150e7ada


CAMEL-10872: camel-jgroups : upgrade to JGroups 4.0


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

Branch: refs/heads/master
Commit: b150e7ada616b1329691621ce92bbc3e4d61130f
Parents: a6f1095
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Wed Mar 8 11:13:21 2017 +0100
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Wed Mar 8 11:13:51 2017 +0100

----------------------------------------------------------------------
 .../src/main/docs/jgroups-component.adoc        |   2 +-
 .../component/jgroups/JGroupsComponent.java     |   7 +-
 .../component/jgroups/JGroupsConsumer.java      |   5 +-
 .../component/jgroups/JGroupsEndpoint.java      |  15 ++-
 .../component/jgroups/JGroupsProducer.java      |  10 +-
 .../jgroups/CamelJGroupsReceiverTest.java       |   5 +-
 .../component/jgroups/JGroupsComponentTest.java |   8 +-
 ...roupsComponentWithChannelPropertiesTest.java | 116 +++++++++++++++++++
 .../component/jgroups/JGroupsConsumerTest.java  |   8 +-
 parent/pom.xml                                  |   2 +-
 .../JGroupsComponentConfiguration.java          |   8 +-
 11 files changed, 156 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b150e7ad/components/camel-jgroups/src/main/docs/jgroups-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-jgroups/src/main/docs/jgroups-component.adoc b/components/camel-jgroups/src/main/docs/jgroups-component.adoc
index 6bd0ce6..06fad21 100644
--- a/components/camel-jgroups/src/main/docs/jgroups-component.adoc
+++ b/components/camel-jgroups/src/main/docs/jgroups-component.adoc
@@ -56,7 +56,7 @@ The JGroups component supports 4 options which are listed below.
 [width="100%",cols="2,1,1m,1m,5",options="header"]
 |=======================================================================
 | Name | Group | Default | Java Type | Description
-| channel | common |  | Channel | Channel to use
+| channel | common |  | JChannel | Channel to use
 | channelProperties | common |  | String | Specifies configuration properties of the JChannel
used by the endpoint.
 | enableViewMessages | consumer | false | boolean | If set to true the consumer endpoint
will receive org.jgroups.View messages as well (not only org.jgroups.Message instances). By
default only regular messages are consumed by the endpoint.
 | resolvePropertyPlaceholders | advanced | true | boolean | Whether the component should
resolve property placeholders on itself when starting. Only properties which are of String
type can use property placeholders.

http://git-wip-us.apache.org/repos/asf/camel/blob/b150e7ad/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsComponent.java
b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsComponent.java
index 436487d..1dff080 100644
--- a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsComponent.java
+++ b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsComponent.java
@@ -22,13 +22,14 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.impl.UriEndpointComponent;
 import org.apache.camel.spi.Metadata;
 import org.jgroups.Channel;
+import org.jgroups.JChannel;
 
 /**
  * Component providing support for messages multicasted from- or to JGroups channels ({@code
org.jgroups.Channel}).
  */
 public class JGroupsComponent extends UriEndpointComponent {
 
-    private Channel channel;
+    private JChannel channel;
     private String channelProperties;
     @Metadata(label = "consumer")
     private boolean enableViewMessages;
@@ -42,14 +43,14 @@ public class JGroupsComponent extends UriEndpointComponent {
         return new JGroupsEndpoint(uri, this, channel, clusterName, channelProperties, enableViewMessages);
     }
 
-    public Channel getChannel() {
+    public JChannel getChannel() {
         return channel;
     }
 
     /**
      * Channel to use
      */
-    public void setChannel(Channel channel) {
+    public void setChannel(JChannel channel) {
         this.channel = channel;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/b150e7ad/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsConsumer.java
b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsConsumer.java
index a2f6815..2c5dd4e 100644
--- a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsConsumer.java
+++ b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsConsumer.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.jgroups;
 import org.apache.camel.Processor;
 import org.apache.camel.impl.DefaultConsumer;
 import org.jgroups.Channel;
+import org.jgroups.JChannel;
 
 /**
  * Consumes messages from the JGroups channels ({@code org.jgroups.Channel}). Received messages
@@ -26,13 +27,13 @@ import org.jgroups.Channel;
  */
 public class JGroupsConsumer extends DefaultConsumer {
 
-    private final Channel channel;
+    private final JChannel channel;
     private final String clusterName;
 
     private final CamelJGroupsReceiver receiver;
     private final JGroupsEndpoint endpoint;
 
-    public JGroupsConsumer(JGroupsEndpoint endpoint, Processor processor, Channel channel,
String clusterName) {
+    public JGroupsConsumer(JGroupsEndpoint endpoint, Processor processor, JChannel channel,
String clusterName) {
         super(endpoint, processor);
 
         this.endpoint = endpoint;

http://git-wip-us.apache.org/repos/asf/camel/blob/b150e7ad/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java
b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java
index d7ee5a4..193fef5 100644
--- a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java
+++ b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java
@@ -28,7 +28,6 @@ import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriPath;
-import org.jgroups.Channel;
 import org.jgroups.JChannel;
 import org.jgroups.Message;
 import org.jgroups.View;
@@ -50,8 +49,8 @@ public class JGroupsEndpoint extends DefaultEndpoint {
 
     private AtomicInteger connectCount = new AtomicInteger(0);
 
-    private Channel channel;
-    private Channel resolvedChannel;
+    private JChannel channel;
+    private JChannel resolvedChannel;
 
     @UriPath @Metadata(required = "true")
     private String clusterName;
@@ -60,7 +59,7 @@ public class JGroupsEndpoint extends DefaultEndpoint {
     @UriParam(label = "consumer")
     private boolean enableViewMessages;
 
-    public JGroupsEndpoint(String endpointUri, Component component, Channel channel, String
clusterName, String channelProperties, boolean enableViewMessages) {
+    public JGroupsEndpoint(String endpointUri, Component component, JChannel channel, String
clusterName, String channelProperties, boolean enableViewMessages) {
         super(endpointUri, component);
         this.channel = channel;
         this.clusterName = clusterName;
@@ -118,7 +117,7 @@ public class JGroupsEndpoint extends DefaultEndpoint {
         super.doStop();
     }
 
-    private Channel resolveChannel() throws Exception {
+    private JChannel resolveChannel() throws Exception {
         if (channel != null) {
             return channel;
         }
@@ -148,14 +147,14 @@ public class JGroupsEndpoint extends DefaultEndpoint {
         }
     }
 
-    public Channel getChannel() {
+    public JChannel getChannel() {
         return channel;
     }
 
     /**
      * The channel to use
      */
-    public void setChannel(Channel channel) {
+    public void setChannel(JChannel channel) {
         this.channel = channel;
     }
 
@@ -181,7 +180,7 @@ public class JGroupsEndpoint extends DefaultEndpoint {
         this.channelProperties = channelProperties;
     }
 
-    Channel getResolvedChannel() {
+    JChannel getResolvedChannel() {
         return resolvedChannel;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/b150e7ad/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsProducer.java
b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsProducer.java
index f49ef82..c9fb80e 100644
--- a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsProducer.java
+++ b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsProducer.java
@@ -20,6 +20,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.impl.DefaultProducer;
 import org.jgroups.Address;
 import org.jgroups.Channel;
+import org.jgroups.JChannel;
 import org.jgroups.Message;
 
 /**
@@ -31,13 +32,13 @@ public class JGroupsProducer extends DefaultProducer {
 
     private final JGroupsEndpoint endpoint;
 
-    private final Channel channel;
+    private final JChannel channel;
 
     private final String clusterName;
 
     // Constructor
 
-    public JGroupsProducer(JGroupsEndpoint endpoint, Channel channel, String clusterName)
{
+    public JGroupsProducer(JGroupsEndpoint endpoint, JChannel channel, String clusterName)
{
         super(endpoint);
 
         this.endpoint = endpoint;
@@ -75,8 +76,9 @@ public class JGroupsProducer extends DefaultProducer {
             if (sourceAddress != null) {
                 log.debug("Posting from custom source address: {}", sourceAddress);
             }
-
-            channel.send(new Message(destinationAddress, sourceAddress, body));
+            Message message = new Message(destinationAddress, body);
+            message.setSrc(sourceAddress);
+            channel.send(message);
         } else {
             log.debug("Body is null, cannot post to channel.");
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/b150e7ad/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/CamelJGroupsReceiverTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/CamelJGroupsReceiverTest.java
b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/CamelJGroupsReceiverTest.java
index bc9ecf0..8b6c761 100644
--- a/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/CamelJGroupsReceiverTest.java
+++ b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/CamelJGroupsReceiverTest.java
@@ -46,9 +46,10 @@ public class CamelJGroupsReceiverTest {
     public void shouldHandleProcessingException() throws Exception {
         // Given
         willThrow(Exception.class).given(processor).process(any(Exchange.class));
-
+        Message message = new Message(null, "someMessage");
+        message.setSrc(null);
         // When
-        receiver.receive(new Message(null, null, "someMessage"));
+        receiver.receive(message);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/b150e7ad/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsComponentTest.java
b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsComponentTest.java
index c10008d..dc31599 100644
--- a/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsComponentTest.java
+++ b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsComponentTest.java
@@ -31,11 +31,11 @@ public class JGroupsComponentTest extends CamelTestSupport {
 
     static final String MESSAGE = "MESSAGE";
 
-    static final String SAMPLE_CHANNEL_PROPERTY = "discard_incompatible_packets=true";
+    static final String SAMPLE_CHANNEL_PROPERTY = "enable_diagnostics=true";
 
     static final String SAMPLE_CHANNEL_PROPERTIES = String.format("UDP(%s)", SAMPLE_CHANNEL_PROPERTY);
 
-    static final String CONFIGURED_ENDPOINT_URI = String.format("jgroups:%s?channelProperties=%s",
CLUSTER_NAME, SAMPLE_CHANNEL_PROPERTIES);
+    static final String CONFIGURED_ENDPOINT_URI = String.format("jgroups:%s", CLUSTER_NAME);
 
     // Fixtures
 
@@ -85,7 +85,9 @@ public class JGroupsComponentTest extends CamelTestSupport {
         mockEndpoint.expectedBodiesReceived(MESSAGE);
 
         // When
-        clientChannel.send(new Message(null, null, MESSAGE));
+        Message message = new Message(null, MESSAGE);
+        message.setSrc(null);
+        clientChannel.send(message);
 
         // Then
         mockEndpoint.assertIsSatisfied();

http://git-wip-us.apache.org/repos/asf/camel/blob/b150e7ad/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsComponentWithChannelPropertiesTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsComponentWithChannelPropertiesTest.java
b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsComponentWithChannelPropertiesTest.java
new file mode 100644
index 0000000..273328f
--- /dev/null
+++ b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsComponentWithChannelPropertiesTest.java
@@ -0,0 +1,116 @@
+/**
+ * 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.jgroups;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.jgroups.JChannel;
+import org.jgroups.Message;
+import org.junit.Test;
+
+public class JGroupsComponentWithChannelPropertiesTest extends CamelTestSupport {
+
+    // Constants
+
+    static final String CLUSTER_NAME = "CLUSTER_NAME";
+
+    static final String MESSAGE = "MESSAGE";
+
+    static final String SAMPLE_CHANNEL_PROPERTY = "enable_diagnostics=true";
+
+    static final String SAMPLE_CHANNEL_PROPERTIES = String.format("UDP(%s)", SAMPLE_CHANNEL_PROPERTY);
+
+    static final String CONFIGURED_ENDPOINT_URI = String.format("jgroups:%s?channelProperties=%s",
CLUSTER_NAME, "udp.xml");
+
+    // Fixtures
+
+    JChannel clientChannel;
+
+    JChannel defaultComponentChannel;
+
+    // Routes fixture
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                JGroupsComponent defaultComponent = new JGroupsComponent();
+                defaultComponent.setChannel(defaultComponentChannel);
+                context().addComponent("my-default-jgroups", defaultComponent);
+
+                from("my-default-jgroups:" + CLUSTER_NAME).to("mock:default");
+                from(CONFIGURED_ENDPOINT_URI).to("mock:configured");
+            }
+        };
+    }
+
+    // Fixture setup
+
+    @Override
+    protected void doPreSetup() throws Exception {
+        super.doPreSetup();
+        clientChannel = new JChannel();
+        clientChannel.connect(CLUSTER_NAME);
+
+        defaultComponentChannel = new JChannel();
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        clientChannel.close();
+        super.tearDown();
+    }
+
+    @Test
+    public void shouldConsumeMulticastedMessage() throws Exception {
+        // Given
+        MockEndpoint mockEndpoint = getMockEndpoint("mock:default");
+        mockEndpoint.setExpectedMessageCount(1);
+        mockEndpoint.expectedBodiesReceived(MESSAGE);
+
+        // When
+        Message message = new Message(null, MESSAGE);
+        message.setSrc(null);
+        clientChannel.send(message);
+
+        // Then
+        mockEndpoint.assertIsSatisfied();
+    }
+
+    @Test
+    public void shouldConfigureChannelWithProperties() throws Exception {
+        // When
+        JGroupsEndpoint endpoint = getMandatoryEndpoint(CONFIGURED_ENDPOINT_URI, JGroupsEndpoint.class);
+
+        // Then
+        assertTrue(endpoint.getResolvedChannel().getProperties().contains(SAMPLE_CHANNEL_PROPERTY));
+    }
+
+    @Test
+    public void shouldCreateChannel() throws Exception {
+        // When
+        JGroupsEndpoint endpoint = getMandatoryEndpoint("my-default-jgroups:" + CLUSTER_NAME,
JGroupsEndpoint.class);
+        JGroupsComponent component = (JGroupsComponent)endpoint.getComponent();
+
+        // Then
+        assertNotNull(component.getChannel());
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/b150e7ad/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsConsumerTest.java
b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsConsumerTest.java
index 5e6dccc..26e5263 100644
--- a/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsConsumerTest.java
+++ b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsConsumerTest.java
@@ -75,7 +75,9 @@ public class JGroupsConsumerTest extends CamelTestSupport {
         mockEndpoint.expectedBodiesReceived(message);
 
         // When
-        channel.send(new Message(null, null, message));
+        Message msg = new Message(null, message);
+        msg.setSrc(null);
+        channel.send(msg);
 
         // Then
         assertMockEndpointsSatisfied();
@@ -88,7 +90,9 @@ public class JGroupsConsumerTest extends CamelTestSupport {
         mockEndpoint.message(0).header(HEADER_JGROUPS_ORIGINAL_MESSAGE).isInstanceOf(Message.class);
 
         // When
-        channel.send(new Message(null, null, message));
+        Message msg = new Message(null, message);
+        msg.setSrc(null);
+        channel.send(msg);
 
         // Then
         assertMockEndpointsSatisfied();

http://git-wip-us.apache.org/repos/asf/camel/blob/b150e7ad/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index fbaee9e..961c129 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -340,7 +340,7 @@
     <jetty-runner-groupId>org.eclipse.jetty</jetty-runner-groupId>
     <jettison-version>1.3.8</jettison-version>
     <jgit-version>4.6.0.201612231935-r</jgit-version>
-    <jgroups-version>3.6.13.Final</jgroups-version>
+    <jgroups-version>4.0.1.Final</jgroups-version>
     <libthrift-version>0.9.3</libthrift-version>
     <jibx-version>1.2.6</jibx-version>
     <jing-bundle-version>20030619_5</jing-bundle-version>

http://git-wip-us.apache.org/repos/asf/camel/blob/b150e7ad/platforms/spring-boot/components-starter/camel-jgroups-starter/src/main/java/org/apache/camel/component/jgroups/springboot/JGroupsComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-jgroups-starter/src/main/java/org/apache/camel/component/jgroups/springboot/JGroupsComponentConfiguration.java
b/platforms/spring-boot/components-starter/camel-jgroups-starter/src/main/java/org/apache/camel/component/jgroups/springboot/JGroupsComponentConfiguration.java
index 1f03ffd..8f61eb1 100644
--- a/platforms/spring-boot/components-starter/camel-jgroups-starter/src/main/java/org/apache/camel/component/jgroups/springboot/JGroupsComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-jgroups-starter/src/main/java/org/apache/camel/component/jgroups/springboot/JGroupsComponentConfiguration.java
@@ -16,7 +16,7 @@
  */
 package org.apache.camel.component.jgroups.springboot;
 
-import org.jgroups.Channel;
+import org.jgroups.JChannel;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.boot.context.properties.NestedConfigurationProperty;
 
@@ -33,7 +33,7 @@ public class JGroupsComponentConfiguration {
      * Channel to use
      */
     @NestedConfigurationProperty
-    private Channel channel;
+    private JChannel channel;
     /**
      * Specifies configuration properties of the JChannel used by the endpoint.
      */
@@ -51,11 +51,11 @@ public class JGroupsComponentConfiguration {
      */
     private Boolean resolvePropertyPlaceholders = true;
 
-    public Channel getChannel() {
+    public JChannel getChannel() {
         return channel;
     }
 
-    public void setChannel(Channel channel) {
+    public void setChannel(JChannel channel) {
         this.channel = channel;
     }
 


Mime
View raw message