Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dartartem committed May 30, 2019
2 parents 0d22a36 + 7349a90 commit 4e50e75
Show file tree
Hide file tree
Showing 16 changed files with 907 additions and 14 deletions.
9 changes: 6 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ jobs:
steps:
- checkout
- restore_cache:
key: eventuate-tram-core-examples-basic-{{ checksum "build.gradle" }}
key: eventuate-tram-core-examples-basic-{{ checksum "gradle.properties" }}
- run: TERM=dumb ./gradlew testClasses
- run: TERM=dumb ./mvnw test-compile
- save_cache:
paths:
- ~/.gradle
key: eventuate-tram-core-examples-basic-{{ checksum "build.gradle" }}
- run: TERM=dumb ./_build-and-test-all.sh
- ~/.m2
key: eventuate-tram-core-examples-basic-{{ checksum "gradle.properties" }}
- run: TERM=dumb ./build-and-test-all.sh
- run: TERM=dumb ./build-and-test-all-maven.sh
- store_test_results:
path: "*/build/test-results"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ build/
*.iml
*.log
out
*/target
target
110 changes: 110 additions & 0 deletions .mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
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.
*/

import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;

public class MavenWrapperDownloader {

/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL =
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";

/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";

/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";

/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";

public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());

// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: : " + url);

File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}

private static void downloadFileFromURL(String urlString, File destination) throws Exception {
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}

}
Binary file added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
1 change: 1 addition & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
88 changes: 88 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,91 @@ It consists of the following modules:
* `eventuate-tram-examples-common` - the examples for basic messaging, domain events and command/async reply
* `eventuate-tram-examples-in-memory` - runs the examples using in-memory stubs
* `eventuate-tram-examples-jdbc-kafka` - runs the examples using MySQL and Apache Kafka

== About `eventuate-tram-examples-common`

This module defines the transactional messaging examples:

* Basic messaging
* Domain events
* Commands, which implement request/asynchronous response

You can run the examples using the tests in the `eventuate-tram-examples-in-memory` and `eventuate-tram-examples-jdbc-kafka` modules.


== About `eventuate-tram-examples-in-memory` - running in-memory examples

This module executes the examples using `eventuate-tram-in-memory` module, which is extremely useful for writing fast running tests.

To run this version of the tests:

```
./gradlew :eventuate-tram-examples-in-memory:test
```

== About `eventuate-tram-examples-jdbc-kafka` - running examples with MySQL and Apache Kafka

This module executes the examples using MySQL and Apache Kafka.

=== Set DOCKER_HOST_IP environment variable

Before running MySQL and Apache Kafka using Docker Compose, you first need to set the `DOCKER_HOST_IP` environment variable.
This must be an IP address or resolvable hostname.
It cannot be `localhost` or `127.0.0.1`.
Please see this http://eventuate.io/docs/usingdocker.html[guide to setting `DOCKER_HOST_IP`] for more information.

=== Run MySQL and Apache Kafka

Once you have set `DOCKER_HOST_IP` you can then run MySQL and Apache Kafka using Docker Compose.

```
docker-compose up -d
```

=== Run the tests

Once the containers have started you can run the tests:

```
./gradlew :eventuate-tram-examples-jdbc-kafka:test
```

=== Inspect the database

You can inspect the Eventuate Tram-related database tables:

```
$ ./mysql-cli.sh -it
Welcome to the MySQL monitor. Commands end with ; or \g.
...

mysql> select * from message\G
*************************** 1. row ***************************
id: 00000168d96469db-acde480011220000
destination: destination1549835461824
headers: {"DESTINATION":"destination1549835461824","ID":"00000168d96469db-acde480011220000"}
payload: Hello1549835461824
published: 0

...
mysql> select * from received_messages\G
*************************** 1. row ***************************
consumer_id: commandDispatcheId1549835467791
message_id: 00000168d9647f65-acde480011220000
*************************** 2. row ***************************
...
mysql> quit
Bye
```

=== Clean up

To clean up:

```
$ docker-compose down -v
```

== For more information

Please read the http://eventuate.io/tram/gettingstarted.html[Eventuate Tram getting started guide] or look at the http://eventuate.io/exampleapps.html[examples].
19 changes: 19 additions & 0 deletions build-and-test-all-maven.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /bin/bash

set -e

. ./set-env.sh

./mvnw clean compile

./mvnw -am -pl eventuate-tram-examples-in-memory test

docker-compose down -v

docker-compose up -d

./wait-for-mysql.sh

./mvnw -am -pl eventuate-tram-examples-jdbc-kafka test

docker-compose down -v
7 changes: 1 addition & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,11 @@ subprojects {
repositories {
mavenCentral()
jcenter()
maven {
url "https://dl.bintray.com/eventuateio-oss/eventuate-maven-release"
}
eventuateMavenRepoUrl.split(',').each { repoUrl -> maven { url repoUrl } }
}


}


task wrapper(type: Wrapper) {
gradleVersion = '2.11'
gradleVersion = '3.5'
}
78 changes: 78 additions & 0 deletions eventuate-tram-examples-common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<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">
<parent>
<groupId>io.eventuate.tram.examples.basic</groupId>
<artifactId>eventuate-tram-core-examples-basic</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>eventuate-tram-examples-common</artifactId>
<packaging>jar</packaging>
<name>eventuate-tram-examples-common</name>
<version>0.1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.eventuate.tram.core</groupId>
<artifactId>eventuate-tram-messaging</artifactId>
<version>${eventuateTramVersion} </version>
</dependency>
<dependency>
<groupId>io.eventuate.tram.core</groupId>
<artifactId>eventuate-tram-commands</artifactId>
<version>${eventuateTramVersion} </version>
</dependency>
<dependency>
<groupId>io.eventuate.tram.core</groupId>
<artifactId>eventuate-tram-events</artifactId>
<version>${eventuateTramVersion} </version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${springBootVersion}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${springBootVersion}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.6</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.6</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
46 changes: 46 additions & 0 deletions eventuate-tram-examples-in-memory/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<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">
<parent>
<groupId>io.eventuate.tram.examples.basic</groupId>
<artifactId>eventuate-tram-core-examples-basic</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>eventuate-tram-examples-in-memory</artifactId>
<packaging>jar</packaging>
<name>eventuate-tram-examples-in-memory</name>

<dependencies>
<dependency>
<groupId>io.eventuate.tram.examples.basic</groupId>
<artifactId>eventuate-tram-examples-common</artifactId>
<version>0.1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.eventuate.tram.core</groupId>
<artifactId>eventuate-tram-in-memory</artifactId>
<version>${eventuateTramVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${springBootVersion}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit 4e50e75

Please sign in to comment.