Skip to content

Commit 3b928fa

Browse files
committed
docs(springboot cloudconfig): A fix of example docs.
Fix the example doc to make cloud config demo works both local and kubernetes Signed-off-by: lony2003 <[email protected]>
1 parent d88cc82 commit 3b928fa

File tree

2 files changed

+4
-104
lines changed

2 files changed

+4
-104
lines changed

spring-boot-examples/cloud-config-demo/src/test/java/io/dapr/springboot/examples/cloudconfig/CloudConfigTests.java

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -54,79 +54,8 @@
5454
@Tag("testcontainers")
5555
class CloudConfigTests {
5656

57-
public static final String CONFIG_STORE_NAME = "democonfigconf";
58-
public static final String CONFIG_MULTI_NAME = "multivalue-yaml";
59-
public static final String CONFIG_SINGLE_NAME = "dapr.spring.demo-config-config.singlevalue";
60-
61-
public static final String SECRET_STORE_NAME = "democonfig";
62-
public static final String SECRET_MULTI_NAME = "multivalue-properties";
63-
public static final String SECRET_SINGLE_NAME = "dapr.spring.demo-config-secret.singlevalue";
64-
65-
public static final String SECRET_STORE_NAME_MULTI = "democonfigMultivalued";
66-
67-
private static final Map<String, String> SINGLE_VALUE_PROPERTY = generateSingleValueProperty();
68-
private static final Map<String, String> MULTI_VALUE_PROPERTY = generateMultiValueProperty();
69-
70-
71-
private static final Map<String, String> STORE_PROPERTY = generateStoreProperty();
72-
73-
private static final Network DAPR_NETWORK = Network.newNetwork();
74-
75-
@Container
76-
private static final RedisContainer REDIS_CONTAINER = new RedisContainer(
77-
RedisContainer.DEFAULT_IMAGE_NAME.withTag(RedisContainer.DEFAULT_TAG)) {
78-
@Override
79-
protected void containerIsStarted(InspectContainerResponse containerInfo) {
80-
super.containerIsStarted(containerInfo);
81-
82-
String address = getHost();
83-
Integer port = getMappedPort(6379);
84-
85-
Logger logger = LoggerFactory.getLogger(CloudConfigTests.class);
86-
// Put values using Jedis
87-
try (Jedis jedis = new Jedis(address, port)) {
88-
logger.info("Putting Dapr Cloud config to {}:{}", address, port);
89-
jedis.set(CloudConfigTests.CONFIG_MULTI_NAME, DaprConfigurationStores.YAML_CONFIG);
90-
jedis.set(CloudConfigTests.CONFIG_SINGLE_NAME, "testvalue");
91-
}
92-
}
93-
}
94-
.withNetworkAliases("redis")
95-
.withCommand()
96-
.withNetwork(DAPR_NETWORK);
97-
98-
@Container
99-
@ServiceConnection
100-
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.14.4")
101-
.withAppName("configuration-dapr-app")
102-
.withNetwork(DAPR_NETWORK)
103-
.withComponent(new Component(CONFIG_STORE_NAME, "configuration.redis", "v1", STORE_PROPERTY))
104-
.withComponent(new Component(SECRET_STORE_NAME, "secretstores.local.file", "v1", SINGLE_VALUE_PROPERTY))
105-
.withComponent(new Component(SECRET_STORE_NAME_MULTI, "secretstores.local.file", "v1", MULTI_VALUE_PROPERTY))
106-
.withDaprLogLevel(DaprLogLevel.DEBUG)
107-
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
108-
.dependsOn(REDIS_CONTAINER)
109-
.withCopyToContainer(Transferable.of(DaprSecretStores.SINGLE_VALUED_SECRET), "/dapr-secrets/singlevalued.json")
110-
.withCopyToContainer(Transferable.of(DaprSecretStores.MULTI_VALUED_SECRET), "/dapr-secrets/multivalued.json");
111-
11257
static {
113-
DAPR_CONTAINER.setPortBindings(List.of("3500:3500", "50001:50001"));
114-
}
115-
116-
private static Map<String, String> generateStoreProperty() {
117-
return Map.of("redisHost", "redis:6379",
118-
"redisPassword", "");
119-
}
120-
121-
private static Map<String, String> generateSingleValueProperty() {
122-
return Map.of("secretsFile", "/dapr-secrets/singlevalued.json",
123-
"multiValued", "false");
124-
}
125-
126-
private static Map<String, String> generateMultiValueProperty() {
127-
return Map.of("secretsFile", "/dapr-secrets/multivalued.json",
128-
"nestedSeparator", ".",
129-
"multiValued", "true");
58+
DaprTestContainersConfig.DAPR_CONTAINER.start();
13059
}
13160

13261
@BeforeEach

spring-boot-examples/cloud-config-demo/src/test/java/io/dapr/springboot/examples/cloudconfig/DaprTestContainersConfig.java

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class DaprTestContainersConfig {
5454

5555
private static final Map<String, String> STORE_PROPERTY = generateStoreProperty();
5656

57-
private static final Network DAPR_NETWORK = getDaprNetwork();
57+
private static final Network DAPR_NETWORK = Network.newNetwork();
5858

5959
private static Map<String, String> generateStoreProperty() {
6060
return Map.of("redisHost", "redis:6379",
@@ -72,35 +72,6 @@ private static Map<String, String> generateMultiValueProperty() {
7272
"multiValued", "true");
7373
}
7474

75-
public static Network getDaprNetwork() {
76-
Network defaultDaprNetwork = new Network() {
77-
@Override
78-
public String getId() {
79-
return "dapr-network";
80-
}
81-
82-
@Override
83-
public void close() {
84-
85-
}
86-
87-
@Override
88-
public Statement apply(Statement base, Description description) {
89-
return null;
90-
}
91-
};
92-
93-
List<com.github.dockerjava.api.model.Network> networks = DockerClientFactory.instance().client().listNetworksCmd()
94-
.withNameFilter("dapr-network").exec();
95-
if (networks.isEmpty()) {
96-
Network.builder().createNetworkCmdModifier(cmd -> cmd.withName("dapr-network")).build().getId();
97-
return defaultDaprNetwork;
98-
} else {
99-
return defaultDaprNetwork;
100-
}
101-
102-
}
103-
10475
@Container
10576
private static final RedisContainer REDIS_CONTAINER = new RedisContainer(
10677
RedisContainer.DEFAULT_IMAGE_NAME.withTag(RedisContainer.DEFAULT_TAG)) {
@@ -115,8 +86,8 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) {
11586
// Put values using Jedis
11687
try (Jedis jedis = new Jedis(address, port)) {
11788
logger.info("Putting Dapr Cloud config to {}:{}", address, port);
118-
jedis.set(CloudConfigTests.CONFIG_MULTI_NAME, DaprConfigurationStores.YAML_CONFIG);
119-
jedis.set(CloudConfigTests.CONFIG_SINGLE_NAME, "testvalue");
89+
jedis.set(DaprTestContainersConfig.CONFIG_MULTI_NAME, DaprConfigurationStores.YAML_CONFIG);
90+
jedis.set(DaprTestContainersConfig.CONFIG_SINGLE_NAME, "testvalue");
12091
}
12192
}
12293
}

0 commit comments

Comments
 (0)