|
14 | 14 | import com.carrotsearch.randomizedtesting.annotations.Name; |
15 | 15 | import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; |
16 | 16 |
|
17 | | -import org.apache.http.entity.ByteArrayEntity; |
18 | | -import org.apache.http.entity.ContentType; |
19 | | -import org.elasticsearch.client.Request; |
20 | | -import org.elasticsearch.common.bytes.BytesReference; |
21 | 17 | import org.elasticsearch.core.Booleans; |
22 | 18 | import org.elasticsearch.multiproject.test.MultipleProjectsClientYamlSuiteTestCase; |
23 | 19 | import org.elasticsearch.test.cluster.ElasticsearchCluster; |
24 | 20 | import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; |
25 | 21 | import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; |
26 | | -import org.elasticsearch.xcontent.XContentBuilder; |
27 | | -import org.elasticsearch.xcontent.json.JsonXContent; |
28 | 22 | import org.junit.Before; |
29 | 23 | import org.junit.ClassRule; |
30 | 24 | import org.junit.rules.RuleChain; |
31 | 25 | import org.junit.rules.TestRule; |
32 | 26 |
|
33 | | -import java.io.IOException; |
34 | | -import java.util.List; |
35 | | -import java.util.Map; |
36 | | -import java.util.concurrent.TimeUnit; |
37 | | - |
38 | | -import static org.hamcrest.Matchers.containsInAnyOrder; |
39 | | -import static org.hamcrest.Matchers.equalTo; |
40 | | -import static org.hamcrest.Matchers.notNullValue; |
| 27 | +import static org.elasticsearch.ingest.geoip.IngestGeoIpClientYamlTestSuiteIT.assertDatabasesLoaded; |
| 28 | +import static org.elasticsearch.ingest.geoip.IngestGeoIpClientYamlTestSuiteIT.putGeoipPipeline; |
41 | 29 |
|
42 | 30 | public class IngestGeoIpClientMultiProjectYamlTestSuiteIT extends MultipleProjectsClientYamlSuiteTestCase { |
43 | 31 |
|
@@ -79,58 +67,7 @@ public static Iterable<Object[]> parameters() throws Exception { |
79 | 67 |
|
80 | 68 | @Before |
81 | 69 | public void waitForDatabases() throws Exception { |
82 | | - putGeoipPipeline(); |
83 | | - assertBusy(() -> { |
84 | | - Request request = new Request("GET", "/_ingest/geoip/stats"); |
85 | | - Map<String, Object> response = entityAsMap(client().performRequest(request)); |
86 | | - // assert databases are downloaded |
87 | | - Map<?, ?> downloadStats = (Map<?, ?>) response.get("stats"); |
88 | | - assertThat(downloadStats.get("databases_count"), equalTo(4)); |
89 | | - // assert databases are loaded to node |
90 | | - Map<?, ?> nodes = (Map<?, ?>) response.get("nodes"); |
91 | | - assertThat(nodes.size(), equalTo(1)); |
92 | | - Map<?, ?> node = (Map<?, ?>) nodes.values().iterator().next(); |
93 | | - List<?> databases = ((List<?>) node.get("databases")); |
94 | | - assertThat(databases, notNullValue()); |
95 | | - List<String> databaseNames = databases.stream().map(o -> (String) ((Map<?, ?>) o).get("name")).toList(); |
96 | | - assertThat( |
97 | | - databaseNames, |
98 | | - containsInAnyOrder("GeoLite2-City.mmdb", "GeoLite2-Country.mmdb", "GeoLite2-ASN.mmdb", "MyCustomGeoLite2-City.mmdb") |
99 | | - ); |
100 | | - }, 10, TimeUnit.SECONDS); |
101 | | - } |
102 | | - |
103 | | - /** |
104 | | - * This creates a pipeline with a geoip processor so that the GeoipDownloader will download its databases. |
105 | | - * @throws IOException |
106 | | - */ |
107 | | - private void putGeoipPipeline() throws IOException { |
108 | | - final BytesReference bytes; |
109 | | - try (XContentBuilder builder = JsonXContent.contentBuilder()) { |
110 | | - builder.startObject(); |
111 | | - { |
112 | | - builder.startArray("processors"); |
113 | | - { |
114 | | - builder.startObject(); |
115 | | - { |
116 | | - builder.startObject("geoip"); |
117 | | - { |
118 | | - builder.field("field", "ip"); |
119 | | - builder.field("target_field", "ip-city"); |
120 | | - builder.field("database_file", "GeoLite2-City.mmdb"); |
121 | | - } |
122 | | - builder.endObject(); |
123 | | - } |
124 | | - builder.endObject(); |
125 | | - } |
126 | | - builder.endArray(); |
127 | | - } |
128 | | - builder.endObject(); |
129 | | - bytes = BytesReference.bytes(builder); |
130 | | - } |
131 | | - Request putPipelineRequest = new Request("PUT", "/_ingest/pipeline/pipeline-with-geoip"); |
132 | | - putPipelineRequest.setEntity(new ByteArrayEntity(bytes.array(), ContentType.APPLICATION_JSON)); |
133 | | - client().performRequest(putPipelineRequest); |
| 70 | + putGeoipPipeline("pipeline-with-geoip"); |
| 71 | + assertDatabasesLoaded(); |
134 | 72 | } |
135 | | - |
136 | 73 | } |
0 commit comments