Return-Path: X-Original-To: apmail-continuum-commits-archive@www.apache.org Delivered-To: apmail-continuum-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 15AD7176A5 for ; Sat, 31 Jan 2015 03:34:03 +0000 (UTC) Received: (qmail 76225 invoked by uid 500); 31 Jan 2015 03:34:03 -0000 Delivered-To: apmail-continuum-commits-archive@continuum.apache.org Received: (qmail 76188 invoked by uid 500); 31 Jan 2015 03:34:03 -0000 Mailing-List: contact commits-help@continuum.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@continuum.apache.org Delivered-To: mailing list commits@continuum.apache.org Received: (qmail 76175 invoked by uid 99); 31 Jan 2015 03:34:03 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 31 Jan 2015 03:34:03 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 8C04EAC0164; Sat, 31 Jan 2015 03:34:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1656158 - in /continuum/trunk/continuum-api: ./ src/main/java/org/apache/continuum/utils/shell/ src/test/java/org/apache/continuum/utils/shell/ Date: Sat, 31 Jan 2015 03:34:03 -0000 To: commits@continuum.apache.org From: batkinson@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150131033403.8C04EAC0164@hades.apache.org> Author: batkinson Date: Sat Jan 31 03:34:03 2015 New Revision: 1656158 URL: http://svn.apache.org/r1656158 Log: Added a test for shell helper isRunning method. Added: continuum/trunk/continuum-api/src/main/java/org/apache/continuum/utils/shell/LogOutputConsumer.java - copied, changed from r1656157, continuum/trunk/continuum-api/src/main/java/org/apache/continuum/utils/shell/FileOutputConsumer.java continuum/trunk/continuum-api/src/test/java/org/apache/continuum/utils/shell/ continuum/trunk/continuum-api/src/test/java/org/apache/continuum/utils/shell/DefaultShellCommandHelperTest.java continuum/trunk/continuum-api/src/test/java/org/apache/continuum/utils/shell/Sleep.java Modified: continuum/trunk/continuum-api/pom.xml continuum/trunk/continuum-api/src/main/java/org/apache/continuum/utils/shell/FileOutputConsumer.java Modified: continuum/trunk/continuum-api/pom.xml URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/pom.xml?rev=1656158&r1=1656157&r2=1656158&view=diff ============================================================================== --- continuum/trunk/continuum-api/pom.xml (original) +++ continuum/trunk/continuum-api/pom.xml Sat Jan 31 03:34:03 2015 @@ -69,8 +69,25 @@ slf4j-api + org.slf4j + slf4j-simple + test + + org.springframework spring-context + + + + maven-surefire-plugin + + + ${project.build.testOutputDirectory} + + + + + Modified: continuum/trunk/continuum-api/src/main/java/org/apache/continuum/utils/shell/FileOutputConsumer.java URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/continuum/utils/shell/FileOutputConsumer.java?rev=1656158&r1=1656157&r2=1656158&view=diff ============================================================================== --- continuum/trunk/continuum-api/src/main/java/org/apache/continuum/utils/shell/FileOutputConsumer.java (original) +++ continuum/trunk/continuum-api/src/main/java/org/apache/continuum/utils/shell/FileOutputConsumer.java Sat Jan 31 03:34:03 2015 @@ -25,7 +25,7 @@ import java.io.IOException; import java.io.PrintWriter; /** - * Collects output to a file using a buffered writer. Unlike the list-based consumer, this should be safer to use when + * Collects output to a file using a buffered writer. Unlike the list-based consumer, this should be safe to use when * the output size is expected to be large. */ public class FileOutputConsumer Copied: continuum/trunk/continuum-api/src/main/java/org/apache/continuum/utils/shell/LogOutputConsumer.java (from r1656157, continuum/trunk/continuum-api/src/main/java/org/apache/continuum/utils/shell/FileOutputConsumer.java) URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/continuum/utils/shell/LogOutputConsumer.java?p2=continuum/trunk/continuum-api/src/main/java/org/apache/continuum/utils/shell/LogOutputConsumer.java&p1=continuum/trunk/continuum-api/src/main/java/org/apache/continuum/utils/shell/FileOutputConsumer.java&r1=1656157&r2=1656158&rev=1656158&view=diff ============================================================================== --- continuum/trunk/continuum-api/src/main/java/org/apache/continuum/utils/shell/FileOutputConsumer.java (original) +++ continuum/trunk/continuum-api/src/main/java/org/apache/continuum/utils/shell/LogOutputConsumer.java Sat Jan 31 03:34:03 2015 @@ -19,47 +19,25 @@ package org.apache.continuum.utils.shell * under the License. */ -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; +import org.slf4j.Logger; /** - * Collects output to a file using a buffered writer. Unlike the list-based consumer, this should be safer to use when - * the output size is expected to be large. + * Collects output to a logger. Unlike the list-based consumer, this should be safe to use when the output size is + * expected to be large. It logs the output at level INFO. */ -public class FileOutputConsumer +public class LogOutputConsumer implements OutputConsumer { - private PrintWriter writer; + private Logger log; - /** - * Creates a output consumer for the given file. - * - * @param outputFile the file to write the results to - * @throws IOException if there is a problem creating a file - */ - public FileOutputConsumer( File outputFile ) - throws IOException + public LogOutputConsumer( Logger log ) { - this.writer = new PrintWriter( new FileWriter( outputFile ) ); + this.log = log; } public void consume( String line ) { - if ( writer != null ) - writer.println( line ); + if ( log != null ) + log.info( line ); } - - public void flush() - { - if ( writer != null ) - writer.flush(); - } - - public void close() - { - if ( writer != null ) - writer.close(); - } -} \ No newline at end of file +} Added: continuum/trunk/continuum-api/src/test/java/org/apache/continuum/utils/shell/DefaultShellCommandHelperTest.java URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/test/java/org/apache/continuum/utils/shell/DefaultShellCommandHelperTest.java?rev=1656158&view=auto ============================================================================== --- continuum/trunk/continuum-api/src/test/java/org/apache/continuum/utils/shell/DefaultShellCommandHelperTest.java (added) +++ continuum/trunk/continuum-api/src/test/java/org/apache/continuum/utils/shell/DefaultShellCommandHelperTest.java Sat Jan 31 03:34:03 2015 @@ -0,0 +1,105 @@ +package org.apache.continuum.utils.shell; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import junit.framework.TestCase; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @see org.apache.continuum.utils.shell.DefaultShellCommandHelper + */ +public class DefaultShellCommandHelperTest + extends TestCase +{ + private static final Logger log = LoggerFactory.getLogger( DefaultShellCommandHelper.class ); + + DefaultShellCommandHelper helper; + + public void setUp() + { + helper = new DefaultShellCommandHelper(); + } + + public void tearDown() + { + helper = null; + } + + /** + * To concurrently check the run status of a process. + */ + private static class RunChecker + implements Runnable + { + ShellCommandHelper shellHelper; + + long pid; + + boolean wasRunning; + + long sleepMillis; + + public RunChecker( ShellCommandHelper shellHelper, long pid, long sleepMillis ) + { + this.shellHelper = shellHelper; + this.pid = pid; + this.sleepMillis = sleepMillis; + } + + public void run() + { + try + { + Thread.sleep( sleepMillis ); + this.wasRunning = shellHelper.isRunning( pid ); + } + catch ( InterruptedException e ) + { + log.error( "run checker interrupted", e ); + } + } + } + + public void testIsRunning() + throws Exception + { + long virtualPid = 1, sleepMillis = 100; + RunChecker checker = new RunChecker( helper, virtualPid, sleepMillis ); + String[] cmdArgs = { "-cp", System.getProperty( "sleepClasspath" ), Sleep.class.getCanonicalName(), "1" }; + + // Verify process isn't running initially + checker.run(); + assertFalse( "Expected that command was not running", checker.wasRunning ); + + // Verify running status is true when running + Thread checkerThread = new Thread( checker ); + checkerThread.start(); + + helper.executeShellCommand( null, "java", cmdArgs, new LogOutputConsumer( log ), virtualPid, null ); + checkerThread.join(); + assertTrue( "Expected that command was running", checker.wasRunning ); + + // Verify process isn't running after + checker.run(); + assertFalse( "Expected that command was not running", checker.wasRunning ); + } + +} Added: continuum/trunk/continuum-api/src/test/java/org/apache/continuum/utils/shell/Sleep.java URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/test/java/org/apache/continuum/utils/shell/Sleep.java?rev=1656158&view=auto ============================================================================== --- continuum/trunk/continuum-api/src/test/java/org/apache/continuum/utils/shell/Sleep.java (added) +++ continuum/trunk/continuum-api/src/test/java/org/apache/continuum/utils/shell/Sleep.java Sat Jan 31 03:34:03 2015 @@ -0,0 +1,39 @@ +package org.apache.continuum.utils.shell; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * A portable program that sleeps. Useful for cross platform shell tests. + */ +public class Sleep +{ + + public static void main( String[] args ) + throws InterruptedException + { + if ( args.length != 1 ) + { + System.err.printf( "usage: java %s \n", Sleep.class.getName() ); + System.exit( 1 ); + } + int sleepTimeInMillis = Integer.valueOf( args[0] ) * 1000; + Thread.sleep( sleepTimeInMillis ); + } +}