Skip to content

Commit

Permalink
test for concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 21, 2025
1 parent f236437 commit af21e2e
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/up.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
title: 'New version in README'
assignees: yegor256
branch: up
base: master
base: master
2 changes: 1 addition & 1 deletion src/it/groovy/invoker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.

invoker.goals = clean
invoker.goals = clean
2 changes: 1 addition & 1 deletion src/it/groovy/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ def same = new XMLDocument(new File(basedir, 'same.xmir'))

assert fist.equals(same)

assert log.text.contains("BUILD SUCCESS")
assert log.text.contains("BUILD SUCCESS")
Empty file modified src/main/java/com/jcabi/xml/ClasspathInput.java
100755 → 100644
Empty file.
Empty file modified src/main/java/com/jcabi/xml/ClasspathResolver.java
100755 → 100644
Empty file.
Empty file modified src/main/java/com/jcabi/xml/StrictXML.java
100755 → 100644
Empty file.
1 change: 0 additions & 1 deletion src/main/java/com/jcabi/xml/XSLDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
Expand Down
Empty file modified src/test/java/com/jcabi/xml/StrictXMLTest.java
100755 → 100644
Empty file.
31 changes: 10 additions & 21 deletions src/test/java/com/jcabi/xml/XSLDocumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
package com.jcabi.xml;

import com.jcabi.matchers.XhtmlMatchers;
import java.util.concurrent.CountDownLatch;
import com.yegor256.Together;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.lang3.StringUtils;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;

/**
Expand Down Expand Up @@ -246,33 +246,22 @@ void catchesSaxonWarnings() {
).transform(new XMLDocument("<x><a/></x>"));
}

@Test
@RepeatedTest(10)
void transformsInManyThreads() throws Exception {
final XSL xsl = new XSLDocument(
this.getClass().getResourceAsStream("first.xsl")
).with(new ClasspathSources());
final XML xml = new XMLDocument(
this.getClass().getResourceAsStream("simple.xml")
);
final AtomicInteger done = new AtomicInteger(0);
final CountDownLatch latch = new CountDownLatch(1);
final int total = 50;
final ExecutorService exec = Executors.newFixedThreadPool(total);
for (int task = 0; task < total; ++task) {
exec.submit(
() -> {
latch.await();
xsl.transform(xml);
xsl.transform(xml);
done.incrementAndGet();
return 0;
}
);
}
latch.countDown();
exec.shutdown();
exec.awaitTermination(1L, TimeUnit.MINUTES);
MatcherAssert.assertThat(done.get(), Matchers.equalTo(total));
MatcherAssert.assertThat(
new Together<>(
total,
t -> xsl.transform(xml)
).asList().size(),
Matchers.equalTo(total)
);
}

}
Empty file modified src/test/resources/com/jcabi/xml/sample-namespaces.xsd
100755 → 100644
Empty file.

0 comments on commit af21e2e

Please sign in to comment.