|
@@ -0,0 +1,59 @@
|
|
|
|
|
+package net.ranides.assira.concurrent;
|
|
|
|
|
+
|
|
|
|
|
+import net.ranides.assira.functional.special.Cancelable;
|
|
|
|
|
+import net.ranides.assira.junit.ManualTestUtils;
|
|
|
|
|
+import org.junit.Ignore;
|
|
|
|
|
+import org.junit.Test;
|
|
|
|
|
+
|
|
|
|
|
+import static org.junit.Assert.*;
|
|
|
|
|
+
|
|
|
|
|
+@Ignore("manual")
|
|
|
|
|
+public class TaskInvokerTest {
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void lazyOnce() {
|
|
|
|
|
+ final long ts = System.currentTimeMillis();
|
|
|
|
|
+
|
|
|
|
|
+ Cancelable lazy = TaskInvoker.lazy(500, () -> {
|
|
|
|
|
+ System.out.println("t=" + (System.currentTimeMillis()-ts) + " executed" );
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println( "t=" + (System.currentTimeMillis()-ts));
|
|
|
|
|
+ lazy.run();
|
|
|
|
|
+ ManualTestUtils.sleep(100);
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println( "t=" + (System.currentTimeMillis()-ts));
|
|
|
|
|
+ lazy.run();
|
|
|
|
|
+ ManualTestUtils.sleep(100);
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println( "t=" + (System.currentTimeMillis()-ts));
|
|
|
|
|
+ lazy.run();
|
|
|
|
|
+ ManualTestUtils.sleep(100);
|
|
|
|
|
+
|
|
|
|
|
+ ManualTestUtils.sleep(1000);
|
|
|
|
|
+ System.out.println( "t=" + (System.currentTimeMillis()-ts) + " end");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void lazyMany() {
|
|
|
|
|
+ final long ts = System.currentTimeMillis();
|
|
|
|
|
+
|
|
|
|
|
+ Cancelable lazy = TaskInvoker.lazy(500, () -> {
|
|
|
|
|
+ System.out.println("t=" + (System.currentTimeMillis()-ts) + " executed" );
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println( "t=" + (System.currentTimeMillis()-ts));
|
|
|
|
|
+ lazy.run();
|
|
|
|
|
+ ManualTestUtils.sleep(1000);
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println( "t=" + (System.currentTimeMillis()-ts));
|
|
|
|
|
+ lazy.run();
|
|
|
|
|
+ ManualTestUtils.sleep(1000);
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println( "t=" + (System.currentTimeMillis()-ts));
|
|
|
|
|
+ lazy.run();
|
|
|
|
|
+ ManualTestUtils.sleep(1000);
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println( "t=" + (System.currentTimeMillis()-ts) + " end");
|
|
|
|
|
+ }
|
|
|
|
|
+}
|