arne-bdt opened a new issue, #2809:
URL: https://github.com/apache/jena/issues/2809
### Version
5.3.0-SNAPSHOT
### Feature
Implementing a JUnit integration test for `JenaSystem#init` is
straightforward, but it must be run as a single-method test to ensure a fresh
JVM. Only then can we effectively debug and test the execution of static
initializers.
```java
@Test
public void init() {
assertDoesNotThrow(
() -> JenaSystem.init());
}
```
A regression test for
[apache/jena#2675](https://github.com/apache/jena/issues/2675) would look like
this:
```java
@Test
public void initRDFConnectionFuseki() {
try (RDFConnection conn =
RDFConnectionFuseki.service("http://localhost:3030/ds").build()) {
assertTrue(true);
}
}
```
For [apache/jena#2787](https://github.com/apache/jena/issues/2787), the
regression test is as follows:
```java
@Test
public void initParallel() {
var pool = Executors.newFixedThreadPool(2);
try {
var futures = IntStream.range(1, 3)
.mapToObj(i -> pool.submit(() -> {
if (i % 2 == 0) {
ModelFactory.createDefaultModel();
} else {
JenaSystem.init();
}
return i;
}))
.toList();
var intSet = new HashSet<Integer>();
assertTimeoutPreemptively(
Duration.of(4, ChronoUnit.SECONDS),
() -> {
for (var future : futures) {
intSet.add(future.get());
}
});
assertEquals(2, intSet.size());
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
pool.shutdown();
}
}
```
When running multiple tests within a suite or a single file, static
initializers may be triggered unpredictably, as any test could initialize them,
and they cannot be re-triggered within the same JVM instance (or class loader).
I attempted various JUnit annotations and methods to make these tests work
within a Maven build, but found no JUnit-based solution. However, I found a
workaround using the JMH benchmark framework, which runs each benchmark in a
freshly started JVM.
JMH uses code generation, which needs to be triggered whenever the benchmark
code is changed. For JetBrains IDEA, there's a
[plugin](https://plugins.jetbrains.com/plugin/7529-jmh-java-microbenchmark-harness)
that automates code generation in the background. Unfortunately, for other
IDEs like Eclipse, this process has to be triggered manually by running `mvn
clean install`.
I would like to submit a PR to extend the integration tests. However, I’d
like to confirm whether introducing JMH into the `jena-integration-tests` is
accepted by the Jena developer community before proceeding further.
### Are you interested in contributing a solution yourself?
Yes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]