This is an automated email from the ASF dual-hosted git repository.
mdrob pushed a commit to branch branch_9_0
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9_0 by this push:
new 10a58c6 SOLR-16036 Race condition in SolrJmxReporterTest (#673)
10a58c6 is described below
commit 10a58c6c3c9e8f8e10083ecca9929056db6eb164
Author: Mike Drob <[email protected]>
AuthorDate: Tue Mar 1 13:32:11 2022 -0600
SOLR-16036 Race condition in SolrJmxReporterTest (#673)
(cherry picked from commit 177374fed27753ac0405926ab628bbe5e59715e4)
---
.../metrics/reporters/SolrJmxReporterTest.java | 43 +++++++++++-----------
1 file changed, 21 insertions(+), 22 deletions(-)
diff --git
a/solr/core/src/test/org/apache/solr/metrics/reporters/SolrJmxReporterTest.java
b/solr/core/src/test/org/apache/solr/metrics/reporters/SolrJmxReporterTest.java
index 58ee10a..b4fedf9 100644
---
a/solr/core/src/test/org/apache/solr/metrics/reporters/SolrJmxReporterTest.java
+++
b/solr/core/src/test/org/apache/solr/metrics/reporters/SolrJmxReporterTest.java
@@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
import com.codahale.metrics.Counter;
import org.apache.lucene.util.TestUtil;
@@ -196,39 +197,37 @@ public class SolrJmxReporterTest extends SolrTestCaseJ4 {
rootName.equals(o.getObjectName().getDomain())).count());
}
- private static boolean stopped = false;
-
@Test
public void testClosedCore() throws Exception {
Set<ObjectInstance> objects = TEST_MBEAN_SERVER.queryMBeans(new
ObjectName("*:category=CORE,name=indexDir,*"), null);
assertEquals("Unexpected number of indexDir beans: " + objects.toString(),
1, objects.size());
final ObjectInstance inst = objects.iterator().next();
- stopped = false;
+ final AtomicBoolean running = new AtomicBoolean(true);
try {
- Thread t = new Thread() {
- public void run() {
- while (!stopped) {
- try {
- Object value =
TEST_MBEAN_SERVER.getAttribute(inst.getObjectName(), "Value");
- assertNotNull(value);
- } catch (InstanceNotFoundException x) {
- // no longer present
- break;
- } catch (Exception e) {
- fail("Unexpected error retrieving attribute: " + e.toString());
- }
+ new Thread(() -> {
+ while (running.get()) {
+ try {
+ Object value =
TEST_MBEAN_SERVER.getAttribute(inst.getObjectName(), "Value");
+ assertNotNull(value);
+ } catch (InstanceNotFoundException x) {
+ // no longer present
+ break;
+ } catch (Exception e) {
+ fail("Unexpected error retrieving attribute: " + e);
}
}
- };
- t.start();
+ }, "TestMBeanThread").start();
+
+ // This should be enough time for the
Thread.sleep(500);
- h.getCoreContainer().unload(h.getCore().getName());
- Thread.sleep(2000);
- objects = TEST_MBEAN_SERVER.queryMBeans(new
ObjectName("*:category=CORE,name=indexDir,*"), null);
- assertEquals("Unexpected number of beans after core closed: " + objects,
0, objects.size());
} finally {
- stopped = true;
+ running.set(false);
}
+
+ h.getCoreContainer().unload(h.getCore().getName());
+ Thread.sleep(2000);
+ objects = TEST_MBEAN_SERVER.queryMBeans(new
ObjectName("*:category=CORE,name=indexDir,*"), null);
+ assertEquals("Unexpected number of beans after core closed: " + objects,
0, objects.size());
}
@Test