You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2017/01/26 03:50:13 UTC

kylin git commit: minor, make DefaultSchedulerTest.testDiscard() more stable

Repository: kylin
Updated Branches:
  refs/heads/master c3fff6d19 -> 0582512ea


minor, make DefaultSchedulerTest.testDiscard() more stable


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/0582512e
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/0582512e
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/0582512e

Branch: refs/heads/master
Commit: 0582512ea06bcd1c662903ff69012ba1cc7cc33c
Parents: c3fff6d
Author: Li Yang <li...@apache.org>
Authored: Thu Jan 26 11:49:04 2017 +0800
Committer: Li Yang <li...@apache.org>
Committed: Thu Jan 26 11:49:56 2017 +0800

----------------------------------------------------------------------
 .../apache/kylin/job/SelfStopExecutable.java    | 31 ++++++++++++++++----
 .../impl/threadpool/DefaultSchedulerTest.java   |  5 ++--
 2 files changed, 27 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/0582512e/core-job/src/test/java/org/apache/kylin/job/SelfStopExecutable.java
----------------------------------------------------------------------
diff --git a/core-job/src/test/java/org/apache/kylin/job/SelfStopExecutable.java b/core-job/src/test/java/org/apache/kylin/job/SelfStopExecutable.java
index b4f6a98..9a3eb48 100644
--- a/core-job/src/test/java/org/apache/kylin/job/SelfStopExecutable.java
+++ b/core-job/src/test/java/org/apache/kylin/job/SelfStopExecutable.java
@@ -26,21 +26,40 @@ import org.apache.kylin.job.execution.ExecuteResult;
  */
 public class SelfStopExecutable extends BaseTestExecutable {
 
+    volatile boolean doingWork;
+
     public SelfStopExecutable() {
         super();
     }
 
     @Override
     protected ExecuteResult doWork(ExecutableContext context) throws ExecuteException {
+        doingWork = true;
         try {
-            Thread.sleep(5000);
-        } catch (InterruptedException e) {
-        }
-        if (isDiscarded()) {
-            return new ExecuteResult(ExecuteResult.State.STOPPED, "stopped");
-        } else {
+            for (int i = 0; i < 20; i++) {
+                sleepOneSecond();
+                
+                if (isDiscarded())
+                    return new ExecuteResult(ExecuteResult.State.STOPPED, "stopped");
+            }
+                
             return new ExecuteResult(ExecuteResult.State.SUCCEED, "succeed");
+        } finally {
+            doingWork = false;
+        }
+    }
+
+    private void sleepOneSecond() {
+        try {
+            Thread.sleep(1000);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
         }
     }
 
+    public void waitForDoWork() {
+        while (doingWork) {
+            sleepOneSecond();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/kylin/blob/0582512e/core-job/src/test/java/org/apache/kylin/job/impl/threadpool/DefaultSchedulerTest.java
----------------------------------------------------------------------
diff --git a/core-job/src/test/java/org/apache/kylin/job/impl/threadpool/DefaultSchedulerTest.java b/core-job/src/test/java/org/apache/kylin/job/impl/threadpool/DefaultSchedulerTest.java
index bcd6a59..2416311 100644
--- a/core-job/src/test/java/org/apache/kylin/job/impl/threadpool/DefaultSchedulerTest.java
+++ b/core-job/src/test/java/org/apache/kylin/job/impl/threadpool/DefaultSchedulerTest.java
@@ -97,7 +97,7 @@ public class DefaultSchedulerTest extends BaseSchedulerTest {
     @Test
     public void testDiscard() throws Exception {
         DefaultChainedExecutable job = new DefaultChainedExecutable();
-        BaseTestExecutable task1 = new SelfStopExecutable();
+        SelfStopExecutable task1 = new SelfStopExecutable();
         job.addTask(task1);
         jobService.addJob(job);
         waitForJobStatus(job.getId(), ExecutableState.RUNNING, 500);
@@ -105,8 +105,7 @@ public class DefaultSchedulerTest extends BaseSchedulerTest {
         waitForJobFinish(job.getId());
         Assert.assertEquals(ExecutableState.DISCARDED, jobService.getOutput(job.getId()).getState());
         Assert.assertEquals(ExecutableState.DISCARDED, jobService.getOutput(task1.getId()).getState());
-        Thread.sleep(5000);
-        System.out.println(job);
+        task1.waitForDoWork();
     }
 
     @SuppressWarnings("rawtypes")