This is an automated email from the ASF dual-hosted git repository.
madhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/master by this push:
new 4ecfa9cf8 ATLAS-4967: atlas-testtools module: update for code
readability improvements (#295)
4ecfa9cf8 is described below
commit 4ecfa9cf8a262bffcc2639aa209e6ca526b4b2f7
Author: jayendrap <[email protected]>
AuthorDate: Tue Feb 18 22:48:38 2025 +0530
ATLAS-4967: atlas-testtools module: update for code readability
improvements (#295)
---
test-tools/pom.xml | 5 +
.../org/apache/atlas/runner/LocalSolrRunner.java | 105 +++++++++++----------
2 files changed, 61 insertions(+), 49 deletions(-)
diff --git a/test-tools/pom.xml b/test-tools/pom.xml
index 72650643b..b7f9e9f96 100644
--- a/test-tools/pom.xml
+++ b/test-tools/pom.xml
@@ -30,6 +30,11 @@
<name>Apache Atlas Test Utility Tools</name>
+ <properties>
+ <checkstyle.failOnViolation>true</checkstyle.failOnViolation>
+ <checkstyle.skip>false</checkstyle.skip>
+ </properties>
+
<dependencies>
<dependency>
diff --git
a/test-tools/src/main/java/org/apache/atlas/runner/LocalSolrRunner.java
b/test-tools/src/main/java/org/apache/atlas/runner/LocalSolrRunner.java
index 7feea0975..07e945cc8 100644
--- a/test-tools/src/main/java/org/apache/atlas/runner/LocalSolrRunner.java
+++ b/test-tools/src/main/java/org/apache/atlas/runner/LocalSolrRunner.java
@@ -1,17 +1,20 @@
-// Copyright 2017 JanusGraph Authors
-//
-// Licensed 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.
-
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.atlas.runner;
import org.apache.atlas.ApplicationProperties;
@@ -38,20 +41,22 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class LocalSolrRunner {
-
- private static final String TARGET_DIRECTORY =
System.getProperty("embedded.solr.directory");
- private static final String COLLECTIONS_FILE = "collections.txt";
- private static final String SOLR_XML = "solr.xml";
- private static final String TEMPLATE_DIRECTORY = "core-template";
- protected static final String[] COLLECTIONS = readCollections();
+ private static final Logger LOG =
LoggerFactory.getLogger(LocalSolrRunner.class);
// from org.apache.atlas.repository.graphdb.janus.AtlasJanusGraphDatabase
public static final String SOLR_ZOOKEEPER_URL =
"atlas.graph.index.search.solr.zookeeper-url";
- private static final Logger LOG =
LoggerFactory.getLogger(LocalSolrRunner.class);
+ protected static final String[] COLLECTIONS = readCollections();
+
+ private static final String TARGET_DIRECTORY =
System.getProperty("embedded.solr.directory");
+ private static final String COLLECTIONS_FILE = "collections.txt";
+ private static final String SOLR_XML = "solr.xml";
+ private static final String TEMPLATE_DIRECTORY = "core-template";
private static MiniSolrCloudCluster miniSolrCloudCluster;
+ private LocalSolrRunner() {}
+
public static void start() throws Exception {
if (isLocalSolrRunning()) {
return;
@@ -60,14 +65,14 @@ public class LocalSolrRunner {
LOG.info("==> LocalSolrRunner.start()");
File templateDirectory = new File(TARGET_DIRECTORY + File.separator +
"solr" + File.separator + TEMPLATE_DIRECTORY);
- File temp = new File(TARGET_DIRECTORY + File.separator + "data" +
File.separator + "index" + File.separator + getRandomString());
+ File temp = new File(TARGET_DIRECTORY + File.separator +
"data" + File.separator + "index" + File.separator + getRandomString());
temp.mkdirs();
temp.deleteOnExit();
miniSolrCloudCluster = new MiniSolrCloudCluster(1, null,
temp.toPath(), readSolrXml(), null, null);
- LOG.info("Started local solr server at: " + getZookeeperUrls());
+ LOG.info("Started local solr server at: {}", getZookeeperUrls());
for (String coreName : COLLECTIONS) {
File coreDirectory = new File(temp.getAbsolutePath() +
File.separator + coreName);
@@ -119,14 +124,38 @@ public class LocalSolrRunner {
return ret;
}
+ public static void main(String[] args) {
+ if (ArrayUtils.isEmpty(args)) {
+ System.out.println("No argument!");
+ } else if (args[0].equals("start")) {
+ try {
+ start();
+ System.out.println("Started Local Solr Server: " +
getZookeeperUrls());
+ } catch (Exception e) {
+ System.out.println("Error starting Local Solr Server: " + e);
+ }
+ } else if (args[0].equals("stop")) {
+ try {
+ System.out.println("Stopping Local Solr Server.");
+ stop();
+ } catch (Exception e) {
+ System.out.println("Error stopping Local Solr Server: " + e);
+ }
+ } else {
+ System.out.println("Bad first argument: " + Arrays.toString(args));
+ }
+ }
+
private static String[] readCollections() {
// For the classloader you need the following path:
"/solr/collections.txt";
// Use explicit '/' separators (not File.separator) because even on
Windows you want '/'
String resName = "/solr/" + COLLECTIONS_FILE;
+
try {
- InputStream inputStream =
LocalSolrRunner.class.getResourceAsStream(resName);
- InputStreamReader isr = new InputStreamReader(inputStream);
- BufferedReader buffer = new BufferedReader(isr);
+ InputStream inputStream =
LocalSolrRunner.class.getResourceAsStream(resName);
+ InputStreamReader isr = new InputStreamReader(inputStream);
+ BufferedReader buffer = new BufferedReader(isr);
+
return
Pattern.compile("\\s+").split(buffer.lines().collect(Collectors.joining("\n")));
} catch (Exception e) {
throw new RuntimeException("Unable to read collections file", e);
@@ -137,6 +166,7 @@ public class LocalSolrRunner {
// For the classloader you need the following path: "/solr/solr.xml";
// Use explicit '/' separators (not File.separator) because even on
Windows you want '/'
String resName = "/solr/" + SOLR_XML;
+
// Use the local classloader rather than the system classloader - i.e.
avoid using
//
Thread.currentThread().getContextClassLoader().getResourceAsStream(resName);
InputStream inputStream =
LocalSolrRunner.class.getResourceAsStream(resName);
@@ -151,27 +181,4 @@ public class LocalSolrRunner {
private static String getRandomString() {
return UUID.randomUUID().toString();
}
-
- public static void main(String[] args) {
- if (ArrayUtils.isEmpty(args)) {
- System.out.println("No argument!");
- } else if (args[0].equals("start")) {
- try {
- start();
- System.out.println("Started Local Solr Server: "+
getZookeeperUrls());
-
- } catch (Exception e) {
- System.out.println("Error starting Local Solr Server: " + e);
- }
- } else if (args[0].equals("stop")) {
- try {
- System.out.println("Stopping Local Solr Server.");
- stop();
- } catch (Exception e) {
- System.out.println("Error stopping Local Solr Server: " + e);
- }
- } else {
- System.out.println("Bad first argument: " + Arrays.toString(args));
- }
- }
}