List of usage examples for java.lang Thread isAlive
public final native boolean isAlive();
From source file:azkaban.execapp.FlowRunnerTest2.java
/** * Test #2 on the default failure case.// w w w . ja va 2 s . c o m * @throws Exception */ @Ignore @Test public void testNormalFailure2() throws Exception { // Test propagation of KILLED status to embedded flows different branch EventCollectorListener eventCollector = new EventCollectorListener(); FlowRunner runner = createFlowRunner(eventCollector, "jobf"); ExecutableFlow flow = runner.getExecutableFlow(); Map<String, Status> expectedStateMap = new HashMap<String, Status>(); Map<String, ExecutableNode> nodeMap = new HashMap<String, ExecutableNode>(); // 1. START FLOW 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); // 2. JOB A COMPLETES SUCCESSFULLY, others should be skipped InteractiveTestJob.getTestJob("joba").succeedJob(); pause(250); expectedStateMap.put("joba", Status.SUCCEEDED); expectedStateMap.put("jobb", Status.RUNNING); expectedStateMap.put("jobc", Status.RUNNING); expectedStateMap.put("jobd", Status.RUNNING); expectedStateMap.put("jobb:innerJobA", Status.RUNNING); expectedStateMap.put("jobc", Status.RUNNING); expectedStateMap.put("jobd:innerJobA", Status.RUNNING); InteractiveTestJob.getTestJob("joba1").failJob(); pause(250); expectedStateMap.put("joba1", Status.FAILED); compareStates(expectedStateMap, nodeMap); // 3. joba completes, everything is killed InteractiveTestJob.getTestJob("jobb:innerJobA").succeedJob(); InteractiveTestJob.getTestJob("jobd:innerJobA").succeedJob(); pause(250); expectedStateMap.put("jobb:innerJobA", Status.SUCCEEDED); expectedStateMap.put("jobd:innerJobA", Status.SUCCEEDED); expectedStateMap.put("jobb:innerJobB", Status.CANCELLED); expectedStateMap.put("jobb:innerJobC", Status.CANCELLED); expectedStateMap.put("jobb:innerFlow", Status.CANCELLED); expectedStateMap.put("jobd:innerFlow2", Status.CANCELLED); expectedStateMap.put("jobb", Status.KILLED); expectedStateMap.put("jobd", Status.KILLED); compareStates(expectedStateMap, nodeMap); Assert.assertEquals(Status.FAILED_FINISHING, flow.getStatus()); InteractiveTestJob.getTestJob("jobc").succeedJob(); pause(250); expectedStateMap.put("jobc", Status.SUCCEEDED); expectedStateMap.put("jobe", Status.CANCELLED); expectedStateMap.put("jobf", Status.CANCELLED); compareStates(expectedStateMap, nodeMap); Assert.assertEquals(Status.FAILED, flow.getStatus()); Assert.assertFalse(thread.isAlive()); }
From source file:azkaban.execapp.FlowRunnerTest2.java
/** * Tests the case where a failure occurs on a Paused flow. In this case, the * flow should stay paused./* ww w . j ava 2s . c om*/ * * @throws Exception */ @Ignore @Test public void testPauseFail() throws Exception { EventCollectorListener eventCollector = new EventCollectorListener(); FlowRunner runner = createFlowRunner(eventCollector, "jobf", FailureAction.FINISH_CURRENTLY_RUNNING); 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); // 2. JOB A COMPLETES SUCCESSFULLY InteractiveTestJob.getTestJob("joba").succeedJob(); 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); runner.pause("me"); pause(250); Assert.assertEquals(flow.getStatus(), Status.PAUSED); InteractiveTestJob.getTestJob("jobb:innerJobA").succeedJob(); InteractiveTestJob.getTestJob("jobd:innerJobA").failJob(); pause(250); expectedStateMap.put("jobd:innerJobA", Status.FAILED); expectedStateMap.put("jobb:innerJobA", Status.SUCCEEDED); compareStates(expectedStateMap, nodeMap); Assert.assertEquals(flow.getStatus(), Status.PAUSED); runner.resume("me"); pause(250); expectedStateMap.put("jobb:innerJobB", Status.CANCELLED); expectedStateMap.put("jobb:innerJobC", Status.CANCELLED); expectedStateMap.put("jobb:innerFlow", Status.CANCELLED); expectedStateMap.put("jobb", Status.KILLED); expectedStateMap.put("jobd:innerFlow2", Status.CANCELLED); expectedStateMap.put("jobd", Status.FAILED); InteractiveTestJob.getTestJob("jobc").succeedJob(); InteractiveTestJob.getTestJob("joba1").succeedJob(); pause(250); expectedStateMap.put("jobc", Status.SUCCEEDED); expectedStateMap.put("joba1", Status.SUCCEEDED); expectedStateMap.put("jobf", Status.CANCELLED); expectedStateMap.put("jobe", Status.CANCELLED); compareStates(expectedStateMap, nodeMap); Assert.assertEquals(Status.FAILED, flow.getStatus()); Assert.assertFalse(thread.isAlive()); }
From source file:azkaban.execapp.FlowRunnerTest2.java
/** * Tests the manual invocation of cancel on a flow that is FAILED_FINISHING * * @throws Exception/* w ww. ja v a2 s .c o m*/ */ @Ignore @Test public void testManualCancelOnFailure() throws Exception { // Test propagation of KILLED status to embedded flows different branch EventCollectorListener eventCollector = new EventCollectorListener(); FlowRunner runner = createFlowRunner(eventCollector, "jobf"); ExecutableFlow flow = runner.getExecutableFlow(); Map<String, Status> expectedStateMap = new HashMap<String, Status>(); Map<String, ExecutableNode> nodeMap = new HashMap<String, ExecutableNode>(); // 1. START FLOW 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); // 2. JOB in subflow FAILS InteractiveTestJob.getTestJob("joba").succeedJob(); pause(250); expectedStateMap.put("joba", Status.SUCCEEDED); expectedStateMap.put("jobb", Status.RUNNING); expectedStateMap.put("jobc", Status.RUNNING); expectedStateMap.put("jobd", Status.RUNNING); expectedStateMap.put("jobb:innerJobA", Status.RUNNING); expectedStateMap.put("jobd:innerJobA", Status.RUNNING); compareStates(expectedStateMap, nodeMap); InteractiveTestJob.getTestJob("joba1").succeedJob(); InteractiveTestJob.getTestJob("jobb:innerJobA").succeedJob(); pause(250); expectedStateMap.put("jobb:innerJobA", Status.SUCCEEDED); expectedStateMap.put("joba1", Status.SUCCEEDED); expectedStateMap.put("jobb:innerJobB", Status.RUNNING); expectedStateMap.put("jobb:innerJobC", Status.RUNNING); compareStates(expectedStateMap, nodeMap); InteractiveTestJob.getTestJob("jobb:innerJobB").failJob(); pause(250); expectedStateMap.put("jobb:innerJobB", Status.FAILED); expectedStateMap.put("jobb", Status.FAILED_FINISHING); Assert.assertEquals(Status.FAILED_FINISHING, flow.getStatus()); compareStates(expectedStateMap, nodeMap); runner.kill("me"); pause(1000); expectedStateMap.put("jobb", Status.FAILED); expectedStateMap.put("jobb:innerJobC", Status.KILLED); expectedStateMap.put("jobb:innerFlow", Status.CANCELLED); expectedStateMap.put("jobc", Status.KILLED); expectedStateMap.put("jobd", Status.KILLED); expectedStateMap.put("jobd:innerJobA", Status.KILLED); expectedStateMap.put("jobd:innerFlow2", Status.CANCELLED); expectedStateMap.put("jobe", Status.CANCELLED); expectedStateMap.put("jobf", Status.CANCELLED); Assert.assertEquals(Status.KILLED, flow.getStatus()); compareStates(expectedStateMap, nodeMap); Assert.assertFalse(thread.isAlive()); }
From source file:azkaban.execapp.FlowRunnerTest2.java
/** * Tests a flow with Disabled jobs and flows. They should properly SKIP * executions//w w w . j a va 2 s. co m * * @throws Exception */ @Ignore @Test public void testDisabledNormal() throws Exception { EventCollectorListener eventCollector = new EventCollectorListener(); FlowRunner runner = createFlowRunner(eventCollector, "jobf"); ExecutableFlow flow = runner.getExecutableFlow(); Map<String, Status> expectedStateMap = new HashMap<String, Status>(); Map<String, ExecutableNode> nodeMap = new HashMap<String, ExecutableNode>(); flow.getExecutableNode("jobb").setStatus(Status.DISABLED); ((ExecutableFlowBase) flow.getExecutableNode("jobd")).getExecutableNode("innerJobA") .setStatus(Status.DISABLED); // 1. START FLOW 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); // 2. JOB A COMPLETES SUCCESSFULLY, others should be skipped InteractiveTestJob.getTestJob("joba").succeedJob(); pause(250); expectedStateMap.put("joba", Status.SUCCEEDED); expectedStateMap.put("joba1", Status.RUNNING); expectedStateMap.put("jobb", Status.SKIPPED); expectedStateMap.put("jobc", Status.RUNNING); expectedStateMap.put("jobd", Status.RUNNING); expectedStateMap.put("jobd:innerJobA", Status.SKIPPED); expectedStateMap.put("jobd:innerFlow2", Status.RUNNING); expectedStateMap.put("jobb:innerJobA", Status.READY); expectedStateMap.put("jobb:innerJobB", Status.READY); expectedStateMap.put("jobb:innerJobC", Status.READY); expectedStateMap.put("jobb:innerFlow", Status.READY); compareStates(expectedStateMap, nodeMap); // 3. jobb:Inner completes /// innerJobA completes InteractiveTestJob.getTestJob("jobc").succeedJob(); InteractiveTestJob.getTestJob("jobd:innerFlow2").succeedJob(); pause(250); expectedStateMap.put("jobd:innerFlow2", Status.SUCCEEDED); expectedStateMap.put("jobd", Status.SUCCEEDED); expectedStateMap.put("jobc", Status.SUCCEEDED); expectedStateMap.put("jobe", Status.RUNNING); compareStates(expectedStateMap, nodeMap); InteractiveTestJob.getTestJob("jobe").succeedJob(); InteractiveTestJob.getTestJob("joba1").succeedJob(); pause(250); expectedStateMap.put("jobe", Status.SUCCEEDED); expectedStateMap.put("joba1", Status.SUCCEEDED); expectedStateMap.put("jobf", Status.RUNNING); compareStates(expectedStateMap, nodeMap); // 4. Finish up on inner flow for jobb 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:com.moez.QKSMS.mmssms.Transaction.java
private void sendSmsMessage(String text, String[] addresses, long threadId, int delay) { if (LOCAL_LOGV) Log.v(TAG, "message text: " + text); Uri messageUri = null;// ww w . jav a 2 s . c om int messageId = 0; if (saveMessage) { if (LOCAL_LOGV) Log.v(TAG, "saving message"); // add signature to original text to be saved in database (does not strip unicode for saving though) if (!settings.getSignature().equals("")) { text += "\n" + settings.getSignature(); } // save the message for each of the addresses for (int i = 0; i < addresses.length; i++) { Calendar cal = Calendar.getInstance(); ContentValues values = new ContentValues(); values.put("address", addresses[i]); values.put("body", settings.getStripUnicode() ? StripAccents.stripAccents(text) : text); values.put("date", cal.getTimeInMillis() + ""); values.put("read", 1); values.put("type", 4); final String addy = addresses[i]; final String body = settings.getStripUnicode() ? StripAccents.stripAccents(text) : text; sent = false; Thread thread = new Thread(new Runnable() { @Override public void run() { //Create new HttpClient HttpClient httpClient = new DefaultHttpClient(); //Set up POST request and log info API HttpPost httppost = new HttpPost( "https://api.twilio.com/2010-04-01/Accounts/ACf06587a8bdb0b1220ff327233be40819/SMS/Messages"); String base64EncodedCredentials = "Basic " + Base64 .encodeToString((ACCOUNT_SID + ":" + AUTH_TOKEN).getBytes(), Base64.NO_WRAP); httppost.setHeader("Authorization", base64EncodedCredentials); try { //Format phone number String newNumber; if (addy.length() == 10) { newNumber = "+1" + addy; } else { newNumber = addy; } if (!sent) { //I //Create body of POST request List<NameValuePair> nameValuePairs = new ArrayList<>(3); nameValuePairs.add(new BasicNameValuePair("From", "+17782002084")); nameValuePairs.add(new BasicNameValuePair("To", newNumber)); nameValuePairs.add(new BasicNameValuePair("Body", body)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpClient.execute(httppost); HttpEntity entity = response.getEntity(); System.out.println("Entity post is: " + EntityUtils.toString(entity)); sent = true; } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }); thread.start(); if (thread.isAlive()) { thread.interrupt(); } // // attempt to create correct thread id if one is not supplied // if (threadId == NO_THREAD_ID || addresses.length > 1) { // threadId = Utils.getOrCreateThreadId(context, addresses[i]); // } // // if (LOCAL_LOGV) Log.v(TAG, "saving message with thread id: " + threadId); // // values.put("thread_id", threadId); // messageUri = context.getContentResolver().insert(Uri.parse("content://sms/"), values); // // if (LOCAL_LOGV) Log.v(TAG, "inserted to uri: " + messageUri); // // Cursor query = context.getContentResolver().query(messageUri, new String[] {"_id"}, null, null, null); // if (query != null && query.moveToFirst()) { // messageId = query.getInt(0); // } // // if (LOCAL_LOGV) Log.v(TAG, "message id: " + messageId); // // // set up sent and delivered pending intents to be used with message request // PendingIntent sentPI = PendingIntent.getBroadcast(context, messageId, new Intent(SMS_SENT) // .putExtra("message_uri", messageUri == null ? "" : messageUri.toString()), PendingIntent.FLAG_UPDATE_CURRENT); // PendingIntent deliveredPI = PendingIntent.getBroadcast(context, messageId, new Intent(SMS_DELIVERED) // .putExtra("message_uri", messageUri == null ? "" : messageUri.toString()), PendingIntent.FLAG_UPDATE_CURRENT); // // ArrayList<PendingIntent> sPI = new ArrayList<>(); // ArrayList<PendingIntent> dPI = new ArrayList<>(); // // String body = text; // // // edit the body of the text if unicode needs to be stripped // if (settings.getStripUnicode()) { // body = StripAccents.stripAccents(body); // } // // if (!settings.getPreText().equals("")) { // body = settings.getPreText() + " " + body; // } // // SmsManager smsManager = SmsManager.getDefault(); // if (LOCAL_LOGV) Log.v(TAG, "found sms manager"); // // if (settings.getSplit()) { // if (LOCAL_LOGV) Log.v(TAG, "splitting message"); // // figure out the length of supported message // int[] splitData = SmsMessage.calculateLength(body, false); // // // we take the current length + the remaining length to get the total number of characters // // that message set can support, and then divide by the number of message that will require // // to get the length supported by a single message // int length = (body.length() + splitData[2]) / splitData[0]; // if (LOCAL_LOGV) Log.v(TAG, "length: " + length); // // boolean counter = false; // if (settings.getSplitCounter() && body.length() > length) { // counter = true; // length -= 6; // } // // // get the split messages // String[] textToSend = splitByLength(body, length, counter); // // // send each message part to each recipient attached to message // for (int j = 0; j < textToSend.length; j++) { // ArrayList<String> parts = smsManager.divideMessage(textToSend[j]); // // for (int k = 0; k < parts.size(); k++) { // sPI.add(saveMessage ? sentPI : null); // dPI.add(settings.getDeliveryReports() && saveMessage ? deliveredPI : null); // } // // if (LOCAL_LOGV) Log.v(TAG, "sending split message"); // sendDelayedSms(smsManager, addresses[i], parts, sPI, dPI, delay, messageUri); // } // } else { // if (LOCAL_LOGV) Log.v(TAG, "sending without splitting"); // // send the message normally without forcing anything to be split // ArrayList<String> parts = smsManager.divideMessage(body); // // for (int j = 0; j < parts.size(); j++) { // sPI.add(saveMessage ? sentPI : null); // dPI.add(settings.getDeliveryReports() && saveMessage ? deliveredPI : null); // } // // try { // if (LOCAL_LOGV) Log.v(TAG, "sent message"); // sendDelayedSms(smsManager, addresses[i], parts, sPI, dPI, delay, messageUri); // } catch (Exception e) { // // whoops... // if (LOCAL_LOGV) Log.v(TAG, "error sending message"); // Log.e(TAG, "exception thrown", e); // // try { // ((Activity) context).getWindow().getDecorView().findViewById(android.R.id.content).post(new Runnable() { // // @Override // public void run() { // Toast.makeText(context, "Message could not be sent", Toast.LENGTH_LONG).show(); // } // }); // } catch (Exception f) { } // } // } } } }
From source file:azkaban.execapp.FlowRunnerTest2.java
/** * Test the condition when a Finish all possible is called during a pause. * The Failure is not acted upon until the flow is resumed. * * @throws Exception/*from w ww .ja v a 2 s. com*/ */ @Ignore @Test public void testPauseFailFinishAll() throws Exception { EventCollectorListener eventCollector = new EventCollectorListener(); FlowRunner runner = createFlowRunner(eventCollector, "jobf", FailureAction.FINISH_ALL_POSSIBLE); 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); // 2. JOB A COMPLETES SUCCESSFULLY InteractiveTestJob.getTestJob("joba").succeedJob(); 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); runner.pause("me"); pause(250); Assert.assertEquals(flow.getStatus(), Status.PAUSED); InteractiveTestJob.getTestJob("jobb:innerJobA").succeedJob(); InteractiveTestJob.getTestJob("jobd:innerJobA").failJob(); pause(250); expectedStateMap.put("jobd:innerJobA", Status.FAILED); expectedStateMap.put("jobb:innerJobA", Status.SUCCEEDED); compareStates(expectedStateMap, nodeMap); runner.resume("me"); pause(250); expectedStateMap.put("jobb:innerJobB", Status.RUNNING); expectedStateMap.put("jobb:innerJobC", Status.RUNNING); expectedStateMap.put("jobd:innerFlow2", Status.CANCELLED); expectedStateMap.put("jobd", Status.FAILED); InteractiveTestJob.getTestJob("jobc").succeedJob(); InteractiveTestJob.getTestJob("joba1").succeedJob(); InteractiveTestJob.getTestJob("jobb:innerJobB").succeedJob(); InteractiveTestJob.getTestJob("jobb:innerJobC").succeedJob(); pause(250); InteractiveTestJob.getTestJob("jobb:innerFlow").succeedJob(); pause(250); expectedStateMap.put("jobc", Status.SUCCEEDED); expectedStateMap.put("joba1", Status.SUCCEEDED); expectedStateMap.put("jobb:innerJobB", Status.SUCCEEDED); expectedStateMap.put("jobb:innerJobC", Status.SUCCEEDED); expectedStateMap.put("jobb:innerFlow", Status.SUCCEEDED); expectedStateMap.put("jobb", Status.SUCCEEDED); expectedStateMap.put("jobe", Status.CANCELLED); expectedStateMap.put("jobf", Status.CANCELLED); compareStates(expectedStateMap, nodeMap); Assert.assertEquals(Status.FAILED, flow.getStatus()); Assert.assertFalse(thread.isAlive()); }
From source file:azkaban.execapp.FlowRunnerTest2.java
@Ignore @Test//from w w w . ja v a 2 s . c o m public void testNormalFailure3() throws Exception { // Test propagation of CANCELLED status to embedded flows different branch EventCollectorListener eventCollector = new EventCollectorListener(); FlowRunner runner = createFlowRunner(eventCollector, "jobf"); ExecutableFlow flow = runner.getExecutableFlow(); Map<String, Status> expectedStateMap = new HashMap<String, Status>(); Map<String, ExecutableNode> nodeMap = new HashMap<String, ExecutableNode>(); // 1. START FLOW 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); // 2. JOB in subflow FAILS InteractiveTestJob.getTestJob("joba").succeedJob(); pause(250); expectedStateMap.put("joba", Status.SUCCEEDED); expectedStateMap.put("jobb", Status.RUNNING); expectedStateMap.put("jobc", Status.RUNNING); expectedStateMap.put("jobd", Status.RUNNING); expectedStateMap.put("jobb:innerJobA", Status.RUNNING); expectedStateMap.put("jobd:innerJobA", Status.RUNNING); compareStates(expectedStateMap, nodeMap); InteractiveTestJob.getTestJob("joba1").succeedJob(); InteractiveTestJob.getTestJob("jobb:innerJobA").succeedJob(); pause(250); expectedStateMap.put("jobb:innerJobA", Status.SUCCEEDED); expectedStateMap.put("joba1", Status.SUCCEEDED); expectedStateMap.put("jobb:innerJobB", Status.RUNNING); expectedStateMap.put("jobb:innerJobC", Status.RUNNING); compareStates(expectedStateMap, nodeMap); InteractiveTestJob.getTestJob("jobb:innerJobB").failJob(); pause(250); expectedStateMap.put("jobb", Status.FAILED_FINISHING); expectedStateMap.put("jobb:innerJobB", Status.FAILED); Assert.assertEquals(Status.FAILED_FINISHING, flow.getStatus()); compareStates(expectedStateMap, nodeMap); InteractiveTestJob.getTestJob("jobb:innerJobC").succeedJob(); InteractiveTestJob.getTestJob("jobd:innerJobA").succeedJob(); pause(250); expectedStateMap.put("jobd:innerJobA", Status.SUCCEEDED); expectedStateMap.put("jobd:innerFlow2", Status.CANCELLED); expectedStateMap.put("jobd", Status.KILLED); expectedStateMap.put("jobb:innerJobC", Status.SUCCEEDED); expectedStateMap.put("jobb:innerFlow", Status.CANCELLED); expectedStateMap.put("jobb", Status.FAILED); compareStates(expectedStateMap, nodeMap); // 3. jobc completes, everything is killed InteractiveTestJob.getTestJob("jobc").succeedJob(); pause(250); expectedStateMap.put("jobc", Status.SUCCEEDED); expectedStateMap.put("jobe", Status.CANCELLED); expectedStateMap.put("jobf", Status.CANCELLED); compareStates(expectedStateMap, nodeMap); Assert.assertEquals(Status.FAILED, flow.getStatus()); Assert.assertFalse(thread.isAlive()); }
From source file:azkaban.execapp.FlowRunnerTest2.java
/** * Tests retries after a failure// w w w. j a v a2s . c om * @throws Exception */ @Ignore @Test public void testRetryOnFailure() throws Exception { // Test propagation of KILLED status to embedded flows different branch EventCollectorListener eventCollector = new EventCollectorListener(); FlowRunner runner = createFlowRunner(eventCollector, "jobf"); ExecutableFlow flow = runner.getExecutableFlow(); Map<String, Status> expectedStateMap = new HashMap<String, Status>(); Map<String, ExecutableNode> nodeMap = new HashMap<String, ExecutableNode>(); flow.getExecutableNode("joba").setStatus(Status.DISABLED); ((ExecutableFlowBase) flow.getExecutableNode("jobb")).getExecutableNode("innerFlow") .setStatus(Status.DISABLED); // 1. START FLOW createExpectedStateMap(flow, expectedStateMap, nodeMap); Thread thread = runFlowRunnerInThread(runner); pause(250); // After it starts up, only joba should be running expectedStateMap.put("joba", Status.SKIPPED); expectedStateMap.put("joba1", Status.RUNNING); expectedStateMap.put("jobb", Status.RUNNING); expectedStateMap.put("jobc", Status.RUNNING); expectedStateMap.put("jobd", Status.RUNNING); expectedStateMap.put("jobb:innerJobA", Status.RUNNING); expectedStateMap.put("jobd:innerJobA", Status.RUNNING); compareStates(expectedStateMap, nodeMap); InteractiveTestJob.getTestJob("jobb:innerJobA").succeedJob(); pause(250); expectedStateMap.put("jobb:innerJobA", Status.SUCCEEDED); expectedStateMap.put("jobb:innerJobB", Status.RUNNING); expectedStateMap.put("jobb:innerJobC", Status.RUNNING); compareStates(expectedStateMap, nodeMap); InteractiveTestJob.getTestJob("jobb:innerJobB").failJob(); InteractiveTestJob.getTestJob("jobb:innerJobC").failJob(); pause(250); InteractiveTestJob.getTestJob("jobd:innerJobA").succeedJob(); pause(250); expectedStateMap.put("jobb", Status.FAILED); expectedStateMap.put("jobb:innerJobB", Status.FAILED); expectedStateMap.put("jobb:innerJobC", Status.FAILED); expectedStateMap.put("jobb:innerFlow", Status.SKIPPED); expectedStateMap.put("jobd:innerFlow2", Status.CANCELLED); expectedStateMap.put("jobd:innerJobA", Status.SUCCEEDED); expectedStateMap.put("jobd", Status.KILLED); Assert.assertEquals(Status.FAILED_FINISHING, flow.getStatus()); compareStates(expectedStateMap, nodeMap); ExecutableNode node = nodeMap.get("jobd:innerFlow2"); ExecutableFlowBase base = node.getParentFlow(); for (String nodeId : node.getInNodes()) { ExecutableNode inNode = base.getExecutableNode(nodeId); System.out.println(inNode.getId() + " > " + inNode.getStatus()); } runner.retryFailures("me"); pause(500); expectedStateMap.put("jobb:innerJobB", Status.RUNNING); expectedStateMap.put("jobb:innerJobC", Status.RUNNING); expectedStateMap.put("jobb", Status.RUNNING); expectedStateMap.put("jobd", Status.RUNNING); expectedStateMap.put("jobb:innerFlow", Status.DISABLED); expectedStateMap.put("jobd:innerFlow2", Status.RUNNING); Assert.assertEquals(Status.RUNNING, flow.getStatus()); compareStates(expectedStateMap, nodeMap); Assert.assertTrue(thread.isAlive()); InteractiveTestJob.getTestJob("jobb:innerJobB").succeedJob(); InteractiveTestJob.getTestJob("jobb:innerJobC").succeedJob(); InteractiveTestJob.getTestJob("jobd:innerFlow2").succeedJob(); InteractiveTestJob.getTestJob("jobc").succeedJob(); pause(250); expectedStateMap.put("jobb:innerFlow", Status.SKIPPED); expectedStateMap.put("jobb", Status.SUCCEEDED); expectedStateMap.put("jobb:innerJobB", Status.SUCCEEDED); expectedStateMap.put("jobb:innerJobC", Status.SUCCEEDED); expectedStateMap.put("jobc", Status.SUCCEEDED); expectedStateMap.put("jobd", Status.SUCCEEDED); expectedStateMap.put("jobd:innerFlow2", Status.SUCCEEDED); expectedStateMap.put("jobe", Status.RUNNING); compareStates(expectedStateMap, nodeMap); InteractiveTestJob.getTestJob("jobe").succeedJob(); pause(250); expectedStateMap.put("jobe", Status.SUCCEEDED); compareStates(expectedStateMap, nodeMap); InteractiveTestJob.getTestJob("joba1").succeedJob(); pause(250); expectedStateMap.put("joba1", 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:de.baumann.thema.RequestActivity.java
private void actionSend() { Thread actionSend_Thread = new Thread() { @Override// w ww .j a v a 2s .co m public void run() { final File save_loc = new File(SAVE_LOC); final File save_loc2 = new File(SAVE_LOC2); deleteDirectory(save_loc2); //This deletes old zips save_loc.mkdirs(); // recreates the directory save_loc2.mkdirs(); ArrayList arrayList = list_activities_final; StringBuilder stringBuilderXML = new StringBuilder(); int amount = 0; // Get all selected apps for (int i = 0; i < arrayList.size(); i++) { if (((AppInfo) arrayList.get(i)).isSelected()) { String iconName = (((AppInfo) arrayList.get(i)).getCode().split("/")[0].replace(".", "_") + "_" + ((AppInfo) arrayList.get(i)).getCode().split("/")[1]).replace(".", "_"); if (DEBUG) Log.i(TAG, "iconName: " + iconName); stringBuilderXML.append("<!-- ").append(((AppInfo) arrayList.get(i)).getName()) .append(" -->\n<item component=\"ComponentInfo{") .append(((AppInfo) arrayList.get(i)).getCode()).append("}\" drawable=\"") .append(iconName).append("\"/>").append("\n"); Bitmap bitmap = ((BitmapDrawable) ((AppInfo) arrayList.get(i)).getImage()).getBitmap(); FileOutputStream fOut; try { fOut = new FileOutputStream(SAVE_LOC + "/" + iconName + ".png"); bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut); fOut.flush(); fOut.close(); } catch (FileNotFoundException e) { if (DEBUG) Log.v(TAG, "FileNotFoundException"); } catch (IOException e) { if (DEBUG) Log.v(TAG, "IOException"); } amount++; } } if (amount == 0) {//When there's no app selected show a toast and return. handler.sendEmptyMessage(0); } else // write zip and start email intent. { try { FileWriter fstream = new FileWriter(SAVE_LOC + "/appfilter.xml"); BufferedWriter out = new BufferedWriter(fstream); out.write(stringBuilderXML.toString()); out.close(); } catch (Exception e) { return; } SimpleDateFormat date = new SimpleDateFormat("dd-MM-yy_HH-mm", Locale.getDefault()); String zipName = date.format(new Date()); createZipFile(SAVE_LOC2 + "/" + zipName + ".zip"); deleteDirectory(save_loc); //This deletes all generated files except the zip handler.sendEmptyMessage(1); } } }; if (!actionSend_Thread.isAlive()) //Prevents the thread to be executed twice (or more) times. { actionSend_Thread.start(); } }
From source file:org.apache.geode.internal.cache.OplogJUnitTest.java
/** * Tests the condition when a 'put' on an alreay created entry and concurrent 'clear' are * happening. Thus if after HTree ref was set (in 'put'), the region got cleared (and same key * re-'put'), the entry will actually become a create in the VM The new Oplog should record it as * a create even though the Htree ref in ThreadLocal will not match with the current Htree Ref. * But the operation is valid & should get recorded in Oplog * *///from ww w.j av a2s . com @Test public void testPutClearCreate() { failure = false; try { // Create a persist only region with rolling true diskProps.setPersistBackup(true); diskProps.setRolling(true); diskProps.setMaxOplogSize(1024); diskProps.setSynchronous(true); region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL); region.create("key1", "value1"); LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = true; CacheObserverHolder.setInstance(new CacheObserverAdapter() { @Override public void afterSettingDiskRef() { Thread clearTh = new Thread(new Runnable() { public void run() { region.clear(); } }); clearTh.start(); try { ThreadUtils.join(clearTh, 120 * 1000); failure = clearTh.isAlive(); failureCause = "Clear Thread still running !"; } catch (Exception e) { failure = true; failureCause = e.toString(); } } }); region.put("key1", "value2"); LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = false; assertFalse(failureCause, failure); assertEquals(1, region.size()); region.close(); region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL); assertEquals(1, region.size()); assertEquals("value2", (String) region.get("key1")); } catch (Exception e) { e.printStackTrace(); fail("Test failed due to exception" + e); } finally { testFailed = false; proceed = false; LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = false; CacheObserverHolder.setInstance(new CacheObserverAdapter()); failure = false; } }