Skip to content

Commit 723be75

Browse files
GH-4592 Make sure tests do not share state as they run concurrently.
Signed-off-by: Jerven Bolleman <[email protected]>
1 parent e6cff43 commit 723be75

20 files changed

+2400
-1855
lines changed

testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/sparql/AbstractComplianceTest.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.io.InputStream;
1616
import java.io.Reader;
1717
import java.net.URL;
18+
import java.util.function.Supplier;
1819

1920
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
2021
import org.eclipse.rdf4j.common.transaction.IsolationLevel;
@@ -60,36 +61,36 @@ public abstract class AbstractComplianceTest {
6061

6162
protected DynamicTest makeTest(String name, Executable x) {
6263
return DynamicTest.dynamicTest(name, () -> {
63-
setUp();
6464
x.execute();
65-
tearDown();
6665
});
6766
}
6867

69-
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
70-
71-
protected final Repository repo;
72-
protected RepositoryConnection conn;
73-
74-
public AbstractComplianceTest(Repository repo) {
75-
this.repo = repo;
68+
protected Repository openRepository() {
69+
Repository r = repo.get();
70+
r.init();
71+
return r;
7672
}
7773

78-
public void setUp() {
79-
repo.init();
80-
conn = new RepositoryConnectionWrapper(repo.getConnection());
74+
protected RepositoryConnection openConnection(Repository r) {
75+
return new RepositoryConnectionWrapper(r.getConnection());
8176
}
8277

83-
public void tearDown() {
84-
try {
78+
protected void closeRepository(Repository r) {
79+
try (RepositoryConnection conn = r.getConnection()) {
8580
conn.clear();
86-
conn.close();
87-
} finally {
88-
repo.shutDown();
8981
}
82+
r.shutDown();
83+
}
84+
85+
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
86+
87+
protected final Supplier<Repository> repo;
88+
89+
public AbstractComplianceTest(Supplier<Repository> repo) {
90+
this.repo = repo;
9091
}
9192

92-
protected void loadTestData(String dataFile, Resource... contexts)
93+
protected void loadTestData(String dataFile, RepositoryConnection conn, Resource... contexts)
9394
throws RDFParseException, RepositoryException, IOException {
9495
logger.debug("loading dataset {}", dataFile);
9596
try (InputStream dataset = this.getClass().getResourceAsStream(dataFile)) {

testsuites/sparql/src/main/java/org/eclipse/rdf4j/testsuite/sparql/RepositorySPARQLComplianceTestSuite.java

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
*******************************************************************************/
1111
package org.eclipse.rdf4j.testsuite.sparql;
1212

13+
import static org.junit.jupiter.api.Assertions.fail;
14+
1315
import java.io.File;
1416
import java.io.IOException;
17+
import java.util.concurrent.atomic.AtomicInteger;
1518
import java.util.stream.Stream;
1619

1720
import org.eclipse.rdf4j.common.annotation.Experimental;
@@ -56,92 +59,92 @@ public abstract class RepositorySPARQLComplianceTestSuite {
5659

5760
@TestFactory
5861
Stream<DynamicTest> aggregate() throws RDF4JException, IOException {
59-
return new AggregateTest(getEmptyInitializedRepository()).tests();
62+
return new AggregateTest(this::getEmptyInitializedRepository).tests();
6063
}
6164

6265
@TestFactory
6366
Stream<DynamicTest> arbitraryLengthPath() throws RDF4JException, IOException {
64-
return new ArbitraryLengthPathTest(getEmptyInitializedRepository()).tests();
67+
return new ArbitraryLengthPathTest(this::getEmptyInitializedRepository).tests();
6568
}
6669

6770
@TestFactory
6871
Stream<DynamicTest> basic() throws RDF4JException, IOException {
69-
return new BasicTest(getEmptyInitializedRepository()).tests();
72+
return new BasicTest(this::getEmptyInitializedRepository).tests();
7073
}
7174

7275
@TestFactory
7376
Stream<DynamicTest> bind() throws RDF4JException, IOException {
74-
return new BindTest(getEmptyInitializedRepository()).tests();
77+
return new BindTest(this::getEmptyInitializedRepository).tests();
7578
}
7679

7780
@TestFactory
7881
Stream<DynamicTest> builtinFunction() throws RDF4JException, IOException {
79-
return new BuiltinFunctionTest(getEmptyInitializedRepository()).tests();
82+
return new BuiltinFunctionTest(this::getEmptyInitializedRepository).tests();
8083
}
8184

8285
@TestFactory
8386
Stream<DynamicTest> construct() throws RDF4JException, IOException {
84-
return new ConstructTest(getEmptyInitializedRepository()).tests();
87+
return new ConstructTest(this::getEmptyInitializedRepository).tests();
8588
}
8689

8790
@TestFactory
8891
Stream<DynamicTest> defaultGraph() throws RDF4JException, IOException {
89-
return new DefaultGraphTest(getEmptyInitializedRepository()).tests();
92+
return new DefaultGraphTest(this::getEmptyInitializedRepository).tests();
9093
}
9194

9295
@TestFactory
9396
Stream<DynamicTest> describe() throws RDF4JException, IOException {
94-
return new DescribeTest(getEmptyInitializedRepository()).tests();
97+
return new DescribeTest(this::getEmptyInitializedRepository).tests();
9598
}
9699

97100
@TestFactory
98101
Stream<DynamicTest> groupBy() throws RDF4JException, IOException {
99-
return new GroupByTest(getEmptyInitializedRepository()).tests();
102+
return new GroupByTest(this::getEmptyInitializedRepository).tests();
100103
}
101104

102105
@TestFactory
103106
Stream<DynamicTest> in() throws RDF4JException, IOException {
104-
return new InTest(getEmptyInitializedRepository()).tests();
107+
return new InTest(this::getEmptyInitializedRepository).tests();
105108
}
106109

107110
@TestFactory
108111
Stream<DynamicTest> optional() throws RDF4JException, IOException {
109-
return new OptionalTest(getEmptyInitializedRepository()).tests();
112+
return new OptionalTest(this::getEmptyInitializedRepository).tests();
110113
}
111114

112115
@TestFactory
113116
Stream<DynamicTest> propertyPath() throws RDF4JException, IOException {
114-
return new PropertyPathTest(getEmptyInitializedRepository()).tests();
117+
return new PropertyPathTest(this::getEmptyInitializedRepository).tests();
115118
}
116119

117120
@TestFactory
118121
Stream<DynamicTest> subselect() throws RDF4JException, IOException {
119-
return new SubselectTest(getEmptyInitializedRepository()).tests();
122+
return new SubselectTest(this::getEmptyInitializedRepository).tests();
120123
}
121124

122125
@TestFactory
123126
Stream<DynamicTest> union() throws RDF4JException, IOException {
124-
return new UnionTest(getEmptyInitializedRepository()).tests();
127+
return new UnionTest(this::getEmptyInitializedRepository).tests();
125128
}
126129

127130
@TestFactory
128131
Stream<DynamicTest> values() throws RDF4JException, IOException {
129-
return new ValuesTest(getEmptyInitializedRepository()).tests();
132+
return new ValuesTest(this::getEmptyInitializedRepository).tests();
130133
}
131134

132135
@TestFactory
133136
Stream<DynamicTest> orderBy() throws RDF4JException, IOException {
134-
return new OrderByTest(getEmptyInitializedRepository()).tests();
137+
return new OrderByTest(this::getEmptyInitializedRepository).tests();
135138
}
136139

137140
@TestFactory
138141
Stream<DynamicTest> exists() throws RDF4JException, IOException {
139-
return new ExistsTest(getEmptyInitializedRepository()).tests();
142+
return new ExistsTest(this::getEmptyInitializedRepository).tests();
140143
}
141144

142145
@TestFactory
143146
Stream<DynamicTest> minus() throws RDF4JException, IOException {
144-
return new MinusTest(getEmptyInitializedRepository()).tests();
147+
return new MinusTest(this::getEmptyInitializedRepository).tests();
145148
}
146149

147150
@BeforeAll
@@ -157,20 +160,33 @@ public static void tearDownClass() {
157160
@TempDir
158161
private File dataDir;
159162

163+
private static final AtomicInteger tempDirNameForRepoCounter = new AtomicInteger();
164+
160165
protected final RepositoryFactory factory;
161166

162167
public RepositorySPARQLComplianceTestSuite(RepositoryFactory factory) {
163168
super();
164169
this.factory = factory;
165170
}
166171

167-
public Repository getEmptyInitializedRepository() throws RDF4JException, IOException {
168-
Repository repository = factory.getRepository(factory.getConfig());
169-
repository.setDataDir(dataDir);
170-
try (RepositoryConnection con = repository.getConnection()) {
171-
con.clear();
172-
con.clearNamespaces();
172+
public Repository getEmptyInitializedRepository() {
173+
try {
174+
Repository repository = factory.getRepository(factory.getConfig());
175+
dataDir.mkdir();
176+
File tmpDirPerRepo = new File(dataDir, "tmpDirPerRepo" + tempDirNameForRepoCounter.getAndIncrement());
177+
if (!tmpDirPerRepo.mkdir()) {
178+
fail("Could not create temporary directory for test");
179+
}
180+
repository.setDataDir(tmpDirPerRepo);
181+
try (RepositoryConnection con = repository.getConnection()) {
182+
con.clear();
183+
con.clearNamespaces();
184+
}
185+
return repository;
186+
187+
} catch (RDF4JException e) {
188+
fail(e);
189+
return null;
173190
}
174-
return repository;
175191
}
176192
}

0 commit comments

Comments
 (0)