|
9 | 9 | package org.elasticsearch.ingest.geoip; |
10 | 10 |
|
11 | 11 | import com.carrotsearch.randomizedtesting.generators.RandomPicks; |
| 12 | + |
12 | 13 | import org.elasticsearch.ElasticsearchParseException; |
13 | 14 | import org.elasticsearch.ResourceNotFoundException; |
14 | 15 | import org.elasticsearch.client.Client; |
15 | 16 | import org.elasticsearch.cluster.ClusterState; |
| 17 | +import org.elasticsearch.cluster.metadata.Metadata; |
16 | 18 | import org.elasticsearch.cluster.service.ClusterService; |
17 | 19 | import org.elasticsearch.common.Randomness; |
18 | 20 | import org.elasticsearch.common.settings.Settings; |
19 | 21 | import org.elasticsearch.index.VersionType; |
20 | 22 | import org.elasticsearch.ingest.IngestDocument; |
21 | 23 | import org.elasticsearch.ingest.IngestService; |
22 | 24 | import org.elasticsearch.ingest.RandomDocumentPicks; |
| 25 | +import org.elasticsearch.persistent.PersistentTasksCustomMetadata; |
23 | 26 | import org.elasticsearch.test.ESTestCase; |
24 | 27 | import org.elasticsearch.test.StreamsUtils; |
25 | 28 | import org.elasticsearch.threadpool.TestThreadPool; |
@@ -367,6 +370,26 @@ public void testFallbackUsingDefaultDatabases() throws Exception { |
367 | 370 | } |
368 | 371 | } |
369 | 372 |
|
| 373 | + public void testDefaultDatabaseWithTaskPresent() throws Exception { |
| 374 | + PersistentTasksCustomMetadata tasks = PersistentTasksCustomMetadata.builder() |
| 375 | + .addTask(GeoIpDownloader.GEOIP_DOWNLOADER, GeoIpDownloader.GEOIP_DOWNLOADER, null, null) |
| 376 | + .updateTaskState(GeoIpDownloader.GEOIP_DOWNLOADER, GeoIpTaskState.EMPTY) |
| 377 | + .build(); |
| 378 | + ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE) |
| 379 | + .metadata(Metadata.builder().putCustom(PersistentTasksCustomMetadata.TYPE, tasks)) |
| 380 | + .build(); |
| 381 | + when(clusterService.state()).thenReturn(clusterState); |
| 382 | + GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(databaseRegistry, clusterService); |
| 383 | + |
| 384 | + Map<String, Object> config = new HashMap<>(); |
| 385 | + config.put("field", "_field"); |
| 386 | + String processorTag = randomAlphaOfLength(10); |
| 387 | + |
| 388 | + GeoIpProcessor processor = factory.create(null, processorTag, null, config); |
| 389 | + |
| 390 | + processor.execute(RandomDocumentPicks.randomIngestDocument(random(), org.elasticsearch.core.Map.of("_field", "89.160.20.128"))); |
| 391 | + } |
| 392 | + |
370 | 393 | public void testFallbackUsingDefaultDatabasesWhileIngesting() throws Exception { |
371 | 394 | copyDatabaseFile(geoipTmpDir, "GeoLite2-City-Test.mmdb"); |
372 | 395 | GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(databaseRegistry, clusterService); |
|
0 commit comments