You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/09/26 08:30:09 UTC
[2/2] camel git commit: Fixed CS. Polished. This closes #621.
Fixed CS. Polished. This closes #621.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e2d378fc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e2d378fc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e2d378fc
Branch: refs/heads/master
Commit: e2d378fcdc5abd157cf500ff883f7085d21250cc
Parents: f38a560
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Sep 26 08:31:47 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Sep 26 08:31:47 2015 +0200
----------------------------------------------------------------------
components/camel-spring-redis/pom.xml | 125 +++++------
...ringIdempotentRepositoryIntegrationTest.java | 210 ++++++++++---------
.../RedisStringIdempotentRepositoryTest.java | 101 +++++----
3 files changed, 232 insertions(+), 204 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e2d378fc/components/camel-spring-redis/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring-redis/pom.xml b/components/camel-spring-redis/pom.xml
index c678016..9e714be 100755
--- a/components/camel-spring-redis/pom.xml
+++ b/components/camel-spring-redis/pom.xml
@@ -15,71 +15,72 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.camel</groupId>
- <artifactId>components</artifactId>
- <version>2.16-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.16-SNAPSHOT</version>
+ </parent>
- <artifactId>camel-spring-redis</artifactId>
- <packaging>bundle</packaging>
- <name>Camel :: Redis</name>
- <description>Camel Spring Redis Component</description>
+ <artifactId>camel-spring-redis</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: Redis</name>
+ <description>Camel Spring Redis Component</description>
- <properties>
- <camel.osgi.export.pkg>org.apache.camel.component.redis.*</camel.osgi.export.pkg>
- <camel.osgi.import.before.defaults>org.springframework.data.*;version="[1.0,2)"</camel.osgi.import.before.defaults>
- <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=redis</camel.osgi.export.service>
- </properties>
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.component.redis.*</camel.osgi.export.pkg>
+ <camel.osgi.import.before.defaults>org.springframework.data.*;version="[1.0,2)"</camel.osgi.import.before.defaults>
+ <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=redis</camel.osgi.export.service>
+ </properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.data</groupId>
- <artifactId>spring-data-redis</artifactId>
- <version>${spring-data-redis-version}</version>
- </dependency>
- <dependency>
- <groupId>redis.clients</groupId>
- <artifactId>jedis</artifactId>
- <version>${jedis-client-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test-spring</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>commons-pool</groupId>
- <artifactId>commons-pool</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.data</groupId>
+ <artifactId>spring-data-redis</artifactId>
+ <version>${spring-data-redis-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>redis.clients</groupId>
+ <artifactId>jedis</artifactId>
+ <version>${jedis-client-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-spring</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-pool</groupId>
+ <artifactId>commons-pool</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/e2d378fc/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepositoryIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepositoryIntegrationTest.java b/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepositoryIntegrationTest.java
index 605eaad..277bb51 100644
--- a/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepositoryIntegrationTest.java
+++ b/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepositoryIntegrationTest.java
@@ -1,5 +1,23 @@
+/**
+ * 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.redis.processor.idempotent;
+import javax.annotation.Resource;
+
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
@@ -12,108 +30,104 @@ import org.junit.Ignore;
import org.junit.Test;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.serializer.StringRedisSerializer;
-import javax.annotation.Resource;
+@Ignore("requires online connection")
+public class RedisStringIdempotentRepositoryIntegrationTest extends CamelTestSupport {
+ private static final JedisConnectionFactory CONNECTION_FACTORY = new JedisConnectionFactory();
-@Ignore
-public class RedisStringIdempotentRepositoryIntegrationTest extends CamelTestSupport {
+ protected RedisStringIdempotentRepository idempotentRepository;
+
+ @Produce(uri = "direct:start")
+ private ProducerTemplate producer;
+
+ @EndpointInject(uri = "mock:result")
+ private MockEndpoint mockResult;
+
+ @Resource
+ private RedisTemplate redisTemplate;
+
+ static {
+ CONNECTION_FACTORY.afterPropertiesSet();
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ redisTemplate = new RedisTemplate();
+ redisTemplate.setConnectionFactory(CONNECTION_FACTORY);
+ redisTemplate.afterPropertiesSet();
+
+ registry.bind("redisTemplate", redisTemplate);
+ return registry;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ idempotentRepository = new RedisStringIdempotentRepository(redisTemplate,
+ "redis-idempotent-repository");
+ RouteBuilder rb = new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").idempotentConsumer(body(), idempotentRepository).to("mock:result");
+ }
+ };
+ return rb;
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ context.setTracing(true);
+ return context;
+ }
+
+ @Test
+ public void blockDoubleSubmission() throws Exception {
+ mockResult.expectedMessageCount(3);
+ mockResult.setResultWaitTime(5000);
+ producer.sendBody("abc");
+ producer.sendBody("bcd");
+ producer.sendBody("abc");
+ producer.sendBody("xyz");
+
+ assertTrue(idempotentRepository.contains("abc"));
+ assertTrue(idempotentRepository.contains("bcd"));
+ assertTrue(idempotentRepository.contains("xyz"));
+ assertFalse(idempotentRepository.contains("mustNotContain"));
+ mockResult.assertIsSatisfied();
+
+ }
+
+ @Test
+ public void clearIdempotentRepository() {
+ for (int i = 0; i < 10000; i++) {
+ redisTemplate.opsForValue().set("key4711", "value4711");
+ }
+ assertEquals("value4711", redisTemplate.opsForValue().get("key4711"));
+ producer.sendBody("abc");
+ producer.sendBody("bcd");
+ redisTemplate.opsForValue().set("redis1", "1");
+ redisTemplate.opsForValue().set("different:xyz", "2");
+ assertTrue(idempotentRepository.contains("abc"));
+ assertTrue(idempotentRepository.contains("bcd"));
+ idempotentRepository.clear();
+ assertFalse(idempotentRepository.contains("abc"));
+ assertFalse(idempotentRepository.contains("bcd"));
+ assertFalse(idempotentRepository.contains("redis1"));
+ assertFalse(idempotentRepository.contains("different:xyz"));
+
+ assertEquals("1", redisTemplate.opsForValue().get("redis1"));
+ assertEquals("2", redisTemplate.opsForValue().get("different:xyz"));
+ }
- @Produce(uri = "direct:start")
- private ProducerTemplate producer;
-
- @EndpointInject(uri = "mock:result")
- private MockEndpoint mockResult;
-
- @Resource
- private RedisTemplate redisTemplate;
-
- protected RedisStringIdempotentRepository idempotentRepository;
-
- private static final JedisConnectionFactory CONNECTION_FACTORY = new JedisConnectionFactory();
-
- static {
- CONNECTION_FACTORY.afterPropertiesSet();
- }
-
- @Override
- protected JndiRegistry createRegistry() throws Exception {
- JndiRegistry registry = super.createRegistry();
- redisTemplate = new RedisTemplate();
- redisTemplate.setConnectionFactory(CONNECTION_FACTORY);
- redisTemplate.afterPropertiesSet();
-
- registry.bind("redisTemplate", redisTemplate);
- return registry;
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- idempotentRepository = new RedisStringIdempotentRepository(redisTemplate,
- "redis-idempotent-repository");
- RouteBuilder rb = new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start").idempotentConsumer(body(), idempotentRepository).to("mock:result");
- }
- };
- return rb;
- }
-
- @Override
- protected CamelContext createCamelContext() throws Exception {
- CamelContext context = super.createCamelContext();
- context.setTracing(true);
- return context;
- }
-
- @Test
- public void blockDoubleSubmission() throws Exception {
- mockResult.expectedMessageCount(3);
- mockResult.setResultWaitTime(5000);
- producer.sendBody("abc");
- producer.sendBody("bcd");
- producer.sendBody("abc");
- producer.sendBody("xyz");
-
- assertTrue(idempotentRepository.contains("abc"));
- assertTrue(idempotentRepository.contains("bcd"));
- assertTrue(idempotentRepository.contains("xyz"));
- assertFalse(idempotentRepository.contains("mustNotContain"));
- mockResult.assertIsSatisfied();
-
- }
-
- @Test
- public void clearIdempotentRepository() {
- for (int i = 0; i < 10000; i++) {
- redisTemplate.opsForValue().set("key4711", "value4711");
+ @Test
+ public void expireIdempotent() throws Exception {
+ idempotentRepository.setExpiry(5L);
+ producer.sendBody("abc");
+ assertTrue(idempotentRepository.contains("abc"));
+ Thread.sleep(5000);
+ assertFalse(idempotentRepository.contains("abc"));
}
- assertEquals("value4711", redisTemplate.opsForValue().get("key4711"));
- producer.sendBody("abc");
- producer.sendBody("bcd");
- redisTemplate.opsForValue().set("redis1", "1");
- redisTemplate.opsForValue().set("different:xyz", "2");
- assertTrue(idempotentRepository.contains("abc"));
- assertTrue(idempotentRepository.contains("bcd"));
- idempotentRepository.clear();
- assertFalse(idempotentRepository.contains("abc"));
- assertFalse(idempotentRepository.contains("bcd"));
- assertFalse(idempotentRepository.contains("redis1"));
- assertFalse(idempotentRepository.contains("different:xyz"));
-
- assertEquals("1", redisTemplate.opsForValue().get("redis1"));
- assertEquals("2", redisTemplate.opsForValue().get("different:xyz"));
- }
-
- @Test
- public void expireIdempotent() throws Exception {
- idempotentRepository.setExpiry(5L);
- producer.sendBody("abc");
- assertTrue(idempotentRepository.contains("abc"));
- Thread.sleep(5000);
- assertFalse(idempotentRepository.contains("abc"));
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/e2d378fc/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepositoryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepositoryTest.java b/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepositoryTest.java
index 946fd95..81ae079 100644
--- a/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepositoryTest.java
+++ b/components/camel-spring-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepositoryTest.java
@@ -1,5 +1,23 @@
+/**
+ * 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.redis.processor.idempotent;
+import java.util.concurrent.TimeUnit;
+
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisConnection;
@@ -8,61 +26,56 @@ import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
-import java.util.concurrent.TimeUnit;
-
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-/**
- * Created with IntelliJ IDEA. User: Marco Zapletal Date: 06.07.2015 Time: 18:47
- */
public class RedisStringIdempotentRepositoryTest {
- private static final String REPOSITORY = "testRepository";
- private static final String KEY = "KEY";
- private RedisTemplate redisTemplate;
- private RedisConnectionFactory redisConnectionFactory;
- private RedisConnection redisConnection;
- private RedisOperations redisOperations;
- private ValueOperations valueOperations;
- private RedisStringIdempotentRepository idempotentRepository;
+ private static final String REPOSITORY = "testRepository";
+ private static final String KEY = "KEY";
+ private RedisTemplate redisTemplate;
+ private RedisConnectionFactory redisConnectionFactory;
+ private RedisConnection redisConnection;
+ private RedisOperations redisOperations;
+ private ValueOperations valueOperations;
+ private RedisStringIdempotentRepository idempotentRepository;
- @Before
- public void setUp() throws Exception {
- redisTemplate = mock(RedisTemplate.class);
- valueOperations = mock(ValueOperations.class);
- redisConnection = mock(RedisConnection.class);
- redisOperations = mock(RedisOperations.class);
- redisConnectionFactory = mock(RedisConnectionFactory.class);
- when(redisTemplate.opsForValue()).thenReturn(valueOperations);
- when(redisTemplate.getConnectionFactory()).thenReturn(redisConnectionFactory);
- when(valueOperations.getOperations()).thenReturn(redisOperations);
- when(redisTemplate.getConnectionFactory().getConnection()).thenReturn(redisConnection);
- idempotentRepository = new RedisStringIdempotentRepository(redisTemplate, REPOSITORY);
- idempotentRepository.setExpiry(1000L);
- }
+ @Before
+ public void setUp() throws Exception {
+ redisTemplate = mock(RedisTemplate.class);
+ valueOperations = mock(ValueOperations.class);
+ redisConnection = mock(RedisConnection.class);
+ redisOperations = mock(RedisOperations.class);
+ redisConnectionFactory = mock(RedisConnectionFactory.class);
+ when(redisTemplate.opsForValue()).thenReturn(valueOperations);
+ when(redisTemplate.getConnectionFactory()).thenReturn(redisConnectionFactory);
+ when(valueOperations.getOperations()).thenReturn(redisOperations);
+ when(redisTemplate.getConnectionFactory().getConnection()).thenReturn(redisConnection);
+ idempotentRepository = new RedisStringIdempotentRepository(redisTemplate, REPOSITORY);
+ idempotentRepository.setExpiry(1000L);
+ }
- @Test
- public void shouldAddKey() {
- idempotentRepository.add(KEY);
- verify(valueOperations).setIfAbsent(idempotentRepository.createRedisKey(KEY), KEY);
- verify(redisOperations)
- .expire(idempotentRepository.createRedisKey(KEY), 1000L, TimeUnit.SECONDS);
- }
+ @Test
+ public void shouldAddKey() {
+ idempotentRepository.add(KEY);
+ verify(valueOperations).setIfAbsent(idempotentRepository.createRedisKey(KEY), KEY);
+ verify(redisOperations)
+ .expire(idempotentRepository.createRedisKey(KEY), 1000L, TimeUnit.SECONDS);
+ }
- @Test
- public void shoulCheckForMembers() {
- idempotentRepository.contains(KEY);
- verify(valueOperations).get(idempotentRepository.createRedisKey(KEY));
- }
+ @Test
+ public void shoulCheckForMembers() {
+ idempotentRepository.contains(KEY);
+ verify(valueOperations).get(idempotentRepository.createRedisKey(KEY));
+ }
- @Test
- public void shouldReturnProcessorName() {
- String processorName = idempotentRepository.getProcessorName();
- assertEquals(REPOSITORY, processorName);
- }
+ @Test
+ public void shouldReturnProcessorName() {
+ String processorName = idempotentRepository.getProcessorName();
+ assertEquals(REPOSITORY, processorName);
+ }
}