Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added reactive version of customer service. #1

Merged
merged 2 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build

on:
push:
pull_request:
types:
- opened
- edited
jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout source
uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '11' # The JDK version to make available on the path.
java-package: jdk # (jre, jdk, or jdk+fx) - defaults to jdk
architecture: x64 # (x64 or x86) - defaults to x64

- name: Build
run: ./build-and-test-all-mysql-binlog.sh

- name: Save test results
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: test-reports
path: ./end-to-end-tests/build/reports

- name: print messages
run: ./.github/workflows/dump-messages.sh
if: ${{ failure() }}

- name: get container logs
run: ./.github/workflows/print-container-logs.sh
if: ${{ always() }}

- name: Save container logs
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: container-logs
path: ~/container-logs
6 changes: 6 additions & 0 deletions .github/workflows/dump-messages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash

set -e

echo 'select * from eventuate.message\G' | ./mysql-cli.sh -i
echo 'select * from eventuate.received_messages\G' | ./mysql-cli.sh -i
20 changes: 20 additions & 0 deletions .github/workflows/print-container-logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /bin/bash -e

CONTAINER_IDS=$(docker ps -a -q)

for id in $CONTAINER_IDS ; do
echo "\n--------------------"
echo "logs of:\n"
docker ps -a -f "id=$id"
echo "\n"
docker logs $id
echo "--------------------\n"
done

mkdir -p ~/container-logs

docker ps -a > ~/container-logs/containers.txt

for name in $(docker ps -a --format "{{.Names}}") ; do
docker logs $name > ~/container-logs/${name}.log
done
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified LICENSE.md
100644 → 100755
Empty file.
Empty file modified README.adoc
100644 → 100755
Empty file.
36 changes: 36 additions & 0 deletions _build-and-test-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#! /bin/bash

set -e

dockerall="./gradlew ${DATABASE?}${MODE?}Compose"
dockerinfrastructure="./gradlew ${DATABASE?}${MODE?}infrastructureCompose"

./gradlew testClasses

${dockerall}Down -P removeContainers=true
${dockerinfrastructure}Up

./gradlew -x :end-to-end-tests:test build

#Testing db cli
if [ "${DATABASE}" == "mysql" ]; then
echo 'show databases;' | ./mysql-cli.sh -i
elif [ "${DATABASE}" == "postgres" ]; then
echo '\l' | ./postgres-cli.sh -i
elif [ "${DATABASE}" == "mssql" ]; then
./mssql-cli.sh "SELECT name FROM master.sys.databases;"
else
echo "Unknown Database"
exit 99
fi


${dockerall}Build
${dockerall}Up

#Testing mongo cli
echo 'show dbs' | ./mongodb-cli.sh -i

./gradlew :end-to-end-tests:cleanTest :end-to-end-tests:test

${dockerall}Down -P removeContainers=true
9 changes: 9 additions & 0 deletions build-and-test-all-mysql-binlog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/bash

set -e

export DATABASE=mysql
export MODE=binlog
export READER=MySqlReader

./_build-and-test-all.sh
16 changes: 16 additions & 0 deletions build-and-test-everything.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /bin/bash -e

set -o pipefail

SCRIPTS="./build-and-test-all-*"

date > build-and-test-everything.log

for script in $SCRIPTS ; do
echo '****************************************** Running' $script
date >> build-and-test-everything.log
echo '****************************************** Running' $script >> build-and-test-everything.log
$script | tee -a build-and-test-everything.log
done

echo 'Finished successfully!!!'
83 changes: 83 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
buildscript {
repositories {
jcenter()
mavenCentral()
mavenLocal()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "com.avast.gradle:gradle-docker-compose-plugin:0.12.0"
}
}

apply plugin: 'docker-compose'

subprojects {

apply plugin: "java"

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenLocal()
mavenCentral()
jcenter()
maven {
url "https://dl.bintray.com/eventuateio-oss/eventuate-maven-release"
}
eventuateMavenRepoUrl.split(',').each { repoUrl -> maven { url repoUrl } }
}

dependencies {
implementation(platform("io.eventuate.platform:eventuate-platform-dependencies:$eventuatePlatformVersion"))
testCompile "junit:junit:4.12"
}

}

dockerCompose {
environment.put "EVENTUATE_COMMON_VERSION", eventuateCommonImageVersion
environment.put "EVENTUATE_CDC_VERSION", eventuateCdcImageVersion
environment.put "EVENTUATE_CDC_KAFKA_ENABLE_BATCH_PROCESSING", eventuateCdcKafkaEnableBatchProcessing
environment.put "EVENTUATE_JAVA_BASE_IMAGE_VERSION", eventuateExamplesBaseImageVersion
environment.put "EVENTUATE_PROXY_VERSION", eventuateProxyImageVersion

removeOrphans = true

mysqlbinlog {
projectName = null
useComposeFiles = ["docker-compose-mysql-binlog.yml"]
removeContainers = project.ext.removeContainers
}

mysqlbinloginfrastructure {
projectName = null
useComposeFiles = ["docker-compose-mysql-binlog.yml"]
startedServices = ["cdc-service", "zipkin"]
removeContainers = project.ext.removeContainers
}
}

subprojects.each {
if (it.name.endsWith("-service") || it.name.endsWith("-gateway")) {
mysqlbinlogComposeUp.dependsOn(":" + it.name + ":assemble")
}
}

mysqlbinlogComposeUp.dependsOn(mysqlbinloginfrastructureComposeUp)

task buildAndStartServicesMySql(type: GradleBuild) {
tasks = ["mysqlbinlogComposeUp"]
}

task endToEndTests(type: GradleBuild) {
tasks = [":end-to-end-tests:test"]
}

endToEndTests.dependsOn(mysqlbinlogComposeUp)
endToEndTests.dependsOn(":end-to-end-tests:cleanTest")

task stopServicesMySql(type: GradleBuild) {
tasks = ["mysqlbinlogComposeDown"]
}
29 changes: 29 additions & 0 deletions buildSrc/src/main/groovy/ServicePlugin.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import org.gradle.api.Plugin
import org.gradle.api.Project

class ServicePlugin implements Plugin<Project> {

@Override
void apply(Project project) {

project.apply(plugin: 'org.springframework.boot')
project.apply(plugin: "io.spring.dependency-management")

project.dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-starter-sleuth:${project.ext.springCloudSleuthVersion}"
}
}


project.dependencies {

compile 'org.springframework.cloud:spring-cloud-starter-sleuth'
compile 'org.springframework.cloud:spring-cloud-starter-zipkin:2.2.8.RELEASE'
compile 'io.zipkin.brave:brave-bom:4.17.1'

compile "io.eventuate.tram.core:eventuate-tram-spring-cloud-sleuth-integration"
}

}
}
3 changes: 3 additions & 0 deletions common-swagger/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
compile "io.eventuate.util:eventuate-util-spring-swagger:$eventuateUtilVersion"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.eventuate.examples.tram.ordersandcustomers.commonswagger;

import io.eventuate.util.spring.swagger.EventuateSwaggerConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonSwaggerConfiguration {
@Bean
public EventuateSwaggerConfig eventuateSwaggerConfig() {
return () -> "io.eventuate.examples.tram.ordersandcustomers";
}
}
4 changes: 4 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
compile "io.eventuate.tram.core:eventuate-tram-events"
compile "commons-lang:commons-lang:2.6"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.eventuate.examples.tram.ordersandcustomers.common.domain;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import java.math.BigDecimal;

public class Money {

public static final Money ZERO = new Money(0);
private BigDecimal amount;

public Money() {
}

public Money(int i) {
this.amount = new BigDecimal(i);
}
public Money(String s) {
this.amount = new BigDecimal(s);
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}

@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}

@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}

public Money(BigDecimal amount) {
this.amount = amount;
}

public BigDecimal getAmount() {
return amount;
}

public void setAmount(BigDecimal amount) {
this.amount = amount;
}

public boolean isGreaterThanOrEqual(Money other) {
return amount.compareTo(other.amount) >= 0;
}

public Money add(Money other) {
return new Money(amount.add(other.amount));
}
public Money subtract(Money other) {
return new Money(amount.subtract(other.amount));
}
}
4 changes: 4 additions & 0 deletions customer-service-api-messaging/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
compile project(":common")
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.eventuate.examples.tram.ordersandcustomers.customers.domain.events;

public abstract class AbstractCustomerOrderEvent implements CustomerEvent {
protected Long orderId;

protected AbstractCustomerOrderEvent(Long orderId) {
this.orderId = orderId;
}

protected AbstractCustomerOrderEvent() {
}

public Long getOrderId() {
return orderId;
}

public void setOrderId(Long orderId) {
this.orderId = orderId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.eventuate.examples.tram.ordersandcustomers.customers.domain.events;

import io.eventuate.examples.tram.ordersandcustomers.common.domain.Money;

public class CustomerCreatedEvent implements CustomerEvent {
private String name;
private Money creditLimit;

public CustomerCreatedEvent() {
}

public CustomerCreatedEvent(String name, Money creditLimit) {
this.name = name;
this.creditLimit = creditLimit;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Money getCreditLimit() {
return creditLimit;
}

public void setCreditLimit(Money creditLimit) {
this.creditLimit = creditLimit;
}
}
Loading