Skip to content

Commit 8c0fac8

Browse files
feat(#3840): identify concurrency issue
1 parent 10a006b commit 8c0fac8

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

eo-parser/src/main/java/org/eolang/parser/TrStepped.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,24 @@ final class TrStepped extends TrEnvelope {
5454
)
5555
);
5656

57+
TrStepped(final Train<Shift> train) {
58+
this(train, TrStepped.STEPPED);
59+
}
60+
5761
/**
5862
* Ctor.
63+
*
5964
* @param train Original train
6065
*/
61-
TrStepped(final Train<Shift> train) {
66+
TrStepped(final Train<Shift> train, Scalar<XSL> stepped) {
6267
super(
6368
new TrLambda(
6469
train,
6570
shift -> new StAfter(
6671
shift,
6772
new StLambda(
6873
shift::uid,
69-
(pos, xml) -> TrStepped.STEPPED.value()
74+
(pos, xml) -> stepped.value()
7075
.with("step", pos)
7176
.with("sheet", shift.uid())
7277
.transform(xml)

eo-parser/src/test/java/org/eolang/parser/TrSteppedTest.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,24 @@
2626
import com.jcabi.matchers.XhtmlMatchers;
2727
import com.jcabi.xml.XML;
2828
import com.jcabi.xml.XMLDocument;
29+
import com.jcabi.xml.XSL;
30+
import com.jcabi.xml.XSLDocument;
31+
import com.yegor256.Together;
2932
import com.yegor256.xsline.Shift;
3033
import com.yegor256.xsline.StClasspath;
3134
import com.yegor256.xsline.TrDefault;
35+
import com.yegor256.xsline.Train;
3236
import 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;
3345
import org.hamcrest.MatcherAssert;
46+
import org.junit.jupiter.api.RepeatedTest;
3447
import 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

Comments
 (0)