Skip to content

[POC] end-to-end Integration test #13

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 0 additions & 24 deletions api-gateway-service/.gitignore

This file was deleted.

50 changes: 47 additions & 3 deletions api-gateway-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
<docker.baseDir>${basedir}/src/main/docker</docker.baseDir>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
Expand Down Expand Up @@ -61,8 +65,48 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<target>
<copy file="${project.build.directory}/${project.build.finalName}.jar"
tofile="${project.build.directory}/${project.artifactId}.jar"/>
</target>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>build-image</id>
<phase>install</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<imageName>${project.artifactId}</imageName>
<dockerDirectory>${docker.baseDir}</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.artifactId}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>


</project>
12 changes: 12 additions & 0 deletions api-gateway-service/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM java:8

RUN mkdir -p /opt/spring-cloud
WORKDIR /opt/spring-cloud

ADD api-gateway-service.jar api-gateway-service.jar
ADD wrapper.sh wrapper.sh

RUN bash -c 'chmod +x ./wrapper.sh'
RUN bash -c 'touch ./api-gateway-service.jar'

ENTRYPOINT ["/bin/bash", "./wrapper.sh"]
41 changes: 41 additions & 0 deletions api-gateway-service/src/main/docker/wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'}

if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then
echo "Starting api-gateway server immediately"
java -jar ./api-gateway-service.jar
exit 0
fi

DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'}
DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761}

echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do
echo -e ".\c"
sleep 1
done
echo

REALTOR_SERVICE=${REALTOR_SERVICE:='realtor-service'}
echo "Trying to get '${REALTOR_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${REALTOR_SERVICE}"); do
echo -e ".\c"
sleep 1
done
echo

CLIENT_SERVICE=${CLIENT_SERVICE:='client-service'}
echo "Trying to get '${CLIENT_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${CLIENT_SERVICE}"); do
echo -e ".\c"
sleep 1
done
echo

echo "Starting api-gateway server"
echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka"
echo
env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \
java -jar ./api-gateway-service.jar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.lohika.jclub;
package com.lohika.jclub.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
14 changes: 13 additions & 1 deletion api-gateway-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
spring.application.name=api-gateway-service
server.port=8090
server.port=8090

eureka.instance.preferIpAddress=true

feign.hystrix.enabled=true

management.security.enabled=false

endpoints.info.id=info
endpoints.info.sensitive=false
endpoints.info.enabled=true

info.app.name=Api gateway service
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.lohika.jclub;
package com.lohika.jclub.gateway;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eureka.client.enabled=false
6 changes: 6 additions & 0 deletions api-gateway-service/src/test/resources/banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_______________________ ___ _ __ _
/_ __/ ____/ ___/_ __/ / | ____ (_) ____ _____ _/ /____ _ ______ ___ __ ________ ______ __(_)_______
/ / / __/ \__ \ / / / /| | / __ \/ / / __ `/ __ `/ __/ _ \ | /| / / __ `/ / / / / ___/ _ \/ ___/ | / / / ___/ _ \
/ / / /___ ___/ // / / ___ |/ /_/ / / / /_/ / /_/ / /_/ __/ |/ |/ / /_/ / /_/ / (__ ) __/ / | |/ / / /__/ __/
/_/ /_____//____//_/ /_/ |_/ .___/_/ \__, /\__,_/\__/\___/|__/|__/\__,_/\__, / /____/\___/_/ |___/_/\___/\___/
/_/ /____/ /____/
7 changes: 7 additions & 0 deletions api-gateway-service/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<configuration>

<include resource="org/springframework/boot/logging/logback/base.xml"/>

<logger name="org.testcontainers" level="INFO"/>
<logger name="org.testcontainers.shaded.com.github.dockerjava.core.async.ResultCallbackTemplate" level="OFF"/>
</configuration>
61 changes: 42 additions & 19 deletions client-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand All @@ -23,9 +23,21 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
<docker.image.prefix>springio</docker.image.prefix>
<docker.baseDir>${basedir}/src/main/docker</docker.baseDir>
</properties>

<dependencies>
<dependency>
<groupId>com.lohika.jclub.storage</groupId>
<artifactId>storage-service-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
Expand All @@ -34,30 +46,25 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.12</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>

<dependency>
<groupId>com.lohika.jclub.storage.client</groupId>
<artifactId>storage-service-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.3.0</version>
<version>1.4.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -80,6 +87,23 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<target>
<copy file="${project.build.directory}/${project.build.finalName}.jar"
tofile="${project.build.directory}/${project.artifactId}.jar"/>
</target>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
Expand All @@ -94,18 +118,17 @@
</execution>
</executions>
<configuration>
<imageName>client-service</imageName>
<baseImage>java</baseImage>
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
<imageName>${project.artifactId}</imageName>
<dockerDirectory>${docker.baseDir}</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
<include>${project.artifactId}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>
</project>
12 changes: 12 additions & 0 deletions client-service/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM java:8

RUN mkdir -p /opt/spring-cloud
WORKDIR /opt/spring-cloud

ADD client-service.jar client-service.jar
ADD wrapper.sh wrapper.sh

RUN bash -c 'chmod +x ./wrapper.sh'
RUN bash -c 'touch ./client-service.jar'

ENTRYPOINT ["/bin/bash", "./wrapper.sh"]
33 changes: 33 additions & 0 deletions client-service/src/main/docker/wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'}

if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then
echo "Starting config server immediately"
java -jar ./client-service.jar
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file is autogenerated ? If yes then do we need it to be pushed ? If no then should we always maintain it and support configuration ?

exit 0
fi

DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'}
DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761}

echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do
echo -e ".\c"
sleep 1
done
echo

STORAGE_SERVICE=${STORAGE_SERVICE:='storage-service'}
echo "Trying to get '${STORAGE_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${STORAGE_SERVICE}"); do
echo -e ".\c"
sleep 1
done
echo

echo "Starting client service"
echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka"
echo
env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \
java -jar ./client-service.jar
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.PagedResources;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;

import javax.annotation.PostConstruct;

@Slf4j
@RestController
public class ClientController {

@Autowired
private StorageServiceClient storageServiceClient;

@GetMapping("/apartments")
@PostConstruct
public void warmUp() {
storageServiceClient.list();
}

@GetMapping(value = "/apartments", produces = MediaType.APPLICATION_JSON_VALUE)
public PagedResources<Apartment> getApartments() {
PagedResources<Apartment> list = storageServiceClient.list();
return new PagedResources<>(list.getContent(), list.getMetadata());
}

}
}
Loading