Skip to content

Commit

Permalink
GH-4425: Migrate tests with timeout config to JUnit 5 (#4426)
Browse files Browse the repository at this point in the history
  • Loading branch information
abrokenjester authored Feb 22, 2023
2 parents edc3056 + 5c85be7 commit 5808bbf
Show file tree
Hide file tree
Showing 36 changed files with 378 additions and 450 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.rdf4j.sail.lucene;

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

import java.io.IOException;
import java.util.Collections;
import java.util.List;
Expand All @@ -20,8 +22,7 @@
import org.eclipse.rdf4j.repository.util.Repositories;
import org.eclipse.rdf4j.sail.lucene.impl.LuceneIndex;
import org.eclipse.testsuite.rdf4j.sail.lucene.AbstractLuceneSailTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* @author jeen
Expand Down Expand Up @@ -56,22 +57,22 @@ public void testReindexing_SingleResource() throws Exception {

// expected empty result => no data in the index
res = Repositories.tupleQuery(repository, query, t -> Iterations.asList(t));
Assert.assertEquals(Collections.emptyList(), res);
assertEquals(Collections.emptyList(), res);

try (RepositoryConnection connection = repository.getConnection()) {
connection.add(SUBJECT_1, PREDICATE_1, vf.createLiteral("one"));
}

// expected single result
res = Repositories.tupleQuery(repository, query, t -> Iterations.asList(t));
Assert.assertEquals(1, res.size());
assertEquals(1, res.size());

// re-index
this.sail.reindex();

// expected single result
res = Repositories.tupleQuery(repository, query, t -> Iterations.asList(t));
Assert.assertEquals(1, res.size());
assertEquals(1, res.size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.testsuite.repository.RepositoryTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

public class HTTPRepositoryTest extends RepositoryTest {

private static HTTPMemServer server;

@BeforeClass
@BeforeAll
public static void startServer() throws Exception {
server = new HTTPMemServer();
try {
Expand All @@ -46,7 +47,7 @@ public static void startServer() throws Exception {
}
}

@AfterClass
@AfterAll
public static void stopServer() throws Exception {
server.stop();
}
Expand All @@ -56,7 +57,8 @@ protected Repository createRepository() {
return new HTTPRepository(HTTPMemServer.REPOSITORY_URL);
}

@Test(timeout = 10_000)
@Test
@Timeout(value = 10)
public void testSubqueryDeadlock() throws Exception {
String mainQueryStr = "SELECT ?property WHERE { ?property a rdf:Property . }";
String subQueryStr = "SELECT ?range WHERE { ?property rdfs:range ?range . }";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.http.HTTPMemServer;
import org.eclipse.rdf4j.testsuite.repository.RepositoryTest;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;

/**
* @author Jeen Broekstra
Expand All @@ -25,7 +25,7 @@ public class SPARQLRepositoryTest extends RepositoryTest {

private static HTTPMemServer server;

@BeforeClass
@BeforeAll
public static void startServer() throws Exception {
server = new HTTPMemServer();
try {
Expand All @@ -37,7 +37,7 @@ public static void startServer() throws Exception {

}

@Before
@BeforeEach
@Override
public void setUp() throws Exception {
super.setUp();
Expand All @@ -49,7 +49,7 @@ public void setUp() throws Exception {

}

@AfterClass
@AfterAll
public static void stopServer() throws Exception {
server.stop();
server = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,25 @@
import org.eclipse.rdf4j.sail.lucene.LuceneSail;
import org.eclipse.rdf4j.sail.solr.SolrIndexTest.PropertiesReader;
import org.eclipse.testsuite.rdf4j.sail.lucene.AbstractLuceneSailTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;

public class SolrSailTest extends AbstractLuceneSailTest {

private static final String DATA_DIR = "target/test-data";

private static String toRestoreSolrHome = null;

@BeforeClass
@BeforeAll
public static void setUpClass() throws Exception {
toRestoreSolrHome = System.getProperty("solr.solr.home");
PropertiesReader reader = new PropertiesReader("maven-config.properties");
String testSolrHome = reader.getProperty("test.solr.home");
System.setProperty("solr.solr.home", testSolrHome);
}

@AfterClass
@AfterAll
public static void tearDownClass() throws Exception {
System.setProperty("solr.solr.home", toRestoreSolrHome == null ? "" : toRestoreSolrHome);
toRestoreSolrHome = null;
Expand All @@ -47,9 +48,8 @@ protected void configure(LuceneSail sail) {
sail.setParameter(SolrIndex.SERVER_KEY, "embedded:");
}

@Override
public void tearDown() throws IOException, RepositoryException {
super.tearDown();
@AfterEach
public void deleteDataDir() throws IOException, RepositoryException {
FileUtils.deleteDirectory(new File(DATA_DIR));
}
}
6 changes: 0 additions & 6 deletions core/rio/trig/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,5 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<!-- This module uses timeout rule, and cannot be fully migrated to JUnit 5 now -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
package org.eclipse.rdf4j.rio.trig;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.StringReader;
import java.util.concurrent.TimeUnit;
Expand All @@ -33,21 +33,17 @@
import org.eclipse.rdf4j.rio.helpers.BasicParserSettings;
import org.eclipse.rdf4j.rio.helpers.ParseErrorCollector;
import org.eclipse.rdf4j.rio.helpers.StatementCollector;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

/**
* Custom (non-manifest) tests for TriG parser.
*
* @author Peter Ansell
*/
@Timeout(value = 10, unit = TimeUnit.MINUTES)
public class TriGParserCustomTest {

@Rule
public Timeout timeout = new Timeout(10, TimeUnit.MINUTES);

private ValueFactory vf;

private ParserConfig settingsNoVerifyLangTag;
Expand All @@ -61,7 +57,7 @@ public class TriGParserCustomTest {
/**
* @throws java.lang.Exception
*/
@Before
@BeforeEach
public void setUp() throws Exception {
vf = SimpleValueFactory.getInstance();
settingsNoVerifyLangTag = new ParserConfig();
Expand Down
6 changes: 0 additions & 6 deletions core/rio/turtle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,5 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<!-- This module uses timeout rule, and cannot be fully migrated to JUnit 5 now -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
package org.eclipse.rdf4j.rio.turtle;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.StringReader;
import java.io.StringWriter;
Expand All @@ -40,10 +40,9 @@
import org.eclipse.rdf4j.rio.helpers.ParseErrorCollector;
import org.eclipse.rdf4j.rio.helpers.ParseErrorLogger;
import org.eclipse.rdf4j.rio.helpers.StatementCollector;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -52,11 +51,9 @@
*
* @author Peter Ansell
*/
@Timeout(1000)
public class CustomTurtleParserTest {

@Rule
public Timeout timeout = Timeout.millis(1000000);

private ValueFactory vf;

private ParserConfig settingsNoVerifyLangTag;
Expand All @@ -72,7 +69,7 @@ public class CustomTurtleParserTest {
/**
* @throws java.lang.Exception
*/
@Before
@BeforeEach
public void setUp() throws Exception {
vf = SimpleValueFactory.getInstance();
settingsNoVerifyLangTag = new ParserConfig();
Expand Down Expand Up @@ -182,8 +179,8 @@ public void testLiteralWithNewlines() throws Exception {

String str = out.toString();

assertTrue("okLiteralString not found", str.contains(okLiteralString));
assertTrue("errLiteralString not found", str.contains(errLiteralString));
assertTrue(str.contains(okLiteralString), "okLiteralString not found");
assertTrue(str.contains(errLiteralString), "errLiteralString not found");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.eclipse.rdf4j.sail.elasticsearchstore.SingletonClientProvider;
import org.eclipse.rdf4j.sail.elasticsearchstore.TestHelpers;
import org.eclipse.rdf4j.testsuite.sail.RDFNotifyingStoreTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

/**
* An extension of RDFStoreTest for testing the class
Expand All @@ -34,13 +34,13 @@ public class ElasticsearchStoreContextIT extends RDFNotifyingStoreTest {
private static ElasticsearchClusterRunner runner;
private static SingletonClientProvider clientPool;

@BeforeClass
@BeforeAll
public static void beforeClass() throws IOException, InterruptedException {
runner = TestHelpers.startElasticsearch(installLocation);
clientPool = new SingletonClientProvider("localhost", TestHelpers.getPort(runner), TestHelpers.CLUSTER);
}

@AfterClass
@AfterAll
public static void afterClass() throws Exception {
clientPool.close();
TestHelpers.stopElasticsearch(runner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import org.eclipse.rdf4j.sail.elasticsearchstore.SingletonClientProvider;
import org.eclipse.rdf4j.sail.elasticsearchstore.TestHelpers;
import org.eclipse.rdf4j.testsuite.sail.RDFNotifyingStoreTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

/**
* An extension of RDFStoreTest for testing the class
Expand All @@ -39,13 +39,13 @@ public class ElasticsearchStoreIT extends RDFNotifyingStoreTest {
private static ElasticsearchClusterRunner runner;
static SingletonClientProvider clientPool;

@BeforeClass
@BeforeAll
public static void beforeClass() throws IOException, InterruptedException {
runner = TestHelpers.startElasticsearch(installLocation);
clientPool = new SingletonClientProvider("localhost", TestHelpers.getPort(runner), TestHelpers.CLUSTER);
}

@AfterClass
@AfterAll
public static void afterClass() throws Exception {
clientPool.close();
TestHelpers.stopElasticsearch(runner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
import org.eclipse.rdf4j.sail.elasticsearchstore.SingletonClientProvider;
import org.eclipse.rdf4j.sail.elasticsearchstore.TestHelpers;
import org.eclipse.rdf4j.testsuite.repository.RepositoryTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;

public class ElasticsearchStoreRepositoryIT extends RepositoryTest {

private static final File installLocation = Files.newTemporaryFolder();
private static ElasticsearchClusterRunner runner;
private static SingletonClientProvider clientPool;

@BeforeClass
@BeforeAll
public static void beforeClass() throws IOException, InterruptedException {
runner = TestHelpers.startElasticsearch(installLocation);
clientPool = new SingletonClientProvider("localhost", TestHelpers.getPort(runner), TestHelpers.CLUSTER);
}

@AfterClass
@AfterAll
public static void afterClass() throws Exception {
clientPool.close();
TestHelpers.stopElasticsearch(runner);
Expand All @@ -50,7 +50,7 @@ protected Repository createRepository() {
return sailRepository;
}

@Ignore
@Disabled
@Override
public void testShutdownFollowedByInit() throws Exception {
// ignore test
Expand Down
Loading

0 comments on commit 5808bbf

Please sign in to comment.