Repository: camel Updated Branches: refs/heads/master 3f6aa3ec1 -> 3aee44041
http://git-wip-us.apache.org/repos/asf/camel/blob/c3cfb652/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/MockQueue.java ---------------------------------------------------------------------- diff --git a/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/MockQueue.java b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/MockQueue.java new file mode 100644 index 0000000..1d917a8 --- /dev/null +++ b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/MockQueue.java @@ -0,0 +1,141 @@ +/** + * 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.ironmq; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; +import java.util.UUID; + +import io.iron.ironmq.Client; +import io.iron.ironmq.EmptyQueueException; +import io.iron.ironmq.HTTPException; +import io.iron.ironmq.Ids; +import io.iron.ironmq.Message; +import io.iron.ironmq.MessageOptions; +import io.iron.ironmq.Messages; +import io.iron.ironmq.Queue; + +public class MockQueue extends Queue { + private Map<String, Message> messages = new LinkedHashMap<String, Message>(); + + public MockQueue(Client client, String name) { + super(client, name); + } + + @Override + public String push(String msg, long delay) throws IOException { + String randint = new BigInteger(24 * 8, new Random()).toString(16); + Message message = new Message(); + message.setBody(msg); + message.setDelay(delay); + message.setId(randint); + message.setReservationId(UUID.randomUUID().toString()); + messages.put(randint, message); + return randint; + } + + @Override + public Ids pushMessages(String[] msg, long delay) throws IOException { + for (String messageName : msg) { + Message message = new Message(); + message.setBody(messageName); + message.setDelay(delay); + String randint = new BigInteger(24 * 8, new Random()).toString(16); + message.setId(randint); + message.setReservationId(UUID.randomUUID().toString()); + messages.put(randint, message); + } + Ids ids = null; + try { + Constructor<Ids> constructor = Ids.class.getDeclaredConstructor(Messages.class); + constructor.setAccessible(true); + Messages messageList = new Messages(new ArrayList<Message>(messages.values())); + ids = constructor.newInstance(messageList); + } catch (Exception e) { + } + return ids; + } + + @Override + public void deleteMessage(String id, String reservationId) throws IOException { + if (messages.containsKey(id)) { + messages.remove(id); + } else { + throw new HTTPException(404, "not found"); + } + } + + @Override + public void deleteMessages(Messages messages) throws IOException { + MessageOptions[] messageOptions = messages.toMessageOptions(); + for (int i = 0; i < messageOptions.length; i++) { + deleteMessage(messageOptions[i].getId(), messageOptions[i].getReservationId()); + } + } + + @Override + public Message peek() throws IOException { + if (messages.size() > 0) { + return messages.entrySet().iterator().next().getValue(); + } + throw new EmptyQueueException(); + } + + @Override + public Message reserve() throws IOException { + if (messages.size() > 0) { + Entry<String, Message> next = messages.entrySet().iterator().next(); + return next.getValue(); + } + throw new EmptyQueueException(); + } + + @Override + public Messages reserve(int numberOfMessages) throws IOException { + return reserve(numberOfMessages, 120); + } + + @Override + public Messages reserve(int numberOfMessages, int timeout, int wait) throws IOException { + if (messages.size() > 0) { + + Iterator<Entry<String, Message>> iterator = messages.entrySet().iterator(); + int i = 0; + List<Message> list = new ArrayList<Message>(); + while (iterator.hasNext() && i < numberOfMessages) { + Entry<String, Message> next = iterator.next(); + list.add(next.getValue()); + i++; + } + Messages messages = new Messages(list.toArray(new Message[list.size()])); + return messages; + } + throw new EmptyQueueException(); + } + + void add(Message message) { + messages.put(message.getId(), message); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/c3cfb652/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/ConcurrentConsumerLoadTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/ConcurrentConsumerLoadTest.java b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/ConcurrentConsumerLoadTest.java new file mode 100644 index 0000000..57e5ce0 --- /dev/null +++ b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/ConcurrentConsumerLoadTest.java @@ -0,0 +1,100 @@ +/** + * 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.ironmq.integrationtest; + +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.ironmq.IronMQConstants; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +@Ignore("Must be manually tested. Provide your own projectId and token!") +public class ConcurrentConsumerLoadTest extends CamelTestSupport { + private static final String IRONMQCLOUD = "https://mq-aws-eu-west-1-1.iron.io"; + private static final int NO_OF_MESSAGES = 50000; + private static final String BATCH_DELETE = "true"; + private static final int CONCURRENT_CONSUMERS = 20; + private static final String PAYLOAD = "{some:text, number:#}"; + + // replace with your project id + private final String projectId = "myIronMQproject"; + // replace with your token + private final String token = "myIronMQToken"; + // replace with your test queue name + private final String ironmqQueue = "testqueue"; + + private final String ironMQEndpoint = "ironmq:" + ironmqQueue + "?projectId=" + projectId + "&token=" + token + "&maxMessagesPerPoll=100&wait=30&ironMQCloud=" + IRONMQCLOUD + + "&concurrentConsumers=" + CONCURRENT_CONSUMERS + "&batchDelete=" + BATCH_DELETE; + private final String sedaEndpoint = "seda:push?concurrentConsumers=" + CONCURRENT_CONSUMERS; + + @Before + public void prepareQueue() throws InterruptedException { + // make sure the queue is empty before test + template.sendBodyAndHeader(ironMQEndpoint, null, IronMQConstants.OPERATION, IronMQConstants.CLEARQUEUE); + long start = System.currentTimeMillis(); + int noOfBlocks = 0; + ArrayList<String> list = new ArrayList<String>(); + for (int i = 1; i <= NO_OF_MESSAGES; i++) { + String payloadToSend = PAYLOAD.replace("#", "" + i); + list.add(payloadToSend); + if (i % 100 == 0) { + noOfBlocks++; + System.out.println("sending blok " + noOfBlocks); + template.sendBody(sedaEndpoint, list.toArray(new String[0])); + list.clear(); + } + } + MockEndpoint mockEndpoint = getMockEndpoint("mock:iron"); + while (mockEndpoint.getReceivedCounter() != noOfBlocks) { + log.info("Waiting for queue to fill up. Current size is " + mockEndpoint.getReceivedCounter() * 100); + Thread.sleep(1000); + } + long delta = System.currentTimeMillis() - start; + int seconds = (int)delta / 1000; + int msgPrSec = (int)(NO_OF_MESSAGES / seconds); + log.info("IronMQPerformanceTest: Took: " + seconds + " seconds to produce " + NO_OF_MESSAGES + " messages. Which is " + msgPrSec + " messages pr. second"); + } + + @Test + public void testConcurrentConsumers() throws Exception { + long start = System.currentTimeMillis(); + context.startRoute("iron"); + MockEndpoint endpoint = getMockEndpoint("mock:result"); + endpoint.expectedMessageCount(NO_OF_MESSAGES); + assertMockEndpointsSatisfied(4, TimeUnit.MINUTES); + long delta = System.currentTimeMillis() - start; + int seconds = (int)delta / 1000; + int msgPrSec = (int)(NO_OF_MESSAGES / seconds); + log.info("IronmqPerformanceTest: Took: " + seconds + " seconds to consume " + NO_OF_MESSAGES + " messages. Which is " + msgPrSec + " messages pr. second"); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from(ironMQEndpoint).id("iron").autoStartup(false).to("mock:result"); + from(sedaEndpoint).to(ironMQEndpoint).to("mock:iron"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/c3cfb652/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/FileCopyExample.java ---------------------------------------------------------------------- diff --git a/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/FileCopyExample.java b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/FileCopyExample.java new file mode 100644 index 0000000..6461bf5 --- /dev/null +++ b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/FileCopyExample.java @@ -0,0 +1,59 @@ +/** + * 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.ironmq.integrationtest; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.ironmq.IronMQConstants; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +@Ignore("Integration test that requires ironmq account.") +public class FileCopyExample extends CamelTestSupport { + // replace with your proejctid + private String projectId = "myIronMQproject"; + // replace with your token + private String token = "myIronMQToken"; + + private final String ironMQEndpoint = "ironmq:testqueue?projectId=" + projectId + "&token=" + token + "&ironMQCloud=https://mq-aws-eu-west-1-1.iron.io&preserveHeaders=true"; + + @Before + public void clean() { + template.sendBodyAndHeader(ironMQEndpoint, "fo", IronMQConstants.OPERATION, IronMQConstants.CLEARQUEUE); + deleteDirectory("target/out"); + } + + @Test + public void testCopyFileOverIronMQ() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(1); + assertMockEndpointsSatisfied(); + assertFileExists("target/out/test.txt"); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + //copies test.txt from test/data to ironmq + from("file:src/test/data?noop=true").convertBodyTo(String.class).log("sending : ${body}").to(ironMQEndpoint); + //Receives test.txt from ironmq and writes it to target/out + from(ironMQEndpoint).log("got message : ${body}").to("file:target/out").to("mock:result"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/c3cfb652/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/IronMQComponentTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/IronMQComponentTest.java b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/IronMQComponentTest.java new file mode 100644 index 0000000..a094a50 --- /dev/null +++ b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/IronMQComponentTest.java @@ -0,0 +1,61 @@ +/** + * 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.ironmq.integrationtest; + +import org.apache.camel.EndpointInject; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; + +@Ignore("Must be manually tested. Provide your own projectId and token!") +public class IronMQComponentTest extends CamelTestSupport { + private String projectId = "myIronMQproject"; + private String token = "myIronMQToken"; + + @EndpointInject(uri = "direct:start") + private ProducerTemplate template; + + @EndpointInject(uri = "mock:result") + private MockEndpoint result; + + @Test + public void testIronMQ() throws Exception { + result.setExpectedMessageCount(1); + result.expectedBodiesReceived("some payload"); + template.sendBody("some payload"); + + assertMockEndpointsSatisfied(); + String id = result.getExchanges().get(0).getIn().getHeader("MESSAGE_ID", String.class); + Assert.assertNotNull(id); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + final String ironMQEndpoint = "ironmq:testqueue?projectId=" + projectId + "&token=" + token; + return new RouteBuilder() { + public void configure() { + from("direct:start").to(ironMQEndpoint); + + from(ironMQEndpoint + "&maxMessagesPerPoll=5").to("mock:result"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/c3cfb652/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/IronMQFIFOTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/IronMQFIFOTest.java b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/IronMQFIFOTest.java new file mode 100644 index 0000000..44d651f --- /dev/null +++ b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/IronMQFIFOTest.java @@ -0,0 +1,74 @@ +/** + * 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.ironmq.integrationtest; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.ironmq.IronMQConstants; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +@Ignore("Integration test that requires ironmq account.") +public class IronMQFIFOTest extends CamelTestSupport { + private String projectId = "replace-this"; + private String token = "replace-this"; + + private final String ironMQEndpoint = "ironmq:testqueue?projectId=" + projectId + "&token=" + token + "&maxMessagesPerPoll=20&ironMQCloud=https://mq-v3-aws-us-east-1.iron.io"; + + @EndpointInject(uri = "direct:start") + private ProducerTemplate template; + + @EndpointInject(uri = "mock:result") + private MockEndpoint result; + + @Before + public void clearQueue() { + template.sendBodyAndHeader(ironMQEndpoint, "fo", IronMQConstants.OPERATION, IronMQConstants.CLEARQUEUE); + for (int i = 1; i <= 50; i++) { + template.sendBody(ironMQEndpoint, "<foo>" + i + "</foo>"); + } + } + + @Test + public void testIronMQFifo() throws Exception { + result.setExpectedMessageCount(50); + assertMockEndpointsSatisfied(30, TimeUnit.SECONDS); + int i = 1; + List<Exchange> exchanges = result.getExchanges(); + for (Exchange exchange : exchanges) { + assertEquals("<foo>" + i + "</foo>", exchange.getIn().getBody(String.class)); + i++; + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + from(ironMQEndpoint).log("got message ${body}").to("mock:result"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/c3cfb652/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/IronMQRackspaceComponentTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/IronMQRackspaceComponentTest.java b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/IronMQRackspaceComponentTest.java new file mode 100644 index 0000000..e241188 --- /dev/null +++ b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/IronMQRackspaceComponentTest.java @@ -0,0 +1,61 @@ +/** + * 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.ironmq.integrationtest; + +import org.apache.camel.EndpointInject; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; + +@Ignore("Must be manually tested. Provide your own projectId and token!") +public class IronMQRackspaceComponentTest extends CamelTestSupport { + private String projectId = "myIronMQproject"; + private String token = "myIronMQToken"; + + @EndpointInject(uri = "direct:start") + private ProducerTemplate template; + + @EndpointInject(uri = "mock:result") + private MockEndpoint result; + + @Test + public void testIronMQ() throws Exception { + result.setExpectedMessageCount(1); + result.expectedBodiesReceived("some payload"); + template.sendBody("some payload"); + + assertMockEndpointsSatisfied(); + String id = result.getExchanges().get(0).getIn().getHeader("MESSAGE_ID", String.class); + Assert.assertNotNull(id); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + final String ironMQEndpoint = "ironmq:testqueue?projectId=" + projectId + "&token=" + token + "&ironMQCloud=https://mq-rackspace-lon.iron.io"; + return new RouteBuilder() { + public void configure() { + from("direct:start").to(ironMQEndpoint); + + from(ironMQEndpoint + "&maxMessagesPerPoll=5").to("mock:result"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/c3cfb652/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/LoadTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/LoadTest.java b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/LoadTest.java new file mode 100644 index 0000000..3708b41 --- /dev/null +++ b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/LoadTest.java @@ -0,0 +1,89 @@ +/** + * 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.ironmq.integrationtest; + +import java.util.concurrent.TimeUnit; + +import javax.naming.Context; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.dataset.DataSetSupport; +import org.apache.camel.component.ironmq.IronMQConstants; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +@Ignore("Integration test that requires ironmq account.") +public class LoadTest extends CamelTestSupport { + private static final String IRONMQCLOUD = "http://mq-v3-aws-us-east-1.iron.io"; + + // replace with your project id + private final String projectId = "replace-this"; + // replace with your token + private final String token = "replace-this"; + + private final String ironMQEndpoint = "ironmq:testqueue?preserveHeaders=true&projectId=" + projectId + "&token=" + token + + "&maxMessagesPerPoll=100&delay=3000&wait=30&ironMQCloud=" + IRONMQCLOUD; + private final String datasetEndpoint = "dataset:foo?produceDelay=5"; + private InputDataset dataSet = new InputDataset(1000); + + @Before + public void clearQueue() { + // make sure the queue is empty before test + template.sendBodyAndHeader(ironMQEndpoint, null, IronMQConstants.OPERATION, IronMQConstants.CLEARQUEUE); + } + + @Test + public void testDataSet() throws Exception { + MockEndpoint endpoint = getMockEndpoint(datasetEndpoint); + endpoint.expectedMessageCount((int)dataSet.getSize()); + + assertMockEndpointsSatisfied(4, TimeUnit.MINUTES); + } + + @Override + protected Context createJndiContext() throws Exception { + Context context = super.createJndiContext(); + context.bind("foo", dataSet); + return context; + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from(datasetEndpoint).to(ironMQEndpoint); + from(ironMQEndpoint).to(datasetEndpoint); + } + }; + } + + public class InputDataset extends DataSetSupport { + + public InputDataset(int size) { + super(size); + } + + @Override + protected Object createMessageBody(long messageIndex) { + return "<hello>" + messageIndex; + } + + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/c3cfb652/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/Queue2QueueExample.java ---------------------------------------------------------------------- diff --git a/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/Queue2QueueExample.java b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/Queue2QueueExample.java new file mode 100644 index 0000000..94766c2 --- /dev/null +++ b/components/camel-ironmq/src/test/java/org/apache/camel/component/ironmq/integrationtest/Queue2QueueExample.java @@ -0,0 +1,66 @@ +/** + * 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.ironmq.integrationtest; + +import java.util.concurrent.TimeUnit; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.ironmq.IronMQConstants; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +@Ignore("Must be manually tested. Provide your own projectId and token!") +public class Queue2QueueExample extends CamelTestSupport { + private static final String PAYLOAD = "{some:text, number:#}"; + + // replace with your proejctid + private String projectId = "myIronMQproject"; + // replace with your token + private String token = "myIronMQToken"; + + private final String ironQueue1 = "ironmq:queue1?projectId=" + projectId + "&token=" + token + "&ironMQCloud=https://mq-aws-eu-west-1-1.iron.io"; + private final String ironQueue2 = "ironmq:queue2?projectId=" + projectId + "&token=" + token + "&ironMQCloud=https://mq-aws-eu-west-1-1.iron.io"; + + @Before + public void clean() { + template.sendBodyAndHeader(ironQueue1, "fo", IronMQConstants.OPERATION, IronMQConstants.CLEARQUEUE); + template.sendBodyAndHeader(ironQueue2, "fo", IronMQConstants.OPERATION, IronMQConstants.CLEARQUEUE); + } + + @Test + public void testSendMessagesBetweenQueues() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(100); + for (int i = 1; i <= 100; i++) { + String payloadToSend = PAYLOAD.replace("#", "" + i); + template.sendBody("direct:start", payloadToSend); + } + assertMockEndpointsSatisfied(2, TimeUnit.MINUTES); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + from("direct:start").to(ironQueue1); + from(ironQueue1).to(ironQueue2); + from(ironQueue2).log("got message : ${body}").to("mock:result"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/c3cfb652/components/camel-ironmq/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-ironmq/src/test/resources/log4j.properties b/components/camel-ironmq/src/test/resources/log4j.properties new file mode 100644 index 0000000..192c631 --- /dev/null +++ b/components/camel-ironmq/src/test/resources/log4j.properties @@ -0,0 +1,41 @@ +## ------------------------------------------------------------------------ +## 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. +## ------------------------------------------------------------------------ + +# +# The logging properties used for testing. +# +log4j.rootLogger=INFO, file + +# uncomment the following line to turn on Camel debugging +#log4j.logger.org.apache.camel.component.ironmq=TRACE + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +# MDC +#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{camel.breadcrumbId} - %-10.10X{camelexchangeId} - %-10.10X{camel.correlationId} - %-10.10X{camel.routeId} - %m%n + +# File appender +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.file=target/camel-ironmq-test.log +log4j.appender.file.append=true +log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +# MDC +#log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{camel.breadcrumbId} - %-10.10X{camel.exchangeId} - %-10.10X{camel.correlationId} - %-10.10X{camel.routeId} - %m%n + http://git-wip-us.apache.org/repos/asf/camel/blob/c3cfb652/components/camel-ironmq/src/test/resources/org/apache/camel/component/ironmq/IronMQComponentSpringTest-context.xml ---------------------------------------------------------------------- diff --git a/components/camel-ironmq/src/test/resources/org/apache/camel/component/ironmq/IronMQComponentSpringTest-context.xml b/components/camel-ironmq/src/test/resources/org/apache/camel/component/ironmq/IronMQComponentSpringTest-context.xml new file mode 100644 index 0000000..293463e --- /dev/null +++ b/components/camel-ironmq/src/test/resources/org/apache/camel/component/ironmq/IronMQComponentSpringTest-context.xml @@ -0,0 +1,39 @@ +<?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"> + + <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:start"/> + <to uri="ironmq://testqueue?client=#client"/> + </route> + + <route> + <from uri="ironmq://testqueue?client=#client&maxMessagesPerPoll=20"/> + <to uri="mock:result"/> + </route> + </camelContext> + + <bean id="client" class="org.apache.camel.component.ironmq.IronMQClientMock"> + <constructor-arg name="projectId" value="foo"/> + <constructor-arg name="token" value="bar"/> + </bean> +</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/c3cfb652/components/pom.xml ---------------------------------------------------------------------- diff --git a/components/pom.xml b/components/pom.xml index eafbc1a..7da5a56 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -129,6 +129,7 @@ <module>camel-ignite</module> <module>camel-infinispan</module> <module>camel-irc</module> + <module>camel-ironmq</module> <module>camel-jackson</module> <module>camel-jacksonxml</module> <module>camel-javaspace</module> http://git-wip-us.apache.org/repos/asf/camel/blob/c3cfb652/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index fa3faa7..8a62705 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -248,6 +248,7 @@ <infinispan-version>8.1.2.Final</infinispan-version> <irclib-bundle-version>1.10_5</irclib-bundle-version> <irclib-version>1.10</irclib-version> + <ironmq-version>3.0.3</ironmq-version> <isorelax-bundle-version>20050913_4</isorelax-bundle-version> <isorelax-version>20090621</isorelax-version> <isorelax-jaxp-bridge-version>1.1</isorelax-jaxp-bridge-version>