File tree Expand file tree Collapse file tree 2 files changed +58
-21
lines changed
egg__12_sc_junit/src/test/java/net/codetojoy Expand file tree Collapse file tree 2 files changed +58
-21
lines changed Original file line number Diff line number Diff line change 1+
2+ package net .codetojoy ;
3+
4+ import static org .junit .jupiter .api .Assertions .assertEquals ;
5+
6+ import org .junit .jupiter .api .Test ;
7+
8+ import java .util .concurrent .atomic .AtomicBoolean ;
9+ import jdk .incubator .concurrent .StructuredTaskScope ;
10+
11+ // Loom: we want to ensure this compiles, runs
12+ class CustomStructuredTaskScope <T > extends StructuredTaskScope <T > {}
13+
14+ class Worker {
15+ static AtomicBoolean isDone = new AtomicBoolean (false );
16+
17+ static void doSleep () {
18+ System .out .println ("TRACER working t: " + Thread .currentThread ());
19+ try { Thread .sleep (500 ); } catch (Exception ex ) {}
20+ isDone .set (true );
21+ }
22+
23+ static void doWork () {
24+ isDone .set (false );
25+ try {
26+ // Loom: we want to ensure this compiles, runs
27+ var thread = Thread .startVirtualThread (Worker ::doSleep );
28+ } catch (Exception ex ) {
29+ System .err .println ("TRACER caught ex !? msg: " + ex .getMessage ());
30+ }
31+ }
32+ }
33+
34+ // This isn't really a unit test, but it exercises Loom features to ensure
35+ // that JUnit is happy and configured properly.
36+
37+ public class TestLoom {
38+ @ Test
39+ void canaryTest () {
40+ // test
41+ var x = 4 + 4 ;
42+
43+ assertEquals (8 , x );
44+ }
45+
46+ @ Test
47+ void workerTest () {
48+ var worker = new Worker ();
49+
50+ // test
51+ worker .doWork ();
52+
53+ while (! worker .isDone .get ()) {
54+ System .out .println ("TRACER waiting on worker" );
55+ try { Thread .sleep (250 ); } catch (Exception ex ) {}
56+ }
57+ }
58+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments