Skip to content

Commit

Permalink
GH-4886 problem with use of @testfactory and @tempdir (#4887)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad authored Jan 29, 2024
2 parents 5f512b6 + 6824528 commit 440dc0e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.rdf4j.sail.lmdb;

import java.io.File;
import java.util.UUID;

import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.dataset.DatasetRepository;
Expand All @@ -29,7 +30,11 @@ public class LmdbPARQL11UpdateComplianceTest extends SPARQL11UpdateComplianceTes

@Override
protected Repository newRepository() throws Exception {

var temp = new File(folder, UUID.randomUUID().toString());
temp.mkdir();

return new DatasetRepository(
new SailRepository(new LmdbStore(folder, new LmdbStoreConfig("spoc"))));
new SailRepository(new LmdbStore(temp, new LmdbStoreConfig("spoc"))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.rdf4j.sail.lmdb;

import java.io.File;
import java.util.UUID;

import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.dataset.DatasetRepository;
Expand All @@ -29,8 +30,10 @@ public class LmdbSPARQL11QueryComplianceTest extends SPARQL11QueryComplianceTest

@Override
protected Repository newRepository() throws Exception {
var temp = new File(folder, UUID.randomUUID().toString());
temp.mkdir();
return new DatasetRepository(
new SailRepository(new LmdbStore(folder, new LmdbStoreConfig("spoc"))));
new SailRepository(new LmdbStore(temp, new LmdbStoreConfig("spoc"))));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private Resource internalNext() {

while (statements.hasNext()) {
Statement next = statements.next();
if (!contexts.contains(next.getContext())) {
if (next.getContext() != null && !contexts.contains(next.getContext())) {
contexts.add(next.getContext());
return next.getContext();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,48 +134,41 @@ protected final void runTest() throws Exception {

logger.debug("running {}", getName());

RepositoryConnection con = dataRep.getConnection();
RepositoryConnection erCon = expectedResultRepo.getConnection();
try {
String updateString = readUpdateString();
try (RepositoryConnection con = dataRep.getConnection()) {
try (RepositoryConnection erCon = expectedResultRepo.getConnection()) {
String updateString = readUpdateString();

con.begin();
con.begin();

Update update = con.prepareUpdate(QueryLanguage.SPARQL, updateString, requestFile);
Update update = con.prepareUpdate(QueryLanguage.SPARQL, updateString, requestFile);

assertThatNoException().isThrownBy(() -> {
int hashCode = update.hashCode();
if (hashCode == System.identityHashCode(update)) {
throw new UnsupportedOperationException(
"hashCode() result is the same as the identityHashCode in "
+ update.getClass().getName());
}
});
assertThatNoException().isThrownBy(() -> {
int hashCode = update.hashCode();
if (hashCode == System.identityHashCode(update)) {
throw new UnsupportedOperationException(
"hashCode() result is the same as the identityHashCode in "
+ update.getClass().getName());
}
});

update.setDataset(dataset);
update.execute();
update.setDataset(dataset);
update.execute();

con.commit();
con.commit();

// check default graph
logger.info("checking default graph");
compareGraphs(Iterations.asList(con.getStatements(null, null, null, true, (Resource) null)),
Iterations.asList(erCon.getStatements(null, null, null, true, (Resource) null)));
// check default graph
logger.info("checking default graph");
compareGraphs(Iterations.asList(con.getStatements(null, null, null, true, (Resource) null)),
Iterations.asList(erCon.getStatements(null, null, null, true, (Resource) null)));

for (String namedGraph : inputNamedGraphs.keySet()) {
logger.info("checking named graph {}", namedGraph);
IRI contextURI = con.getValueFactory().createIRI(namedGraph.replaceAll("\"", ""));
compareGraphs(Iterations.asList(con.getStatements(null, null, null, true, contextURI)),
Iterations.asList(erCon.getStatements(null, null, null, true, contextURI)));
}

for (String namedGraph : inputNamedGraphs.keySet()) {
logger.info("checking named graph {}", namedGraph);
IRI contextURI = con.getValueFactory().createIRI(namedGraph.replaceAll("\"", ""));
compareGraphs(Iterations.asList(con.getStatements(null, null, null, true, contextURI)),
Iterations.asList(erCon.getStatements(null, null, null, true, contextURI)));
}
} catch (Exception e) {
if (con.isActive()) {
con.rollback();
}
throw e;
} finally {
con.close();
erCon.close();
}
}

Expand Down Expand Up @@ -207,7 +200,7 @@ public void setUp() throws Exception {
}
}

expectedResultRepo = createRepository();
expectedResultRepo = new SailRepository(new MemoryStore());

try (RepositoryConnection conn = expectedResultRepo.getConnection()) {
conn.clear();
Expand All @@ -229,7 +222,7 @@ public void setUp() throws Exception {
}

@Override
public void tearDown() throws Exception {
public void tearDown() {
if (dataRep != null) {
clear(dataRep);
dataRep.shutDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,14 @@ public DynamicSparqlComplianceTest(String displayName, String testURI, String na
this.name = name;
}

public void test() {
public void test() throws Exception {
assumeThat(getIgnoredTests().contains(getName())).withFailMessage("test case '%s' is ignored", getName())
.isFalse();
try {
setUp();
runTest();
} catch (Exception e) {
try {
tearDown();
} catch (Exception e2) {

}
} finally {
tearDown();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,6 @@ private void testSES2052If1(RepositoryConnection conn) throws Exception {
assertNotNull(p);
assertEquals(RDF.TYPE, p);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}

Expand All @@ -266,9 +263,6 @@ private void testSES2052If2(RepositoryConnection conn) throws Exception {
assertNotNull(p);
assertEquals(RDF.TYPE, p);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}

Expand Down

0 comments on commit 440dc0e

Please sign in to comment.