Skip to content

Commit

Permalink
GH-4592 Make sure tests do not share state as they may concurrently.
Browse files Browse the repository at this point in the history
  • Loading branch information
JervenBolleman committed Nov 3, 2023
1 parent 8c33d62 commit e9d57aa
Show file tree
Hide file tree
Showing 21 changed files with 2,383 additions and 1,856 deletions.
2 changes: 1 addition & 1 deletion core/sail/elasticsearch-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
<httpPort>9200</httpPort>
<environmentVariables>
<ingest.geoip.downloader.enabled>false</ingest.geoip.downloader.enabled>
<ES_JAVA_OPTS>${java.sec.mgr}</ES_JAVA_OPTS>
<ES_JAVA_OPTS>${java.sec.mgr} -Xmx512m</ES_JAVA_OPTS>
</environmentVariables>
<instanceCount>1</instanceCount>
<instanceSettings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.InputStream;
import java.io.Reader;
import java.net.URL;
import java.util.function.Supplier;

import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.common.transaction.IsolationLevel;
Expand Down Expand Up @@ -60,36 +61,36 @@ public abstract class AbstractComplianceTest {

protected DynamicTest makeTest(String name, Executable x) {
return DynamicTest.dynamicTest(name, () -> {
setUp();
x.execute();
tearDown();
});
}

protected final Logger logger = LoggerFactory.getLogger(this.getClass());

protected final Repository repo;
protected RepositoryConnection conn;

public AbstractComplianceTest(Repository repo) {
this.repo = repo;
protected Repository openRepository() {
Repository r = repo.get();
r.init();
return r;
}

public void setUp() {
repo.init();
conn = new RepositoryConnectionWrapper(repo.getConnection());
protected RepositoryConnection openConnection(Repository r) {
return new RepositoryConnectionWrapper(r.getConnection());
}

public void tearDown() {
try {
protected void closeRepository(Repository r) {
try (RepositoryConnection conn = r.getConnection()) {
conn.clear();
conn.close();
} finally {
repo.shutDown();
}
r.shutDown();
}

protected final Logger logger = LoggerFactory.getLogger(this.getClass());

protected final Supplier<Repository> repo;

public AbstractComplianceTest(Supplier<Repository> repo) {
this.repo = repo;
}

protected void loadTestData(String dataFile, Resource... contexts)
protected void loadTestData(String dataFile, RepositoryConnection conn, Resource... contexts)
throws RDFParseException, RepositoryException, IOException {
logger.debug("loading dataset {}", dataFile);
try (InputStream dataset = this.getClass().getResourceAsStream(dataFile)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.rdf4j.testsuite.sparql;

import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.io.IOException;
import java.util.stream.Stream;
Expand Down Expand Up @@ -56,92 +58,92 @@ public abstract class RepositorySPARQLComplianceTestSuite {

@TestFactory
Stream<DynamicTest> aggregate() throws RDF4JException, IOException {
return new AggregateTest(getEmptyInitializedRepository()).tests();
return new AggregateTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> arbitraryLengthPath() throws RDF4JException, IOException {
return new ArbitraryLengthPathTest(getEmptyInitializedRepository()).tests();
return new ArbitraryLengthPathTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> basic() throws RDF4JException, IOException {
return new BasicTest(getEmptyInitializedRepository()).tests();
return new BasicTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> bind() throws RDF4JException, IOException {
return new BindTest(getEmptyInitializedRepository()).tests();
return new BindTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> builtinFunction() throws RDF4JException, IOException {
return new BuiltinFunctionTest(getEmptyInitializedRepository()).tests();
return new BuiltinFunctionTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> construct() throws RDF4JException, IOException {
return new ConstructTest(getEmptyInitializedRepository()).tests();
return new ConstructTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> defaultGraph() throws RDF4JException, IOException {
return new DefaultGraphTest(getEmptyInitializedRepository()).tests();
return new DefaultGraphTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> describe() throws RDF4JException, IOException {
return new DescribeTest(getEmptyInitializedRepository()).tests();
return new DescribeTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> groupBy() throws RDF4JException, IOException {
return new GroupByTest(getEmptyInitializedRepository()).tests();
return new GroupByTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> in() throws RDF4JException, IOException {
return new InTest(getEmptyInitializedRepository()).tests();
return new InTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> optional() throws RDF4JException, IOException {
return new OptionalTest(getEmptyInitializedRepository()).tests();
return new OptionalTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> propertyPath() throws RDF4JException, IOException {
return new PropertyPathTest(getEmptyInitializedRepository()).tests();
return new PropertyPathTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> subselect() throws RDF4JException, IOException {
return new SubselectTest(getEmptyInitializedRepository()).tests();
return new SubselectTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> union() throws RDF4JException, IOException {
return new UnionTest(getEmptyInitializedRepository()).tests();
return new UnionTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> values() throws RDF4JException, IOException {
return new ValuesTest(getEmptyInitializedRepository()).tests();
return new ValuesTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> orderBy() throws RDF4JException, IOException {
return new OrderByTest(getEmptyInitializedRepository()).tests();
return new OrderByTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> exists() throws RDF4JException, IOException {
return new ExistsTest(getEmptyInitializedRepository()).tests();
return new ExistsTest(this::getEmptyInitializedRepository).tests();
}

@TestFactory
Stream<DynamicTest> minus() throws RDF4JException, IOException {
return new MinusTest(getEmptyInitializedRepository()).tests();
return new MinusTest(this::getEmptyInitializedRepository).tests();
}

@BeforeAll
Expand All @@ -164,13 +166,19 @@ public RepositorySPARQLComplianceTestSuite(RepositoryFactory factory) {
this.factory = factory;
}

public Repository getEmptyInitializedRepository() throws RDF4JException, IOException {
Repository repository = factory.getRepository(factory.getConfig());
repository.setDataDir(dataDir);
try (RepositoryConnection con = repository.getConnection()) {
con.clear();
con.clearNamespaces();
public Repository getEmptyInitializedRepository() {
try {
Repository repository = factory.getRepository(factory.getConfig());
repository.setDataDir(dataDir);
try (RepositoryConnection con = repository.getConnection()) {
con.clear();
con.clearNamespaces();
}
return repository;

} catch (RDF4JException e) {
fail(e);
return null;
}
return repository;
}
}
Loading

0 comments on commit e9d57aa

Please sign in to comment.