2626import com .jcabi .matchers .XhtmlMatchers ;
2727import com .jcabi .xml .XML ;
2828import com .jcabi .xml .XMLDocument ;
29+ import com .jcabi .xml .XSL ;
30+ import com .jcabi .xml .XSLDocument ;
31+ import com .yegor256 .Together ;
2932import com .yegor256 .xsline .Shift ;
3033import com .yegor256 .xsline .StClasspath ;
3134import com .yegor256 .xsline .TrDefault ;
35+ import com .yegor256 .xsline .Train ;
3236import com .yegor256 .xsline .Xsline ;
37+ import java .io .InputStream ;
38+ import java .net .URLClassLoader ;
39+ import java .util .concurrent .CountDownLatch ;
40+ import java .util .concurrent .atomic .AtomicReference ;
41+ import org .cactoos .Input ;
42+ import org .cactoos .io .ResourceOf ;
43+ import org .cactoos .scalar .Sticky ;
44+ import org .cactoos .text .TextOf ;
3345import org .hamcrest .MatcherAssert ;
46+ import org .junit .jupiter .api .RepeatedTest ;
3447import org .junit .jupiter .api .Test ;
3548
3649/**
@@ -49,11 +62,44 @@ void addsSheetName() {
4962 new TrDefault <Shift >().with (
5063 new StClasspath ("/org/eolang/parser/print/wrap-data.xsl" ))
5164 )).pass (
52- new XMLDocument ("<program><language>EO</language ></program>" )
65+ new XMLDocument ("<program><concurrency>no</concurrency ></program>" )
5366 ).toString (),
5467 XhtmlMatchers .hasXPath ("/program/sheets/sheet[text()='wrap-data']" )
5568 );
5669 }
5770
71+ @ RepeatedTest (10 )
72+ void addsSheetNameConcurrently () {
73+ final XML doc = new XMLDocument ("<program><concurrency>yes</concurrency></program>" );
74+ final CountDownLatch once = new CountDownLatch (1 );
75+ final Sticky <XSL > loading = new Sticky <>(
76+ () -> {
77+ if (once .getCount () == 0 ) {
78+ throw new IllegalStateException ("Resource should be loaded only once" );
79+ }
80+ once .countDown ();
81+ return new XSLDocument (
82+ new TextOf (
83+ () -> new ResourceOf ("org/eolang/parser/_stepped.xsl" ).stream ()
84+ ).asString ()
85+ );
86+ }
87+ );
88+ MatcherAssert .assertThat (
89+ "We expect the sheet name to be added successfully in concurrent environment" ,
90+ new Together <>(
91+ i -> new Xsline (
92+ new TrStepped (
93+ new TrDefault <Shift >().with (
94+ new StClasspath ("/org/eolang/parser/print/wrap-data.xsl" )
95+ ),
96+ loading
97+ )
98+ ).pass (doc ).toString ()
99+ ).iterator ().next (),
100+ XhtmlMatchers .hasXPath ("/program/sheets/sheet[text()='wrap-data']" )
101+ );
102+ }
103+
58104
59105}
0 commit comments