You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by md...@apache.org on 2022/03/01 20:05:15 UTC
[solr] branch branch_9x updated: SOLR-16036 Race condition in SolrJmxReporterTest (#673)
This is an automated email from the ASF dual-hosted git repository.
mdrob pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 67c6264e SOLR-16036 Race condition in SolrJmxReporterTest (#673)
67c6264e is described below
commit 67c6264e36b317061cc683803c0472184b868524
Author: Mike Drob <md...@apache.org>
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