Skip to content

Commit 37f9cec

Browse files
committed
Fix and update tests
1 parent 77e2f4c commit 37f9cec

File tree

11 files changed

+81
-184
lines changed

11 files changed

+81
-184
lines changed

.github/workflows/workflows.yaml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
java: [ 8, 11 ]
11-
kubernetes: [ 'v1.21.6', 'v1.20.12', 'v1.19.16', 'v1.18.20', 'v1.17.17', 'v1.16.15']
10+
java:
11+
- 8
12+
- 11
13+
kubernetes:
14+
- 'v1.21.6'
15+
- 'v1.22.17'
16+
- 'v1.23.15'
17+
- 'v1.24.9'
18+
- 'v1.25.5'
1219

1320
steps:
1421
- uses: actions/checkout@v2
@@ -23,20 +30,27 @@ jobs:
2330
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
2431
restore-keys: ${{ runner.os }}-m2
2532
- name: Setup Minikube
26-
uses: manusa/actions-setup-minikube@v2.3.0
33+
uses: manusa/actions-setup-minikube@v2.7.2
2734
with:
28-
minikube version: 'v1.16.0'
35+
minikube version: 'v1.28.0'
2936
kubernetes version: ${{ matrix.kubernetes }}
37+
github token: ${{ secrets.GITHUB_TOKEN }}
3038
- name: Setup Docker
3139
run: sudo apt-get -qq -y install conntrack socat ; nohup socat TCP-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock &
3240
- name: Setup Docker Swarm
3341
run: docker swarm init
3442
- name: Pull Image
3543
run: docker pull openanalytics/shinyproxy-demo:latest
44+
- name: Run redis
45+
run: docker run -d -p 6379:6379 redis
3646
- name: Build with Maven
3747
run: mvn -B -U clean install -DskipTests
3848
- name: Copy Artifact
3949
run: cp target/containerproxy-*-exec.jar target/containerproxy-app-recovery.jar
50+
- name: debug
51+
run: |
52+
docker ps -a
53+
kubectl get pod -A
4054
- name: Run Tests
4155
run: mvn -B test
4256

@@ -52,4 +66,3 @@ jobs:
5266
with:
5367
name: dependency-check-report
5468
path: target/dependency-check-report.html
55-

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@
557557
<goals>
558558
<goal>check</goal>
559559
</goals>
560+
<configuration>
561+
<nodeAnalyzerEnabled>false</nodeAnalyzerEnabled>
562+
<assemblyAnalyzerEnabled>false</assemblyAnalyzerEnabled>
563+
<nodeAuditAnalyzerEnabled>false</nodeAuditAnalyzerEnabled>
564+
</configuration>
560565
</execution>
561566
</executions>
562567
</plugin>

src/main/java/eu/openanalytics/containerproxy/backend/docker/AbstractDockerBackend.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public void initialize() throws ContainerProxyException {
9090
if (confUrl != null) builder.uri(confUrl);
9191

9292
dockerClient = builder.build();
93-
portRangeFrom = environment.getProperty(PROPERTY_PORT_RANGE_START, Integer.class, 20000);
94-
portRangeTo= environment.getProperty(PROPERTY_PORT_RANGE_MAX, Integer.class, -1);
93+
portRangeFrom = environment.getProperty(getPropertyPrefix() + PROPERTY_PORT_RANGE_START, Integer.class, 20000);
94+
portRangeTo= environment.getProperty(getPropertyPrefix() + PROPERTY_PORT_RANGE_MAX, Integer.class, -1);
9595
}
9696

9797
@Override

src/main/java/eu/openanalytics/containerproxy/backend/kubernetes/KubernetesBackend.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public void initialize(KubernetesClient client) {
170170
super.initialize();
171171
kubeClient = client;
172172
kubernetesManifestsRemover = new KubernetesManifestsRemover(kubeClient, getAppNamespaces(), identifierService);
173+
logManifests = environment.getProperty(DEBUG_PROPERTY, Boolean.class, false);
173174
}
174175

175176
@Override

src/test/java/eu/openanalytics/containerproxy/test/e2e/app_recovery/TestAppRecovery.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private void assertEverythingCleanedUp() throws DockerCertificateException, Dock
5959
// Docker
6060
DefaultDockerClient dockerClient = DefaultDockerClient.fromEnv().build();
6161
Assertions.assertEquals(0, dockerClient.listContainers().stream()
62-
.filter(it -> !(it.labels() != null && it.labels().containsKey("created_by.minikube.sigs.k8s.io") && it.labels().get("created_by.minikube.sigs.k8s.io").equals("true")))
62+
.filter(it -> it.labels() != null && it.labels().containsKey("openanalytics.eu/sp-proxied-app"))
6363
.count());
6464

6565
// Docker swarm
@@ -130,9 +130,18 @@ public void simple_recover_single_app_after_shutdown(String backend, String extr
130130
}
131131
}
132132

133+
private static Stream<Arguments> new_app_should_work_after_recovery_src() {
134+
return Stream.of(
135+
Arguments.of("docker", ""),
136+
Arguments.of("docker-swarm", ""),
137+
Arguments.of("kubernetes", ""),
138+
Arguments.of("kubernetes", "--proxy.docker.internal-networking=true")
139+
);
140+
}
141+
133142
// note: this test only works with minikube running on the same local machine, because it uses the NodePort services
134143
@ParameterizedTest
135-
@MethodSource("provideStringsForIsBlank")
144+
@MethodSource("new_app_should_work_after_recovery_src")
136145
public void new_app_should_work_after_recovery(String backend, String extraArgs) throws IOException, InterruptedException {
137146
ShinyProxyClient shinyProxyClient = new ShinyProxyClient("demo", "demo");
138147
List<ShinyProxyInstance> instances = new ArrayList<>();
@@ -145,6 +154,9 @@ public void new_app_should_work_after_recovery(String backend, String extraArgs)
145154
// 2. create a proxy
146155
String id1 = shinyProxyClient.startProxy("01_hello");
147156
Assertions.assertNotNull(id1);
157+
Thread.sleep(10000); // give the app some time to get ready (we are not using ShinyProxyTestStrategy, so status is not reliable)
158+
Assertions.assertTrue(shinyProxyClient.getProxyRequest(id1));
159+
148160

149161
// 3. get defined proxies
150162
HashSet<JsonObject> originalProxies = shinyProxyClient.getProxies();
@@ -168,10 +180,11 @@ public void new_app_should_work_after_recovery(String backend, String extraArgs)
168180
// 8. create a proxy
169181
String id2 = shinyProxyClient.startProxy("02_hello");
170182
Assertions.assertNotNull(id2);
183+
Thread.sleep(10000); // give the app some time to get ready (we are not using ShinyProxyTestStrategy, so status is not reliable)
171184

172185
// 9. test if both proxies are still reachable
173-
Assertions.assertNotNull(shinyProxyClient.getProxyRequest(id1));
174-
Assertions.assertNotNull(shinyProxyClient.getProxyRequest(id2));
186+
Assertions.assertTrue(shinyProxyClient.getProxyRequest(id1));
187+
Assertions.assertTrue(shinyProxyClient.getProxyRequest(id2));
175188

176189
// 8. stop both proxy
177190
Assertions.assertTrue(shinyProxyClient.stopProxy(id1));

src/test/java/eu/openanalytics/containerproxy/test/helpers/ShinyProxyClient.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
package eu.openanalytics.containerproxy.test.helpers;
2222

23+
import com.fasterxml.jackson.databind.ObjectMapper;
24+
import com.fasterxml.jackson.datatype.jsr353.JSR353Module;
2325
import okhttp3.*;
2426

2527
import javax.json.*;
@@ -32,6 +34,7 @@ public class ShinyProxyClient {
3234
private final String baseUrl;
3335

3436
public static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
37+
private ObjectMapper objectMapper = new ObjectMapper();
3538

3639
public ShinyProxyClient(String username, String password, int port) {
3740
this.baseUrl = "http://localhost:" + port;
@@ -40,6 +43,7 @@ public ShinyProxyClient(String username, String password, int port) {
4043
.callTimeout(Duration.ofSeconds(120))
4144
.readTimeout(Duration.ofSeconds(120))
4245
.build();
46+
objectMapper.registerModule(new JSR353Module());
4347
}
4448

4549
public ShinyProxyClient(String username, String password) {
@@ -57,7 +61,7 @@ public String startProxy(String specId) {
5761
JsonReader jsonReader = Json.createReader(response.body().byteStream());
5862
JsonObject object = jsonReader.readObject();
5963
jsonReader.close();
60-
return object.getString("id");
64+
return object.getJsonObject("data").getString("id");
6165
} else {
6266
System.out.println("BODY: " + response.body().string());
6367
System.out.println("CODE: " + response.code());
@@ -71,8 +75,8 @@ public String startProxy(String specId) {
7175

7276
public boolean stopProxy(String proxyId) {
7377
Request request = new Request.Builder()
74-
.delete(RequestBody.create(null, new byte[0]))
75-
.url(baseUrl + "/api/proxy/" + proxyId)
78+
.put(RequestBody.create("{\"desiredState\":\"Stopping\"}", JSON))
79+
.url(baseUrl + "/api/" + proxyId + "/status")
7680
.build();
7781

7882
try (Response response = client.newCall(request).execute()) {
@@ -91,16 +95,13 @@ public HashSet<JsonObject> getProxies() {
9195
.build();
9296

9397
try (Response response = client.newCall(request).execute()) {
94-
JsonReader jsonReader = Json.createReader(response.body().byteStream());
95-
JsonArray array = jsonReader.readArray();
96-
jsonReader.close();
98+
JsonObject resp = objectMapper.readValue(response.body().byteStream(), JsonObject.class);
9799

98100
HashSet<JsonObject> result = new HashSet<>();
99101

100-
for (JsonValue v: array) {
101-
JsonObject x = v.asJsonObject();
102+
for (JsonObject proxy : resp.getJsonArray("data").getValuesAs(JsonObject.class)) {
102103
JsonObjectBuilder builder = Json.createObjectBuilder();
103-
x.entrySet().forEach(e -> builder.add(e.getKey(), e.getValue()));
104+
proxy.forEach(builder::add);
104105
// remove startupTimestamp since it is different after app recovery
105106
builder.add("startupTimestamp", "null");
106107
result.add(builder.build());
@@ -112,17 +113,17 @@ public HashSet<JsonObject> getProxies() {
112113
}
113114
}
114115

115-
public String getProxyRequest(String id) {
116+
public boolean getProxyRequest(String id) {
116117
Request request = new Request.Builder()
117118
.get()
118119
.url(baseUrl + "/api/route/" + id + "/")
119120
.build();
120121

121122
try (Response response = client.newCall(request).execute()) {
122-
return response.body().string();
123+
return response.code() == 200;
123124
} catch (Exception e) {
124125
e.printStackTrace();
125-
return null;
126+
return false;
126127
}
127128
}
128129

src/test/java/eu/openanalytics/containerproxy/test/proxy/TestConcurrentUsers.java

Lines changed: 0 additions & 143 deletions
This file was deleted.

src/test/java/eu/openanalytics/containerproxy/test/proxy/TestIntegrationOnKube.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import eu.openanalytics.containerproxy.model.spec.ProxySpec;
3030
import eu.openanalytics.containerproxy.service.ProxyService;
3131
import eu.openanalytics.containerproxy.service.UserService;
32+
import eu.openanalytics.containerproxy.spec.expression.SpelException;
3233
import eu.openanalytics.containerproxy.test.helpers.KubernetesTestBase;
3334
import eu.openanalytics.containerproxy.test.proxy.TestIntegrationOnKube.TestConfiguration;
3435
import eu.openanalytics.containerproxy.util.ProxyMappingManager;
@@ -1596,8 +1597,13 @@ public void launchProxyWithParametersWithError() {
15961597
}, "The parameter with id \"non-existing-parameter\" does not exist");
15971598

15981599
Assertions.assertEquals("Container failed to start", ex.getMessage());
1599-
Assertions.assertEquals(IllegalArgumentException.class, ex.getCause().getClass());
1600-
Assertions.assertEquals("The parameter with id \"non-existing-parameter\" does not exist!", ex.getCause().getMessage());
1600+
Assertions.assertEquals(SpelException.class, ex.getCause().getClass());
1601+
Assertions.assertEquals("Error while resolving expression: \"- op: add\n" +
1602+
" path: /spec/containers/0/env/-\n" +
1603+
" value:\n" +
1604+
" name: ERROR\n" +
1605+
" value: \"#{proxy.getRuntimeObject('SHINYPROXY_PARAMETERS').getValue('non-existing-parameter')}\"\n" +
1606+
"\", error: The parameter with id \"non-existing-parameter\" does not exist!", ex.getCause().getMessage());
16011607

16021608
Thread.sleep(2000);
16031609

0 commit comments

Comments
 (0)