Skip to content

Commit abbc749

Browse files
committed
Fix tests
1 parent bb9e88b commit abbc749

50 files changed

Lines changed: 50 additions & 97 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/eu/openanalytics/containerproxy/event/NewProxyEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public NewProxyEvent(Proxy proxy, Authentication authentication) {
8181
proxy.getId(),
8282
proxy.getUserId(),
8383
proxy.getSpecId(),
84-
proxy.getRuntimeValueOrNull("SHINYPROXY_APP_INSTANCE"),
84+
proxy.getRuntimeValueOrDefault("SHINYPROXY_APP_INSTANCE", ""),
8585
proxy.getCreatedTimestamp(),
8686
proxy.getContainers().isEmpty() ? null : proxy.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst),
8787
authentication);

src/main/java/eu/openanalytics/containerproxy/event/ProxyStartEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public ProxyStartEvent(Proxy proxy, ProxyStartupLog proxyStartupLog, Authenticat
8585
proxy.getId(),
8686
proxy.getUserId(),
8787
proxy.getSpecId(),
88-
proxy.getRuntimeValue("SHINYPROXY_APP_INSTANCE"),
88+
proxy.getRuntimeValueOrDefault("SHINYPROXY_APP_INSTANCE", ""),
8989
proxy.getCreatedTimestamp(),
9090
proxy.getContainers().isEmpty() ? null : proxy.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst),
9191
proxyStartupLog,

src/main/java/eu/openanalytics/containerproxy/event/ProxyStartFailedEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public ProxyStartFailedEvent(Proxy proxy) {
6565
proxy.getId(),
6666
proxy.getUserId(),
6767
proxy.getSpecId(),
68-
proxy.getRuntimeValue("SHINYPROXY_APP_INSTANCE"),
68+
proxy.getRuntimeValueOrDefault("SHINYPROXY_APP_INSTANCE", ""),
6969
proxy.getCreatedTimestamp(),
7070
proxy.getContainers().isEmpty() ? null : proxy.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst)
7171
);

src/main/java/eu/openanalytics/containerproxy/event/ProxyStopEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public ProxyStopEvent(Proxy proxy, ProxyStopReason proxyStopReason, Authenticati
9191
proxy.getId(),
9292
proxy.getUserId(),
9393
proxy.getSpecId(),
94-
proxy.getRuntimeValue("SHINYPROXY_APP_INSTANCE"),
94+
proxy.getRuntimeValueOrDefault("SHINYPROXY_APP_INSTANCE", ""),
9595
proxy.getCreatedTimestamp(),
9696
proxy.getContainers().isEmpty() ? null : proxy.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst),
9797
proxyStopReason,

src/main/java/eu/openanalytics/containerproxy/model/runtime/Container.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static Container createFromJson(@JsonProperty("index") Integer index,
6363
.id(id);
6464

6565
for (Map.Entry<String, String> runtimeValue : runtimeValues.entrySet()) {
66-
RuntimeValueKey<?> key = RuntimeValueKeyRegistry.getRuntimeValue(runtimeValue.getKey());
66+
RuntimeValueKey<?> key = RuntimeValueKeyRegistry.getRuntimeValueKey(runtimeValue.getKey());
6767
builder.addRuntimeValue(new RuntimeValue(key, key.deserializeFromString(runtimeValue.getValue())), false);
6868
}
6969

src/main/java/eu/openanalytics/containerproxy/model/runtime/Proxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static Proxy createFromJson(@JsonProperty("id") String id,
9696
.containers(containers);
9797

9898
for (Map.Entry<String, String> runtimeValue : runtimeValues.entrySet()) {
99-
RuntimeValueKey<?> key = RuntimeValueKeyRegistry.getRuntimeValue(runtimeValue.getKey());
99+
RuntimeValueKey<?> key = RuntimeValueKeyRegistry.getRuntimeValueKey(runtimeValue.getKey());
100100
builder.addRuntimeValue(new RuntimeValue(key, key.deserializeFromString(runtimeValue.getValue())), false);
101101
}
102102

src/main/java/eu/openanalytics/containerproxy/model/runtime/runtimevalues/RuntimeValueKeyRegistry.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,18 @@ public static Collection<RuntimeValueKey<?>> getRuntimeValueKeys() {
6767
return KEYS.values();
6868
}
6969

70-
public static RuntimeValueKey<?> getRuntimeValue(String key) {
70+
public static RuntimeValueKey<?> getRuntimeValueKey(String key) {
7171
if (!KEYS.containsKey(key)) {
7272
throw new IllegalArgumentException("Could not find RuntimeValueKey using key " + key);
7373
}
7474
return KEYS.get(key);
7575
}
7676

77+
public static RuntimeValueKey<?> getRuntimeValueKeyOrNull(String key) {
78+
if (!KEYS.containsKey(key)) {
79+
return null;
80+
}
81+
return KEYS.get(key);
82+
}
83+
7784
}

src/main/java/eu/openanalytics/containerproxy/model/runtime/runtimevalues/RuntimeValueStore.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ public Map<String, Object> geAllRuntimeValuesJson() {
6464
*/
6565
public String getRuntimeValue(String keyAsEnvVar) {
6666
Objects.requireNonNull(keyAsEnvVar, "key may not be null");
67-
return getRuntimeValue(RuntimeValueKeyRegistry.getRuntimeValue(keyAsEnvVar));
67+
return getRuntimeValue(RuntimeValueKeyRegistry.getRuntimeValueKey(keyAsEnvVar));
6868
}
6969

7070
public Object getRuntimeObject(String keyAsEnvVar) {
7171
Objects.requireNonNull(keyAsEnvVar, "key may not be null");
72-
return getRuntimeObject(RuntimeValueKeyRegistry.getRuntimeValue(keyAsEnvVar));
72+
return getRuntimeObject(RuntimeValueKeyRegistry.getRuntimeValueKey(keyAsEnvVar));
7373
}
7474

7575
public <T> T getRuntimeObject(RuntimeValueKey<T> key) {
@@ -113,9 +113,31 @@ public <T> String getRuntimeValueOrNull(RuntimeValueKey<T> key) {
113113
return key.serializeToString(runtimeValue.getObject());
114114
}
115115

116+
public <T> String getRuntimeValueOrDefault(RuntimeValueKey<T> key, String defaultValue) {
117+
Objects.requireNonNull(key, "key may not be null");
118+
RuntimeValue runtimeValue = getRuntimeValues().get(key);
119+
if (runtimeValue == null) {
120+
return defaultValue;
121+
}
122+
return key.serializeToString(runtimeValue.getObject());
123+
}
124+
116125
public String getRuntimeValueOrNull(String keyAsEnvVar) {
117126
Objects.requireNonNull(keyAsEnvVar, "key may not be null");
118-
return getRuntimeValueOrNull(RuntimeValueKeyRegistry.getRuntimeValue(keyAsEnvVar));
127+
RuntimeValueKey<?> key = RuntimeValueKeyRegistry.getRuntimeValueKeyOrNull(keyAsEnvVar);
128+
if (key == null) {
129+
return null;
130+
}
131+
return getRuntimeValueOrNull(key);
132+
}
133+
134+
public String getRuntimeValueOrDefault(String keyAsEnvVar, String defaultValue) {
135+
Objects.requireNonNull(keyAsEnvVar, "key may not be null");
136+
RuntimeValueKey<?> key = RuntimeValueKeyRegistry.getRuntimeValueKeyOrNull(keyAsEnvVar);
137+
if (key == null) {
138+
return defaultValue;
139+
}
140+
return getRuntimeValueOrDefault(key, defaultValue);
119141
}
120142

121143
}

src/main/java/eu/openanalytics/containerproxy/stat/impl/Micrometer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ private void updateAppInfo() {
438438
Tags.of(
439439
"spec.id", proxy.getSpecId(),
440440
"user.id", proxy.getUserId(),
441-
"proxy.instance", proxy.getRuntimeValue("SHINYPROXY_APP_INSTANCE"),
441+
"proxy.instance", proxy.getRuntimeValueOrDefault("SHINYPROXY_APP_INSTANCE", ""),
442442
"proxy.id", proxy.getId(),
443443
"proxy.created.timestamp", Long.toString(proxy.getCreatedTimestamp()),
444444
"resource.id", backendContainerName.getName(),

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ public void test_resource_name_docker() {
3838
Assertions.assertNotNull(id1);
3939
Proxy proxy = inst.proxyService.getProxy(id1);
4040

41-
Assertions.assertEquals("sp-container-" + proxy.getId() + "-0", proxy.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst));
41+
Assertions.assertEquals("sp-container-" + proxy.getId() + "-0", proxy.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst).toString());
4242
inst.client.stopProxy(id1);
4343

4444
String id2 = inst.client.startProxy("custom_resource_name");
4545
Assertions.assertNotNull(id2);
4646
Proxy proxy2 = inst.proxyService.getProxy(id2);
4747

48-
Assertions.assertEquals("my-app-custom_resource_name-demo", proxy2.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst));
48+
Assertions.assertEquals("my-app-custom_resource_name-demo", proxy2.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst).toString());
4949
inst.client.stopProxy(id2);
5050
}
5151
}
@@ -59,14 +59,14 @@ public void test_resource_name_docker_swarm() {
5959
Assertions.assertNotNull(id1);
6060
Proxy proxy1 = inst.proxyService.getProxy(id1);
6161

62-
Assertions.assertEquals("sp-service-" + proxy1.getId() + "-0", proxy1.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst));
62+
Assertions.assertEquals("sp-service-" + proxy1.getId() + "-0", proxy1.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst).toString());
6363
inst.client.stopProxy(id1);
6464

6565
String id2 = inst.client.startProxy("custom_resource_name");
6666
Assertions.assertNotNull(id2);
6767
Proxy proxy2 = inst.proxyService.getProxy(id2);
6868

69-
Assertions.assertEquals("my-app-custom_resource_name-demo", proxy2.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst));
69+
Assertions.assertEquals("my-app-custom_resource_name-demo", proxy2.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst).toString());
7070
inst.client.stopProxy(id2);
7171
}
7272
}
@@ -80,14 +80,14 @@ public void test_resource_name_k8s() {
8080
Assertions.assertNotNull(id1);
8181
Proxy proxy1 = inst.proxyService.getProxy(id1);
8282

83-
Assertions.assertEquals("itest/sp-pod-" + proxy1.getId() + "-0", proxy1.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst));
83+
Assertions.assertEquals("itest/sp-pod-" + proxy1.getId() + "-0", proxy1.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst).toString());
8484
inst.client.stopProxy(id1);
8585

8686
String id2 = inst.client.startProxy("custom-resource-name");
8787
Assertions.assertNotNull(id2);
8888
Proxy proxy2 = inst.proxyService.getProxy(id2);
8989

90-
Assertions.assertEquals("itest/my-app-custom-resource-name-demo", proxy2.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst));
90+
Assertions.assertEquals("itest/my-app-custom-resource-name-demo", proxy2.getContainers().get(0).getRuntimeObjectOrNull(BackendContainerNameKey.inst).toString());
9191
inst.client.stopProxy(id2);
9292
}
9393
}

0 commit comments

Comments
 (0)