@@ -44,7 +44,7 @@ public class DefaultProgressTest extends AbstractTestEnvironment {
4444 };
4545
4646 @ Test
47- public void testSimpleReporter () throws InterruptedException {
47+ public void testSimpleReporter () {
4848 // obtain the Op
4949 Function <Integer , Integer > op = //
5050 ops .op ("test.progressReporter" ) //
@@ -56,15 +56,12 @@ public void testSimpleReporter() throws InterruptedException {
5656 Progress .addListener (op , (t ) -> {
5757 testProgress (t .progress (), numIterations );
5858 });
59- Thread t = new Thread (() -> op .apply (numIterations ));
60- t .start ();
61- t .join ();
62- Assert .assertEquals (numIterations , this .numUpdates );
59+ op .apply (numIterations );
6360
6461 }
6562
6663 @ Test
67- public void testMultiStageReporter () throws InterruptedException {
64+ public void testMultiStageReporter () {
6865 // obtain the Op
6966 BiFunction <Integer , Integer , Integer > op = //
7067 ops .op ("test.progressReporter" ) //
@@ -77,15 +74,11 @@ public void testMultiStageReporter() throws InterruptedException {
7774 Progress .addListener (op , (t ) -> {
7875 testProgress (t .progress (), numStages * numIterations );
7976 });
80- Thread t = new Thread (() -> op .apply (numStages , numIterations ));
81- t .start ();
82- t .join ();
83- Assert .assertEquals (numStages * numIterations , this .numUpdates );
84-
77+ op .apply (numStages , numIterations );
8578 }
8679
8780 @ Test
88- public void testDependentReporter () throws InterruptedException {
81+ public void testDependentReporter () {
8982 // obtain the Op
9083 Function <Integer , Integer > op = //
9184 ops .op ("test.dependentProgressReporter" ) //
@@ -97,11 +90,41 @@ public void testDependentReporter() throws InterruptedException {
9790 Progress .addListener (op , (t ) -> {
9891 testProgress (t .progress (), 3 );
9992 });
100- Thread t = new Thread (() -> op .apply (numIterations ));
101- t .start ();
102- t .join ();
103- Assert .assertEquals (3 , this .numUpdates );
93+ op .apply (numIterations );
94+
95+ }
10496
97+ @ Test
98+ public void testComplexDependentReporter () {
99+ // obtain the Op
100+ Function <Integer , Integer > op = //
101+ ops .op ("test.dependentComplexProgressReporter" ) //
102+ .inType (Integer .class ) //
103+ .outType (Integer .class ) //
104+ .function ();
105+
106+ int numIterations = 100 ;
107+ Progress .addListener (op , (t ) -> {
108+ testComplexProgress (t .progress (), numIterations );
109+ });
110+ op .apply (numIterations );
111+ }
112+
113+ boolean firstStageComplete = false ;
114+
115+ private void testComplexProgress (double progress , int numIterations ) {
116+ if (!firstStageComplete ) {
117+ Assert .assertEquals (1. / 3 , progress , 1e-6 );
118+ firstStageComplete = true ;
119+ return ;
120+ }
121+ else if (numUpdates < numIterations ) {
122+ double expected = (1. + (double ) ++numUpdates / numIterations ) / 3 ;
123+ Assert .assertEquals (expected , progress , 1e-6 );
124+ }
125+ else {
126+ Assert .assertEquals (1. , progress , 1e-6 );
127+ }
105128 }
106129
107130 private int numUpdates = 0 ;
@@ -128,3 +151,25 @@ public Integer apply(Integer t) {
128151 }
129152
130153}
154+
155+ @ Plugin (type = Op .class , name = "test.dependentComplexProgressReporter" )
156+ class DependentComplexProgressReportingOp implements Function <Integer , Integer > {
157+
158+ @ OpDependency (name = "test.progressReporter" )
159+ private Function <Integer , Integer > dependency ;
160+
161+ @ Override
162+ public Integer apply (Integer t ) {
163+ Progress .defineTotalProgress (1 , 2 );
164+ dependency .apply (t );
165+
166+ Progress .setStageMax (t );
167+ for (int i = 0 ; i < t ; i ++) {
168+ Progress .update ();
169+ }
170+
171+ dependency .apply (t );
172+ return 3 * t ;
173+ }
174+
175+ }
0 commit comments