You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2017/06/21 16:27:27 UTC
[2/6] camel git commit: CAMEL-10054: Create camel-atomix component
http://git-wip-us.apache.org/repos/asf/camel/blob/3756fba2/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/map/SpringAtomixMapProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/map/SpringAtomixMapProducerTest.java b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/map/SpringAtomixMapProducerTest.java
new file mode 100644
index 0000000..bbd697e
--- /dev/null
+++ b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/map/SpringAtomixMapProducerTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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.atomix.client.map;
+
+import io.atomix.collections.DistributedMap;
+import org.apache.camel.Message;
+import org.apache.camel.builder.DefaultFluentProducerTemplate;
+import org.apache.camel.component.atomix.client.AtomixClientConstants;
+import org.apache.camel.component.atomix.client.AtomixClientSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.test.annotation.DirtiesContext;
+
+@DirtiesContext
+public class SpringAtomixMapProducerTest extends AtomixClientSpringTestSupport {
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/atomix/client/map/SpringAtomixMapProducerTest.xml");
+ }
+
+ @Test
+ public void testPut() throws Exception {
+ final String key = context().getUuidGenerator().generateUuid();
+ final String val = context().getUuidGenerator().generateUuid();
+ final DistributedMap<Object, Object> map = getClient().getMap("test-map").join();
+
+ Message result = DefaultFluentProducerTemplate.on(context)
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMap.Action.PUT)
+ .withHeader(AtomixClientConstants.RESOURCE_KEY, key)
+ .withBody(val)
+ .to("direct:start")
+ .request(Message.class);
+
+ assertFalse(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(val, result.getBody());
+ assertEquals(val, map.get(key).join());
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3756fba2/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/messaging/AtomixMessagingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/messaging/AtomixMessagingTest.java b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/messaging/AtomixMessagingTest.java
new file mode 100644
index 0000000..e77c039
--- /dev/null
+++ b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/messaging/AtomixMessagingTest.java
@@ -0,0 +1,98 @@
+/**
+ * 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.atomix.client.messaging;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.camel.Component;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.atomix.client.AtomixClientConstants;
+import org.apache.camel.component.atomix.client.AtomixClientTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+
+public class AtomixMessagingTest extends AtomixClientTestSupport {
+ private static final String NODE_NAME = UUID.randomUUID().toString();
+
+ @EndpointInject(uri = "direct:start")
+ private FluentProducerTemplate template;
+
+ // ************************************
+ // Setup
+ // ************************************
+
+ @Override
+ protected Map<String, Component> createComponents() {
+ AtomixMessagingComponent component = new AtomixMessagingComponent();
+ component.setNodes(Collections.singletonList(getReplicaAddress()));
+
+ return Collections.singletonMap("atomix-messaging", component);
+ }
+
+ // ************************************
+ // Test
+ // ************************************
+
+ @Test
+ public void testMessaging() throws Exception {
+ MockEndpoint mock1 = getMockEndpoint("mock:member-1");
+ mock1.expectedMessageCount(2);
+ mock1.expectedBodiesReceived("direct-message", "broadcast-message");
+
+ MockEndpoint mock2 = getMockEndpoint("mock:member-2");
+ mock2.expectedMessageCount(1);
+ mock2.expectedBodiesReceived("broadcast-message");
+
+ template.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMessaging.Action.DIRECT)
+ .withHeader(AtomixClientConstants.MEMBER_NAME, "member-1")
+ .withHeader(AtomixClientConstants.CHANNEL_NAME, "channel")
+ .withBody("direct-message")
+ .send();
+
+ template.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMessaging.Action.BROADCAST)
+ .withHeader(AtomixClientConstants.CHANNEL_NAME, "channel")
+ .withBody("direct-message")
+ .send();
+ }
+
+ // ************************************
+ // Routes
+ // ************************************
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .to("atomix-messaging:group");
+
+ from("atomix-messaging:group?memberName=member-1&channelName=channel")
+ .to("mock:member-1");
+ from("atomix-messaging:group?memberName=member-2&channelName=channel")
+ .to("mock:member-2");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3756fba2/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/multimap/AtomixMultiMapProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/multimap/AtomixMultiMapProducerTest.java b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/multimap/AtomixMultiMapProducerTest.java
new file mode 100644
index 0000000..73a2f66
--- /dev/null
+++ b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/multimap/AtomixMultiMapProducerTest.java
@@ -0,0 +1,352 @@
+/**
+ * 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.atomix.client.multimap;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import io.atomix.collections.DistributedMultiMap;
+import org.apache.camel.Component;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.Message;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.atomix.client.AtomixClientConstants;
+import org.apache.camel.component.atomix.client.AtomixClientTestSupport;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class AtomixMultiMapProducerTest extends AtomixClientTestSupport {
+ private static final String MAP_NAME = UUID.randomUUID().toString();
+ private DistributedMultiMap<Object, Object> map;
+
+ @EndpointInject(uri = "direct:start")
+ private FluentProducerTemplate fluent;
+
+ // ************************************
+ // Setup
+ // ************************************
+
+ @Override
+ protected Map<String, Component> createComponents() {
+ AtomixMultiMapComponent component = new AtomixMultiMapComponent();
+ component.setNodes(Collections.singletonList(getReplicaAddress()));
+
+ return Collections.singletonMap("atomix-multimap", component);
+ }
+
+ @Override
+ protected void doPreSetup() throws Exception {
+ super.doPreSetup();
+
+ map = getClient().getMultiMap(MAP_NAME).join();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ map.close();
+
+ super.tearDown();
+ }
+
+ // ************************************
+ // Test
+ // ************************************
+
+ @Test
+ public void testPut() throws Exception {
+ final String key = context().getUuidGenerator().generateUuid();
+ final String val1 = context().getUuidGenerator().generateUuid();
+ final String val2 = context().getUuidGenerator().generateUuid();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.PUT)
+ .withHeader(AtomixClientConstants.RESOURCE_KEY, key)
+ .withBody(val1)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(result.getBody(Boolean.class));
+ assertEquals(Arrays.asList(val1), map.get(key).join());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.PUT)
+ .withHeader(AtomixClientConstants.RESOURCE_KEY, key)
+ .withBody(val2)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(result.getBody(Boolean.class));
+ assertEquals(Arrays.asList(val1, val2), map.get(key).join());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ final String key = context().getUuidGenerator().generateUuid();
+ final String val = context().getUuidGenerator().generateUuid();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.GET)
+ .withHeader(AtomixClientConstants.RESOURCE_KEY, key)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(result.getBody(Collection.class).isEmpty());
+ assertFalse(map.containsKey(key).join());
+
+ map.put(key, val).join();
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.GET)
+ .withHeader(AtomixClientConstants.RESOURCE_KEY, key)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(Arrays.asList(val), result.getBody(Collection.class));
+ assertTrue(map.containsKey(key).join());
+ }
+
+ @Test
+ public void testSizeClearIsEmpty() throws Exception {
+ final String key1 = context().getUuidGenerator().generateUuid();
+ final String key2 = context().getUuidGenerator().generateUuid();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.SIZE)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(0, result.getBody(Integer.class).intValue());
+ assertEquals(map.size().join(), result.getBody(Integer.class));
+
+ map.put(key1, context().getUuidGenerator().generateUuid()).join();
+ map.put(key1, context().getUuidGenerator().generateUuid()).join();
+ map.put(key2, context().getUuidGenerator().generateUuid()).join();
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.SIZE)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(map.size().join(), result.getBody(Integer.class));
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.SIZE)
+ .withHeader(AtomixClientConstants.RESOURCE_KEY, key1)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(map.size(key1).join(), result.getBody(Integer.class));
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.IS_EMPTY)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertFalse(result.getBody(Boolean.class));
+ assertFalse(map.isEmpty().join());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.CLEAR)
+ .request(Message.class);
+
+ assertFalse(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(0, map.size().join().intValue());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.IS_EMPTY)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(result.getBody(Boolean.class));
+ assertTrue(map.isEmpty().join());
+ }
+
+ @Test
+ public void testContainsKey() throws Exception {
+ final String key = context().getUuidGenerator().generateUuid();
+ final String val = context().getUuidGenerator().generateUuid();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.CONTAINS_KEY)
+ .withHeader(AtomixClientConstants.RESOURCE_KEY, key)
+ .withBody(val)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertFalse(result.getBody(Boolean.class));
+ assertFalse(map.containsKey(key).join());
+
+ map.put(key, val).join();
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.CONTAINS_KEY)
+ .withHeader(AtomixClientConstants.RESOURCE_KEY, key)
+ .withBody(val)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(result.getBody(Boolean.class));
+ assertTrue(map.containsKey(key).join());
+ }
+
+// @Test
+// public void testContainsValue() throws Exception {
+// final String key = context().getUuidGenerator().generateUuid();
+// final String val1 = context().getUuidGenerator().generateUuid();
+// final String val2 = context().getUuidGenerator().generateUuid();
+//
+// Message result;
+//
+// result = fluent.clearAll()
+// .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixClientMultiMapAction.CONTAINS_VALUE)
+// .withHeader(AtomixClientConstants.RESOURCE_VALUE, val1)
+// .request(Message.class);
+//
+// assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+// assertFalse(result.getBody(Boolean.class));
+// assertFalse(map.containsValue(val1).join());
+//
+// map.put(key, val1).join();
+// map.put(key, val2).join();
+//
+// result = fluent.clearAll()
+// .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixClientMultiMapAction.CONTAINS_VALUE)
+// .withHeader(AtomixClientConstants.RESOURCE_VALUE, val1)
+// .request(Message.class);
+//
+// assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+// assertTrue(result.getBody(Boolean.class));
+// assertTrue(map.containsValue(val1).join());
+//
+// result = fluent.clearAll()
+// .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixClientMultiMapAction.CONTAINS_VALUE)
+// .withHeader(AtomixClientConstants.RESOURCE_VALUE, val2)
+// .request(Message.class);
+//
+// assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+// assertTrue(result.getBody(Boolean.class));
+// assertTrue(map.containsValue(val2).join());
+// }
+
+//
+// @Test
+// public void testContainsEntry() throws Exception {
+// final String key = context().getUuidGenerator().generateUuid();
+// final String val1 = context().getUuidGenerator().generateUuid();
+// final String val2 = context().getUuidGenerator().generateUuid();
+// map.put(key, val1).join();
+// map.put(key, val2).join();
+//
+// Message result;
+//
+// result = fluent.clearAll()
+// .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixClientMultiMapAction.CONTAINS_ENTRY)
+// .withHeader(AtomixClientConstants.RESOURCE_KEY, key)
+// .withHeader(AtomixClientConstants.RESOURCE_VALUE, val1)
+// .request(Message.class);
+//
+// assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+// assertTrue(result.getBody(Boolean.class));
+// assertTrue(map.containsEntry(key, val1).join());
+//
+// result = fluent.clearAll()
+// .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixClientMultiMapAction.CONTAINS_ENTRY)
+// .withHeader(AtomixClientConstants.RESOURCE_KEY, key)
+// .withHeader(AtomixClientConstants.RESOURCE_VALUE, val2)
+// .request(Message.class);
+//
+// assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+// assertTrue(result.getBody(Boolean.class));
+// assertTrue(map.containsEntry(key, val2).join());
+//
+// }
+
+ @Test
+ public void testRemove() throws Exception {
+ final String key = context().getUuidGenerator().generateUuid();
+ final String val1 = context().getUuidGenerator().generateUuid();
+ final String val2 = context().getUuidGenerator().generateUuid();
+ final String val3 = context().getUuidGenerator().generateUuid();
+
+ map.put(key, val1).join();
+ map.put(key, val2).join();
+ map.put(key, val3).join();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.REMOVE)
+ .withHeader(AtomixClientConstants.RESOURCE_KEY, key)
+ .withHeader(AtomixClientConstants.RESOURCE_VALUE, val1)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(Arrays.asList(val2, val3), map.get(key).join());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.REMOVE_VALUE)
+ .withHeader(AtomixClientConstants.RESOURCE_VALUE, val2)
+ .request(Message.class);
+
+ assertFalse(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(Arrays.asList(val3), map.get(key).join());
+ assertTrue(map.containsKey(key).join());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixMultiMap.Action.REMOVE)
+ .withHeader(AtomixClientConstants.RESOURCE_KEY, key)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertFalse(map.containsKey(key).join());
+ }
+
+ @Ignore
+ @Test
+ public void test() {
+ //Assert.assertFalse(map.containsValue("abc").join());
+ Assert.assertFalse(map.containsEntry("abc", "abc").join());
+ }
+
+ // ************************************
+ // Routes
+ // ************************************
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .toF("atomix-multimap:%s", MAP_NAME);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3756fba2/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/queue/AtomixQueueConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/queue/AtomixQueueConsumerTest.java b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/queue/AtomixQueueConsumerTest.java
new file mode 100644
index 0000000..99a2d4e
--- /dev/null
+++ b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/queue/AtomixQueueConsumerTest.java
@@ -0,0 +1,108 @@
+/**
+ * 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.atomix.client.queue;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import io.atomix.collections.DistributedMap;
+import io.atomix.collections.DistributedQueue;
+import org.apache.camel.Component;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.atomix.client.AtomixClientConstants;
+import org.apache.camel.component.atomix.client.AtomixClientTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+public class AtomixQueueConsumerTest extends AtomixClientTestSupport {
+ private static final String QUEUE_NAME = UUID.randomUUID().toString();
+ private DistributedQueue<Object> queue;
+
+ // ************************************
+ // Setup
+ // ************************************
+
+ @Override
+ protected Map<String, Component> createComponents() {
+ AtomixQueueComponent component = new AtomixQueueComponent();
+ component.setNodes(Collections.singletonList(getReplicaAddress()));
+
+ return Collections.singletonMap("atomix-queue", component);
+ }
+
+ @Override
+ protected void doPreSetup() throws Exception {
+ super.doPreSetup();
+
+ queue = getClient().getQueue(QUEUE_NAME).join();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ queue.close();
+
+ super.tearDown();
+ }
+
+ // ************************************
+ // Test
+ // ************************************
+
+ @Test
+ public void testEvents() throws Exception {
+ String val1 = context().getUuidGenerator().generateUuid();
+ String val2 = context().getUuidGenerator().generateUuid();
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(4);
+
+ mock.message(0).body().isEqualTo(val1);
+ mock.message(0).header(AtomixClientConstants.EVENT_TYPE).isEqualTo(DistributedQueue.Events.ADD);
+
+ mock.message(1).body().isEqualTo(val2);
+ mock.message(1).header(AtomixClientConstants.EVENT_TYPE).isEqualTo(DistributedQueue.Events.ADD);
+
+ mock.message(2).body().isEqualTo(val2);
+ mock.message(2).header(AtomixClientConstants.EVENT_TYPE).isEqualTo(DistributedQueue.Events.REMOVE);
+
+ mock.message(3).body().isEqualTo(val1);
+ mock.message(3).header(AtomixClientConstants.EVENT_TYPE).isEqualTo(DistributedMap.Events.REMOVE);
+
+ queue.add(val1).join();
+ queue.add(val2).join();
+ queue.remove(val2).join();
+ queue.remove(val1).join();
+
+ mock.assertIsSatisfied();
+ }
+
+ // ************************************
+ // Routes
+ // ************************************
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ fromF("atomix-queue:%s", QUEUE_NAME)
+ .to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3756fba2/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/queue/AtomixQueueProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/queue/AtomixQueueProducerTest.java b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/queue/AtomixQueueProducerTest.java
new file mode 100644
index 0000000..0d74ad9
--- /dev/null
+++ b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/queue/AtomixQueueProducerTest.java
@@ -0,0 +1,235 @@
+/**
+ * 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.atomix.client.queue;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import io.atomix.collections.DistributedQueue;
+import org.apache.camel.Component;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.Message;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.atomix.client.AtomixClientConstants;
+import org.apache.camel.component.atomix.client.AtomixClientTestSupport;
+import org.junit.Test;
+
+public class AtomixQueueProducerTest extends AtomixClientTestSupport {
+ private static final String QUEUE_NAME = UUID.randomUUID().toString();
+ private DistributedQueue<Object> queue;
+
+ @EndpointInject(uri = "direct:start")
+ private FluentProducerTemplate fluent;
+
+ // ************************************
+ // Setup
+ // ************************************
+
+ @Override
+ protected Map<String, Component> createComponents() {
+ AtomixQueueComponent component = new AtomixQueueComponent();
+ component.setNodes(Collections.singletonList(getReplicaAddress()));
+
+ return Collections.singletonMap("atomix-queue", component);
+ }
+
+ @Override
+ protected void doPreSetup() throws Exception {
+ super.doPreSetup();
+
+ queue = getClient().getQueue(QUEUE_NAME).join();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ queue.close();
+
+ super.tearDown();
+ }
+
+ // ************************************
+ // Test
+ // ************************************
+
+ @Test
+ public void testAdd() throws Exception {
+ final String val1 = context().getUuidGenerator().generateUuid();
+ final String val2 = context().getUuidGenerator().generateUuid();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixQueue.Action.ADD)
+ .withBody(val1)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(queue.contains(val1).join());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixQueue.Action.ADD)
+ .withBody(val2)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(queue.contains(val2).join());
+ }
+
+ @Test
+ public void testOfferPeekAndPoll() throws Exception {
+ final String val = context().getUuidGenerator().generateUuid();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixQueue.Action.OFFER)
+ .withBody(val)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(queue.contains(val).join());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixQueue.Action.PEEK)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(queue.contains(val).join());
+ assertEquals(val, result.getBody());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixQueue.Action.POLL)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertFalse(queue.contains(val).join());
+ assertEquals(val, result.getBody());
+ }
+
+ @Test
+ public void testSizeClearIsEmpty() throws Exception {
+ final String val1 = context().getUuidGenerator().generateUuid();
+ final String val2 = context().getUuidGenerator().generateUuid();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixQueue.Action.SIZE)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(0, result.getBody(Integer.class).intValue());
+ assertEquals(queue.size().join(), result.getBody(Integer.class));
+
+ queue.add(val1).join();
+ queue.add(val2).join();
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixQueue.Action.SIZE)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(queue.size().join(), result.getBody(Integer.class));
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixQueue.Action.IS_EMPTY)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertFalse(result.getBody(Boolean.class));
+ assertFalse(queue.isEmpty().join());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixQueue.Action.CLEAR)
+ .request(Message.class);
+
+ assertFalse(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(0, queue.size().join().intValue());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixQueue.Action.IS_EMPTY)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(result.getBody(Boolean.class));
+ assertTrue(queue.isEmpty().join());
+ }
+
+ @Test
+ public void testContains() throws Exception {
+ final String val = context().getUuidGenerator().generateUuid();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixQueue.Action.CONTAINS)
+ .withBody(val)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertFalse(result.getBody(Boolean.class));
+ assertFalse(queue.contains(val).join());
+
+ queue.add(val);
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixQueue.Action.CONTAINS)
+ .withBody(val)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(result.getBody(Boolean.class));
+ assertTrue(queue.contains(val).join());
+ }
+
+ @Test
+ public void testRemove() throws Exception {
+ final String val1 = context().getUuidGenerator().generateUuid();
+ final String val2 = context().getUuidGenerator().generateUuid();
+
+ queue.add(val1).join();
+ queue.add(val2).join();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixQueue.Action.REMOVE)
+ .withHeader(AtomixClientConstants.RESOURCE_VALUE, val1)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertFalse(queue.contains(val1).join());
+ assertTrue(queue.contains(val2).join());
+ }
+
+ // ************************************
+ // Routes
+ // ************************************
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .toF("atomix-queue:%s", QUEUE_NAME);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3756fba2/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/set/AtomixSetConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/set/AtomixSetConsumerTest.java b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/set/AtomixSetConsumerTest.java
new file mode 100644
index 0000000..ddc1221
--- /dev/null
+++ b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/set/AtomixSetConsumerTest.java
@@ -0,0 +1,108 @@
+/**
+ * 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.atomix.client.set;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import io.atomix.collections.DistributedMap;
+import io.atomix.collections.DistributedSet;
+import org.apache.camel.Component;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.atomix.client.AtomixClientConstants;
+import org.apache.camel.component.atomix.client.AtomixClientTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+public class AtomixSetConsumerTest extends AtomixClientTestSupport {
+ private static final String SET_NAME = UUID.randomUUID().toString();
+ private DistributedSet<Object> set;
+
+ // ************************************
+ // Setup
+ // ************************************
+
+ @Override
+ protected Map<String, Component> createComponents() {
+ AtomixSetComponent component = new AtomixSetComponent();
+ component.setNodes(Collections.singletonList(getReplicaAddress()));
+
+ return Collections.singletonMap("atomix-set", component);
+ }
+
+ @Override
+ protected void doPreSetup() throws Exception {
+ super.doPreSetup();
+
+ set = getClient().getSet(SET_NAME).join();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ set.close();
+
+ super.tearDown();
+ }
+
+ // ************************************
+ // Test
+ // ************************************
+
+ @Test
+ public void testEvents() throws Exception {
+ String val1 = context().getUuidGenerator().generateUuid();
+ String val2 = context().getUuidGenerator().generateUuid();
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(4);
+
+ mock.message(0).body().isEqualTo(val1);
+ mock.message(0).header(AtomixClientConstants.EVENT_TYPE).isEqualTo(DistributedSet.Events.ADD);
+
+ mock.message(1).body().isEqualTo(val2);
+ mock.message(1).header(AtomixClientConstants.EVENT_TYPE).isEqualTo(DistributedSet.Events.ADD);
+
+ mock.message(2).body().isEqualTo(val2);
+ mock.message(2).header(AtomixClientConstants.EVENT_TYPE).isEqualTo(DistributedSet.Events.REMOVE);
+
+ mock.message(3).body().isEqualTo(val1);
+ mock.message(3).header(AtomixClientConstants.EVENT_TYPE).isEqualTo(DistributedMap.Events.REMOVE);
+
+ set.add(val1).join();
+ set.add(val2).join();
+ set.remove(val2).join();
+ set.remove(val1).join();
+
+ mock.assertIsSatisfied();
+ }
+
+ // ************************************
+ // Routes
+ // ************************************
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ fromF("atomix-set:%s", SET_NAME)
+ .to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3756fba2/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/set/AtomixSetProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/set/AtomixSetProducerTest.java b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/set/AtomixSetProducerTest.java
new file mode 100644
index 0000000..e72c4c3
--- /dev/null
+++ b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/set/AtomixSetProducerTest.java
@@ -0,0 +1,204 @@
+/**
+ * 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.atomix.client.set;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import io.atomix.collections.DistributedSet;
+import org.apache.camel.Component;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.Message;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.atomix.client.AtomixClientConstants;
+import org.apache.camel.component.atomix.client.AtomixClientTestSupport;
+import org.junit.Test;
+
+public class AtomixSetProducerTest extends AtomixClientTestSupport {
+ private static final String SET_NAME = UUID.randomUUID().toString();
+ private DistributedSet<Object> set;
+
+ @EndpointInject(uri = "direct:start")
+ private FluentProducerTemplate fluent;
+
+ // ************************************
+ // Setup
+ // ************************************
+
+ @Override
+ protected Map<String, Component> createComponents() {
+ AtomixSetComponent component = new AtomixSetComponent();
+ component.setNodes(Collections.singletonList(getReplicaAddress()));
+
+ return Collections.singletonMap("atomix-set", component);
+ }
+
+ @Override
+ protected void doPreSetup() throws Exception {
+ super.doPreSetup();
+
+ set = getClient().getSet(SET_NAME).join();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ set.close();
+
+ super.tearDown();
+ }
+
+ // ************************************
+ // Test
+ // ************************************
+
+ @Test
+ public void testAdd() throws Exception {
+ final String val1 = context().getUuidGenerator().generateUuid();
+ final String val2 = context().getUuidGenerator().generateUuid();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixSet.Action.ADD)
+ .withBody(val1)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(set.contains(val1).join());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixSet.Action.ADD)
+ .withBody(val2)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(set.contains(val2).join());
+ }
+
+ @Test
+ public void testSizeClearIsEmpty() throws Exception {
+ final String val1 = context().getUuidGenerator().generateUuid();
+ final String val2 = context().getUuidGenerator().generateUuid();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixSet.Action.SIZE)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(0, result.getBody(Integer.class).intValue());
+ assertEquals(set.size().join(), result.getBody(Integer.class));
+
+ set.add(val1).join();
+ set.add(val2).join();
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixSet.Action.SIZE)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(set.size().join(), result.getBody(Integer.class));
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixSet.Action.IS_EMPTY)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertFalse(result.getBody(Boolean.class));
+ assertFalse(set.isEmpty().join());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixSet.Action.CLEAR)
+ .request(Message.class);
+
+ assertFalse(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(0, set.size().join().intValue());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixSet.Action.IS_EMPTY)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(result.getBody(Boolean.class));
+ assertTrue(set.isEmpty().join());
+ }
+
+ @Test
+ public void testContains() throws Exception {
+ final String val = context().getUuidGenerator().generateUuid();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixSet.Action.CONTAINS)
+ .withBody(val)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertFalse(result.getBody(Boolean.class));
+ assertFalse(set.contains(val).join());
+
+ set.add(val);
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixSet.Action.CONTAINS)
+ .withBody(val)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertTrue(result.getBody(Boolean.class));
+ assertTrue(set.contains(val).join());
+ }
+
+ @Test
+ public void testRemove() throws Exception {
+ final String val1 = context().getUuidGenerator().generateUuid();
+ final String val2 = context().getUuidGenerator().generateUuid();
+
+ set.add(val1).join();
+ set.add(val2).join();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixSet.Action.REMOVE)
+ .withHeader(AtomixClientConstants.RESOURCE_VALUE, val1)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertFalse(set.contains(val1).join());
+ assertTrue(set.contains(val2).join());
+ }
+
+ // ************************************
+ // Routes
+ // ************************************
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .toF("atomix-set:%s", SET_NAME);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3756fba2/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/value/AtomixValueConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/value/AtomixValueConsumerTest.java b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/value/AtomixValueConsumerTest.java
new file mode 100644
index 0000000..e5e7ac0
--- /dev/null
+++ b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/value/AtomixValueConsumerTest.java
@@ -0,0 +1,98 @@
+/**
+ * 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.atomix.client.value;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import io.atomix.variables.DistributedValue;
+import org.apache.camel.Component;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.atomix.client.AtomixClientConstants;
+import org.apache.camel.component.atomix.client.AtomixClientTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+public class AtomixValueConsumerTest extends AtomixClientTestSupport {
+ private static final String VALUE_NAME = UUID.randomUUID().toString();
+ private DistributedValue<Object> value;
+
+ // ************************************
+ // Setup
+ // ************************************
+
+ @Override
+ protected Map<String, Component> createComponents() {
+ AtomixValueComponent component = new AtomixValueComponent();
+ component.setNodes(Collections.singletonList(getReplicaAddress()));
+
+ return Collections.singletonMap("atomix-value", component);
+ }
+
+ @Override
+ protected void doPreSetup() throws Exception {
+ super.doPreSetup();
+
+ value = getClient().getValue(VALUE_NAME).join();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ value.close();
+
+ super.tearDown();
+ }
+
+ // ************************************
+ // Test
+ // ************************************
+
+ @Test
+ public void testEvents() throws Exception {
+ String val1 = context().getUuidGenerator().generateUuid();
+ String val2 = context().getUuidGenerator().generateUuid();
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(2);
+
+ mock.message(0).body().isEqualTo(val1);
+ mock.message(0).header(AtomixClientConstants.EVENT_TYPE).isEqualTo(DistributedValue.Events.CHANGE);
+ mock.message(1).body().isEqualTo(val2);
+ mock.message(1).header(AtomixClientConstants.EVENT_TYPE).isEqualTo(DistributedValue.Events.CHANGE);
+
+ value.set(val1).join();
+ value.compareAndSet(val1, val2).join();
+
+ mock.assertIsSatisfied();
+ }
+
+ // ************************************
+ // Routes
+ // ************************************
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ fromF("atomix-value:%s", VALUE_NAME)
+ .to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3756fba2/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/value/AtomixValueProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/value/AtomixValueProducerTest.java b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/value/AtomixValueProducerTest.java
new file mode 100644
index 0000000..6ed7ec6
--- /dev/null
+++ b/components/camel-atomix/src/test/java/org/apache/camel/component/atomix/client/value/AtomixValueProducerTest.java
@@ -0,0 +1,127 @@
+/**
+ * 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.atomix.client.value;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import io.atomix.variables.DistributedValue;
+import org.apache.camel.Component;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.Message;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.atomix.client.AtomixClientConstants;
+import org.apache.camel.component.atomix.client.AtomixClientTestSupport;
+import org.junit.Test;
+
+public class AtomixValueProducerTest extends AtomixClientTestSupport {
+ private static final String VALUE_NAME = UUID.randomUUID().toString();
+ private DistributedValue<Object> value;
+
+ @EndpointInject(uri = "direct:start")
+ private FluentProducerTemplate fluent;
+
+ // ************************************
+ // Setup
+ // ************************************
+
+ @Override
+ protected Map<String, Component> createComponents() {
+ AtomixValueComponent component = new AtomixValueComponent();
+ component.setNodes(Collections.singletonList(getReplicaAddress()));
+
+ return Collections.singletonMap("atomix-value", component);
+ }
+
+ @Override
+ protected void doPreSetup() throws Exception {
+ super.doPreSetup();
+
+ value = getClient().getValue(VALUE_NAME).join();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ value.close();
+
+ super.tearDown();
+ }
+
+ // ************************************
+ // Test
+ // ************************************
+
+ @Test
+ public void test() throws Exception {
+ final String val1 = context().getUuidGenerator().generateUuid();
+ final String val2 = context().getUuidGenerator().generateUuid();
+
+ Message result;
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixValue.Action.SET)
+ .withBody(val1)
+ .request(Message.class);
+
+ assertFalse(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(val1, value.get().join());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixValue.Action.COMPARE_AND_SET)
+ .withHeader(AtomixClientConstants.RESOURCE_OLD_VALUE, val1)
+ .withBody(val2)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(val2, value.get().join());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixValue.Action.GET)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(val2, result.getBody());
+ assertEquals(val2, value.get().join());
+
+ result = fluent.clearAll()
+ .withHeader(AtomixClientConstants.RESOURCE_ACTION, AtomixValue.Action.GET_AND_SET)
+ .withBody(val1)
+ .request(Message.class);
+
+ assertTrue(result.getHeader(AtomixClientConstants.RESOURCE_ACTION_HAS_RESULT, Boolean.class));
+ assertEquals(val2, result.getBody());
+ assertEquals(val1, value.get().join());
+ }
+
+
+ // ************************************
+ // Routes
+ // ************************************
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .toF("atomix-value:%s", VALUE_NAME);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3756fba2/components/camel-atomix/src/test/resources/org/apache/camel/component/atomix/client/map/SpringAtomixMapProducerTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-atomix/src/test/resources/org/apache/camel/component/atomix/client/map/SpringAtomixMapProducerTest.xml b/components/camel-atomix/src/test/resources/org/apache/camel/component/atomix/client/map/SpringAtomixMapProducerTest.xml
new file mode 100644
index 0000000..070ee7e
--- /dev/null
+++ b/components/camel-atomix/src/test/resources/org/apache/camel/component/atomix/client/map/SpringAtomixMapProducerTest.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring
+ http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <!-- ******************************************* -->
+ <!-- Beans -->
+ <!-- ******************************************* -->
+
+ <bean id="replica-address" class="org.apache.camel.component.atomix.client.AtomixFactory" factory-method="address">
+ <constructor-arg value="127.0.0.1"/>
+ </bean>
+
+ <bean id="replica" class="org.apache.camel.component.atomix.client.AtomixFactory" factory-method="replica">
+ <constructor-arg ref="replica-address"/>
+ </bean>
+
+ <bean id="client" class="org.apache.camel.component.atomix.client.AtomixFactory" factory-method="client">
+ <constructor-arg ref="replica-address"/>
+ </bean>
+
+ <bean id="atomix-map" class="org.apache.camel.component.atomix.client.map.AtomixMapComponent">
+ <property name="nodes">
+ <list>
+ <ref bean="replica-address"/>
+ </list>
+ </property>
+ </bean>
+
+ <!-- ******************************************* -->
+ <!-- Camel Context -->
+ <!-- ******************************************* -->
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+ <route>
+ <from uri="direct:start"/>
+ <to uri="atomix-map:test-map"/>
+ </route>
+
+ </camelContext>
+
+</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/3756fba2/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixClientMapComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixClientMapComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixClientMapComponentAutoConfiguration.java
deleted file mode 100644
index f6e8b5a..0000000
--- a/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixClientMapComponentAutoConfiguration.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/**
- * 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.atomix.client.map.springboot;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.Generated;
-import org.apache.camel.CamelContext;
-import org.apache.camel.component.atomix.client.map.AtomixClientMapComponent;
-import org.apache.camel.spi.ComponentCustomizer;
-import org.apache.camel.spi.HasId;
-import org.apache.camel.spring.boot.CamelAutoConfiguration;
-import org.apache.camel.spring.boot.ComponentConfigurationProperties;
-import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
-import org.apache.camel.spring.boot.util.GroupCondition;
-import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
-import org.apache.camel.util.IntrospectionSupport;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Lazy;
-
-/**
- * Generated by camel-package-maven-plugin - do not edit this file!
- */
-@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
-@Configuration
-@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class,
- AtomixClientMapComponentAutoConfiguration.GroupConditions.class})
-@AutoConfigureAfter(CamelAutoConfiguration.class)
-@EnableConfigurationProperties({ComponentConfigurationProperties.class,
- AtomixClientMapComponentConfiguration.class})
-public class AtomixClientMapComponentAutoConfiguration {
-
- private static final Logger LOGGER = LoggerFactory
- .getLogger(AtomixClientMapComponentAutoConfiguration.class);
- @Autowired
- private ApplicationContext applicationContext;
- @Autowired
- private CamelContext camelContext;
- @Autowired
- private AtomixClientMapComponentConfiguration configuration;
- @Autowired(required = false)
- private List<ComponentCustomizer<AtomixClientMapComponent>> customizers;
-
- static class GroupConditions extends GroupCondition {
- public GroupConditions() {
- super("camel.component", "camel.component.atomix-map");
- }
- }
-
- @Lazy
- @Bean(name = "atomix-map-component")
- @ConditionalOnMissingBean(AtomixClientMapComponent.class)
- public AtomixClientMapComponent configureAtomixClientMapComponent()
- throws Exception {
- AtomixClientMapComponent component = new AtomixClientMapComponent();
- component.setCamelContext(camelContext);
- Map<String, Object> parameters = new HashMap<>();
- IntrospectionSupport.getProperties(configuration, parameters, null,
- false);
- for (Map.Entry<String, Object> entry : parameters.entrySet()) {
- Object value = entry.getValue();
- Class<?> paramClass = value.getClass();
- if (paramClass.getName().endsWith("NestedConfiguration")) {
- Class nestedClass = null;
- try {
- nestedClass = (Class) paramClass.getDeclaredField(
- "CAMEL_NESTED_CLASS").get(null);
- HashMap<String, Object> nestedParameters = new HashMap<>();
- IntrospectionSupport.getProperties(value, nestedParameters,
- null, false);
- Object nestedProperty = nestedClass.newInstance();
- IntrospectionSupport.setProperties(camelContext,
- camelContext.getTypeConverter(), nestedProperty,
- nestedParameters);
- entry.setValue(nestedProperty);
- } catch (NoSuchFieldException e) {
- }
- }
- }
- IntrospectionSupport.setProperties(camelContext,
- camelContext.getTypeConverter(), component, parameters);
- if (ObjectHelper.isNotEmpty(customizers)) {
- for (ComponentCustomizer<AtomixClientMapComponent> customizer : customizers) {
- boolean useCustomizer = (customizer instanceof HasId)
- ? HierarchicalPropertiesEvaluator.evaluate(
- applicationContext.getEnvironment(),
- "camel.component.customizer",
- "camel.component.atomix-map.customizer",
- ((HasId) customizer).getId())
- : HierarchicalPropertiesEvaluator.evaluate(
- applicationContext.getEnvironment(),
- "camel.component.customizer",
- "camel.component.atomix-map.customizer");
- if (useCustomizer) {
- LOGGER.debug("Configure component {}, with customizer {}",
- component, customizer);
- customizer.customize(component);
- }
- }
- }
- return component;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/3756fba2/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixClientMapComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixClientMapComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixClientMapComponentConfiguration.java
deleted file mode 100644
index 1fe3057..0000000
--- a/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixClientMapComponentConfiguration.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/**
- * 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.atomix.client.map.springboot;
-
-import java.util.List;
-import javax.annotation.Generated;
-import io.atomix.AtomixClient;
-import io.atomix.catalyst.transport.Address;
-import org.apache.camel.component.atomix.client.AtomixClientAction;
-import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.boot.context.properties.NestedConfigurationProperty;
-
-/**
- * Camel Atomix support
- *
- * Generated by camel-package-maven-plugin - do not edit this file!
- */
-@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
-@ConfigurationProperties(prefix = "camel.component.atomix-map")
-public class AtomixClientMapComponentConfiguration
- extends
- ComponentConfigurationPropertiesCommon {
-
- /**
- * The shared component configuration
- */
- private AtomixClientMapConfigurationNestedConfiguration configuration;
- /**
- * The shared AtomixClient instance
- */
- @NestedConfigurationProperty
- private AtomixClient atomix;
- /**
- * The nodes the AtomixClient should connect to
- */
- private List<Address> nodes;
- /**
- * The path to the AtomixClient configuration
- */
- private String configurationUri;
- /**
- * Whether the component should resolve property placeholders on itself when
- * starting. Only properties which are of String type can use property
- * placeholders.
- */
- private Boolean resolvePropertyPlaceholders = true;
-
- public AtomixClientMapConfigurationNestedConfiguration getConfiguration() {
- return configuration;
- }
-
- public void setConfiguration(
- AtomixClientMapConfigurationNestedConfiguration configuration) {
- this.configuration = configuration;
- }
-
- public AtomixClient getAtomix() {
- return atomix;
- }
-
- public void setAtomix(AtomixClient atomix) {
- this.atomix = atomix;
- }
-
- public List<Address> getNodes() {
- return nodes;
- }
-
- public void setNodes(List<Address> nodes) {
- this.nodes = nodes;
- }
-
- public String getConfigurationUri() {
- return configurationUri;
- }
-
- public void setConfigurationUri(String configurationUri) {
- this.configurationUri = configurationUri;
- }
-
- public Boolean getResolvePropertyPlaceholders() {
- return resolvePropertyPlaceholders;
- }
-
- public void setResolvePropertyPlaceholders(
- Boolean resolvePropertyPlaceholders) {
- this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
- }
-
- public static class AtomixClientMapConfigurationNestedConfiguration {
- public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.atomix.client.map.AtomixClientMapConfiguration.class;
- /**
- * The default action.
- */
- private AtomixClientAction defaultAction;
- /**
- * The resource ttl.
- */
- private Long ttl;
- /**
- * The header that wil carry the result.
- */
- private String resultHeader;
-
- public AtomixClientAction getDefaultAction() {
- return defaultAction;
- }
-
- public void setDefaultAction(AtomixClientAction defaultAction) {
- this.defaultAction = defaultAction;
- }
-
- public Long getTtl() {
- return ttl;
- }
-
- public void setTtl(Long ttl) {
- this.ttl = ttl;
- }
-
- public String getResultHeader() {
- return resultHeader;
- }
-
- public void setResultHeader(String resultHeader) {
- this.resultHeader = resultHeader;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/3756fba2/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixMapComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixMapComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixMapComponentAutoConfiguration.java
new file mode 100644
index 0000000..8f41b4e
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixMapComponentAutoConfiguration.java
@@ -0,0 +1,128 @@
+/**
+ * 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.atomix.client.map.springboot;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Generated;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.atomix.client.map.AtomixMapComponent;
+import org.apache.camel.spi.ComponentCustomizer;
+import org.apache.camel.spi.HasId;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.ComponentConfigurationProperties;
+import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+/**
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@Configuration
+@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class,
+ AtomixMapComponentAutoConfiguration.GroupConditions.class})
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties({ComponentConfigurationProperties.class,
+ AtomixMapComponentConfiguration.class})
+public class AtomixMapComponentAutoConfiguration {
+
+ private static final Logger LOGGER = LoggerFactory
+ .getLogger(AtomixMapComponentAutoConfiguration.class);
+ @Autowired
+ private ApplicationContext applicationContext;
+ @Autowired
+ private CamelContext camelContext;
+ @Autowired
+ private AtomixMapComponentConfiguration configuration;
+ @Autowired(required = false)
+ private List<ComponentCustomizer<AtomixMapComponent>> customizers;
+
+ static class GroupConditions extends GroupCondition {
+ public GroupConditions() {
+ super("camel.component", "camel.component.atomix-map");
+ }
+ }
+
+ @Lazy
+ @Bean(name = "atomix-map-component")
+ @ConditionalOnMissingBean(AtomixMapComponent.class)
+ public AtomixMapComponent configureAtomixMapComponent() throws Exception {
+ AtomixMapComponent component = new AtomixMapComponent();
+ component.setCamelContext(camelContext);
+ Map<String, Object> parameters = new HashMap<>();
+ IntrospectionSupport.getProperties(configuration, parameters, null,
+ false);
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ Object value = entry.getValue();
+ Class<?> paramClass = value.getClass();
+ if (paramClass.getName().endsWith("NestedConfiguration")) {
+ Class nestedClass = null;
+ try {
+ nestedClass = (Class) paramClass.getDeclaredField(
+ "CAMEL_NESTED_CLASS").get(null);
+ HashMap<String, Object> nestedParameters = new HashMap<>();
+ IntrospectionSupport.getProperties(value, nestedParameters,
+ null, false);
+ Object nestedProperty = nestedClass.newInstance();
+ IntrospectionSupport.setProperties(camelContext,
+ camelContext.getTypeConverter(), nestedProperty,
+ nestedParameters);
+ entry.setValue(nestedProperty);
+ } catch (NoSuchFieldException e) {
+ }
+ }
+ }
+ IntrospectionSupport.setProperties(camelContext,
+ camelContext.getTypeConverter(), component, parameters);
+ if (ObjectHelper.isNotEmpty(customizers)) {
+ for (ComponentCustomizer<AtomixMapComponent> customizer : customizers) {
+ boolean useCustomizer = (customizer instanceof HasId)
+ ? HierarchicalPropertiesEvaluator.evaluate(
+ applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.atomix-map.customizer",
+ ((HasId) customizer).getId())
+ : HierarchicalPropertiesEvaluator.evaluate(
+ applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.atomix-map.customizer");
+ if (useCustomizer) {
+ LOGGER.debug("Configure component {}, with customizer {}",
+ component, customizer);
+ customizer.customize(component);
+ }
+ }
+ }
+ return component;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/3756fba2/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixMapComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixMapComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixMapComponentConfiguration.java
new file mode 100644
index 0000000..dcac61f
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-atomix-starter/src/main/java/org/apache/camel/component/atomix/client/map/springboot/AtomixMapComponentConfiguration.java
@@ -0,0 +1,158 @@
+/**
+ * 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.atomix.client.map.springboot;
+
+import java.util.List;
+import javax.annotation.Generated;
+import io.atomix.AtomixClient;
+import io.atomix.catalyst.transport.Address;
+import org.apache.camel.component.atomix.client.map.AtomixMap.Action;
+import org.apache.camel.component.atomix.client.map.AtomixMapComponent;
+import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
+
+/**
+ * Camel Atomix support
+ *
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@ConfigurationProperties(prefix = "camel.component.atomix-map")
+public class AtomixMapComponentConfiguration
+ extends
+ ComponentConfigurationPropertiesCommon {
+
+ /**
+ * The shared component configuration
+ */
+ private AtomixMapConfigurationNestedConfiguration configuration;
+ /**
+ * The shared AtomixClient instance
+ */
+ @NestedConfigurationProperty
+ private AtomixClient atomix;
+ /**
+ * The nodes the AtomixClient should connect to
+ */
+ private List<Address> nodes;
+ /**
+ * The path to the AtomixClient configuration
+ */
+ private String configurationUri;
+ /**
+ * Whether the component should resolve property placeholders on itself when
+ * starting. Only properties which are of String type can use property
+ * placeholders.
+ */
+ private Boolean resolvePropertyPlaceholders = true;
+
+ public AtomixMapConfigurationNestedConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(
+ AtomixMapConfigurationNestedConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public AtomixClient getAtomix() {
+ return atomix;
+ }
+
+ public void setAtomix(AtomixClient atomix) {
+ this.atomix = atomix;
+ }
+
+ public List<Address> getNodes() {
+ return nodes;
+ }
+
+ public void setNodes(List<Address> nodes) {
+ this.nodes = nodes;
+ }
+
+ public String getConfigurationUri() {
+ return configurationUri;
+ }
+
+ public void setConfigurationUri(String configurationUri) {
+ this.configurationUri = configurationUri;
+ }
+
+ public Boolean getResolvePropertyPlaceholders() {
+ return resolvePropertyPlaceholders;
+ }
+
+ public void setResolvePropertyPlaceholders(
+ Boolean resolvePropertyPlaceholders) {
+ this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
+ }
+
+ public static class AtomixMapConfigurationNestedConfiguration {
+ public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.atomix.client.map.AtomixMapConfiguration.class;
+ /**
+ * The default action.
+ */
+ private Action defaultAction = Action.PUT;
+ /**
+ * The key to use if none is set in the header or to listen for events
+ * for a specific key.
+ */
+ private Object key;
+ /**
+ * The resource ttl.
+ */
+ private Long ttl;
+ /**
+ * The header that wil carry the result.
+ */
+ private String resultHeader;
+
+ public Action getDefaultAction() {
+ return defaultAction;
+ }
+
+ public void setDefaultAction(Action defaultAction) {
+ this.defaultAction = defaultAction;
+ }
+
+ public Object getKey() {
+ return key;
+ }
+
+ public void setKey(Object key) {
+ this.key = key;
+ }
+
+ public Long getTtl() {
+ return ttl;
+ }
+
+ public void setTtl(Long ttl) {
+ this.ttl = ttl;
+ }
+
+ public String getResultHeader() {
+ return resultHeader;
+ }
+
+ public void setResultHeader(String resultHeader) {
+ this.resultHeader = resultHeader;
+ }
+ }
+}
\ No newline at end of file