Skip to content

Commit 42f5e2c

Browse files
committed
rebased and Integration test RF
1 parent 45e624e commit 42f5e2c

File tree

22 files changed

+283
-123
lines changed

22 files changed

+283
-123
lines changed

api-gateway-service/src/main/docker/wrapper.sh

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,17 @@ until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVE
1818
done
1919
echo
2020

21-
REALTOR_SERVICE_HOST=${REALTOR_SERVICE_HOST:='realtor-service'}
22-
REALTOR_SERVICE_PORT=${REALTOR_SERVICE_PORT:=8080}
23-
24-
echo "Trying to connect to on ${REALTOR_SERVICE_HOST}:${REALTOR_SERVICE_PORT}"
25-
until $(curl --output /dev/null --silent --head --fail "http://${REALTOR_SERVICE_HOST}:${REALTOR_SERVICE_PORT}/info"); do
21+
REALTOR_SERVICE=${REALTOR_SERVICE:='realtor-service'}
22+
echo "Trying to get '${REALTOR_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
23+
until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${REALTOR_SERVICE}"); do
2624
echo -e ".\c"
2725
sleep 1
2826
done
2927
echo
3028

31-
# rem TODO replace with client-service
32-
STORAGE_SERVICE_HOST=${STORAGE_SERVICE_HOST:='storage-service'}
33-
STORAGE_SERVICE_PORT=${STORAGE_SERVICE_PORT:=8091}
34-
35-
echo "Trying to connect to on ${STORAGE_SERVICE_HOST}:${STORAGE_SERVICE_PORT}"
36-
until $(curl --output /dev/null --silent --head --fail "http://${STORAGE_SERVICE_HOST}:${STORAGE_SERVICE_PORT}/info"); do
29+
CLIENT_SERVICE=${CLIENT_SERVICE:='client-service'}
30+
echo "Trying to get '${CLIENT_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
31+
until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${CLIENT_SERVICE}"); do
3732
echo -e ".\c"
3833
sleep 1
3934
done

client-service/pom.xml

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,21 @@
2323
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2424
<java.version>1.8</java.version>
2525
<spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
26+
<docker.image.prefix>springio</docker.image.prefix>
27+
<docker.baseDir>${basedir}/src/main/docker</docker.baseDir>
2628
</properties>
2729

2830
<dependencies>
31+
<dependency>
32+
<groupId>com.lohika.jclub.storage.client</groupId>
33+
<artifactId>storage-service-client</artifactId>
34+
<version>0.0.1-SNAPSHOT</version>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-actuator</artifactId>
40+
</dependency>
2941
<dependency>
3042
<groupId>org.springframework.cloud</groupId>
3143
<artifactId>spring-cloud-starter-eureka</artifactId>
@@ -34,25 +46,20 @@
3446
<groupId>org.springframework.boot</groupId>
3547
<artifactId>spring-boot-starter-web</artifactId>
3648
</dependency>
37-
3849
<dependency>
39-
<groupId>org.springframework.boot</groupId>
40-
<artifactId>spring-boot-starter-test</artifactId>
41-
<scope>test</scope>
50+
<groupId>org.springframework.cloud</groupId>
51+
<artifactId>spring-cloud-starter-feign</artifactId>
4252
</dependency>
53+
4354
<dependency>
4455
<groupId>org.projectlombok</groupId>
4556
<artifactId>lombok</artifactId>
46-
<version>1.16.12</version>
47-
</dependency>
48-
<dependency>
49-
<groupId>org.springframework.cloud</groupId>
50-
<artifactId>spring-cloud-starter-feign</artifactId>
5157
</dependency>
58+
5259
<dependency>
53-
<groupId>com.lohika.jclub.storage.client</groupId>
54-
<artifactId>storage-service-client</artifactId>
55-
<version>0.0.1-SNAPSHOT</version>
60+
<groupId>org.springframework.boot</groupId>
61+
<artifactId>spring-boot-starter-test</artifactId>
62+
<scope>test</scope>
5663
</dependency>
5764
<dependency>
5865
<groupId>org.testcontainers</groupId>
@@ -80,6 +87,23 @@
8087
<groupId>org.springframework.boot</groupId>
8188
<artifactId>spring-boot-maven-plugin</artifactId>
8289
</plugin>
90+
<plugin>
91+
<artifactId>maven-antrun-plugin</artifactId>
92+
<configuration>
93+
<tasks>
94+
<copy file="${project.build.directory}/${project.build.finalName}.jar"
95+
tofile="${project.build.directory}/${project.artifactId}.jar"/>
96+
</tasks>
97+
</configuration>
98+
<executions>
99+
<execution>
100+
<phase>install</phase>
101+
<goals>
102+
<goal>run</goal>
103+
</goals>
104+
</execution>
105+
</executions>
106+
</plugin>
83107
<plugin>
84108
<groupId>com.spotify</groupId>
85109
<artifactId>docker-maven-plugin</artifactId>
@@ -94,18 +118,17 @@
94118
</execution>
95119
</executions>
96120
<configuration>
97-
<imageName>client-service</imageName>
98-
<baseImage>java</baseImage>
99-
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
121+
<imageName>${project.artifactId}</imageName>
122+
<dockerDirectory>${docker.baseDir}</dockerDirectory>
100123
<resources>
101124
<resource>
102125
<targetPath>/</targetPath>
103126
<directory>${project.build.directory}</directory>
104-
<include>${project.build.finalName}.jar</include>
127+
<include>${project.artifactId}.jar</include>
105128
</resource>
106129
</resources>
107130
</configuration>
108131
</plugin>
109132
</plugins>
110133
</build>
111-
</project>
134+
</project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM java:8
2+
ADD client-service.jar client-service.jar
3+
ADD wrapper.sh wrapper.sh
4+
RUN bash -c 'chmod +x /wrapper.sh'
5+
RUN bash -c 'touch /client-service.jar'
6+
ENTRYPOINT ["/bin/bash", "./wrapper.sh"]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'}
4+
5+
if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then
6+
echo "Starting config server immediately"
7+
java -jar ./client-service.jar
8+
exit 0
9+
fi
10+
11+
DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'}
12+
DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761}
13+
14+
echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
15+
until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do
16+
echo -e ".\c"
17+
sleep 1
18+
done
19+
echo
20+
21+
STORAGE_SERVICE=${STORAGE_SERVICE:='storage-service'}
22+
echo "Trying to get '${STORAGE_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
23+
until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${STORAGE_SERVICE}"); do
24+
echo -e ".\c"
25+
sleep 1
26+
done
27+
echo
28+
29+
echo "Starting client service"
30+
echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka"
31+
32+
env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \
33+
java -jar ./client-service.jar

client-service/src/main/java/com/lohika/jclub/client/ClientController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.hateoas.PagedResources;
8+
import org.springframework.http.MediaType;
89
import org.springframework.web.bind.annotation.GetMapping;
910
import org.springframework.web.bind.annotation.RestController;
1011

@@ -17,10 +18,9 @@ public class ClientController {
1718
@Autowired
1819
private StorageServiceClient storageServiceClient;
1920

20-
@GetMapping("/apartments")
21+
@GetMapping(value = "/apartments", produces = MediaType.APPLICATION_JSON_VALUE)
2122
public PagedResources<Apartment> getApartments() {
2223
PagedResources<Apartment> list = storageServiceClient.list();
2324
return new PagedResources<>(list.getContent(), list.getMetadata());
2425
}
25-
26-
}
26+
}

client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.lohika.jclub.storage.client.StorageServiceClient;
55

66
import org.junit.ClassRule;
7-
import org.junit.Rule;
87
import org.junit.Test;
98
import org.junit.runner.RunWith;
109
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,33 +30,16 @@
3130
public class ClientServiceTest {
3231

3332
@ClassRule
34-
public static GenericContainer discoveryService = new GenericContainer("discovery-service:latest")
35-
.waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started EurekaServerApplication in.*\\s"))
36-
.withExposedPorts(8761);
37-
38-
@Rule
39-
public GenericContainer storageService = new GenericContainer("storage-service:latest")
40-
.withExposedPorts(8091)
41-
.withEnv("eureka.client.serviceUrl.defaultZone", "http://" + discoveryService.getContainerIpAddress() + ":" + discoveryService.getMappedPort(8761) + "/eureka")
42-
.withEnv("eureka.instance.preferIpAddress", "true")
43-
.waitingFor(new LogMessageWaitStrategy().withRegEx(".*DiscoveryClient_STORAGE-SERVICE.*registration status: 204.*\\s"));
33+
public static GenericContainer storageService = new GenericContainer("storage-service:latest")
34+
.withExposedPorts(8091)
35+
.waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started StorageServiceApplication in.*\\s"));
4436

4537
@Autowired
4638
private StorageServiceClient storageServiceClient;
4739

4840
@Autowired
4941
private MockMvc mockMvc;
5042

51-
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
52-
@Override
53-
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
54-
EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
55-
"eureka.client.serviceUrl.defaultZone=http://" + discoveryService.getContainerIpAddress() +
56-
":" + discoveryService.getMappedPort(8761) + "/eureka",
57-
"storage-service.ribbon.servers=http://");
58-
}
59-
}
60-
6143
@Test
6244
public void testGetApartments() throws Exception {
6345
// Given
@@ -79,4 +61,15 @@ public void testGetApartments() throws Exception {
7961
//TODO storageServiceClient does not creating the records.
8062
// fallback is working with 0 paging
8163
}
64+
65+
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
66+
@Override
67+
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
68+
69+
EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
70+
"storage-service.ribbon.servers=http://" + storageService.getContainerIpAddress() + ":"
71+
+ storageService.getMappedPort(8091) + "/"
72+
);
73+
}
74+
}
8275
}

config-server/src/main/docker/wrapper.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVE
1818
done
1919
echo
2020

21+
sleep 15
2122
echo "Starting config server"
2223
echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka"
2324

hackster-service-client/src/test/java/com/lohika/jclub/hackster/client/HacksterServiceClientTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class HacksterServiceClientTest {
2626
public static GenericContainer HacksterService = new GenericContainer("hackster-service:latest")
2727
.withExposedPorts(8082)
2828
.withEnv("maxAllowedApartmentsPerRealtor", Integer.toString(MAX_ALLOWED_APARTMENTS_PER_REALTOR))
29+
.withEnv("spring.cloud.config.fail-fast", "false")
30+
.withEnv("spring.cloud.config.discovery.enabled", "false")
2931
.waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started HacksterServiceApplication in.*\\s"));
3032

3133
@Autowired

hackster-service/src/main/docker/wrapper.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVE
1818
done
1919
echo
2020

21-
CONFIG_SERVER_HOST=${CONFIG_SERVER_HOST:='config-server'}
22-
CONFIG_SERVER_PORT=${CONFIG_SERVER_PORT:=8888}
23-
24-
echo "Trying to connect to on ${CONFIG_SERVER_HOST}:${CONFIG_SERVER_PORT}"
25-
until $(curl --output /dev/null --silent --head --fail "http://${CONFIG_SERVER_HOST}:${CONFIG_SERVER_PORT}/info"); do
21+
CONFIG_SERVER=${CONFIG_SERVER:='config-server'}
22+
echo "Trying to get '${CONFIG_SERVER}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
23+
until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${CONFIG_SERVER}"); do
2624
echo -e ".\c"
2725
sleep 1
2826
done
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.cloud.config.discovery.enabled=false

0 commit comments

Comments
 (0)