Skip to content

Commit be38621

Browse files
authored
Improve GeoIpDownloaderIT test case (#70640)
GeoIpDownloaderIT should be able to reuse test clusters and run tests against a test cluster with multiple nodes.
1 parent 11bd61d commit be38621

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.plugins.Plugin;
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;
@@ -66,7 +63,6 @@
6663
import static org.hamcrest.Matchers.equalTo;
6764
import static org.hamcrest.Matchers.is;
6865

69-
@ClusterScope(scope = Scope.TEST, maxNumDataNodes = 1)
7066
public class GeoIpDownloaderIT extends AbstractGeoIpIT {
7167

7268
private static final String ENDPOINT = System.getProperty("geoip_endpoint");
@@ -89,7 +85,7 @@ protected Settings nodeSettings(int nodeOrdinal) {
8985
public void disableDownloader() {
9086
ClusterUpdateSettingsResponse settingsResponse = client().admin().cluster()
9187
.prepareUpdateSettings()
92-
.setPersistentSettings(Settings.builder().put(GeoIpDownloaderTaskExecutor.ENABLED_SETTING.getKey(), false))
88+
.setPersistentSettings(Settings.builder().put(GeoIpDownloaderTaskExecutor.ENABLED_SETTING.getKey(), (String) null))
9389
.get();
9490
assertTrue(settingsResponse.isAcknowledged());
9591
}
@@ -236,19 +232,13 @@ public void testUseGeoIpProcessorWithDownloadedDBs() throws Exception {
236232
final Set<String> ids = StreamSupport.stream(clusterService().state().nodes().getDataNodes().values().spliterator(), false)
237233
.map(c -> c.value.getId())
238234
.collect(Collectors.toSet());
239-
final List<Path> geoipTmpDirs = StreamSupport.stream(internalCluster().getDataNodeInstances(Environment.class).spliterator(), false)
240-
.map(env -> {
241-
Path geoipTmpDir = env.tmpFile().resolve("geoip-databases");
242-
assertThat(Files.exists(geoipTmpDir), is(true));
243-
return geoipTmpDir;
244-
}).flatMap(path -> {
245-
try {
246-
return Files.list(path);
247-
} catch (IOException e) {
248-
throw new UncheckedIOException(e);
249-
}
250-
}).filter(path -> ids.contains(path.getFileName().toString()))
251-
.collect(Collectors.toList());
235+
// All nodes share the same geoip base dir in the shared tmp dir:
236+
Path geoipBaseTmpDir = internalCluster().getDataNodeInstance(Environment.class).tmpFile().resolve("geoip-databases");
237+
assertThat(Files.exists(geoipBaseTmpDir), is(true));
238+
final List<Path> geoipTmpDirs;
239+
try (Stream<Path> files = Files.list(geoipBaseTmpDir)) {
240+
geoipTmpDirs = files.filter(path -> ids.contains(path.getFileName().toString())).collect(Collectors.toList());
241+
}
252242
assertThat(geoipTmpDirs.size(), equalTo(internalCluster().numDataNodes()));
253243
assertBusy(() -> {
254244
for (Path geoipTmpDir : geoipTmpDirs) {

0 commit comments

Comments
 (0)