You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2021/03/30 10:41:50 UTC

[lucene] 04/06: Remove legacy ant hacks - add conf to test sourceSet. Correct jvm options hack (don't apply to benchmarks run).

This is an automated email from the ASF dual-hosted git repository.

dweiss pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit f83c9462bbbc2310e99c9466a351c64726b3daf4
Author: Dawid Weiss <da...@carrotsearch.com>
AuthorDate: Tue Mar 30 11:33:27 2021 +0200

    Remove legacy ant hacks - add conf to test sourceSet. Correct jvm options hack (don't apply to benchmarks run).
---
 build.gradle                                       |  1 -
 gradle/ant-compat/misc.gradle                      | 27 ----------------------
 gradle/hacks/turbocharge-jvm-opts.gradle           |  7 +++++-
 lucene/benchmark/build.gradle                      |  8 ++++++-
 .../benchmark/byTask/TestPerfTasksParse.java       | 15 +++++++++---
 5 files changed, 25 insertions(+), 33 deletions(-)

diff --git a/build.gradle b/build.gradle
index a288e0d..2ae2826 100644
--- a/build.gradle
+++ b/build.gradle
@@ -170,7 +170,6 @@ apply from: file('gradle/help.gradle')
 // Ant-compatibility layer. ALL OF THESE SHOULD BE GONE at some point. They are
 // here so that we can coexist with current ant build but they are indicative
 // of potential problems with the build conventions, dependencies, etc.
-apply from: file('gradle/ant-compat/misc.gradle')
 apply from: file('gradle/ant-compat/test-classes-cross-deps.gradle')
 
 apply from: file('gradle/documentation/documentation.gradle')
diff --git a/gradle/ant-compat/misc.gradle b/gradle/ant-compat/misc.gradle
deleted file mode 100644
index baefa2b..0000000
--- a/gradle/ant-compat/misc.gradle
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.
- */
-
-// Resources from top-level project folder are looked up via getClass(). Strange.
-configure(project(":lucene:benchmark")) {
-  plugins.withType(JavaPlugin) {
-    task syncConf(type: Sync) {
-      from('conf')
-      into file("${sourceSets.test.java.outputDir}/conf")
-    }
-    processTestResources.dependsOn syncConf
-  }
-}
diff --git a/gradle/hacks/turbocharge-jvm-opts.gradle b/gradle/hacks/turbocharge-jvm-opts.gradle
index cdb226a..5682dc1 100644
--- a/gradle/hacks/turbocharge-jvm-opts.gradle
+++ b/gradle/hacks/turbocharge-jvm-opts.gradle
@@ -30,7 +30,12 @@ allprojects {
 
     // Inject vm options into any JavaExec task... We could narrow it
     // down but I don't think there is any harm in keeping it broad.
-    tasks.withType(JavaExec) {
+    tasks.withType(JavaExec) { task ->
+        // Skip tuning java exec for benchmarks.
+        if (task.path == ":lucene:benchmark:run") {
+            return
+        }
+
         jvmArgs += vmOpts
     }
 }
\ No newline at end of file
diff --git a/lucene/benchmark/build.gradle b/lucene/benchmark/build.gradle
index 9271b00..565516a 100644
--- a/lucene/benchmark/build.gradle
+++ b/lucene/benchmark/build.gradle
@@ -19,7 +19,7 @@ plugins {
   id "java"
 }
 
-description = 'System for benchmarking Lucene'
+description = 'Lucene benchmarking module'
 
 dependencies {  
   implementation project(':lucene:core')
@@ -43,9 +43,15 @@ dependencies {
   testImplementation project(':lucene:test-framework')
 }
 
+// We add 'conf' to resources because we validate *.alg script correctness in one of the tests.
+sourceSets {
+  test.resources.srcDirs += ['conf']
+}
+
 task run(type: JavaExec) {
   description "Run a perf test (optional: -PtaskAlg=conf/your-algorithm-file -PmaxHeapSize=1G)"
   main 'org.apache.lucene.benchmark.byTask.Benchmark'
+
   classpath sourceSets.main.runtimeClasspath
   // allow these to be specified on the CLI via -PtaskAlg=  for example
   args = [propertyOrDefault('taskAlg', 'conf/micro-standard.alg')]
diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java
index 026a571..b3ccee7 100644
--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java
+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java
@@ -18,6 +18,7 @@ package org.apache.lucene.benchmark.byTask;
 
 import java.io.IOException;
 import java.io.StringReader;
+import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
@@ -35,6 +36,7 @@ import org.apache.lucene.benchmark.byTask.utils.Config;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks;
+import org.junit.Assert;
 
 /** Test very simply that perf tasks are parsed as expected. */
 @SuppressSysoutChecks(bugUrl = "very noisy")
@@ -122,9 +124,14 @@ public class TestPerfTasksParse extends LuceneTestCase {
   /** Test the parsing of example scripts * */
   @SuppressWarnings("try")
   public void testParseExamples() throws Exception {
-    // hackedy-hack-hack
+
+    // Locate the folder with *.alg resources. This is hacky - we look up
+    // one of the resources and then assume it's an accessible path.
+    URL resource = getClass().getClassLoader().getResource("addIndexes.alg");
+    Assert.assertNotNull("Couldn't locate *.alg resources?", resource);
+
     boolean foundFiles = false;
-    final Path examplesDir = Paths.get(getClass().getResource("/conf").toURI());
+    final Path examplesDir = Paths.get(resource.toURI()).getParent();
     try (DirectoryStream<Path> stream = Files.newDirectoryStream(examplesDir, "*.alg")) {
       for (Path path : stream) {
         Config config = new Config(Files.newBufferedReader(path, StandardCharsets.UTF_8));
@@ -152,10 +159,12 @@ public class TestPerfTasksParse extends LuceneTestCase {
           config.set("query.maker", MockQueryMaker.class.getName());
         }
         PerfRunData data = new PerfRunData(config);
-        try (Algorithm algo = new Algorithm(data)) {}
+        new Algorithm(data).close();
+
         foundFiles = true;
       }
     }
+
     if (!foundFiles) {
       fail("could not find any .alg files!");
     }