Skip to content

Commit 7323b59

Browse files
committed
rebased and Integration test RF
1 parent a3a5352 commit 7323b59

File tree

19 files changed

+279
-124
lines changed

19 files changed

+279
-124
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 & 22 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.Ignore;
87
import org.junit.Rule;
98
import org.junit.Test;
109
import org.junit.runner.RunWith;
@@ -25,41 +24,23 @@
2524

2625
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
2726

28-
@Ignore
2927
@RunWith(SpringRunner.class)
3028
@SpringBootTest(classes = ClientServiceApplication.class)
3129
@ContextConfiguration(initializers = ClientServiceTest.Initializer.class)
3230
@AutoConfigureMockMvc
3331
public class ClientServiceTest {
3432

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

4738
@Autowired
4839
private StorageServiceClient storageServiceClient;
4940

5041
@Autowired
5142
private MockMvc mockMvc;
5243

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

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/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

integration-test/pom.xml

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<parent>
6-
<artifactId>spring-cloud</artifactId>
7-
<groupId>com.lohika.jclub</groupId>
8-
<version>0.0.1-SNAPSHOT</version>
9-
</parent>
105
<modelVersion>4.0.0</modelVersion>
116

127
<groupId>com.lohika.jclub.integration</groupId>
@@ -15,18 +10,56 @@
1510
<name>Integration test</name>
1611
<description>Ent-to-ent integration test</description>
1712

13+
<parent>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter-parent</artifactId>
16+
<version>1.5.3.RELEASE</version>
17+
<relativePath/> <!-- lookup parent from repository -->
18+
</parent>
19+
20+
<properties>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23+
<java.version>1.8</java.version>
24+
<spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
25+
</properties>
26+
1827
<dependencies>
1928
<dependency>
20-
<groupId>org.testcontainers</groupId>
21-
<artifactId>testcontainers</artifactId>
22-
<version>1.3.0</version>
23-
<scope>test</scope>
29+
<groupId>org.springframework.cloud</groupId>
30+
<artifactId>spring-cloud-starter-eureka</artifactId>
2431
</dependency>
32+
2533
<dependency>
2634
<groupId>com.lohika.jclub.gateway</groupId>
2735
<artifactId>api-gateway-service</artifactId>
2836
<version>0.0.1-SNAPSHOT</version>
2937
<scope>test</scope>
3038
</dependency>
39+
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter-test</artifactId>
43+
<scope>test</scope>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>org.testcontainers</groupId>
48+
<artifactId>testcontainers</artifactId>
49+
<version>1.3.0</version>
50+
<scope>test</scope>
51+
</dependency>
3152
</dependencies>
53+
54+
<dependencyManagement>
55+
<dependencies>
56+
<dependency>
57+
<groupId>org.springframework.cloud</groupId>
58+
<artifactId>spring-cloud-dependencies</artifactId>
59+
<version>${spring-cloud.version}</version>
60+
<type>pom</type>
61+
<scope>import</scope>
62+
</dependency>
63+
</dependencies>
64+
</dependencyManagement>
3265
</project>

0 commit comments

Comments
 (0)