modules/graphics/src/test/java/test/javafx/concurrent/AbstractTask.java

Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:

*** 21,33 **** * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! package javafx.concurrent; import java.util.concurrent.Semaphore; /** * For testing purposes, we use this subclass of Task that will fake out the * runLater and isFxApplicationThread calls, such that we can actually run * and test Task in a single-threaded manner. --- 21,35 ---- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! package test.javafx.concurrent; import java.util.concurrent.Semaphore; + import javafx.concurrent.Task; + import javafx.concurrent.TaskShim; /** * For testing purposes, we use this subclass of Task that will fake out the * runLater and isFxApplicationThread calls, such that we can actually run * and test Task in a single-threaded manner.
*** 43,53 **** * mechanism where either can happen. What we will do is use a semaphore for * each state. As the state is entered, we will give back a permit for that * state. Any code wishing to pick up at the right point can then just acquire * the permit to wait for the state to occur and then join. */ ! public abstract class AbstractTask extends Task<String> { public final Semaphore scheduledSemaphore = new Semaphore(0); public final Semaphore runningSemaphore = new Semaphore(0); public final Semaphore succeededSemaphore = new Semaphore(0); public final Semaphore cancelledSemaphore = new Semaphore(0); public final Semaphore failedSemaphore = new Semaphore(0); --- 45,55 ---- * mechanism where either can happen. What we will do is use a semaphore for * each state. As the state is entered, we will give back a permit for that * state. Any code wishing to pick up at the right point can then just acquire * the permit to wait for the state to occur and then join. */ ! public abstract class AbstractTask extends TaskShim<String> { public final Semaphore scheduledSemaphore = new Semaphore(0); public final Semaphore runningSemaphore = new Semaphore(0); public final Semaphore succeededSemaphore = new Semaphore(0); public final Semaphore cancelledSemaphore = new Semaphore(0); public final Semaphore failedSemaphore = new Semaphore(0);
*** 55,74 **** Thread appThread; ServiceTestBase test; // Simulates scheduling the concurrent for execution public void simulateSchedule() { ! setState(State.SCHEDULED); } // For most tests, we want to pretend that we are on the FX app thread, always. ! @Override boolean isFxApplicationThread() { return appThread == null || Thread.currentThread() == appThread; } // For most tests, we want to just run this stuff immediately ! @Override void runLater(Runnable r) { if (test != null) { test.eventQueue.add(r); } else { r.run(); } --- 57,76 ---- Thread appThread; ServiceTestBase test; // Simulates scheduling the concurrent for execution public void simulateSchedule() { ! shim_setState(State.SCHEDULED); } // For most tests, we want to pretend that we are on the FX app thread, always. ! @Override public boolean isFxApplicationThread() { return appThread == null || Thread.currentThread() == appThread; } // For most tests, we want to just run this stuff immediately ! @Override public void runLater(Runnable r) { if (test != null) { test.eventQueue.add(r); } else { r.run(); }
*** 91,96 **** --- 93,102 ---- } @Override protected void failed() { failedSemaphore.release(); } + + public ServiceTestBase set_test(ServiceTestBase v) { + return test = v; + } }