forked from spring-projects/spring-integration-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INTSAMPLES-146 Fix Kafka tests and some polishing
- Loading branch information
1 parent
23f4a04
commit 5c4b817
Showing
5 changed files
with
211 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ activemq-data | |
|
||
/.gradle | ||
build/ | ||
/classes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.3.0.M5</version> | ||
</parent> | ||
<groupId>org.springframework.integration.samples</groupId> | ||
<artifactId>kafka</artifactId> | ||
<version>4.1.0.BUILD-SNAPSHOT</version> | ||
<name>Apache Kafka Sample</name> | ||
<description>Apache Kafka Sample</description> | ||
<url>http://projects.spring.io/spring-integration</url> | ||
<organization> | ||
<name>SpringIO</name> | ||
<url>https://spring.io</url> | ||
</organization> | ||
<licenses> | ||
<license> | ||
<name>The Apache Software License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
<developers> | ||
<developer> | ||
<id>garyrussell</id> | ||
<name>Gary Russell</name> | ||
<email>grussell@pivotal.io</email> | ||
<roles> | ||
<role>project lead</role> | ||
</roles> | ||
</developer> | ||
<developer> | ||
<id>markfisher</id> | ||
<name>Mark Fisher</name> | ||
<email>mfisher@pivotal.io</email> | ||
<roles> | ||
<role>project founder and lead emeritus</role> | ||
</roles> | ||
</developer> | ||
<developer> | ||
<id>ghillert</id> | ||
<name>Gunnar Hillert</name> | ||
<email>ghillert@pivotal.io</email> | ||
</developer> | ||
<developer> | ||
<id>abilan</id> | ||
<name>Artem Bilan</name> | ||
<email>abilan@pivotal.io</email> | ||
</developer> | ||
</developers> | ||
<scm> | ||
<connection>scm:git:scm:git:git://github.com/spring-projects/spring-integration-samples.git</connection> | ||
<developerConnection>scm:git:scm:git:ssh://git@github.com:spring-projects/spring-integration-samples.git</developerConnection> | ||
<url>https://github.com/spring-projects/spring-integration-samples</url> | ||
</scm> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.integration</groupId> | ||
<artifactId>spring-integration-core</artifactId> | ||
<version>4.2.0.RELEASE</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<version>1.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-integration</artifactId> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.integration</groupId> | ||
<artifactId>spring-integration-kafka</artifactId> | ||
<version>1.2.2.BUILD-SNAPSHOT</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>4.2.0.RELEASE</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version>1.9.5</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<repositories> | ||
<repository> | ||
<id>repo.spring.io.milestone</id> | ||
<name>Spring Framework Maven Milestone Repository</name> | ||
<url>https://repo.spring.io/libs-milestone</url> | ||
</repository> | ||
</repositories> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
basic/kafka/src/test/java/org/springframework/integration/samples/barrier/KafkaRunning.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2015 the original author or authors. | ||
* | ||
* Licensed 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.springframework.integration.samples.barrier; | ||
|
||
import org.I0Itec.zkclient.ZkClient; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.junit.Assume; | ||
import org.junit.rules.TestWatcher; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
import org.springframework.integration.kafka.core.BrokerAddress; | ||
import org.springframework.integration.kafka.core.ZookeeperConnectDefaults; | ||
|
||
import com.gs.collections.impl.utility.ListIterate; | ||
|
||
import kafka.cluster.Broker; | ||
import kafka.utils.ZKStringSerializer$; | ||
import kafka.utils.ZkUtils; | ||
import scala.collection.JavaConversions; | ||
import scala.collection.Seq; | ||
|
||
/** | ||
* * A rule that prevents integration tests from failing if the Kafka server is not running or not | ||
* accessible. If the Kafka server is not running in the background all the tests here will simply be skipped because | ||
* of a violated assumption (showing as successful). | ||
* The rule can be declared as static so that it only has to check once for all tests in the enclosing test case, but | ||
* there isn't a lot of overhead in making it non-static. | ||
* | ||
* @author Dave Syer | ||
* @author Artem Bilan | ||
* @author Gary Russell | ||
* @author Marius Bogoevici | ||
* @since 4.2 | ||
*/ | ||
public class KafkaRunning extends TestWatcher { | ||
|
||
private static final String ZOOKEEPER_CONNECT_STRING = ZookeeperConnectDefaults.ZK_CONNECT; | ||
|
||
private static final Log logger = LogFactory.getLog(KafkaRunning.class); | ||
|
||
@Override | ||
public Statement apply(Statement base, Description description) { | ||
try { | ||
ZkClient zkClient = new ZkClient(ZOOKEEPER_CONNECT_STRING, 1000, 1000, ZKStringSerializer$.MODULE$); | ||
Seq<Broker> allBrokersInCluster = ZkUtils.getAllBrokersInCluster(zkClient); | ||
BrokerAddress[] brokerAddresses = ListIterate | ||
.collect(JavaConversions.asJavaList(allBrokersInCluster), | ||
broker -> new BrokerAddress(broker.host(), broker.port())) | ||
.toArray(new BrokerAddress[allBrokersInCluster.size()]); | ||
if (brokerAddresses.length == 0) { | ||
throw new IllegalStateException("No running Kafka brokers"); | ||
} | ||
} | ||
catch (Exception e) { | ||
logger.warn("Not executing tests because basic connectivity test failed"); | ||
Assume.assumeNoException(e); | ||
} | ||
|
||
return super.apply(base, description); | ||
} | ||
|
||
} |