You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2017/03/16 12:22:16 UTC
lucene-solr:jira/solr-9959: SOLR-9959 Fix broken tests.
Repository: lucene-solr
Updated Branches:
refs/heads/jira/solr-9959 fbba0d979 -> 0cea9fcff
SOLR-9959 Fix broken tests.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/0cea9fcf
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/0cea9fcf
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/0cea9fcf
Branch: refs/heads/jira/solr-9959
Commit: 0cea9fcff6f8ec5c156744cea5792691ba09fa94
Parents: fbba0d9
Author: Andrzej Bialecki <ab...@apache.org>
Authored: Thu Mar 16 13:22:01 2017 +0100
Committer: Andrzej Bialecki <ab...@apache.org>
Committed: Thu Mar 16 13:22:01 2017 +0100
----------------------------------------------------------------------
.../org/apache/solr/metrics/SolrMetricInfo.java | 13 ++++++--
.../metrics/reporters/JmxObjectNameFactory.java | 16 ++++++---
.../src/java/org/apache/solr/util/JmxUtil.java | 3 --
.../test/org/apache/solr/SolrInfoBeanTest.java | 7 ++++
.../cloud/CollectionsAPIDistributedZkTest.java | 34 ++++++++++++--------
5 files changed, 49 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0cea9fcf/solr/core/src/java/org/apache/solr/metrics/SolrMetricInfo.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/metrics/SolrMetricInfo.java b/solr/core/src/java/org/apache/solr/metrics/SolrMetricInfo.java
index 966ce2e..8edfa04 100644
--- a/solr/core/src/java/org/apache/solr/metrics/SolrMetricInfo.java
+++ b/solr/core/src/java/org/apache/solr/metrics/SolrMetricInfo.java
@@ -45,7 +45,7 @@ public final class SolrMetricInfo {
return null;
}
String[] names = fullName.split("\\.");
- if (names.length < 3) { // not a valid info
+ if (names.length < 2) { // not a valid info
return null;
}
// check top-level name for valid category
@@ -55,8 +55,15 @@ public final class SolrMetricInfo {
} catch (IllegalArgumentException e) { // not a valid category
return null;
}
- String scope = names[1];
- String name = fullName.substring(names[0].length() + names[1].length() + 2);
+ String scope;
+ String name;
+ if (names.length == 2) {
+ scope = null;
+ name = fullName.substring(names[0].length() + 1);
+ } else {
+ scope = names[1];
+ name = fullName.substring(names[0].length() + names[1].length() + 2);
+ }
return new SolrMetricInfo(category, scope, name);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0cea9fcf/solr/core/src/java/org/apache/solr/metrics/reporters/JmxObjectNameFactory.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/metrics/reporters/JmxObjectNameFactory.java b/solr/core/src/java/org/apache/solr/metrics/reporters/JmxObjectNameFactory.java
index 1f5b4f0..0826d4f 100644
--- a/solr/core/src/java/org/apache/solr/metrics/reporters/JmxObjectNameFactory.java
+++ b/solr/core/src/java/org/apache/solr/metrics/reporters/JmxObjectNameFactory.java
@@ -59,8 +59,12 @@ public class JmxObjectNameFactory implements ObjectNameFactory {
*/
@Override
public ObjectName createName(String type, String currentDomain, String name) {
+ if (name.contains("indexDir")) {
+ name = name;
+ }
SolrMetricInfo metricInfo = SolrMetricInfo.of(name);
-
+ String safeName = metricInfo != null ? metricInfo.name : name;
+ safeName = safeName.replaceAll(":", "_");
// It turns out that ObjectName(String) mostly preserves key ordering
// as specified in the constructor (except for the 'type' key that ends
// up at top level) - unlike ObjectName(String, Map) constructor
@@ -96,18 +100,20 @@ public class JmxObjectNameFactory implements ObjectNameFactory {
if (metricInfo != null) {
sb.append("category=");
sb.append(metricInfo.category.toString());
- sb.append(",scope=");
- sb.append(metricInfo.scope);
+ if (metricInfo.scope != null) {
+ sb.append(",scope=");
+ sb.append(metricInfo.scope);
+ }
// we could also split by type, but don't call it 'type' :)
// if (type != null) {
// sb.append(",class=");
// sb.append(type);
// }
sb.append(",name=");
- sb.append(metricInfo.name);
+ sb.append(safeName);
} else {
// make dotted names into hierarchies
- String[] path = name.split("\\.");
+ String[] path = safeName.split("\\.");
for (int i = 0; i < path.length - 1; i++) {
if (i > 0) {
sb.append(',');
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0cea9fcf/solr/core/src/java/org/apache/solr/util/JmxUtil.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/util/JmxUtil.java b/solr/core/src/java/org/apache/solr/util/JmxUtil.java
index 02a070d..f27a55e 100644
--- a/solr/core/src/java/org/apache/solr/util/JmxUtil.java
+++ b/solr/core/src/java/org/apache/solr/util/JmxUtil.java
@@ -27,9 +27,6 @@ import java.util.List;
/**
* Utility methods to find a MBeanServer.
- *
- * This was factored out from {@link org.apache.solr.core.JmxMonitoredMap}
- * and can eventually replace the logic used there.
*/
public final class JmxUtil {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0cea9fcf/solr/core/src/test/org/apache/solr/SolrInfoBeanTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/SolrInfoBeanTest.java b/solr/core/src/test/org/apache/solr/SolrInfoBeanTest.java
index cff8b17..5acb086 100644
--- a/solr/core/src/test/org/apache/solr/SolrInfoBeanTest.java
+++ b/solr/core/src/test/org/apache/solr/SolrInfoBeanTest.java
@@ -21,6 +21,8 @@ import org.apache.solr.handler.StandardRequestHandler;
import org.apache.solr.handler.admin.LukeRequestHandler;
import org.apache.solr.handler.component.SearchComponent;
import org.apache.solr.highlight.DefaultSolrHighlighter;
+import org.apache.solr.metrics.SolrMetricManager;
+import org.apache.solr.metrics.SolrMetricProducer;
import org.apache.solr.search.LRUCache;
import org.junit.BeforeClass;
import java.io.File;
@@ -54,10 +56,15 @@ public class SolrInfoBeanTest extends SolrTestCaseJ4
// System.out.println(classes);
int checked = 0;
+ SolrMetricManager metricManager = h.getCoreContainer().getMetricManager();
+ String registry = h.getCore().getCoreMetricManager().getRegistryName();
for( Class clazz : classes ) {
if( SolrInfoBean.class.isAssignableFrom( clazz ) ) {
try {
SolrInfoBean info = (SolrInfoBean)clazz.newInstance();
+ if (info instanceof SolrMetricProducer) {
+ ((SolrMetricProducer)info).initializeMetrics(metricManager, registry, null);
+ }
//System.out.println( info.getClass() );
assertNotNull( info.getName() );
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0cea9fcf/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
index f35d467..6525ab4 100644
--- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
@@ -16,10 +16,13 @@
*/
package org.apache.solr.cloud;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import java.io.IOException;
+import java.lang.invoke.MethodHandles;
import java.lang.management.ManagementFactory;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -37,6 +40,7 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import com.google.common.collect.ImmutableList;
+import org.apache.commons.io.IOUtils;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.client.solrj.SolrClient;
@@ -74,6 +78,8 @@ import org.apache.solr.util.TimeOut;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;
import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
@@ -83,6 +89,7 @@ import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
*/
@Slow
public class CollectionsAPIDistributedZkTest extends SolrCloudTestCase {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@BeforeClass
public static void beforeCollectionsAPIDistributedZkTest() {
@@ -94,9 +101,11 @@ public class CollectionsAPIDistributedZkTest extends SolrCloudTestCase {
@BeforeClass
public static void setupCluster() throws Exception {
+ String solrXml = IOUtils.toString(CollectionsAPIDistributedZkTest.class.getResourceAsStream("/solr/solr-jmxreporter.xml"), "UTF-8");
configureCluster(4)
.addConfig("conf", configset("cloud-minimal"))
.addConfig("conf2", configset("cloud-minimal-jmx"))
+ .withSolrXml(solrXml)
.configure();
}
@@ -620,24 +629,23 @@ public class CollectionsAPIDistributedZkTest extends SolrCloudTestCase {
Set<ObjectName> mbeans = new HashSet<>();
mbeans.addAll(server.queryNames(null, null));
for (final ObjectName mbean : mbeans) {
- Object value;
- Object indexDir;
- Object name;
try {
- if (((value = server.getAttribute(mbean, "category")) != null && value
- .toString().equals(Category.CORE.toString()))
- && ((indexDir = server.getAttribute(mbean, "coreName")) != null)
- && ((indexDir = server.getAttribute(mbean, "indexDir")) != null)
- && ((name = server.getAttribute(mbean, "name")) != null)) {
- if (!indexDirToShardNamesMap.containsKey(indexDir.toString())) {
- indexDirToShardNamesMap.put(indexDir.toString(),
- new HashSet<String>());
+ Map<String, String> props = mbean.getKeyPropertyList();
+ MBeanAttributeInfo[] attrs = server.getMBeanInfo(mbean).getAttributes();
+ String category = props.get("category");
+ String name = props.get("name");
+ if ((category != null && category.toString().equals(Category.CORE.toString())) &&
+ (name != null && name.equals("indexDir"))) {
+ String indexDir = server.getAttribute(mbean, "Value").toString();
+ String key = props.get("dom2") + "." + props.get("dom3") + "." + props.get("dom4");
+ if (!indexDirToShardNamesMap.containsKey(indexDir)) {
+ indexDirToShardNamesMap.put(indexDir.toString(), new HashSet<String>());
}
- indexDirToShardNamesMap.get(indexDir.toString()).add(
- name.toString());
+ indexDirToShardNamesMap.get(indexDir.toString()).add(key);
}
} catch (Exception e) {
+ log.info(e.toString());
// ignore, just continue - probably a "category" or "source" attribute
// not found
}