-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build new version based on JUnit 5 (#3)
* Refactor SharedResource into JUnit5 extension * Refactor ZookeeperSharedResource instance into JUnit5 extension * Refactoring into modules * add kafka-junit4 module * refactor common code into core module * update changelog
- Loading branch information
Showing
25 changed files
with
1,372 additions
and
168 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
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
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,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>kafka-junit</artifactId> | ||
<groupId>com.salesforce.kafka.test</groupId> | ||
<version>2.0.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>kafka-junit-core</artifactId> | ||
<version>1.0.0</version> | ||
|
||
|
||
</project> |
2 changes: 1 addition & 1 deletion
2
...alesforce/kafka/test/KafkaTestServer.java → ...alesforce/kafka/test/KafkaTestServer.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
2 changes: 1 addition & 1 deletion
2
...salesforce/kafka/test/KafkaTestUtils.java → ...salesforce/kafka/test/KafkaTestUtils.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
2 changes: 1 addition & 1 deletion
2
...force/kafka/test/ProducedKafkaRecord.java → ...force/kafka/test/ProducedKafkaRecord.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
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,96 @@ | ||
# Kafka-JUnit4 | ||
|
||
This library wraps Kafka Test Server and allows you to easily create and run tests against | ||
a "real" kafka server running within your tests, no more needing to stand up an external kafka cluster! | ||
|
||
Kafka-JUnit4 is built on-top of **JUnit 4** as a SharedResource using the **@ClassRule** annotation. | ||
|
||
For usage with JUnit5 or more project information please review top level [README](../README.md). | ||
|
||
## Using Kafka-JUnit with JUnit 4. | ||
|
||
### Usage & Examples | ||
|
||
Include this in your project with scope test. | ||
|
||
``` | ||
<dependency> | ||
<groupId>com.salesforce.kafka.test</groupId> | ||
<artifactId>kafka-junit4</artifactId> | ||
<version>1.0.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
``` | ||
|
||
#### KafkaTestServer | ||
|
||
A great example of how to use this can be found within our tests! Check out [KafkaTestServerTest.java](src/test/java/com/salesforce/kafka/test/KafkaTestServerTest.java) | ||
|
||
Add the following to your JUnit test file and it will handle automatically starting and stopping the embedded Kafka | ||
instance for you. | ||
|
||
```java | ||
/** | ||
* We have a single embedded kafka server that gets started when this test class is initialized. | ||
* | ||
* It's automatically started before any methods are run via the @ClassRule annotation. | ||
* It's automatically stopped after all of the tests are completed via the @ClassRule annotation. | ||
*/ | ||
@ClassRule | ||
public static final SharedKafkaTestResource sharedKafkaTestResource = new SharedKafkaTestResource(); | ||
``` | ||
|
||
SharedKafkaTestResource has two accessors that you can make use of in your tests to interact with the service. | ||
|
||
```java | ||
/** | ||
* @return Shared Kafka Test server instance. | ||
*/ | ||
public KafkaTestServer getKafkaTestServer(); | ||
|
||
/** | ||
* @return Instance of KafkaTestUtils configured and ready to go. | ||
*/ | ||
public KafkaTestUtils getKafkaTestUtils(); | ||
``` | ||
|
||
#### KafkaTestUtils | ||
|
||
Often times you'll end up rebuilding the same patterns around producing and consuming data from this internal | ||
kafka server. We've tried to collect some of these within [KafkaTestUtils](src/main/java/com/salesforce/kafka/test/KafkaTestUtils.java)! | ||
|
||
For usage and examples, check out it's test at [KafkaTestUtilsTest](src/test/java/com/salesforce/kafka/test/KafkaTestUtilsTest.java). | ||
|
||
#### Zookeeper Test Server | ||
|
||
**Note** Since Kafka depends on Zookeeper, you get this for *free* if you use the SharedKafkaTestResource, you do not, and should not, use | ||
both of these together within the same Test class. | ||
|
||
If you need to run tests against an **only** embedded Zookeeper server and not all of Kafka, we have you covered as well. Add the following | ||
to your JUnit test file | ||
and it will handle automatically start and stopping the embedded Zookeeper instance for you. | ||
|
||
```java | ||
/** | ||
* We have a single embedded zookeeper server that gets started when this test class is initialized. | ||
* | ||
* It's automatically started before any methods are run via the @ClassRule annotation. | ||
* It's automatically stopped after all of the tests are completed via the @ClassRule annotation. | ||
*/ | ||
@ClassRule | ||
public static final SharedZookeeperTestResource sharedZookeeperTestResource = new SharedZookeeperTestResource(); | ||
``` | ||
|
||
SharedZookeeperTestResource has the following accessors that you can make use of in your tests to interact with the Zookeeper instance. | ||
|
||
```java | ||
/** | ||
* @return Shared Zookeeper test server instance. | ||
*/ | ||
public TestingServer getZookeeperTestServer(); | ||
|
||
/** | ||
* @return Connection string to connect to the Zookeeper instance. | ||
*/ | ||
public String getZookeeperConnectString(); | ||
``` |
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,115 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2017-2018, Salesforce.com, Inc. | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided with the distribution. | ||
* Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
--> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
|
||
<parent> | ||
<artifactId>kafka-junit</artifactId> | ||
<groupId>com.salesforce.kafka.test</groupId> | ||
<version>2.0.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>kafka-junit4</artifactId> | ||
<version>1.0.0</version> | ||
|
||
<!-- defined properties --> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
|
||
<!-- Define which JUnit version --> | ||
<junit.version>4.12</junit.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- Core module --> | ||
<dependency> | ||
<groupId>com.salesforce.kafka.test</groupId> | ||
<artifactId>kafka-junit-core</artifactId> | ||
<version>1.0.0</version> | ||
</dependency> | ||
|
||
<!-- JUnit is Required --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<sourceDirectory>src/main/java</sourceDirectory> | ||
<testSourceDirectory>src/test/java</testSourceDirectory> | ||
|
||
<plugins> | ||
<!-- Build Jar with Dependencies --> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
<archive> | ||
<manifest> | ||
<mainClass/> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<!-- Surefire plugin for running tests --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.19.1</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven.surefire</groupId> | ||
<artifactId>surefire-junit47</artifactId> | ||
<version>2.19</version> | ||
</dependency> | ||
</dependencies> | ||
<configuration> | ||
<argLine>-Xmx512M</argLine> | ||
<skipTests>${skipTests}</skipTests> | ||
<reportFormat>plain</reportFormat> | ||
</configuration> | ||
</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
Oops, something went wrong.