Skip to content

Commit

Permalink
Updates problematic IT test and constrains its scope to run only with…
Browse files Browse the repository at this point in the history
… V3 servers. V2 support is deprecated and marked for removal.

Signed-off-by: Santiago Pericas-Geertsen <[email protected]>
  • Loading branch information
spericas committed Jan 22, 2025
1 parent 34d053e commit 3c5e8f0
Showing 1 changed file with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2022 Oracle and/or its affiliates.
* Copyright (c) 2017, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,29 +29,27 @@
import io.helidon.config.etcd.internal.client.EtcdClient;
import io.helidon.config.hocon.HoconConfigParser;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.core.Is.is;

/**
* Tests {@link EtcdConfigSource} with both version, {@link EtcdApi#v2} and {@link EtcdApi#v3}.
* Integration test for {@link EtcdConfigSource} using {@link EtcdApi#v3}.
*/
public class EtcdConfigSourceIT {

private static final URI DEFAULT_URI = URI.create("http://localhost:2379");

@ParameterizedTest
@EnumSource(EtcdApi.class)
public void testConfig(EtcdApi version) throws Exception {
putConfiguration(version, "/application.conf");
@Test
public void testConfig() throws Exception {
putConfiguration("/application.conf");
Config config = Config.builder()
.sources(EtcdConfigSource.builder()
.uri(DEFAULT_URI)
.key("configuration")
.api(version)
.api(EtcdApi.v3)
.mediaType(MediaTypes.APPLICATION_HOCON)
.build())
.addParser(HoconConfigParser.create())
Expand All @@ -60,15 +58,14 @@ public void testConfig(EtcdApi version) throws Exception {
assertThat(config.get("security").asNodeList().get(), hasSize(1));
}

@ParameterizedTest
@EnumSource(EtcdApi.class)
public void testConfigChanges(EtcdApi version) throws Exception {
putConfiguration(version, "/application.conf");
@Test
public void testConfigChanges() throws Exception {
putConfiguration("/application.conf");
Config config = Config.builder()
.sources(EtcdConfigSource.builder()
.uri(DEFAULT_URI)
.key("configuration")
.api(version)
.api(EtcdApi.v3)
.mediaType(MediaTypes.APPLICATION_HOCON)
.changeWatcher(EtcdWatcher.create())
.build())
Expand All @@ -77,27 +74,23 @@ public void testConfigChanges(EtcdApi version) throws Exception {

assertThat(config.get("security").asNodeList().get(), hasSize(1));

CountDownLatch initLatch = new CountDownLatch(1);
CountDownLatch nextLatch = new CountDownLatch(3);
config.onChange(it -> nextLatch.countDown());

config.onChange(it -> initLatch.countDown());

assertThat(initLatch.await(1, TimeUnit.SECONDS), is(true));

putConfiguration(version, "/application2.conf");
putConfiguration("/application2.conf");
TimeUnit.MILLISECONDS.sleep(10);
putConfiguration(version, "/application3.conf");
putConfiguration("/application3.conf");
TimeUnit.MILLISECONDS.sleep(10);
putConfiguration(version, "/application4.conf");
putConfiguration("/application4.conf");

assertThat(nextLatch.await(20, TimeUnit.SECONDS), is(true));
}

private static void putConfiguration(EtcdApi version, String resourcePath) throws Exception {
EtcdClient etcd = version.clientFactory().createClient(DEFAULT_URI);

private static void putConfiguration(String resourcePath) throws Exception {
EtcdClient etcd = EtcdApi.v3.clientFactory().createClient(DEFAULT_URI);
File file = new File(EtcdConfigSourceIT.class.getResource(resourcePath).getFile());
etcd.put("configuration", String.join("\n", Files.readAllLines(file.toPath(), Charset.defaultCharset())));
etcd.put("configuration", String.join("\n",
Files.readAllLines(file.toPath(), Charset.defaultCharset())));
etcd.close();
}
}

0 comments on commit 3c5e8f0

Please sign in to comment.