From e6a44f7282cacb3bb694eef7500df1bd3bc859a2 Mon Sep 17 00:00:00 2001 From: Nuno Santos Date: Mon, 26 Sep 2022 09:23:55 +0100 Subject: [PATCH] Fix: Elasticsearch indexes created by common tests (oak-search module) were not being deleted at the end of the tests. --- .../oak/plugins/index/elastic/ElasticConnectionRule.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticConnectionRule.java b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticConnectionRule.java index d915493bc9b..9bb4cf022d1 100644 --- a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticConnectionRule.java +++ b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticConnectionRule.java @@ -16,6 +16,7 @@ */ package org.apache.jackrabbit.oak.plugins.index.elastic; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.RandomStringUtils; import org.junit.rules.ExternalResource; import org.junit.runner.Description; @@ -74,10 +75,11 @@ protected void after() { ElasticConnection esConnection = getElasticConnection(); if (esConnection != null) { try { - esConnection.getClient().indices().delete(d->d.index(esConnection.getIndexPrefix() + "*")); - esConnection.close(); + esConnection.getClient().indices().delete(d -> d.index(this.indexPrefix + "*")); } catch (IOException e) { - LOG.error("Unable to delete indexes with prefix {}", esConnection.getIndexPrefix()); + LOG.error("Unable to delete indexes with prefix {}", this.indexPrefix); + } finally { + IOUtils.closeQuietly(esConnection, e -> LOG.debug("Error closing Elasticsearch connection", e)); } } }