diff --git a/integrationtest/backend/tck/src/main/java/org/hibernate/search/integrationtest/backend/tck/work/IndexIndexerLargeDocumentsIT.java b/integrationtest/backend/tck/src/main/java/org/hibernate/search/integrationtest/backend/tck/work/IndexIndexerLargeDocumentsIT.java index 4c3e77bfb62..54671f09b28 100644 --- a/integrationtest/backend/tck/src/main/java/org/hibernate/search/integrationtest/backend/tck/work/IndexIndexerLargeDocumentsIT.java +++ b/integrationtest/backend/tck/src/main/java/org/hibernate/search/integrationtest/backend/tck/work/IndexIndexerLargeDocumentsIT.java @@ -12,7 +12,6 @@ import java.io.IOException; import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; import java.util.concurrent.CompletableFuture; import java.util.function.IntFunction; @@ -25,6 +24,7 @@ import org.hibernate.search.engine.backend.work.execution.spi.IndexIndexer; import org.hibernate.search.integrationtest.backend.tck.testsupport.configuration.DefaultAnalysisDefinitions; import org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper; +import org.hibernate.search.util.impl.test.data.TextContent; import org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex; import org.hibernate.search.util.impl.test.annotation.TestForIssue; @@ -32,7 +32,6 @@ import org.junit.Rule; import org.junit.Test; -import com.google.common.io.Resources; import org.awaitility.Awaitility; /** @@ -51,10 +50,7 @@ public class IndexIndexerLargeDocumentsIT { private static final String GREAT_EXPECTATIONS; static { try { - GREAT_EXPECTATIONS = Resources.toString( - IndexIndexerLargeDocumentsIT.class.getResource( "/great_expectations.txt" ), - StandardCharsets.UTF_8 - ); + GREAT_EXPECTATIONS = TextContent.greatExpectations().read(); } catch (IOException e) { throw new UncheckedIOException( e ); diff --git a/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/DatasetHolder.java b/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/DatasetHolder.java index 09358a13705..24467a5992b 100644 --- a/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/DatasetHolder.java +++ b/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/DatasetHolder.java @@ -8,8 +8,6 @@ import java.io.IOException; -import org.hibernate.search.integrationtest.performance.backend.base.testsupport.filesystem.TemporaryFileHolder; - import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Param; import org.openjdk.jmh.annotations.Scope; @@ -19,14 +17,14 @@ @State(Scope.Benchmark) public class DatasetHolder { - @Param({ Datasets.HIBERNATE_DEV_ML_2016_01 }) + @Param({ Datasets.GREAT_EXPECTATIONS }) private String dataset; private Dataset datasetInstance; @Setup(Level.Trial) - public void setup(TemporaryFileHolder temporaryFileHolder) throws IOException { - datasetInstance = Datasets.createDataset( dataset, temporaryFileHolder.getCacheDirectory() ); + public void setup() throws IOException { + datasetInstance = Datasets.createDataset( dataset ); } public Dataset getDataset() { diff --git a/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/Datasets.java b/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/Datasets.java index 92a56ebb9da..fe2424949fe 100644 --- a/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/Datasets.java +++ b/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/Datasets.java @@ -6,69 +6,36 @@ */ package org.hibernate.search.integrationtest.performance.backend.base.testsupport.dataset; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.nio.channels.Channels; -import java.nio.channels.FileChannel; -import java.nio.channels.ReadableByteChannel; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardOpenOption; import java.util.List; -public final class Datasets { +import org.hibernate.search.util.impl.test.data.TextContent; - public static final String CONSTANT_TEXT = "constant-text"; +import com.google.common.io.CharSource; - public static final String HIBERNATE_DEV_ML_2016_01 = "hibernate-dev-ml-2016-01"; +public final class Datasets { - private static final String DATASET_CACHE_DIRECTORY = "dataset"; + public static final String CONSTANT_TEXT = "constant-text"; - private static final URI HIBERNATE_DEV_MAILING_LIST_URI = - URI.create( "https://lists.jboss.org/pipermail/hibernate-dev/2016-January.txt" ); + public static final String GREAT_EXPECTATIONS = "hibernate-dev-ml-2016-01"; private Datasets() { } - public static Dataset createDataset(String name, Path cacheDirectory) + public static Dataset createDataset(String name) throws IOException { switch ( name ) { case CONSTANT_TEXT: return new ConstantDataset(); - case HIBERNATE_DEV_ML_2016_01: - Path path = fetch( name, HIBERNATE_DEV_MAILING_LIST_URI, cacheDirectory ); - return new SampleDataset( parseMailingListDigest( path ) ); + case GREAT_EXPECTATIONS: + return new SampleDataset( parseSimple( TextContent.greatExpectations() ) ); default: throw new IllegalArgumentException( "Unknown dataset: " + name ); } } - private static Path fetch(String name, URI uri, Path cacheDirectory) throws IOException { - Path datasetCacheDirectory = cacheDirectory.resolve( DATASET_CACHE_DIRECTORY ); - if ( !Files.exists( datasetCacheDirectory ) ) { - Files.createDirectory( datasetCacheDirectory ); - } - - Path outputPath = datasetCacheDirectory.resolve( name ); - if ( Files.exists( outputPath ) ) { - return outputPath; - } - - try ( InputStream input = uri.toURL().openStream(); - ReadableByteChannel inputChannel = Channels.newChannel( input ); - FileChannel outputChannel = FileChannel.open( - outputPath, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW ) ) { - outputChannel.transferFrom( inputChannel, 0, Long.MAX_VALUE ); - } - return outputPath; - } - - private static List parseMailingListDigest(Path path) throws IOException { - try ( BufferedReader reader = Files.newBufferedReader( path ) ) { - return new MailingListDigestParser( reader ).parse(); - } + private static List parseSimple(CharSource charSource) throws IOException { + return charSource.readLines( new SimpleDataSampleParser() ); } } diff --git a/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/MailingListDigestParser.java b/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/MailingListDigestParser.java deleted file mode 100644 index 7b5bff7d6e8..00000000000 --- a/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/MailingListDigestParser.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Hibernate Search, full-text search for your domain model - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.search.integrationtest.performance.backend.base.testsupport.dataset; - -import java.io.BufferedReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -final class MailingListDigestParser { - - private final BufferedReader reader; - - private final List result = new ArrayList<>(); - - private int currentSampleId = 0; - - private String currentSampleSubject = null; - - private final StringBuilder currentSampleText = new StringBuilder(); - - private final List peekBuffer = new ArrayList<>(); - - private State state = State.INITIAL; - - public MailingListDigestParser(BufferedReader reader) { - this.reader = reader; - } - - public List parse() throws IOException { - String line = reader.readLine(); - while ( line != null ) { - peekBuffer.add( line ); - state = state.parseLine( this, line ); - line = reader.readLine(); - } - flushPeekBuffer(); - pushCurrentSample(); - return result; - } - - private void flushPeekBuffer() { - for ( String line : peekBuffer ) { - currentSampleText.append( line ).append( "\n" ); - } - peekBuffer.clear(); - } - - public void setCurrentSampleSubject(String currentSampleSubject) { - this.currentSampleSubject = currentSampleSubject; - } - - private void pushCurrentSample() { - if ( currentSampleSubject != null ) { - result.add( new SampleDataset.DataSample( - currentSampleSubject, currentSampleText.toString(), currentSampleId - ) ); - ++this.currentSampleId; - } - this.currentSampleSubject = null; - this.currentSampleText.setLength( 0 ); - } - - private abstract static class State { - - private static final State INITIAL = new State( Pattern.compile( "^From " ) ) { - @Override - protected State nextState(MailingListDigestParser parser, Matcher matcher) { - return AFTER_FROM_1; - } - }; - - private static final State AFTER_FROM_1 = new State( Pattern.compile( "^From: " ) ) { - @Override - protected State nextState(MailingListDigestParser parser, Matcher matcher) { - return AFTER_FROM_2; - } - }; - - private static final State AFTER_FROM_2 = new State( Pattern.compile( "^Date: " ) ) { - @Override - protected State nextState(MailingListDigestParser parser, Matcher matcher) { - return AFTER_DATE; - } - }; - - private static final State AFTER_DATE = new State( Pattern.compile( "^Subject: (.*)" ) ) { - @Override - protected State nextState(MailingListDigestParser parser, Matcher matcher) { - parser.pushCurrentSample(); - parser.flushPeekBuffer(); - parser.setCurrentSampleSubject( matcher.group( 1 ) ); - return INITIAL; - } - }; - - private final Pattern pattern; - - private State(Pattern pattern) { - this.pattern = pattern; - } - - public State parseLine(MailingListDigestParser parser, String line) { - Matcher matcher = pattern.matcher( line ); - if ( matcher.find() ) { - return nextState( parser, matcher ); - } - else { - parser.flushPeekBuffer(); - return State.INITIAL; - } - } - - protected abstract State nextState(MailingListDigestParser parser, Matcher matcher); - } - -} diff --git a/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/SampleDataset.java b/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/SampleDataset.java index 4bbd9a5fc30..24948210bb3 100644 --- a/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/SampleDataset.java +++ b/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/SampleDataset.java @@ -48,9 +48,9 @@ public void populate(MappedIndex index, DocumentElement documentElement, long do public static class DataSample { - private final String shortText; - private final String longText; - private final int numeric; + final String shortText; + final String longText; + final int numeric; public DataSample(String shortText, String longText, int numeric) { // Just in case something turned wrong during sample generation diff --git a/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/SimpleDataSampleParser.java b/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/SimpleDataSampleParser.java new file mode 100644 index 00000000000..d824ed0631d --- /dev/null +++ b/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/SimpleDataSampleParser.java @@ -0,0 +1,65 @@ +/* + * Hibernate Search, full-text search for your domain model + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.search.integrationtest.performance.backend.base.testsupport.dataset; + +import java.util.ArrayList; +import java.util.List; + +import com.google.common.io.LineProcessor; + +final class SimpleDataSampleParser implements LineProcessor> { + + private static final int LINES_PER_SAMPLE = 10; + + private final List result = new ArrayList<>(); + + private int currentSampleId = 0; + private int currentLineCount = 0; + private String currentSampleFirstLine = null; + private final StringBuilder currentSampleWholeText = new StringBuilder(); + + @Override + public boolean processLine(String line) { + if ( line.isEmpty() ) { + return true; + } + if ( currentLineCount == 0 ) { + currentSampleFirstLine = line; + } + else { + currentSampleWholeText.append( "\n" ); + } + currentSampleWholeText.append( line ); + ++currentLineCount; + if ( currentLineCount >= LINES_PER_SAMPLE ) { + pushCurrentSample(); + } + return true; + } + + @Override + public List getResult() { + pushCurrentSample(); + return result; + } + + private void pushCurrentSample() { + if ( currentLineCount == 0 ) { + return; + } + + result.add( new SampleDataset.DataSample( + currentSampleFirstLine, currentSampleWholeText.toString(), currentSampleId + ) ); + ++this.currentSampleId; + + currentLineCount = 0; + currentSampleFirstLine = null; + currentSampleWholeText.setLength( 0 ); + } + +} diff --git a/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/filesystem/TemporaryFileHolder.java b/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/filesystem/TemporaryFileHolder.java index e71327a8cfb..49ef5a0b77a 100644 --- a/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/filesystem/TemporaryFileHolder.java +++ b/integrationtest/performance/backend/base/src/main/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/filesystem/TemporaryFileHolder.java @@ -24,13 +24,6 @@ @State(Scope.Benchmark) public class TemporaryFileHolder { - /** - * Set this system property to an alternative path if you want - * cache files (downloads) to be stored in a specific place - * (other than "/tmp/" + TEST_DIR_PREFIX + "cache-path"). - */ - private static final String CACHE_PATH_PROPERTY_KEY = "cache-path"; - /** * Set this system property to an alternative path if you want * index files to be stored in a specific place @@ -51,10 +44,6 @@ public void cleanUp() throws IOException { deleteAll( toCleanUp ); } - public Path getCacheDirectory() throws IOException { - return getTemporaryDirectory( CACHE_PATH_PROPERTY_KEY, false ); - } - public Path getIndexesDirectory() throws IOException { return getTemporaryDirectory( INDEXES_PATH_PROPERTY_KEY, true ); } diff --git a/integrationtest/performance/backend/base/src/test/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/SimpleDataSampleParserTest.java b/integrationtest/performance/backend/base/src/test/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/SimpleDataSampleParserTest.java new file mode 100644 index 00000000000..cf199e6bcab --- /dev/null +++ b/integrationtest/performance/backend/base/src/test/java/org/hibernate/search/integrationtest/performance/backend/base/testsupport/dataset/SimpleDataSampleParserTest.java @@ -0,0 +1,61 @@ +/* + * Hibernate Search, full-text search for your domain model + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.search.integrationtest.performance.backend.base.testsupport.dataset; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.util.List; + +import org.hibernate.search.util.common.annotation.impl.SuppressJQAssistant; + +import org.junit.Test; + +import com.google.common.io.CharSource; + +@SuppressJQAssistant(reason = "This really is a unit test, not an IT, so we want the 'Test' suffix") +public class SimpleDataSampleParserTest { + + @Test + public void test() throws IOException { + List samples = CharSource.wrap( "\n" + + "This is the first real line\n" + + "Followed by another one\n" + + "Then a few empty lines:\n" + + "\n\n\n\n\n\n\n\n\n\n" + + "Then line 4\n" + + "Then line 5\n" + + "Then line 6\n" + + "Then line 7\n" + + "Then line 8\n" + + "Then line 9\n" + + "\n" + + "Then line 10\n" + + "This is the first line of the next sample" ) + .readLines( new SimpleDataSampleParser() ); + + assertThat( samples ).hasSize( 2 ); + + assertThat( samples.get( 0 ).shortText ).isEqualTo( "This is the first real line" ); + assertThat( samples.get( 0 ).longText ).isEqualTo( "This is the first real line\n" + + "Followed by another one\n" + + "Then a few empty lines:\n" + + "Then line 4\n" + + "Then line 5\n" + + "Then line 6\n" + + "Then line 7\n" + + "Then line 8\n" + + "Then line 9\n" + + "Then line 10" ); + assertThat( samples.get( 0 ).numeric ).isEqualTo( 0L ); + + assertThat( samples.get( 1 ).shortText ).isEqualTo( "This is the first line of the next sample" ); + assertThat( samples.get( 1 ).longText ).isEqualTo( "This is the first line of the next sample" ); + assertThat( samples.get( 1 ).numeric ).isEqualTo( 1L ); + } + +} \ No newline at end of file diff --git a/jqassistant/rules.xml b/jqassistant/rules.xml index b3c60cd8b0f..4021acdb84c 100644 --- a/jqassistant/rules.xml +++ b/jqassistant/rules.xml @@ -7,6 +7,22 @@ --> + + + Contributes the :SuppressJQAssistant label at the type level. + + ()-[:OF_TYPE]->(suppressAnnotation:Type) + WHERE + suppressAnnotation.fqn = "org.hibernate.search.util.common.annotation.impl.SuppressJQAssistant" + SET + type:SuppressJQAssistant + RETURN + type + ]]> + + @@ -661,6 +677,7 @@ + @@ -674,12 +691,14 @@ NOT artifact:IntegrationTest AND testAnnotation.fqn = "org.junit.Test" AND NOT type.name ENDS WITH "Test" + AND NOT type:SuppressJQAssistant RETURN DISTINCT artifact.name AS Artifact, type.fqn AS Test ]]> + @@ -692,6 +711,7 @@ WHERE testAnnotation.fqn = "org.junit.Test" AND NOT type.name ENDS WITH "IT" + AND NOT type:SuppressJQAssistant RETURN DISTINCT artifact.name AS Artifact, type.fqn AS Test ]]> diff --git a/util/common/src/main/java/org/hibernate/search/util/common/annotation/impl/SuppressJQAssistant.java b/util/common/src/main/java/org/hibernate/search/util/common/annotation/impl/SuppressJQAssistant.java new file mode 100644 index 00000000000..f6d62d423cf --- /dev/null +++ b/util/common/src/main/java/org/hibernate/search/util/common/annotation/impl/SuppressJQAssistant.java @@ -0,0 +1,29 @@ +/* + * Hibernate Search, full-text search for your domain model + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.search.util.common.annotation.impl; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.CLASS; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Internal annotation to suppress some JQAssistant rules. + *

+ * Note that rules must be specifically designed to take the annotation into account; + * not all rules are. + */ +@Documented +@Target(TYPE) +@Retention(CLASS) +public @interface SuppressJQAssistant { + + String reason(); + +} diff --git a/util/internal/test/common/src/main/java/org/hibernate/search/util/impl/test/data/TextContent.java b/util/internal/test/common/src/main/java/org/hibernate/search/util/impl/test/data/TextContent.java new file mode 100644 index 00000000000..8cd9a92ca4c --- /dev/null +++ b/util/internal/test/common/src/main/java/org/hibernate/search/util/impl/test/data/TextContent.java @@ -0,0 +1,26 @@ +/* + * Hibernate Search, full-text search for your domain model + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.search.util.impl.test.data; + +import java.nio.charset.StandardCharsets; + +import com.google.common.io.CharSource; +import com.google.common.io.Resources; + +public final class TextContent { + + private TextContent() { + } + + public static CharSource greatExpectations() { + return Resources.asCharSource( + TextContent.class.getResource( "/great_expectations.txt" ), + StandardCharsets.UTF_8 + ); + } + +} diff --git a/integrationtest/backend/tck/src/main/resources/great_expectations.txt b/util/internal/test/common/src/main/resources/great_expectations.txt similarity index 100% rename from integrationtest/backend/tck/src/main/resources/great_expectations.txt rename to util/internal/test/common/src/main/resources/great_expectations.txt