Skip to content

Commit 918072c

Browse files
masseykeafoucret
authored andcommitted
Adding a cleanup method to EnterpriseGeoIpDownloaderIT (elastic#125958)
1 parent 18de253 commit 918072c

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.ExceptionsHelper;
1515
import org.elasticsearch.ResourceAlreadyExistsException;
1616
import org.elasticsearch.action.ActionListener;
17+
import org.elasticsearch.action.LatchedActionListener;
1718
import org.elasticsearch.action.bulk.BulkItemResponse;
1819
import org.elasticsearch.action.bulk.BulkRequest;
1920
import org.elasticsearch.action.bulk.BulkResponse;
@@ -22,13 +23,16 @@
2223
import org.elasticsearch.action.index.IndexRequest;
2324
import org.elasticsearch.action.search.SearchRequest;
2425
import org.elasticsearch.action.search.SearchResponse;
26+
import org.elasticsearch.action.support.SubscribableListener;
27+
import org.elasticsearch.action.support.master.AcknowledgedResponse;
2528
import org.elasticsearch.common.Strings;
2629
import org.elasticsearch.common.settings.MockSecureSettings;
2730
import org.elasticsearch.common.settings.Settings;
2831
import org.elasticsearch.common.util.CollectionUtils;
2932
import org.elasticsearch.core.TimeValue;
3033
import org.elasticsearch.ingest.EnterpriseGeoIpTask;
3134
import org.elasticsearch.ingest.geoip.direct.DatabaseConfiguration;
35+
import org.elasticsearch.ingest.geoip.direct.DeleteDatabaseConfigurationAction;
3236
import org.elasticsearch.ingest.geoip.direct.PutDatabaseConfigurationAction;
3337
import org.elasticsearch.persistent.PersistentTasksService;
3438
import org.elasticsearch.plugins.Plugin;
@@ -38,12 +42,15 @@
3842
import org.elasticsearch.test.junit.annotations.TestLogging;
3943
import org.elasticsearch.transport.RemoteTransportException;
4044
import org.elasticsearch.xcontent.XContentType;
45+
import org.junit.After;
4146
import org.junit.ClassRule;
4247

4348
import java.io.IOException;
4449
import java.util.Collection;
4550
import java.util.List;
4651
import java.util.Map;
52+
import java.util.concurrent.CountDownLatch;
53+
import java.util.concurrent.TimeUnit;
4754

4855
import static org.elasticsearch.ingest.EnterpriseGeoIpTask.ENTERPRISE_GEOIP_DOWNLOADER;
4956
import static org.elasticsearch.ingest.geoip.EnterpriseGeoIpDownloaderTaskExecutor.IPINFO_TOKEN_SETTING;
@@ -54,6 +61,8 @@ public class EnterpriseGeoIpDownloaderIT extends ESIntegTestCase {
5461

5562
private static final String MAXMIND_DATABASE_TYPE = "GeoIP2-City";
5663
private static final String IPINFO_DATABASE_TYPE = "asn";
64+
private static final String MAXMIND_CONFIGURATION = "test-1";
65+
private static final String IPINFO_CONFIGURATION = "test-2";
5766

5867
@ClassRule
5968
public static final EnterpriseGeoIpHttpFixture fixture = new EnterpriseGeoIpHttpFixture(
@@ -140,6 +149,28 @@ public void testEnterpriseDownloaderTask() throws Exception {
140149
});
141150
}
142151

152+
@After
153+
public void cleanup() throws InterruptedException {
154+
/*
155+
* This method cleans up the database configurations that the test created. This allows the test to be run repeatedly.
156+
*/
157+
CountDownLatch latch = new CountDownLatch(1);
158+
LatchedActionListener<AcknowledgedResponse> listener = new LatchedActionListener<>(ActionListener.noop(), latch);
159+
SubscribableListener.<AcknowledgedResponse>newForked(l -> deleteDatabaseConfiguration(MAXMIND_CONFIGURATION, l))
160+
.<AcknowledgedResponse>andThen(l -> deleteDatabaseConfiguration(IPINFO_CONFIGURATION, l))
161+
.addListener(listener);
162+
latch.await(10, TimeUnit.SECONDS);
163+
}
164+
165+
private void deleteDatabaseConfiguration(String configurationName, ActionListener<AcknowledgedResponse> listener) {
166+
admin().cluster()
167+
.execute(
168+
DeleteDatabaseConfigurationAction.INSTANCE,
169+
new DeleteDatabaseConfigurationAction.Request(TimeValue.MAX_VALUE, TimeValue.timeValueSeconds(10), configurationName),
170+
listener
171+
);
172+
}
173+
143174
private void startEnterpriseGeoIpDownloaderTask() {
144175
PersistentTasksService persistentTasksService = internalCluster().getInstance(PersistentTasksService.class);
145176
persistentTasksService.sendStartRequest(
@@ -163,7 +194,7 @@ private void configureMaxmindDatabase(String databaseType) {
163194
new PutDatabaseConfigurationAction.Request(
164195
TimeValue.MAX_VALUE,
165196
TimeValue.MAX_VALUE,
166-
new DatabaseConfiguration("test-1", databaseType, new DatabaseConfiguration.Maxmind("test_account"))
197+
new DatabaseConfiguration(MAXMIND_CONFIGURATION, databaseType, new DatabaseConfiguration.Maxmind("test_account"))
167198
)
168199
)
169200
.actionGet();
@@ -176,7 +207,7 @@ private void configureIpinfoDatabase(String databaseType) {
176207
new PutDatabaseConfigurationAction.Request(
177208
TimeValue.MAX_VALUE,
178209
TimeValue.MAX_VALUE,
179-
new DatabaseConfiguration("test-2", databaseType, new DatabaseConfiguration.Ipinfo())
210+
new DatabaseConfiguration(IPINFO_CONFIGURATION, databaseType, new DatabaseConfiguration.Ipinfo())
180211
)
181212
)
182213
.actionGet();

0 commit comments

Comments
 (0)