List of usage examples for java.lang Thread isAlive
public final native boolean isAlive();
From source file:azkaban.execapp.FlowRunnerTest2.java
/** * Tests the basic successful flow run, and also tests all output variables * from each job.//from ww w.j av a 2 s . c o m * * @throws Exception */ @Ignore @Test public void testBasicRun() throws Exception { EventCollectorListener eventCollector = new EventCollectorListener(); FlowRunner runner = createFlowRunner(eventCollector, "jobf"); Map<String, Status> expectedStateMap = new HashMap<String, Status>(); Map<String, ExecutableNode> nodeMap = new HashMap<String, ExecutableNode>(); // 1. START FLOW ExecutableFlow flow = runner.getExecutableFlow(); createExpectedStateMap(flow, expectedStateMap, nodeMap); Thread thread = runFlowRunnerInThread(runner); pause(250); // After it starts up, only joba should be running expectedStateMap.put("joba", Status.RUNNING); expectedStateMap.put("joba1", Status.RUNNING); compareStates(expectedStateMap, nodeMap); Props joba = nodeMap.get("joba").getInputProps(); Assert.assertEquals("joba.1", joba.get("param1")); Assert.assertEquals("test1.2", joba.get("param2")); Assert.assertEquals("test1.3", joba.get("param3")); Assert.assertEquals("override.4", joba.get("param4")); Assert.assertEquals("test2.5", joba.get("param5")); Assert.assertEquals("test2.6", joba.get("param6")); Assert.assertEquals("test2.7", joba.get("param7")); Assert.assertEquals("test2.8", joba.get("param8")); Props joba1 = nodeMap.get("joba1").getInputProps(); Assert.assertEquals("test1.1", joba1.get("param1")); Assert.assertEquals("test1.2", joba1.get("param2")); Assert.assertEquals("test1.3", joba1.get("param3")); Assert.assertEquals("override.4", joba1.get("param4")); Assert.assertEquals("test2.5", joba1.get("param5")); Assert.assertEquals("test2.6", joba1.get("param6")); Assert.assertEquals("test2.7", joba1.get("param7")); Assert.assertEquals("test2.8", joba1.get("param8")); // 2. JOB A COMPLETES SUCCESSFULLY InteractiveTestJob.getTestJob("joba") .succeedJob(Props.of("output.joba", "joba", "output.override", "joba")); pause(250); expectedStateMap.put("joba", Status.SUCCEEDED); expectedStateMap.put("joba1", Status.RUNNING); expectedStateMap.put("jobb", Status.RUNNING); expectedStateMap.put("jobc", Status.RUNNING); expectedStateMap.put("jobd", Status.RUNNING); expectedStateMap.put("jobd:innerJobA", Status.RUNNING); expectedStateMap.put("jobb:innerJobA", Status.RUNNING); compareStates(expectedStateMap, nodeMap); ExecutableNode node = nodeMap.get("jobb"); Assert.assertEquals(Status.RUNNING, node.getStatus()); Props jobb = node.getInputProps(); Assert.assertEquals("override.4", jobb.get("param4")); // Test that jobb properties overwrites the output properties Assert.assertEquals("moo", jobb.get("testprops")); Assert.assertEquals("jobb", jobb.get("output.override")); Assert.assertEquals("joba", jobb.get("output.joba")); Props jobbInnerJobA = nodeMap.get("jobb:innerJobA").getInputProps(); Assert.assertEquals("test1.1", jobbInnerJobA.get("param1")); Assert.assertEquals("test1.2", jobbInnerJobA.get("param2")); Assert.assertEquals("test1.3", jobbInnerJobA.get("param3")); Assert.assertEquals("override.4", jobbInnerJobA.get("param4")); Assert.assertEquals("test2.5", jobbInnerJobA.get("param5")); Assert.assertEquals("test2.6", jobbInnerJobA.get("param6")); Assert.assertEquals("test2.7", jobbInnerJobA.get("param7")); Assert.assertEquals("test2.8", jobbInnerJobA.get("param8")); Assert.assertEquals("joba", jobbInnerJobA.get("output.joba")); // 3. jobb:Inner completes /// innerJobA completes InteractiveTestJob.getTestJob("jobb:innerJobA") .succeedJob(Props.of("output.jobb.innerJobA", "jobb.innerJobA")); pause(250); expectedStateMap.put("jobb:innerJobA", Status.SUCCEEDED); expectedStateMap.put("jobb:innerJobB", Status.RUNNING); expectedStateMap.put("jobb:innerJobC", Status.RUNNING); compareStates(expectedStateMap, nodeMap); Props jobbInnerJobB = nodeMap.get("jobb:innerJobB").getInputProps(); Assert.assertEquals("test1.1", jobbInnerJobB.get("param1")); Assert.assertEquals("override.4", jobbInnerJobB.get("param4")); Assert.assertEquals("jobb.innerJobA", jobbInnerJobB.get("output.jobb.innerJobA")); Assert.assertEquals("moo", jobbInnerJobB.get("testprops")); /// innerJobB, C completes InteractiveTestJob.getTestJob("jobb:innerJobB") .succeedJob(Props.of("output.jobb.innerJobB", "jobb.innerJobB")); InteractiveTestJob.getTestJob("jobb:innerJobC") .succeedJob(Props.of("output.jobb.innerJobC", "jobb.innerJobC")); pause(250); expectedStateMap.put("jobb:innerJobB", Status.SUCCEEDED); expectedStateMap.put("jobb:innerJobC", Status.SUCCEEDED); expectedStateMap.put("jobb:innerFlow", Status.RUNNING); compareStates(expectedStateMap, nodeMap); Props jobbInnerJobD = nodeMap.get("jobb:innerFlow").getInputProps(); Assert.assertEquals("test1.1", jobbInnerJobD.get("param1")); Assert.assertEquals("override.4", jobbInnerJobD.get("param4")); Assert.assertEquals("jobb.innerJobB", jobbInnerJobD.get("output.jobb.innerJobB")); Assert.assertEquals("jobb.innerJobC", jobbInnerJobD.get("output.jobb.innerJobC")); // 4. Finish up on inner flow for jobb InteractiveTestJob.getTestJob("jobb:innerFlow") .succeedJob(Props.of("output1.jobb", "test1", "output2.jobb", "test2")); pause(250); expectedStateMap.put("jobb:innerFlow", Status.SUCCEEDED); expectedStateMap.put("jobb", Status.SUCCEEDED); compareStates(expectedStateMap, nodeMap); Props jobbOutput = nodeMap.get("jobb").getOutputProps(); Assert.assertEquals("test1", jobbOutput.get("output1.jobb")); Assert.assertEquals("test2", jobbOutput.get("output2.jobb")); // 5. Finish jobc, jobd InteractiveTestJob.getTestJob("jobc").succeedJob(Props.of("output.jobc", "jobc")); pause(250); expectedStateMap.put("jobc", Status.SUCCEEDED); compareStates(expectedStateMap, nodeMap); InteractiveTestJob.getTestJob("jobd:innerJobA").succeedJob(); pause(250); InteractiveTestJob.getTestJob("jobd:innerFlow2").succeedJob(); pause(250); expectedStateMap.put("jobd:innerJobA", Status.SUCCEEDED); expectedStateMap.put("jobd:innerFlow2", Status.SUCCEEDED); expectedStateMap.put("jobd", Status.SUCCEEDED); expectedStateMap.put("jobe", Status.RUNNING); compareStates(expectedStateMap, nodeMap); Props jobd = nodeMap.get("jobe").getInputProps(); Assert.assertEquals("test1", jobd.get("output1.jobb")); Assert.assertEquals("jobc", jobd.get("output.jobc")); // 6. Finish off flow InteractiveTestJob.getTestJob("joba1").succeedJob(); pause(250); InteractiveTestJob.getTestJob("jobe").succeedJob(); pause(250); expectedStateMap.put("joba1", Status.SUCCEEDED); expectedStateMap.put("jobe", Status.SUCCEEDED); expectedStateMap.put("jobf", Status.RUNNING); compareStates(expectedStateMap, nodeMap); InteractiveTestJob.getTestJob("jobf").succeedJob(); pause(250); expectedStateMap.put("jobf", Status.SUCCEEDED); compareStates(expectedStateMap, nodeMap); Assert.assertEquals(Status.SUCCEEDED, flow.getStatus()); Assert.assertFalse(thread.isAlive()); }
From source file:src.gui.ItSIMPLE.java
@Override public void windowClosing(WindowEvent evt) { if (itsimpleInst != null) { //Kill all threads if (itsimpleInst.getExe() != null) { itsimpleInst.getExe().destroyProcess(); }/*w w w .j a va 2 s.c om*/ Thread currentThread = itsimpleInst.getCurrentThread(); if (currentThread != null && currentThread.isAlive()) { currentThread.interrupt(); } Thread plannerThread = itsimpleInst.getPlannerThread(); if (plannerThread != null && plannerThread.isAlive()) { plannerThread.interrupt(); } } System.exit(0); }
From source file:org.eclipse.jdt.core.tests.model.JavaSearchBugsTests.java
/** * @bug 261722: [search] NPE after removing a project * @test Ensure that no NPE occurs when project is deleted before the end of the search request * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=261722" *///from w w w. j a v a 2 s .c o m public void testBug261722() throws Exception { IPath projectPath = null; IJavaProject javaProject = null; try { // Create jar and project final int MAX = 10; final String[] pathsAndContents = new String[(1 + MAX) * 2]; pathsAndContents[0] = "p261722/X.java"; pathsAndContents[1] = "package p261722;\n" + "public class X {}"; for (int i = 1; i <= MAX; i++) { String className = (i < 10) ? "X0" + i : "X" + i; pathsAndContents[i * 2] = "p261722/" + className + ".java"; pathsAndContents[i * 2 + 1] = "package p261722;\n" + "public class " + className + " extends X {}"; } javaProject = createJavaProject("P"); projectPath = javaProject.getProject().getLocation(); addLibrary(javaProject, "lib261722.jar", "lib261722.zip", pathsAndContents, "1.4"); waitUntilIndexesReady(); // Create a specific requestor slowed down to give the main thread // a chance to delete the project before the end of the search request class TestSearchRequestor extends SearchRequestor { int count = 0; public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException { try { Thread.sleep(100); } catch (InterruptedException e) { // skip } this.count++; } } // Search in separated thread final TestSearchRequestor requestor = new TestSearchRequestor(); final SearchPattern pattern = SearchPattern.createPattern("X*", IJavaSearchConstants.DECLARATIONS, IJavaSearchConstants.TYPE, SearchPattern.R_PATTERN_MATCH); final IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }); Runnable search = new Runnable() { public void run() { try { new SearchEngine().search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); } catch (CoreException e) { throw new RuntimeException(e); } } }; Thread thread = new Thread(search); thread.start(); // Delete project in current thread after being sure that the search // request was started while (requestor.count < (MAX / 3)) { Thread.sleep(10); } deleteProject(javaProject); // Wait until search thread is finished while (thread.isAlive()) { Thread.sleep(100); } // Verify search results assertEquals("Unexpected matches count", MAX + 1, requestor.count); } finally { if (projectPath != null) { deleteFile("/P/lib261722.jar"); deleteFile("/P/lib261722.zip"); } } }