Skip to content

Commit

Permalink
CAMEL-17907: Add camel-infinispan-starter test
Browse files Browse the repository at this point in the history
  • Loading branch information
Croway committed Apr 12, 2022
1 parent 9d76ec1 commit c642c24
Show file tree
Hide file tree
Showing 25 changed files with 3,122 additions and 0 deletions.
121 changes: 121 additions & 0 deletions components-starter/camel-infinispan-starter/pom.xml
Expand Up @@ -38,11 +38,132 @@
<artifactId>camel-infinispan</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-master-starter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-infra-infinispan</artifactId>
<version>${camel-version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<!-- testing - infinispan -->
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
<version>${infinispan-version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-commons-test</artifactId>
<version>${infinispan-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-spring5-remote</artifactId>
<version>${infinispan-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>sample-domain-definition</artifactId>
<version>${protostream-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>sample-domain-implementation</artifactId>
<version>${protostream-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<!--START OF GENERATED CODE-->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-core-starter</artifactId>
</dependency>
<!--END OF GENERATED CODE-->
</dependencies>
<profiles>
<!-- activate integration test if the docker socket file is accessible -->
<profile>
<id>infinispan-integration-tests-docker-file</id>
<activation>
<file>
<exists>/var/run/docker.sock</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<visibleassertions.silence>true</visibleassertions.silence>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- activate integration test if the DOCKER_HOST env var is set -->
<profile>
<id>infinispan-integration-tests-docker-env</id>
<activation>
<property>
<name>env.DOCKER_HOST</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<visibleassertions.silence>true</visibleassertions.silence>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
@@ -0,0 +1,32 @@
/*
* 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.infinispan;

import org.apache.camel.component.mock.MockEndpoint;
import org.infinispan.commons.api.BasicCache;

public interface InfinispanConsumerTestSupport {
String KEY_ONE = "keyOne";
String VALUE_ONE = "valueOne";
String VALUE_TWO = "valueTwo";

BasicCache<Object, Object> getCache();

BasicCache<Object, Object> getCache(String name);

MockEndpoint getMockEndpoint(String id);
}
@@ -0,0 +1,103 @@
/*
* 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.infinispan;

import java.util.UUID;
import java.util.stream.IntStream;

import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.spi.IdempotentRepository;
import org.infinispan.commons.api.BasicCache;
import org.junit.jupiter.api.Test;

import static org.jgroups.util.Util.assertFalse;
import static org.jgroups.util.Util.assertTrue;

public interface InfinispanIdempotentRepositoryTestSupport {
IdempotentRepository getIdempotentRepository();

BasicCache<Object, Object> getCache();

MockEndpoint getMockEndpoint(String id);

ProducerTemplate template();

@Test
default void addsNewKeysToCache() {
assertTrue(getIdempotentRepository().add("One"));
assertTrue(getIdempotentRepository().add("Two"));

assertTrue(getCache().containsKey("One"));
assertTrue(getCache().containsKey("Two"));
}

@Test
default void skipsAddingSecondTimeTheSameKey() {
assertTrue(getIdempotentRepository().add("One"));
assertFalse(getIdempotentRepository().add("One"));
}

@Test
default void containsPreviouslyAddedKey() {
assertFalse(getIdempotentRepository().contains("One"));

getIdempotentRepository().add("One");

assertTrue(getIdempotentRepository().contains("One"));
}

@Test
default void removesAnExistingKey() {
getIdempotentRepository().add("One");

assertTrue(getIdempotentRepository().remove("One"));

assertFalse(getIdempotentRepository().contains("One"));
}

@Test
default void doesntRemoveMissingKey() {
assertFalse(getIdempotentRepository().remove("One"));
}

@Test
default void clearCache() {
assertTrue(getIdempotentRepository().add("One"));
assertTrue(getIdempotentRepository().add("Two"));

assertTrue(getCache().containsKey("One"));
assertTrue(getCache().containsKey("Two"));

getIdempotentRepository().clear();

assertFalse(getCache().containsKey("One"));
assertFalse(getCache().containsKey("Two"));
}

@Test
default void producerQueryOperationWithoutQueryBuilder() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);

final String messageId = UUID.randomUUID().toString();
IntStream.range(0, 10).forEach(
i -> template().sendBodyAndHeader("direct:start", "message-" + i, "MessageID", messageId));

mock.assertIsSatisfied();
}
}

0 comments on commit c642c24

Please sign in to comment.