forked from apache/jena
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apacheGH-2787: Deadlock in JenaSystem.init()
- printing an error to System.err, with a detailed message -> unable to fix the deadlock itself, that is all I came up with - added integration tests for JenaSystem.init(), also for the parallel case.
- Loading branch information
arne-bdt
committed
Oct 23, 2024
1 parent
4247422
commit f2c8baa
Showing
3 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
jena-integration-tests/src/test/java/org/apache/jena/sys/TS_Sys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.jena.sys; | ||
|
||
import org.apache.jena.sparql.exec.http.*; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Suite; | ||
|
||
@RunWith(Suite.class) | ||
@Suite.SuiteClasses( | ||
{ TestJenaSystem.class | ||
}) | ||
|
||
public class TS_Sys { } |
93 changes: 93 additions & 0 deletions
93
jena-integration-tests/src/test/java/org/apache/jena/sys/TestJenaSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.jena.sys; | ||
|
||
import org.apache.jena.rdf.model.ModelFactory; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import java.time.Duration; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Executors; | ||
import java.util.stream.IntStream; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class TestJenaSystem { | ||
|
||
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); | ||
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); | ||
private final PrintStream originalOut = System.out; | ||
private final PrintStream originalErr = System.err; | ||
|
||
@Before | ||
public void setUpStreams() { | ||
System.setOut(new PrintStream(outContent)); | ||
System.setErr(new PrintStream(errContent)); | ||
} | ||
|
||
@After | ||
public void restoreStreams() { | ||
System.setOut(originalOut); | ||
System.setErr(originalErr); | ||
} | ||
|
||
@Test | ||
public void testInit() { | ||
assertDoesNotThrow(() -> JenaSystem.init()); | ||
|
||
assertEquals("", errContent.toString(), "System.err should be empty"); | ||
} | ||
|
||
@Test | ||
public void testInitParallel() throws ExecutionException, InterruptedException { | ||
|
||
// it is mandatory to init JenaSystem before running anything in parallel | ||
JenaSystem.init(); | ||
|
||
var pool = Executors.newFixedThreadPool(8); | ||
|
||
var futures = IntStream.range(0, 16) | ||
.mapToObj(i -> pool.submit(() -> { | ||
if (i % 2 == 0) | ||
ModelFactory.createDefaultModel(); | ||
else | ||
JenaSystem.init(); | ||
|
||
return i; | ||
})) | ||
.toList(); | ||
|
||
assertTimeoutPreemptively( | ||
Duration.of(5, ChronoUnit.SECONDS), | ||
() -> { | ||
for (var future : futures) { | ||
System.out.println(future.get()); | ||
} | ||
}); | ||
|
||
var output = outContent.toString(); | ||
|
||
assertEquals(16, output.lines().count()); | ||
} | ||
} |