1010 *******************************************************************************/
1111package org .eclipse .rdf4j .testsuite .sparql ;
1212
13+ import static org .junit .jupiter .api .Assertions .fail ;
14+
1315import java .io .File ;
1416import java .io .IOException ;
17+ import java .util .concurrent .atomic .AtomicInteger ;
1518import java .util .stream .Stream ;
1619
1720import 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