justinrsweeney commented on code in PR #948:
URL: https://github.com/apache/solr/pull/948#discussion_r927035097


##########
solr/core/src/test/org/apache/solr/handler/RequestHandlerMetricsTest.java:
##########
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.handler;
+
+import java.io.IOException;
+import java.util.Map;
+import org.apache.solr.client.solrj.*;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.response.SolrResponseBase;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Most of the tests for {@link 
org.apache.solr.handler.component.SearchHandler} are in {@link
+ * org.apache.solr.ConvertedLegacyTest}.
+ */
+public class RequestHandlerMetricsTest extends SolrCloudTestCase {
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    System.setProperty("metricsEnabled", "true");
+    configureCluster(1)
+        .addConfig(
+            "conf1",
+            TEST_PATH()
+                .resolve("configsets")
+                .resolve("cloud-aggregate-node-metrics")
+                .resolve("conf"))
+        .configure();
+  }
+
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+    cluster.deleteAllCollections();
+  }
+
+  @AfterClass
+  public static void afterClass() {
+    System.clearProperty("metricsEnabled");
+  }
+
+  @Test
+  @SuppressWarnings({"unchecked"})
+  public void testAggregateNodeLevelMetrics() throws SolrServerException, 
IOException {
+    String collection1 = "testRequestHandlerMetrics1";
+    String collection2 = "testRequestHandlerMetrics2";
+
+    CloudSolrClient cloudClient = cluster.getSolrClient();
+
+    CollectionAdminRequest.Create create =
+        CollectionAdminRequest.createCollection(collection1, "conf1", 1, 1);
+    cloudClient.request(create);
+    cluster.waitForActiveCollection(collection1, 1, 1);
+
+    create = CollectionAdminRequest.createCollection(collection2, "conf1", 1, 
1);
+    cloudClient.request(create);
+    cluster.waitForActiveCollection(collection2, 1, 1);
+
+    SolrInputDocument solrInputDocument =
+        new SolrInputDocument("id", "10", "title", "test", "val_s1", "aaa");
+    cloudClient.add(collection1, solrInputDocument);
+    cloudClient.add(collection2, solrInputDocument);
+
+    SolrQuery solrQuery = new SolrQuery("*:*");
+    cloudClient.query(collection1, solrQuery);
+    cloudClient.query(collection2, solrQuery);
+
+    NamedList<Object> response =
+        cloudClient.request(
+            new SolrRequest<>(SolrRequest.METHOD.GET, "/admin/metrics") {
+              @Override
+              public String getRequestType() {
+                return "metricsRequest";
+              }
+
+              @Override
+              public SolrParams getParams() {
+                return null;
+              }
+
+              @Override
+              protected SolrResponse createResponse(SolrClient client) {
+                return new SolrResponseBase();
+              }
+            });
+
+    NamedList<Object> metrics = (NamedList<Object>) response.get("metrics");
+
+    final double[] minQueryTime = {Double.MAX_VALUE};
+    final double[] maxQueryTime = {-1.0};
+    final double[] minUpdateTime = {Double.MAX_VALUE};
+    final double[] maxUpdateTime = {-1.0};
+    metrics.forEachKey(
+        (key) -> {
+          if (key.startsWith("solr.core.testRequestHandlerMetrics")) {

Review Comment:
   Improved this part of the test



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to