8000 Fix #33 - Allow using the config map store outisde of kubernetes · soujava/vertx-config@30055a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 30055a2

Browse files
committed
Fix vert-x3#33 - Allow using the config map store outisde of kubernetes
When marked as optional, it just returns an empty JSON object
1 parent 4824def commit 30055a2

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

vertx-config-kubernetes-configmap/src/main/java/io/vertx/config/kubernetes/ConfigMapStore.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ private synchronized void closeOnContext(Handler<Void> completionHandler) {
116116
if (client != null) {
117117
client.close();
118118
}
119+
if (completionHandler != null) {
120+
completionHandler.handle(null);
121+
}
119122
}
120123

121124
private void runOnContext(Handler<Void> action) {
@@ -142,7 +145,7 @@ private Future<String> getToken() {
142145
if (ar.failed()) {
143146
if (optional) {
144147
this.token = "";
145-
result.tryComplete(token);
148+
result.tryComplete(this.token);
146149
} else {
147150
result.tryFail(ar.cause());
148151
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2014 Red Hat, Inc. and others
3+
*
4+
* Red Hat licenses this file to you under the Apache License, version 2.0
5+
* (the "License"); you may not use this file except in compliance with the
6+
* License. You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*
16+
*/
17+
18+
package io.vertx.config.kubernetes;
19+
20+
import io.vertx.config.ConfigRetriever;
21+
import io.vertx.config.ConfigRetrieverOptions;
22+
import io.vertx.config.ConfigStoreOptions;
23+
import io.vertx.core.Vertx;
24+
import io.vertx.core.json.JsonObject;
25+
import io.vertx.ext.unit.Async;
26+
import io.vertx.ext.unit.TestContext;
27+
import io.vertx.ext.unit.junit.VertxUnitRunner;
28+
import org.junit.After;
29+
import org.junit.Before;
30+
import org.junit.Test;
31+
import org.junit.runner.RunWith;
32+
33+
import java.net.MalformedURLException;
34+
35+
/**
36+
* @author <a href="http://escoffier.me">Clement Escoffier</a>
37+
*/
38+
@RunWith(VertxUnitRunner.class)
39+
public class ConfigMapStoreOutsideOfKubernetesTest {
40+
41+
protected Vertx vertx;
42+
private ConfigRetriever retriever;
43+
44+
@Before
45+
public void setUp(TestContext tc) throws MalformedURLException {
46+
vertx = Vertx.vertx();
47+
vertx.exceptionHandler(tc.exceptionHandler());
48+
ConfigStoreOptions store = new ConfigStoreOptions()
49+
.setType("configmap")
50+
.setConfig(new JsonObject()
51+
.put("name", "my-config-map")
52+
.put("key", "my-app-json"));
53+
retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(store));
54+
}
55+
56+
@After
57+
public void tearDown() {
58+
vertx.close();
59+
}
60+
61+
@Test
62+
public void test(TestContext tc) {
63+
Async async = tc.async();
64+
retriever.getConfig(ar -> {
65+
if (ar.failed()) {
66+
ar.cause().printStackTrace();
67+
}
68+
tc.assertTrue(ar.succeeded());
69+
tc.assertTrue(ar.result().isEmpty());
70+
async.complete();
71+
});
72+
}
73+
74+
75+
}

0 commit comments

Comments
 (0)
0