Skip to content

Commit 2f848ba

Browse files
authored
Improve GeoIpDownloaderIT test case (#70640) (#70812)
GeoIpDownloaderIT should be able to reuse test clusters and run tests against a test cluster with multiple nodes.
1 parent 7f1ae62 commit 2f848ba

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

modules/ingest-geoip/src/internalClusterTest/java/org/elasticsearch/ingest/geoip/GeoIpDownloaderIT.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import org.elasticsearch.persistent.PersistentTasksCustomMetadata;
3232
import org.elasticsearch.search.SearchHit;
3333
import org.elasticsearch.search.sort.SortOrder;
34-
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
35-
import org.elasticsearch.test.ESIntegTestCase.Scope;
3634
import org.elasticsearch.test.junit.annotations.TestLogging;
3735
import org.junit.After;
3836

@@ -41,7 +39,6 @@
4139
import java.io.IOException;
4240
import java.io.InputStream;
4341
import java.io.OutputStream;
44-
import java.io.UncheckedIOException;
4542
import java.nio.file.Files;
4643
import java.nio.file.Path;
4744
import java.util.ArrayList;
@@ -63,7 +60,6 @@
6360
import static org.hamcrest.Matchers.equalTo;
6461
import static org.hamcrest.Matchers.is;
6562

66-
@ClusterScope(scope = Scope.TEST, maxNumDataNodes = 1)
6763
public class GeoIpDownloaderIT extends AbstractGeoIpIT {
6864

6965
private static final String ENDPOINT = System.getProperty("geoip_endpoint");
@@ -81,7 +77,7 @@ protected Settings nodeSettings(int nodeOrdinal) {
8177
public void disableDownloader() {
8278
ClusterUpdateSettingsResponse settingsResponse = client().admin().cluster()
8379
.prepareUpdateSettings()
84-
.setPersistentSettings(Settings.builder().put(GeoIpDownloaderTaskExecutor.ENABLED_SETTING.getKey(), false))
80+
.setPersistentSettings(Settings.builder().put(GeoIpDownloaderTaskExecutor.ENABLED_SETTING.getKey(), (String) null))
8581
.get();
8682
assertTrue(settingsResponse.isAcknowledged());
8783
}
@@ -233,19 +229,13 @@ public void testUseGeoIpProcessorWithDownloadedDBs() throws Exception {
233229
final java.util.Set<String> ids = StreamSupport.stream(nodes.getDataNodes().values().spliterator(), false)
234230
.map(c -> c.value.getId())
235231
.collect(Collectors.toSet());
236-
final List<Path> geoipTmpDirs = StreamSupport.stream(internalCluster().getDataNodeInstances(Environment.class).spliterator(), false)
237-
.map(env -> {
238-
Path geoipTmpDir = env.tmpFile().resolve("geoip-databases");
239-
assertThat(Files.exists(geoipTmpDir), is(true));
240-
return geoipTmpDir;
241-
}).flatMap(path -> {
242-
try {
243-
return Files.list(path);
244-
} catch (IOException e) {
245-
throw new UncheckedIOException(e);
246-
}
247-
}).filter(path -> ids.contains(path.getFileName().toString()))
248-
.collect(Collectors.toList());
232+
// All nodes share the same geoip base dir in the shared tmp dir:
233+
Path geoipBaseTmpDir = internalCluster().getDataNodeInstance(Environment.class).tmpFile().resolve("geoip-databases");
234+
assertThat(Files.exists(geoipBaseTmpDir), is(true));
235+
final List<Path> geoipTmpDirs;
236+
try (Stream<Path> files = Files.list(geoipBaseTmpDir)) {
237+
geoipTmpDirs = files.filter(path -> ids.contains(path.getFileName().toString())).collect(Collectors.toList());
238+
}
249239
assertThat(geoipTmpDirs.size(), equalTo(internalCluster().numDataNodes()));
250240
assertBusy(() -> {
251241
for (Path geoipTmpDir : geoipTmpDirs) {

0 commit comments

Comments
 (0)