diff --git a/modules/ingest-geoip/src/internalClusterTest/java/org/elasticsearch/ingest/geoip/EnterpriseGeoIpDownloaderIT.java b/modules/ingest-geoip/src/internalClusterTest/java/org/elasticsearch/ingest/geoip/EnterpriseGeoIpDownloaderIT.java index 196a8c9c454a8..5b8461e5febd1 100644 --- a/modules/ingest-geoip/src/internalClusterTest/java/org/elasticsearch/ingest/geoip/EnterpriseGeoIpDownloaderIT.java +++ b/modules/ingest-geoip/src/internalClusterTest/java/org/elasticsearch/ingest/geoip/EnterpriseGeoIpDownloaderIT.java @@ -14,6 +14,7 @@ import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.ResourceAlreadyExistsException; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.LatchedActionListener; import org.elasticsearch.action.bulk.BulkItemResponse; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.bulk.BulkResponse; @@ -23,6 +24,8 @@ import org.elasticsearch.action.ingest.PutPipelineRequest; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.support.SubscribableListener; +import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.MockSecureSettings; @@ -31,6 +34,7 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.ingest.EnterpriseGeoIpTask; import org.elasticsearch.ingest.geoip.direct.DatabaseConfiguration; +import org.elasticsearch.ingest.geoip.direct.DeleteDatabaseConfigurationAction; import org.elasticsearch.ingest.geoip.direct.PutDatabaseConfigurationAction; import org.elasticsearch.persistent.PersistentTasksService; import org.elasticsearch.plugins.Plugin; @@ -42,12 +46,15 @@ import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.json.JsonXContent; +import org.junit.After; import org.junit.ClassRule; import java.io.IOException; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import static org.elasticsearch.ingest.EnterpriseGeoIpTask.ENTERPRISE_GEOIP_DOWNLOADER; import static org.elasticsearch.ingest.geoip.EnterpriseGeoIpDownloaderTaskExecutor.IPINFO_TOKEN_SETTING; @@ -59,6 +66,8 @@ public class EnterpriseGeoIpDownloaderIT extends ESIntegTestCase { private static final String MAXMIND_DATABASE_TYPE = "GeoIP2-City"; private static final String IPINFO_DATABASE_TYPE = "asn"; + private static final String MAXMIND_CONFIGURATION = "test-1"; + private static final String IPINFO_CONFIGURATION = "test-2"; @ClassRule public static final EnterpriseGeoIpHttpFixture fixture = new EnterpriseGeoIpHttpFixture( @@ -145,6 +154,28 @@ public void testEnterpriseDownloaderTask() throws Exception { }); } + @After + public void cleanup() throws InterruptedException { + /* + * This method cleans up the database configurations that the test created. This allows the test to be run repeatedly. + */ + CountDownLatch latch = new CountDownLatch(1); + LatchedActionListener listener = new LatchedActionListener<>(ActionListener.noop(), latch); + SubscribableListener.newForked(l -> deleteDatabaseConfiguration(MAXMIND_CONFIGURATION, l)) + .andThen(l -> deleteDatabaseConfiguration(IPINFO_CONFIGURATION, l)) + .addListener(listener); + latch.await(10, TimeUnit.SECONDS); + } + + private void deleteDatabaseConfiguration(String configurationName, ActionListener listener) { + admin().cluster() + .execute( + DeleteDatabaseConfigurationAction.INSTANCE, + new DeleteDatabaseConfigurationAction.Request(TimeValue.MAX_VALUE, TimeValue.timeValueSeconds(10), configurationName), + listener + ); + } + private void startEnterpriseGeoIpDownloaderTask() { PersistentTasksService persistentTasksService = internalCluster().getInstance(PersistentTasksService.class); persistentTasksService.sendStartRequest( @@ -168,7 +199,7 @@ private void configureMaxmindDatabase(String databaseType) { new PutDatabaseConfigurationAction.Request( TimeValue.MAX_VALUE, TimeValue.MAX_VALUE, - new DatabaseConfiguration("test-1", databaseType, new DatabaseConfiguration.Maxmind("test_account")) + new DatabaseConfiguration(MAXMIND_CONFIGURATION, databaseType, new DatabaseConfiguration.Maxmind("test_account")) ) ) .actionGet(); @@ -181,7 +212,7 @@ private void configureIpinfoDatabase(String databaseType) { new PutDatabaseConfigurationAction.Request( TimeValue.MAX_VALUE, TimeValue.MAX_VALUE, - new DatabaseConfiguration("test-2", databaseType, new DatabaseConfiguration.Ipinfo()) + new DatabaseConfiguration(IPINFO_CONFIGURATION, databaseType, new DatabaseConfiguration.Ipinfo()) ) ) .actionGet();