Replace println(String.format(...)) with printf(...) (#12976)

This commit is contained in:
sabi0 2023-12-28 19:32:06 +01:00 committed by GitHub
parent 57b104e806
commit 91272f45da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 275 additions and 366 deletions

View File

@ -43,7 +43,7 @@ import org.junit.runner.RunWith;
@RunWith(RandomizedRunner.class) @RunWith(RandomizedRunner.class)
public class TestCodecLoadingDeadlock extends Assert { public class TestCodecLoadingDeadlock extends Assert {
private static int MAX_TIME_SECONDS = 30; private static final int MAX_TIME_SECONDS = 30;
@Test @Test
public void testDeadlock() throws Exception { public void testDeadlock() throws Exception {
@ -59,8 +59,7 @@ public class TestCodecLoadingDeadlock extends Assert {
new ArrayList<>(avail = DocValuesFormat.availableDocValuesFormats()) new ArrayList<>(avail = DocValuesFormat.availableDocValuesFormats())
.get(rnd.nextInt(avail.size())); .get(rnd.nextInt(avail.size()));
System.out.println( System.out.printf(Locale.ROOT, "codec: %s, pf: %s, dvf: %s%n", codecName, pfName, dvfName);
String.format(Locale.ROOT, "codec: %s, pf: %s, dvf: %s", codecName, pfName, dvfName));
List<String> args = new ArrayList<>(); List<String> args = new ArrayList<>();
args.add(Paths.get(System.getProperty("java.home"), "bin", "java").toString()); args.add(Paths.get(System.getProperty("java.home"), "bin", "java").toString());

View File

@ -19,7 +19,6 @@ package org.apache.lucene.search.grouping;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -185,8 +184,7 @@ public class TestAllGroupHeadsCollector extends LuceneTestCase {
int numberOfRuns = atLeast(1); int numberOfRuns = atLeast(1);
for (int iter = 0; iter < numberOfRuns; iter++) { for (int iter = 0; iter < numberOfRuns; iter++) {
if (VERBOSE) { if (VERBOSE) {
System.out.println( System.out.printf(Locale.ROOT, "TEST: iter=%d total=%d%n", iter, numberOfRuns);
String.format(Locale.ROOT, "TEST: iter=%d total=%d", iter, numberOfRuns));
} }
final int numDocs = TestUtil.nextInt(random(), 100, 1000) * RANDOM_MULTIPLIER; final int numDocs = TestUtil.nextInt(random(), 100, 1000) * RANDOM_MULTIPLIER;
@ -205,7 +203,7 @@ public class TestAllGroupHeadsCollector extends LuceneTestCase {
// For that reason we don't generate empty string groups. // For that reason we don't generate empty string groups.
randomValue = TestUtil.randomRealisticUnicodeString(random()); randomValue = TestUtil.randomRealisticUnicodeString(random());
// randomValue = TestUtil.randomSimpleString(random()); // randomValue = TestUtil.randomSimpleString(random());
} while ("".equals(randomValue)); } while (randomValue.isEmpty());
groups.add(new BytesRef(randomValue)); groups.add(new BytesRef(randomValue));
} }
final String[] contentStrings = new String[TestUtil.nextInt(random(), 2, 20)]; final String[] contentStrings = new String[TestUtil.nextInt(random(), 2, 20)];
@ -221,7 +219,7 @@ public class TestAllGroupHeadsCollector extends LuceneTestCase {
} }
contentStrings[contentIDX] = sb.toString(); contentStrings[contentIDX] = sb.toString();
if (VERBOSE) { if (VERBOSE) {
System.out.println(" content=" + sb.toString()); System.out.println(" content=" + sb);
} }
} }
@ -231,8 +229,7 @@ public class TestAllGroupHeadsCollector extends LuceneTestCase {
Document doc = new Document(); Document doc = new Document();
Document docNoGroup = new Document(); Document docNoGroup = new Document();
Field valuesField = null; Field valuesField = new SortedDocValuesField("group", new BytesRef());
valuesField = new SortedDocValuesField("group", new BytesRef());
doc.add(valuesField); doc.add(valuesField);
Field sort1 = new SortedDocValuesField("sort1", new BytesRef()); Field sort1 = new SortedDocValuesField("sort1", new BytesRef());
doc.add(sort1); doc.add(sort1);
@ -373,32 +370,30 @@ public class TestAllGroupHeadsCollector extends LuceneTestCase {
GroupDoc expectedGroupDoc = groupDocs[expectedDocId]; GroupDoc expectedGroupDoc = groupDocs[expectedDocId];
String expectedGroup = String expectedGroup =
expectedGroupDoc.group == null ? null : expectedGroupDoc.group.utf8ToString(); expectedGroupDoc.group == null ? null : expectedGroupDoc.group.utf8ToString();
System.out.println( System.out.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"Group:%10s score%5f Sort1:%10s Sort2:%10s Sort3:%10s doc:%5d", "Group:%10s score%5f Sort1:%10s Sort2:%10s Sort3:%10s doc:%5d%n",
expectedGroup, expectedGroup,
expectedGroupDoc.score, expectedGroupDoc.score,
expectedGroupDoc.sort1.utf8ToString(), expectedGroupDoc.sort1.utf8ToString(),
expectedGroupDoc.sort2.utf8ToString(), expectedGroupDoc.sort2.utf8ToString(),
expectedGroupDoc.sort3.utf8ToString(), expectedGroupDoc.sort3.utf8ToString(),
expectedDocId)); expectedDocId);
} }
System.out.println("\n=== Actual: \n"); System.out.println("\n=== Actual: \n");
for (int actualDocId : actualGroupHeads) { for (int actualDocId : actualGroupHeads) {
GroupDoc actualGroupDoc = groupDocs[actualDocId]; GroupDoc actualGroupDoc = groupDocs[actualDocId];
String actualGroup = String actualGroup =
actualGroupDoc.group == null ? null : actualGroupDoc.group.utf8ToString(); actualGroupDoc.group == null ? null : actualGroupDoc.group.utf8ToString();
System.out.println( System.out.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"Group:%10s score%5f Sort1:%10s Sort2:%10s Sort3:%10s doc:%5d", "Group:%10s score%5f Sort1:%10s Sort2:%10s Sort3:%10s doc:%5d%n",
actualGroup, actualGroup,
actualGroupDoc.score, actualGroupDoc.score,
actualGroupDoc.sort1.utf8ToString(), actualGroupDoc.sort1.utf8ToString(),
actualGroupDoc.sort2.utf8ToString(), actualGroupDoc.sort2.utf8ToString(),
actualGroupDoc.sort3.utf8ToString(), actualGroupDoc.sort3.utf8ToString(),
actualDocId)); actualDocId);
} }
System.out.println( System.out.println(
"\n==================================================================================="); "\n===================================================================================");
@ -487,7 +482,7 @@ public class TestAllGroupHeadsCollector extends LuceneTestCase {
int i = 0; int i = 0;
for (BytesRef groupValue : groupHeads.keySet()) { for (BytesRef groupValue : groupHeads.keySet()) {
List<GroupDoc> docs = groupHeads.get(groupValue); List<GroupDoc> docs = groupHeads.get(groupValue);
Collections.sort(docs, getComparator(docSort, sortByScoreOnly, fieldIdToDocID)); docs.sort(getComparator(docSort, sortByScoreOnly, fieldIdToDocID));
allGroupHeads[i++] = docs.get(0).id; allGroupHeads[i++] = docs.get(0).id;
} }
@ -516,15 +511,13 @@ public class TestAllGroupHeadsCollector extends LuceneTestCase {
} else if (!scoreOnly) { } else if (!scoreOnly) {
sortFields.add(new SortField("id", SortField.Type.INT)); sortFields.add(new SortField("id", SortField.Type.INT));
} }
return new Sort(sortFields.toArray(new SortField[sortFields.size()])); return new Sort(sortFields.toArray(new SortField[0]));
} }
private Comparator<GroupDoc> getComparator( private Comparator<GroupDoc> getComparator(
Sort sort, final boolean sortByScoreOnly, final int[] fieldIdToDocID) { Sort sort, final boolean sortByScoreOnly, final int[] fieldIdToDocID) {
final SortField[] sortFields = sort.getSort(); final SortField[] sortFields = sort.getSort();
return new Comparator<GroupDoc>() { return (d1, d2) -> {
@Override
public int compare(GroupDoc d1, GroupDoc d2) {
for (SortField sf : sortFields) { for (SortField sf : sortFields) {
final int cmp; final int cmp;
if (sf.getType() == SortField.Type.SCORE) { if (sf.getType() == SortField.Type.SCORE) {
@ -552,11 +545,9 @@ public class TestAllGroupHeadsCollector extends LuceneTestCase {
// Our sort always fully tie breaks: // Our sort always fully tie breaks:
fail(); fail();
return 0; return 0;
}
}; };
} }
@SuppressWarnings({"unchecked", "rawtypes"})
private AllGroupHeadsCollector<?> createRandomCollector(String groupField, Sort sortWithinGroup) { private AllGroupHeadsCollector<?> createRandomCollector(String groupField, Sort sortWithinGroup) {
if (random().nextBoolean()) { if (random().nextBoolean()) {
ValueSource vs = new BytesRefFieldSource(groupField); ValueSource vs = new BytesRefFieldSource(groupField);

View File

@ -19,7 +19,6 @@ package org.apache.lucene.search.grouping;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -453,13 +452,12 @@ public class TestGroupFacetCollector extends AbstractGroupingTestCase {
System.out.println("Total missing count " + expectedFacetResult.getTotalMissingCount()); System.out.println("Total missing count " + expectedFacetResult.getTotalMissingCount());
int counter = 0; int counter = 0;
for (TermGroupFacetCollector.FacetEntry expectedFacetEntry : expectedFacetEntries) { for (TermGroupFacetCollector.FacetEntry expectedFacetEntry : expectedFacetEntries) {
System.out.println( System.out.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"%d. Expected facet value %s with count %d", "%d. Expected facet value %s with count %d%n",
counter++, counter++,
expectedFacetEntry.getValue().utf8ToString(), expectedFacetEntry.getValue().utf8ToString(),
expectedFacetEntry.getCount())); expectedFacetEntry.getCount());
} }
System.out.println("\n=== Actual: \n"); System.out.println("\n=== Actual: \n");
@ -467,13 +465,12 @@ public class TestGroupFacetCollector extends AbstractGroupingTestCase {
System.out.println("Total missing count " + actualFacetResult.getTotalMissingCount()); System.out.println("Total missing count " + actualFacetResult.getTotalMissingCount());
counter = 0; counter = 0;
for (TermGroupFacetCollector.FacetEntry actualFacetEntry : actualFacetEntries) { for (TermGroupFacetCollector.FacetEntry actualFacetEntry : actualFacetEntries) {
System.out.println( System.out.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"%d. Actual facet value %s with count %d", "%d. Actual facet value %s with count %d%n",
counter++, counter++,
actualFacetEntry.getValue().utf8ToString(), actualFacetEntry.getValue().utf8ToString(),
actualFacetEntry.getCount())); actualFacetEntry.getCount());
} }
System.out.println( System.out.println(
"\n==================================================================================="); "\n===================================================================================");
@ -581,10 +578,7 @@ public class TestGroupFacetCollector extends AbstractGroupingTestCase {
NavigableSet<String> uniqueFacetValues = NavigableSet<String> uniqueFacetValues =
new TreeSet<>( new TreeSet<>(
new Comparator<String>() { (a, b) -> {
@Override
public int compare(String a, String b) {
if (a == b) { if (a == b) {
return 0; return 0;
} else if (a == null) { } else if (a == null) {
@ -594,7 +588,6 @@ public class TestGroupFacetCollector extends AbstractGroupingTestCase {
} else { } else {
return a.compareTo(b); return a.compareTo(b);
} }
}
}); });
Map<String, Map<String, Set<String>>> searchTermToFacetToGroups = new HashMap<>(); Map<String, Map<String, Set<String>>> searchTermToFacetToGroups = new HashMap<>();
int facetWithMostGroups = 0; int facetWithMostGroups = 0;
@ -610,7 +603,7 @@ public class TestGroupFacetCollector extends AbstractGroupingTestCase {
String contentStr = contentBrs[random.nextInt(contentBrs.length)]; String contentStr = contentBrs[random.nextInt(contentBrs.length)];
if (!searchTermToFacetToGroups.containsKey(contentStr)) { if (!searchTermToFacetToGroups.containsKey(contentStr)) {
searchTermToFacetToGroups.put(contentStr, new HashMap<String, Set<String>>()); searchTermToFacetToGroups.put(contentStr, new HashMap<>());
} }
Map<String, Set<String>> facetToGroups = searchTermToFacetToGroups.get(contentStr); Map<String, Set<String>> facetToGroups = searchTermToFacetToGroups.get(contentStr);
@ -619,7 +612,7 @@ public class TestGroupFacetCollector extends AbstractGroupingTestCase {
String facetValue = facetValues.get(random.nextInt(facetValues.size())); String facetValue = facetValues.get(random.nextInt(facetValues.size()));
uniqueFacetValues.add(facetValue); uniqueFacetValues.add(facetValue);
if (!facetToGroups.containsKey(facetValue)) { if (!facetToGroups.containsKey(facetValue)) {
facetToGroups.put(facetValue, new HashSet<String>()); facetToGroups.put(facetValue, new HashSet<>());
} }
Set<String> groupsInFacet = facetToGroups.get(facetValue); Set<String> groupsInFacet = facetToGroups.get(facetValue);
groupsInFacet.add(groupValue); groupsInFacet.add(groupValue);
@ -634,7 +627,7 @@ public class TestGroupFacetCollector extends AbstractGroupingTestCase {
String facetValue = facetValues.get(random.nextInt(facetValues.size())); String facetValue = facetValues.get(random.nextInt(facetValues.size()));
uniqueFacetValues.add(facetValue); uniqueFacetValues.add(facetValue);
if (!facetToGroups.containsKey(facetValue)) { if (!facetToGroups.containsKey(facetValue)) {
facetToGroups.put(facetValue, new HashSet<String>()); facetToGroups.put(facetValue, new HashSet<>());
} }
Set<String> groupsInFacet = facetToGroups.get(facetValue); Set<String> groupsInFacet = facetToGroups.get(facetValue);
groupsInFacet.add(groupValue); groupsInFacet.add(groupValue);
@ -740,13 +733,8 @@ public class TestGroupFacetCollector extends AbstractGroupingTestCase {
} }
} }
Collections.sort( entries.sort(
entries, (a, b) -> {
new Comparator<TermGroupFacetCollector.FacetEntry>() {
@Override
public int compare(
TermGroupFacetCollector.FacetEntry a, TermGroupFacetCollector.FacetEntry b) {
if (orderByCount) { if (orderByCount) {
int cmp = b.getCount() - a.getCount(); int cmp = b.getCount() - a.getCount();
if (cmp != 0) { if (cmp != 0) {
@ -754,7 +742,6 @@ public class TestGroupFacetCollector extends AbstractGroupingTestCase {
} }
} }
return a.getValue().compareTo(b.getValue()); return a.getValue().compareTo(b.getValue());
}
}); });
int endOffset = offset + limit; int endOffset = offset + limit;

View File

@ -22,7 +22,6 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -195,7 +194,7 @@ public class TestJoinUtil extends LuceneTestCase {
public void testSimpleOrdinalsJoin() throws Exception { public void testSimpleOrdinalsJoin() throws Exception {
final String idField = "id"; final String idField = "id";
final String productIdField = "productId"; final String productIdField = "productId";
// A field indicating to what type a document belongs, which is then used to distinques between // A field indicating to what type a document belongs, which is then used to distinguish between
// documents during joining. // documents during joining.
final String typeField = "type"; final String typeField = "type";
// A single sorted doc values field that holds the join values for all document types. // A single sorted doc values field that holds the join values for all document types.
@ -310,7 +309,7 @@ public class TestJoinUtil extends LuceneTestCase {
public void testOrdinalsJoinExplainNoMatches() throws Exception { public void testOrdinalsJoinExplainNoMatches() throws Exception {
final String idField = "id"; final String idField = "id";
final String productIdField = "productId"; final String productIdField = "productId";
// A field indicating to what type a document belongs, which is then used to distinques between // A field indicating to what type a document belongs, which is then used to distinguish between
// documents during joining. // documents during joining.
final String typeField = "type"; final String typeField = "type";
// A single sorted doc values field that holds the join values for all document types. // A single sorted doc values field that holds the join values for all document types.
@ -1496,7 +1495,7 @@ public class TestJoinUtil extends LuceneTestCase {
final Query joinQuery; final Query joinQuery;
{ {
// single val can be handled by multiple-vals // single val can be handled by multiple-vals
final boolean muliValsQuery = multipleValuesPerDocument || random().nextBoolean(); final boolean multiValsQuery = multipleValuesPerDocument || random().nextBoolean();
final String fromField = from ? "from" : "to"; final String fromField = from ? "from" : "to";
final String toField = from ? "to" : "from"; final String toField = from ? "to" : "from";
@ -1521,7 +1520,7 @@ public class TestJoinUtil extends LuceneTestCase {
joinQuery = joinQuery =
JoinUtil.createJoinQuery( JoinUtil.createJoinQuery(
fromField + suffix, fromField + suffix,
muliValsQuery, multiValsQuery,
toField + suffix, toField + suffix,
numType, numType,
actualQuery, actualQuery,
@ -1531,7 +1530,7 @@ public class TestJoinUtil extends LuceneTestCase {
case 1: case 1:
joinQuery = joinQuery =
JoinUtil.createJoinQuery( JoinUtil.createJoinQuery(
fromField, muliValsQuery, toField, actualQuery, indexSearcher, scoreMode); fromField, multiValsQuery, toField, actualQuery, indexSearcher, scoreMode);
break; break;
default: default:
throw new RuntimeException("unexpected value " + surpriseMe); throw new RuntimeException("unexpected value " + surpriseMe);
@ -1568,24 +1567,22 @@ public class TestJoinUtil extends LuceneTestCase {
for (int doc = iterator.nextDoc(); for (int doc = iterator.nextDoc();
doc != DocIdSetIterator.NO_MORE_DOCS; doc != DocIdSetIterator.NO_MORE_DOCS;
doc = iterator.nextDoc()) { doc = iterator.nextDoc()) {
System.out.println( System.out.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"Expected doc[%d] with id value %s", "Expected doc[%d] with id value %s%n",
doc, doc,
indexSearcher.storedFields().document(doc).get("id"))); indexSearcher.storedFields().document(doc).get("id"));
} }
System.out.println("actual cardinality:" + actualResult.cardinality()); System.out.println("actual cardinality:" + actualResult.cardinality());
iterator = new BitSetIterator(actualResult, actualResult.cardinality()); iterator = new BitSetIterator(actualResult, actualResult.cardinality());
for (int doc = iterator.nextDoc(); for (int doc = iterator.nextDoc();
doc != DocIdSetIterator.NO_MORE_DOCS; doc != DocIdSetIterator.NO_MORE_DOCS;
doc = iterator.nextDoc()) { doc = iterator.nextDoc()) {
System.out.println( System.out.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"Actual doc[%d] with id value %s", "Actual doc[%d] with id value %s%n",
doc, doc,
indexSearcher.storedFields().document(doc).get("id"))); indexSearcher.storedFields().document(doc).get("id"));
} }
} }
assertEquals(expectedResult, actualResult); assertEquals(expectedResult, actualResult);
@ -1661,7 +1658,7 @@ public class TestJoinUtil extends LuceneTestCase {
final int nextInt = random.nextInt(0xFFFFFF); final int nextInt = random.nextInt(0xFFFFFF);
uniqueRandomValue = String.format(Locale.ROOT, "%08x", nextInt); uniqueRandomValue = String.format(Locale.ROOT, "%08x", nextInt);
assert nextInt == Integer.parseUnsignedInt(uniqueRandomValue, 16); assert nextInt == Integer.parseUnsignedInt(uniqueRandomValue, 16);
} while ("".equals(uniqueRandomValue) || trackSet.contains(uniqueRandomValue)); } while (uniqueRandomValue.isEmpty() || trackSet.contains(uniqueRandomValue));
// Generate unique values and empty strings aren't allowed. // Generate unique values and empty strings aren't allowed.
trackSet.add(uniqueRandomValue); trackSet.add(uniqueRandomValue);
@ -1867,8 +1864,7 @@ public class TestJoinUtil extends LuceneTestCase {
Terms terms = MultiTerms.getTerms(topLevelReader, toField); Terms terms = MultiTerms.getTerms(topLevelReader, toField);
if (terms != null) { if (terms != null) {
PostingsEnum postingsEnum = null; PostingsEnum postingsEnum = null;
SortedSet<BytesRef> joinValues = new TreeSet<>(); SortedSet<BytesRef> joinValues = new TreeSet<>(joinValueToJoinScores.keySet());
joinValues.addAll(joinValueToJoinScores.keySet());
for (BytesRef joinValue : joinValues) { for (BytesRef joinValue : joinValues) {
TermsEnum termsEnum = terms.iterator(); TermsEnum termsEnum = terms.iterator();
if (termsEnum.seekExact(joinValue)) { if (termsEnum.seekExact(joinValue)) {
@ -1993,13 +1989,8 @@ public class TestJoinUtil extends LuceneTestCase {
hitsToJoinScores = context.toHitsToJoinScore.get(queryValue); hitsToJoinScores = context.toHitsToJoinScore.get(queryValue);
} }
List<Map.Entry<Integer, JoinScore>> hits = new ArrayList<>(hitsToJoinScores.entrySet()); List<Map.Entry<Integer, JoinScore>> hits = new ArrayList<>(hitsToJoinScores.entrySet());
Collections.sort( hits.sort(
hits, (hit1, hit2) -> {
new Comparator<Map.Entry<Integer, JoinScore>>() {
@Override
public int compare(
Map.Entry<Integer, JoinScore> hit1, Map.Entry<Integer, JoinScore> hit2) {
float score1 = hit1.getValue().score(scoreMode); float score1 = hit1.getValue().score(scoreMode);
float score2 = hit2.getValue().score(scoreMode); float score2 = hit2.getValue().score(scoreMode);
@ -2008,7 +1999,6 @@ public class TestJoinUtil extends LuceneTestCase {
return cmp; return cmp;
} }
return hit1.getKey() - hit2.getKey(); return hit1.getKey() - hit2.getKey();
}
}); });
ScoreDoc[] scoreDocs = new ScoreDoc[Math.min(10, hits.size())]; ScoreDoc[] scoreDocs = new ScoreDoc[Math.min(10, hits.size())];
for (int i = 0; i < scoreDocs.length; i++) { for (int i = 0; i < scoreDocs.length; i++) {

View File

@ -72,7 +72,7 @@ public abstract class Node implements Closeable {
protected ReferenceManager<IndexSearcher> mgr; protected ReferenceManager<IndexSearcher> mgr;
/** /**
* Startup time of original test, carefully propogated to all nodes to produce consistent "seconds * Startup time of original test, carefully propagated to all nodes to produce consistent "seconds
* since start time" in messages * since start time" in messages
*/ */
public static long globalStartNS; public static long globalStartNS;
@ -118,45 +118,42 @@ public abstract class Node implements Closeable {
public static void nodeMessage(PrintStream printStream, String message) { public static void nodeMessage(PrintStream printStream, String message) {
if (printStream != null) { if (printStream != null) {
long now = System.nanoTime(); long now = System.nanoTime();
printStream.println( printStream.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"%5.3fs %5.1fs: [%11s] %s", "%5.3fs %5.1fs: [%11s] %s%n",
(now - globalStartNS) / (double) TimeUnit.SECONDS.toNanos(1), (now - globalStartNS) / (double) TimeUnit.SECONDS.toNanos(1),
(now - localStartNS) / (double) TimeUnit.SECONDS.toNanos(1), (now - localStartNS) / (double) TimeUnit.SECONDS.toNanos(1),
Thread.currentThread().getName(), Thread.currentThread().getName(),
message)); message);
} }
} }
public static void nodeMessage(PrintStream printStream, int id, String message) { public static void nodeMessage(PrintStream printStream, int id, String message) {
if (printStream != null) { if (printStream != null) {
long now = System.nanoTime(); long now = System.nanoTime();
printStream.println( printStream.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"%5.3fs %5.1fs: N%d [%11s] %s", "%5.3fs %5.1fs: N%d [%11s] %s%n",
(now - globalStartNS) / (double) TimeUnit.SECONDS.toNanos(1), (now - globalStartNS) / (double) TimeUnit.SECONDS.toNanos(1),
(now - localStartNS) / (double) TimeUnit.SECONDS.toNanos(1), (now - localStartNS) / (double) TimeUnit.SECONDS.toNanos(1),
id, id,
Thread.currentThread().getName(), Thread.currentThread().getName(),
message)); message);
} }
} }
public void message(String message) { public void message(String message) {
if (printStream != null) { if (printStream != null) {
long now = System.nanoTime(); long now = System.nanoTime();
printStream.println( printStream.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"%5.3fs %5.1fs: %7s %2s [%11s] %s", "%5.3fs %5.1fs: %7s %2s [%11s] %s%n",
(now - globalStartNS) / (double) TimeUnit.SECONDS.toNanos(1), (now - globalStartNS) / (double) TimeUnit.SECONDS.toNanos(1),
(now - localStartNS) / (double) TimeUnit.SECONDS.toNanos(1), (now - localStartNS) / (double) TimeUnit.SECONDS.toNanos(1),
state, state,
name(), name(),
Thread.currentThread().getName(), Thread.currentThread().getName(),
message)); message);
} }
} }

View File

@ -130,7 +130,7 @@ public class TestNRTReplication extends LuceneTestCase {
int tcpPort = -1; int tcpPort = -1;
long initCommitVersion = -1; long initCommitVersion = -1;
long initInfosVersion = -1; long initInfosVersion = -1;
Pattern logTimeStart = Pattern.compile("^[0-9\\.]+s .*"); Pattern logTimeStart = Pattern.compile("^[0-9.]+s .*");
while (true) { while (true) {
String l = r.readLine(); String l = r.readLine();
@ -173,9 +173,7 @@ public class TestNRTReplication extends LuceneTestCase {
AtomicBoolean nodeClosing = new AtomicBoolean(); AtomicBoolean nodeClosing = new AtomicBoolean();
Thread pumper = Thread pumper =
ThreadPumper.start( ThreadPumper.start(
new Runnable() { () -> {
@Override
public void run() {
message("now wait for process " + p); message("now wait for process " + p);
try { try {
p.waitFor(); p.waitFor();
@ -191,7 +189,6 @@ public class TestNRTReplication extends LuceneTestCase {
throw new RuntimeException( throw new RuntimeException(
"node " + id + " process had unexpected non-zero exit status=" + exitValue); "node " + id + " process had unexpected non-zero exit status=" + exitValue);
} }
}
}, },
r, r,
System.out, System.out,
@ -656,7 +653,7 @@ public class TestNRTReplication extends LuceneTestCase {
primary.crash(); primary.crash();
// At this point replica is "in the future": it has 10 docs committed, but the primary crashed // At this point replica is "in the future": it has 10 docs committed, but the primary crashed
// before committing so it has 0 docs // before committing, so it has 0 docs
// Restart primary: // Restart primary:
primary = startNode(-1, 0, path1, -1, true); primary = startNode(-1, 0, path1, -1, true);
@ -735,10 +732,7 @@ public class TestNRTReplication extends LuceneTestCase {
private void assertWriteLockHeld(Path path) throws Exception { private void assertWriteLockHeld(Path path) throws Exception {
try (FSDirectory dir = FSDirectory.open(path)) { try (FSDirectory dir = FSDirectory.open(path)) {
expectThrows( expectThrows(
LockObtainFailedException.class, LockObtainFailedException.class, () -> dir.obtainLock(IndexWriter.WRITE_LOCK_NAME));
() -> {
dir.obtainLock(IndexWriter.WRITE_LOCK_NAME);
});
} }
} }
@ -948,8 +942,7 @@ public class TestNRTReplication extends LuceneTestCase {
try (Connection c = new Connection(primary.tcpPort)) { try (Connection c = new Connection(primary.tcpPort)) {
c.out.writeByte(SimplePrimaryNode.CMD_SET_REPLICAS); c.out.writeByte(SimplePrimaryNode.CMD_SET_REPLICAS);
c.out.writeVInt(replicas.length); c.out.writeVInt(replicas.length);
for (int id = 0; id < replicas.length; id++) { for (NodeProcess replica : replicas) {
NodeProcess replica = replicas[id];
c.out.writeVInt(replica.id); c.out.writeVInt(replica.id);
c.out.writeVInt(replica.tcpPort); c.out.writeVInt(replica.tcpPort);
} }
@ -998,12 +991,11 @@ public class TestNRTReplication extends LuceneTestCase {
static void message(String message) { static void message(String message) {
long now = System.nanoTime(); long now = System.nanoTime();
System.out.println( System.out.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"%5.3fs : parent [%11s] %s", "%5.3fs : parent [%11s] %s%n",
(now - Node.globalStartNS) / (double) TimeUnit.SECONDS.toNanos(1), (now - Node.globalStartNS) / (double) TimeUnit.SECONDS.toNanos(1),
Thread.currentThread().getName(), Thread.currentThread().getName(),
message)); message);
} }
} }

View File

@ -94,8 +94,7 @@ import org.apache.lucene.util.ThreadInterruptedException;
// hazardous window // hazardous window
// - replica comes up just as the primary is crashing / moving // - replica comes up just as the primary is crashing / moving
// - electing a new primary when a replica is just finishing its nrt sync: we need to wait for it // - electing a new primary when a replica is just finishing its nrt sync: we need to wait for it
// so we are sure to get the "most up to // so we are sure to get the "most up to date" replica
// date" replica
// - replica comes up after merged segment finished so it doesn't copy over the merged segment // - replica comes up after merged segment finished so it doesn't copy over the merged segment
// "promptly" (i.e. only sees it on NRT refresh) // "promptly" (i.e. only sees it on NRT refresh)
@ -210,7 +209,7 @@ public class TestStressNRTReplication extends LuceneTestCase {
if (NUM_NODES == null) { if (NUM_NODES == null) {
numNodes = TestUtil.nextInt(random(), 2, 10); numNodes = TestUtil.nextInt(random(), 2, 10);
} else { } else {
numNodes = NUM_NODES.intValue(); numNodes = NUM_NODES;
} }
System.out.println("TEST: using " + numNodes + " nodes"); System.out.println("TEST: using " + numNodes + " nodes");
@ -347,7 +346,7 @@ public class TestStressNRTReplication extends LuceneTestCase {
} }
restarter.join(); restarter.join();
// Close replicas before primary so we cancel any in-progres replications: // Close replicas before primary so we cancel any in-progress replications:
System.out.println("TEST: top: now close replicas"); System.out.println("TEST: top: now close replicas");
List<Closeable> toClose = new ArrayList<>(); List<Closeable> toClose = new ArrayList<>();
for (NodeProcess node : nodes) { for (NodeProcess node : nodes) {
@ -484,7 +483,7 @@ public class TestStressNRTReplication extends LuceneTestCase {
// When the primary starts, the userData in its latest commit point tells us which version it // When the primary starts, the userData in its latest commit point tells us which version it
// had indexed up to, so we know where to // had indexed up to, so we know where to
// replay from in the xlog. However, we forcefuly advance the version, and then IW on init (or // replay from in the xlog. However, we forcefully advance the version, and then IW on init (or
// maybe getReader) also adds 1 to it. // maybe getReader) also adds 1 to it.
// Since we publish the primary in this state (before xlog replay is done), a replica can start // Since we publish the primary in this state (before xlog replay is done), a replica can start
// up at this point and pull this version, // up at this point and pull this version,
@ -648,7 +647,7 @@ public class TestStressNRTReplication extends LuceneTestCase {
int tcpPort = -1; int tcpPort = -1;
long initCommitVersion = -1; long initCommitVersion = -1;
long initInfosVersion = -1; long initInfosVersion = -1;
Pattern logTimeStart = Pattern.compile("^[0-9\\.]+s .*"); Pattern logTimeStart = Pattern.compile("^[0-9.]+s .*");
boolean willCrash = false; boolean willCrash = false;
while (true) { while (true) {
@ -723,9 +722,7 @@ public class TestStressNRTReplication extends LuceneTestCase {
// nodeClosed once it exits: // nodeClosed once it exits:
Thread pumper = Thread pumper =
ThreadPumper.start( ThreadPumper.start(
new Runnable() { () -> {
@Override
public void run() {
message("now wait for process " + p); message("now wait for process " + p);
try { try {
p.waitFor(); p.waitFor();
@ -744,9 +741,7 @@ public class TestStressNRTReplication extends LuceneTestCase {
throw new RuntimeException(ioe); throw new RuntimeException(ioe);
} }
} }
if (exitValue != 0 if (exitValue != 0 && finalWillCrash == false && crashingNodes.remove(id) == false) {
&& finalWillCrash == false
&& crashingNodes.remove(id) == false) {
// should fail test // should fail test
failed.set(true); failed.set(true);
if (childLog != null) { if (childLog != null) {
@ -764,7 +759,6 @@ public class TestStressNRTReplication extends LuceneTestCase {
} }
} }
nodeClosed(id); nodeClosed(id);
}
}, },
r, r,
System.out, System.out,
@ -920,7 +914,7 @@ public class TestStressNRTReplication extends LuceneTestCase {
} }
b.append(String.format(Locale.ROOT, "%s%d(%.1fs)", prefix, i, sec)); b.append(String.format(Locale.ROOT, "%s%d(%.1fs)", prefix, i, sec));
} }
message("node status" + b.toString()); message("node status" + b);
message("downNodes=" + downNodes); message("downNodes=" + downNodes);
// If primary is down, promote a replica: // If primary is down, promote a replica:
@ -1084,23 +1078,18 @@ public class TestStressNRTReplication extends LuceneTestCase {
} else { } else {
// Just ensure that all nodes show the same hit count for // Just ensure that all nodes show the same hit count for
// the same version, i.e. they really are replicas of one another: // the same version, i.e. they really are replicas of one another:
if (oldHitCount.intValue() != hitCount) { if (oldHitCount != hitCount) {
failed.set(true); failed.set(true);
stop.set(true); stop.set(true);
message( message(
"top: searcher: wrong version hitCount: version=" "top: searcher: wrong version hitCount: version="
+ version + version
+ " oldHitCount=" + " oldHitCount="
+ oldHitCount.intValue() + oldHitCount
+ " hitCount=" + " hitCount="
+ hitCount); + hitCount);
fail( fail(
"version=" "version=" + version + " oldHitCount=" + oldHitCount + " hitCount=" + hitCount);
+ version
+ " oldHitCount="
+ oldHitCount.intValue()
+ " hitCount="
+ hitCount);
} }
} }
} catch ( } catch (
@ -1333,24 +1322,22 @@ public class TestStressNRTReplication extends LuceneTestCase {
static void message(String message) { static void message(String message) {
long now = System.nanoTime(); long now = System.nanoTime();
System.out.println( System.out.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"%5.3fs : parent [%11s] %s", "%5.3fs : parent [%11s] %s%n",
(now - Node.globalStartNS) / (double) TimeUnit.SECONDS.toNanos(1), (now - Node.globalStartNS) / (double) TimeUnit.SECONDS.toNanos(1),
Thread.currentThread().getName(), Thread.currentThread().getName(),
message)); message);
} }
static void message(String message, long localStartNS) { static void message(String message, long localStartNS) {
long now = System.nanoTime(); long now = System.nanoTime();
System.out.println( System.out.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"%5.3fs %5.1fs: parent [%11s] %s", "%5.3fs %5.1fs: parent [%11s] %s%n",
(now - Node.globalStartNS) / (double) TimeUnit.SECONDS.toNanos(1), (now - Node.globalStartNS) / (double) TimeUnit.SECONDS.toNanos(1),
(now - localStartNS) / (double) TimeUnit.SECONDS.toNanos(1), (now - localStartNS) / (double) TimeUnit.SECONDS.toNanos(1),
Thread.currentThread().getName(), Thread.currentThread().getName(),
message)); message);
} }
} }

View File

@ -264,14 +264,12 @@ public class TestTermAutomatonQuery extends LuceneTestCase {
TokenStream ts = TokenStream ts =
new CannedTokenStream( new CannedTokenStream(
new Token[] {
token("fast", 1, 1), token("fast", 1, 1),
token("speedy", 0, 1), token("speedy", 0, 1),
token("wi", 1, 1), token("wi", 1, 1),
token("wifi", 0, 2), token("wifi", 0, 2),
token("fi", 1, 1), token("fi", 1, 1),
token("network", 1, 1) token("network", 1, 1));
});
TermAutomatonQuery q = new TokenStreamToTermAutomatonQuery().toQuery("field", ts); TermAutomatonQuery q = new TokenStreamToTermAutomatonQuery().toQuery("field", ts);
// System.out.println("DOT: " + q.toDot()); // System.out.println("DOT: " + q.toDot());
@ -322,11 +320,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase {
q.setAccept(s2, true); q.setAccept(s2, true);
q.addAnyTransition(s0, s1); q.addAnyTransition(s0, s1);
q.addTransition(s1, s2, "b"); q.addTransition(s1, s2, "b");
expectThrows( expectThrows(IllegalStateException.class, q::finish);
IllegalStateException.class,
() -> {
q.finish();
});
} }
public void testInvalidTrailWithAny() throws Exception { public void testInvalidTrailWithAny() throws Exception {
@ -337,11 +331,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase {
q.setAccept(s2, true); q.setAccept(s2, true);
q.addTransition(s0, s1, "b"); q.addTransition(s0, s1, "b");
q.addAnyTransition(s1, s2); q.addAnyTransition(s1, s2);
expectThrows( expectThrows(IllegalStateException.class, q::finish);
IllegalStateException.class,
() -> {
q.finish();
});
} }
public void testAnyFromTokenStream() throws Exception { public void testAnyFromTokenStream() throws Exception {
@ -369,13 +359,11 @@ public class TestTermAutomatonQuery extends LuceneTestCase {
TokenStream ts = TokenStream ts =
new CannedTokenStream( new CannedTokenStream(
new Token[] {
token("comes", 1, 1), token("comes", 1, 1),
token("comes", 0, 2), token("comes", 0, 2),
token("*", 1, 1), token("*", 1, 1),
token("sun", 1, 1), token("sun", 1, 1),
token("moon", 0, 1) token("moon", 0, 1));
});
TermAutomatonQuery q = new TokenStreamToTermAutomatonQuery().toQuery("field", ts); TermAutomatonQuery q = new TokenStreamToTermAutomatonQuery().toQuery("field", ts);
// System.out.println("DOT: " + q.toDot()); // System.out.println("DOT: " + q.toDot());
@ -443,9 +431,9 @@ public class TestTermAutomatonQuery extends LuceneTestCase {
public TokenStreamComponents createComponents(String fieldName) { public TokenStreamComponents createComponents(String fieldName) {
MockTokenizer tokenizer = new MockTokenizer(MockTokenizer.WHITESPACE, true, 100); MockTokenizer tokenizer = new MockTokenizer(MockTokenizer.WHITESPACE, true, 100);
tokenizer.setEnableChecks(true); tokenizer.setEnableChecks(true);
TokenFilter filt = new MockTokenFilter(tokenizer, MockTokenFilter.EMPTY_STOPSET); TokenFilter filter = new MockTokenFilter(tokenizer, MockTokenFilter.EMPTY_STOPSET);
filt = new RandomSynonymFilter(filt); filter = new RandomSynonymFilter(filter);
return new TokenStreamComponents(tokenizer, filt); return new TokenStreamComponents(tokenizer, filter);
} }
}; };
@ -570,14 +558,12 @@ public class TestTermAutomatonQuery extends LuceneTestCase {
System.out.println("FAILED:"); System.out.println("FAILED:");
for (String id : hits1Docs) { for (String id : hits1Docs) {
if (hits2Docs.contains(id) == false) { if (hits2Docs.contains(id) == false) {
System.out.println( System.out.printf(Locale.ROOT, " id=%3s matched but should not have%n", id);
String.format(Locale.ROOT, " id=%3s matched but should not have", id));
} }
} }
for (String id : hits2Docs) { for (String id : hits2Docs) {
if (hits1Docs.contains(id) == false) { if (hits1Docs.contains(id) == false) {
System.out.println( System.out.printf(Locale.ROOT, " id=%3s did not match but should have%n", id);
String.format(Locale.ROOT, " id=%3s did not match but should have", id));
} }
} }
throw ae; throw ae;
@ -598,7 +584,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase {
private static class RandomQuery extends Query { private static class RandomQuery extends Query {
private final long seed; private final long seed;
private float density; private final float density;
// density should be 0.0 ... 1.0 // density should be 0.0 ... 1.0
public RandomQuery(long seed, float density) { public RandomQuery(long seed, float density) {
@ -731,11 +717,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase {
IndexReader r = w.getReader(); IndexReader r = w.getReader();
IndexSearcher s = newSearcher(r); IndexSearcher s = newSearcher(r);
TokenStream ts = TokenStream ts = new CannedTokenStream(token("a", 1, 1));
new CannedTokenStream(
new Token[] {
token("a", 1, 1),
});
TermAutomatonQuery q = new TokenStreamToTermAutomatonQuery().toQuery("field", ts); TermAutomatonQuery q = new TokenStreamToTermAutomatonQuery().toQuery("field", ts);
// System.out.println("DOT: " + q.toDot()); // System.out.println("DOT: " + q.toDot());
@ -756,11 +738,7 @@ public class TestTermAutomatonQuery extends LuceneTestCase {
IndexReader r = w.getReader(); IndexReader r = w.getReader();
IndexSearcher s = newSearcher(r); IndexSearcher s = newSearcher(r);
TokenStream ts = TokenStream ts = new CannedTokenStream(token("a", 1, 1), token("x", 1, 1));
new CannedTokenStream(
new Token[] {
token("a", 1, 1), token("x", 1, 1),
});
TermAutomatonQuery q = new TokenStreamToTermAutomatonQuery().toQuery("field", ts); TermAutomatonQuery q = new TokenStreamToTermAutomatonQuery().toQuery("field", ts);
// System.out.println("DOT: " + q.toDot()); // System.out.println("DOT: " + q.toDot());

View File

@ -50,7 +50,6 @@ import org.junit.Ignore;
/** Benchmarks tests for implementations of {@link Lookup} interface. */ /** Benchmarks tests for implementations of {@link Lookup} interface. */
@Ignore("COMMENT ME TO RUN BENCHMARKS!") @Ignore("COMMENT ME TO RUN BENCHMARKS!")
public class TestLookupBenchmark extends LuceneTestCase { public class TestLookupBenchmark extends LuceneTestCase {
@SuppressWarnings({"unchecked", "deprecation"})
private final List<Class<? extends Lookup>> benchmarkClasses = private final List<Class<? extends Lookup>> benchmarkClasses =
Arrays.asList( Arrays.asList(
FuzzySuggester.class, FuzzySuggester.class,
@ -82,7 +81,7 @@ public class TestLookupBenchmark extends LuceneTestCase {
assert false : "disable assertions before running benchmarks!"; assert false : "disable assertions before running benchmarks!";
List<Input> input = readTop50KWiki(); List<Input> input = readTop50KWiki();
Collections.shuffle(input, random); Collections.shuffle(input, random);
TestLookupBenchmark.dictionaryInput = input.toArray(new Input[input.size()]); TestLookupBenchmark.dictionaryInput = input.toArray(new Input[0]);
Collections.shuffle(input, random); Collections.shuffle(input, random);
TestLookupBenchmark.benchmarkInput = input; TestLookupBenchmark.benchmarkInput = input;
} }
@ -96,7 +95,7 @@ public class TestLookupBenchmark extends LuceneTestCase {
URL resource = URL resource =
IOUtils.requireResourceNonNull(TestLookupBenchmark.class.getResource(name), name); IOUtils.requireResourceNonNull(TestLookupBenchmark.class.getResource(name), name);
String line = null; String line;
BufferedReader br = new BufferedReader(new InputStreamReader(resource.openStream(), UTF_8)); BufferedReader br = new BufferedReader(new InputStreamReader(resource.openStream(), UTF_8));
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
int tab = line.indexOf('|'); int tab = line.indexOf('|');
@ -115,21 +114,17 @@ public class TestLookupBenchmark extends LuceneTestCase {
for (final Class<? extends Lookup> cls : benchmarkClasses) { for (final Class<? extends Lookup> cls : benchmarkClasses) {
BenchmarkResult result = BenchmarkResult result =
measure( measure(
new Callable<Integer>() { () -> {
@Override
public Integer call() throws Exception {
final Lookup lookup = buildLookup(cls, dictionaryInput); final Lookup lookup = buildLookup(cls, dictionaryInput);
return lookup.hashCode(); return lookup.hashCode();
}
}); });
System.err.println( System.err.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"%-15s input: %d, time[ms]: %s", "%-15s input: %d, time[ms]: %s%n",
cls.getSimpleName(), cls.getSimpleName(),
dictionaryInput.length, dictionaryInput.length,
result.average.toString())); result.average);
} }
} }
@ -139,15 +134,14 @@ public class TestLookupBenchmark extends LuceneTestCase {
for (Class<? extends Lookup> cls : benchmarkClasses) { for (Class<? extends Lookup> cls : benchmarkClasses) {
Lookup lookup = buildLookup(cls, dictionaryInput); Lookup lookup = buildLookup(cls, dictionaryInput);
long sizeInBytes = lookup.ramBytesUsed(); long sizeInBytes = lookup.ramBytesUsed();
System.err.println( System.err.printf(
String.format( Locale.ROOT, "%-15s size[B]:%,13d%n", lookup.getClass().getSimpleName(), sizeInBytes);
Locale.ROOT, "%-15s size[B]:%,13d", lookup.getClass().getSimpleName(), sizeInBytes));
} }
} }
/** Create {@link Lookup} instance and populate it. */ /** Create {@link Lookup} instance and populate it. */
private Lookup buildLookup(Class<? extends Lookup> cls, Input[] input) throws Exception { private Lookup buildLookup(Class<? extends Lookup> cls, Input[] input) throws Exception {
Lookup lookup = null; Lookup lookup;
if (cls == TSTLookup.class if (cls == TSTLookup.class
|| cls == FSTCompletionLookup.class || cls == FSTCompletionLookup.class
|| cls == WFSTCompletionLookup.class) { || cls == WFSTCompletionLookup.class) {
@ -203,14 +197,13 @@ public class TestLookupBenchmark extends LuceneTestCase {
public void runPerformanceTest( public void runPerformanceTest(
final int minPrefixLen, final int maxPrefixLen, final int num, final boolean onlyMorePopular) final int minPrefixLen, final int maxPrefixLen, final int num, final boolean onlyMorePopular)
throws Exception { throws Exception {
System.err.println( System.err.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"-- prefixes: %d-%d, num: %d, onlyMorePopular: %s", "-- prefixes: %d-%d, num: %d, onlyMorePopular: %s%n",
minPrefixLen, minPrefixLen,
maxPrefixLen, maxPrefixLen,
num, num,
onlyMorePopular)); onlyMorePopular);
for (Class<? extends Lookup> cls : benchmarkClasses) { for (Class<? extends Lookup> cls : benchmarkClasses) {
final Lookup lookup = buildLookup(cls, dictionaryInput); final Lookup lookup = buildLookup(cls, dictionaryInput);
@ -228,25 +221,21 @@ public class TestLookupBenchmark extends LuceneTestCase {
BenchmarkResult result = BenchmarkResult result =
measure( measure(
new Callable<Integer>() { () -> {
@Override
public Integer call() throws Exception {
int v = 0; int v = 0;
for (String term : input) { for (String term : input) {
v += lookup.lookup(term, onlyMorePopular, num).size(); v += lookup.lookup(term, onlyMorePopular, num).size();
} }
return v; return v;
}
}); });
System.err.println( System.err.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"%-15s queries: %d, time[ms]: %s, ~kQPS: %.0f", "%-15s queries: %d, time[ms]: %s, ~kQPS: %.0f%n",
lookup.getClass().getSimpleName(), lookup.getClass().getSimpleName(),
input.size(), input.size(),
result.average.toString(), result.average,
input.size() / result.average.avg)); input.size() / result.average.avg);
} }
} }
@ -258,7 +247,7 @@ public class TestLookupBenchmark extends LuceneTestCase {
List<Double> times = new ArrayList<>(); List<Double> times = new ArrayList<>();
for (int i = 0; i < warmup + rounds; i++) { for (int i = 0; i < warmup + rounds; i++) {
final long start = System.nanoTime(); final long start = System.nanoTime();
guard = callable.call().intValue(); guard = callable.call();
times.add((System.nanoTime() - start) / NANOS_PER_MS); times.add((System.nanoTime() - start) / NANOS_PER_MS);
} }
return new BenchmarkResult(times, warmup, rounds); return new BenchmarkResult(times, warmup, rounds);

View File

@ -24,13 +24,12 @@ import org.junit.Test;
public class TestJvmInfo extends RandomizedTest { public class TestJvmInfo extends RandomizedTest {
@Test @Test
public void testEchoJvmInfo() { public void testEchoJvmInfo() {
System.out.println( System.out.printf(
String.format(
Locale.ROOT, Locale.ROOT,
"This test runs with Java %s (%s, %s %s).", "This test runs with Java %s (%s, %s %s).%n",
System.getProperty("java.version"), System.getProperty("java.version"),
System.getProperty("java.vendor"), System.getProperty("java.vendor"),
System.getProperty("java.vm.name"), System.getProperty("java.vm.name"),
System.getProperty("java.vm.version"))); System.getProperty("java.vm.version"));
} }
} }