You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ec...@apache.org on 2013/07/19 05:47:39 UTC

svn commit: r1504759 [4/6] - in /hive/trunk: ./ testutils/ptest2/ testutils/ptest2/conf/ testutils/ptest2/src/ testutils/ptest2/src/main/ testutils/ptest2/src/main/java/ testutils/ptest2/src/main/java/org/ testutils/ptest2/src/main/java/org/apache/ tes...

Added: hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/context/ServiceNotAvailableException.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/context/ServiceNotAvailableException.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/context/ServiceNotAvailableException.java (added)
+++ hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/context/ServiceNotAvailableException.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution.context;
+
+public class ServiceNotAvailableException extends Exception {
+
+  private static final long serialVersionUID = 4593168151574842785L;
+  public ServiceNotAvailableException(String msg, Throwable t) {
+    super(msg, t);
+  }
+  public ServiceNotAvailableException(String msg) {
+    this(msg, null);
+  }
+}

Added: hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/AbstractSSHCommand.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/AbstractSSHCommand.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/AbstractSSHCommand.java (added)
+++ hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/AbstractSSHCommand.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution.ssh;
+
+import java.util.concurrent.Callable;
+
+public abstract class AbstractSSHCommand<RESULT> implements Callable<RESULT> {
+    private final String privateKey;
+    private final String user;
+    private final String host;
+    private final int instance;
+    private int exitCode = -1;
+    private Exception exception;
+    private String output;
+
+    public AbstractSSHCommand(String privateKey,
+        String user, String host, int instance) {
+      this.privateKey = privateKey;
+      this.user = user;
+      this.host = host;
+      this.instance = instance;
+    }
+
+    public void setException(Exception exception) {
+      this.exception = exception;
+    }
+    public void setExitCode(int exitCode) {
+      this.exitCode = exitCode;
+    }
+    public void setOutput(String output) {
+      this.output = output;
+    }
+    public int getExitCode() {
+      return exitCode;
+    }
+    public Exception getException() {
+      return exception;
+    }
+    public String getOutput() {
+      return output;
+    }
+    public String getPrivateKey() {
+      return privateKey;
+    }
+    public String getUser() {
+      return user;
+    }
+    public String getHost() {
+      return host;
+    }
+    public int getInstance() {
+      return instance;
+    }
+}

Added: hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/AbstractSSHResult.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/AbstractSSHResult.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/AbstractSSHResult.java (added)
+++ hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/AbstractSSHResult.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution.ssh;
+
+public class AbstractSSHResult implements RemoteCommandResult {
+
+  private final String user;
+  private final String host;
+  private final int instance;
+  private final int exitCode;
+  private final Exception exception;
+  private final String output;
+  public AbstractSSHResult(String user, String host, int instance,
+      int exitCode, Exception exception, String output) {
+    this.user = user;
+    this.host = host;
+    this.instance = instance;
+    this.exitCode = exitCode;
+    this.exception = exception;
+    this.output = output;
+  }
+  @Override
+  public int getExitCode() {
+    return exitCode;
+  }
+  @Override
+  public Exception getException() {
+    return exception;
+  }
+  @Override
+  public String getOutput() {
+    return output;
+  }
+  @Override
+  public String getUser() {
+    return user;
+  }
+  @Override
+  public String getHost() {
+    return host;
+  }
+  @Override
+  public int getInstance() {
+    return instance;
+  }
+}

Added: hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/NonZeroExitCodeException.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/NonZeroExitCodeException.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/NonZeroExitCodeException.java (added)
+++ hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/NonZeroExitCodeException.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution.ssh;
+
+public class NonZeroExitCodeException extends Exception {
+  private static final long serialVersionUID = 6673699997331155666L;
+  public NonZeroExitCodeException(String msg) {
+    this(msg, null);
+  }
+  public NonZeroExitCodeException(String msg, Throwable throwable) {
+    super(msg, throwable);
+  }
+}

Added: hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RSyncCommand.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RSyncCommand.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RSyncCommand.java (added)
+++ hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RSyncCommand.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution.ssh;
+
+public class RSyncCommand extends AbstractSSHCommand<RSyncResult> {
+  private final RSyncCommandExecutor executor;
+  private final String localFile;
+  private final String remoteFile;
+  private RSyncCommand.Type type;
+  public RSyncCommand(RSyncCommandExecutor executor, String privateKey,
+      String user, String host, int instance,
+      String localFile, String remoteFile, RSyncCommand.Type type) {
+    super(privateKey, user, host, instance);
+    this.executor = executor;
+    this.localFile = localFile;
+    this.remoteFile = remoteFile;
+    this.type = type;
+  }
+  public RSyncCommand.Type getType() {
+    return type;
+  }
+  public String getLocalFile() {
+    return localFile;
+  }
+  public String getRemoteFile() {
+    return remoteFile;
+  }
+  @Override
+  public RSyncResult call() {
+    executor.execute(this);
+    return new RSyncResult(getUser(), getHost(), getInstance(), getLocalFile(), getRemoteFile(),
+        getExitCode(), getException(), getOutput());
+  }
+
+  @Override
+  public String toString() {
+    return "RSyncCommand [executor=" + executor + ", localFile=" + localFile
+        + ", remoteFile=" + remoteFile + ", type=" + type + ", getHost()="
+        + getHost() + ", getInstance()=" + getInstance() + "]";
+  }
+
+  public static enum Type {
+    FROM_LOCAL(),
+    TO_LOCAL();
+  }
+}
\ No newline at end of file

Added: hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RSyncCommandExecutor.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RSyncCommandExecutor.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RSyncCommandExecutor.java (added)
+++ hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RSyncCommandExecutor.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution.ssh;
+
+import java.io.IOException;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hive.ptest.execution.LocalCommand;
+import org.apache.hive.ptest.execution.LocalCommand.CollectPolicy;
+import org.slf4j.Logger;
+
+
+public class RSyncCommandExecutor {
+
+  private final Logger mLogger;
+  private final Semaphore mSemaphore;
+
+  public RSyncCommandExecutor(Logger logger) {
+    mLogger = logger;
+    mSemaphore = new Semaphore(5);
+  }
+  /**
+   * Execute the given RSync. If the command exits with a non-zero
+   * exit status the command will be retried up to three times.
+   */
+  public void execute(RSyncCommand command) {
+    CollectPolicy collector = new CollectPolicy();
+    boolean release = false;
+    try {
+      mSemaphore.acquire();
+      release = true;
+      int attempts = 0;
+      boolean retry;
+      LocalCommand cmd;
+      do {
+        retry = false;
+        if(command.getType() == RSyncCommand.Type.TO_LOCAL) {
+          cmd = new LocalCommand(mLogger, collector,
+              String.format("rsync -qaPe \"ssh -i %s\" %s@%s:%s %s",
+                  command.getPrivateKey(), command.getUser(), command.getHost(),
+                  command.getRemoteFile(), command.getLocalFile()));
+        } else if(command.getType() == RSyncCommand.Type.FROM_LOCAL) {
+          cmd = new LocalCommand(mLogger, collector,
+              String.format("rsync -qaPe \"ssh -i %s\" --delete --delete-during --force %s %s@%s:%s",
+                  command.getPrivateKey(), command.getLocalFile(), command.getUser(), command.getHost(),
+                  command.getRemoteFile()));
+        } else {
+          throw new UnsupportedOperationException(String.valueOf(command.getType()));
+        }
+        // 12 is timeout and 255 is unspecified error
+        if(attempts++ <= 3 && cmd.getExitCode() != 0) {
+          mLogger.warn("Command exited with " + cmd.getExitCode() + ", will retry: " + command);
+          retry = true;
+          TimeUnit.SECONDS.sleep(20);
+        }
+      } while (retry); // an error occurred, re-try
+      command.setExitCode(cmd.getExitCode());
+    } catch (IOException e) {
+      command.setException(e);
+    } catch (InterruptedException e) {
+      command.setException(e);
+    } finally {
+      if(release) {
+        mSemaphore.release();
+      }
+      command.setOutput(collector.getOutput());
+    }
+  }
+}

Added: hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RSyncResult.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RSyncResult.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RSyncResult.java (added)
+++ hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RSyncResult.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution.ssh;
+
+public class RSyncResult extends AbstractSSHResult {
+  private final String localFile;
+  private final String remoteFile;
+  public RSyncResult(String user, String host, int instance,
+      String localFile, String remoteFile, int exitCode,
+      Exception exception, String output) {
+    super(user, host, instance, exitCode, exception, output);
+    this.localFile = localFile;
+    this.remoteFile = remoteFile;
+  }
+  public String getLocalFile() {
+    return localFile;
+  }
+  public String getRemoteFile() {
+    return remoteFile;
+  }
+  @Override
+  public String toString() {
+    return "RSyncResult [localFile=" + localFile + ", remoteFile="
+        + remoteFile + ", getExitCode()=" + getExitCode() + ", getException()="
+        + getException() + ", getUser()=" + getUser() + ", getHost()="
+        + getHost() + ", getInstance()=" + getInstance() + "]";
+  }
+}

Added: hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RemoteCommandResult.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RemoteCommandResult.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RemoteCommandResult.java (added)
+++ hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/RemoteCommandResult.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution.ssh;
+
+public interface RemoteCommandResult {
+  public int getExitCode();
+  public Exception getException();
+  public String getOutput();
+  public String getUser();
+  public String getHost();
+  public int getInstance();
+}

Added: hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHCommand.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHCommand.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHCommand.java (added)
+++ hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHCommand.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution.ssh;
+
+public class SSHCommand extends AbstractSSHCommand<SSHResult> {
+
+  private final SSHCommandExecutor executor;
+  private final String command;
+
+  public SSHCommand(SSHCommandExecutor executor, String privateKey,
+      String user, String host, int instance, String command) {
+    super(privateKey, user, host, instance);
+    this.executor = executor;
+    this.command = command;
+  }
+
+  @Override
+  public SSHResult call() {
+    executor.execute(this);
+    return new SSHResult(getUser(), getHost(), getInstance(), getCommand(),
+        getExitCode(), getException(), getOutput());
+  }
+
+  public String getCommand() {
+    return command;
+  }
+
+  @Override
+  public String toString() {
+    return "SSHCommand [command=" + command + ", getHost()=" + getHost()
+        + ", getInstance()=" + getInstance() + "]";
+  }
+}
\ No newline at end of file

Added: hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHCommandExecutor.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHCommandExecutor.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHCommandExecutor.java (added)
+++ hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHCommandExecutor.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution.ssh;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hive.ptest.execution.Constants;
+import org.apache.hive.ptest.execution.LocalCommand;
+import org.apache.hive.ptest.execution.LocalCommand.CollectPolicy;
+import org.slf4j.Logger;
+
+public class SSHCommandExecutor {
+
+  private final Logger mLogger;
+
+  public SSHCommandExecutor(Logger logger) {
+    mLogger = logger;
+  }
+  /**
+   * Execute the given command via the ssh command line tool. If the command
+   * exits with status code 255 the command will be tries up to three times.
+   */
+  public void execute(SSHCommand command) {
+    CollectPolicy collector = new CollectPolicy();
+    try {
+      String commandText = String.format("ssh -v -i %s -l %s %s '%s'", command.getPrivateKey(),
+          command.getUser(), command.getHost(), command.getCommand());
+      int attempts = 0;
+      boolean retry;
+      LocalCommand cmd;
+      do {
+        retry = false;
+        cmd = new LocalCommand(mLogger, collector, commandText);
+        if(attempts++ <= 3 && cmd.getExitCode() == Constants.EXIT_CODE_UNKNOWN) {
+          mLogger.warn("Command exited with " + cmd.getExitCode() + ", will retry: " + command);
+          retry = true;
+          TimeUnit.SECONDS.sleep(20);
+        }
+      } while (retry); // an error occurred, re-try
+      command.setExitCode(cmd.getExitCode());
+    } catch (Exception e) {
+      command.setException(e);
+    } finally {
+      command.setOutput(collector.getOutput());
+    }
+  }
+}

Added: hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHExecutionException.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHExecutionException.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHExecutionException.java (added)
+++ hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHExecutionException.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution.ssh;
+
+
+public class SSHExecutionException extends Exception {
+  private static final long serialVersionUID = 1L;
+  private final RemoteCommandResult result;
+  public SSHExecutionException(RemoteCommandResult result) {
+    super(result.toString(), result.getException());
+    this.result = result;
+  }
+
+  @Override
+  public String getMessage() {
+    String msg = String.format("%s: '%s'", super.getMessage(),
+        result.getOutput());
+    return msg;
+  }
+}

Added: hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHResult.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHResult.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHResult.java (added)
+++ hive/trunk/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/ssh/SSHResult.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution.ssh;
+
+public class SSHResult extends AbstractSSHResult {
+
+  private final String command;
+  public SSHResult(String user, String host, int instance, String command,
+      int exitCode, Exception exception, String output) {
+    super(user, host, instance, exitCode, exception, output);
+    this.command = command;
+  }
+  public String getCommand() {
+    return command;
+  }
+  @Override
+  public String toString() {
+    return "SSHResult [command=" + command + ", getExitCode()="
+        + getExitCode() + ", getException()=" + getException()
+        + ", getUser()=" + getUser() + ", getHost()=" + getHost()
+        + ", getInstance()=" + getInstance() + "]";
+  }
+}

Added: hive/trunk/testutils/ptest2/src/main/resources/batch-exec.vm
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/resources/batch-exec.vm?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/resources/batch-exec.vm (added)
+++ hive/trunk/testutils/ptest2/src/main/resources/batch-exec.vm Fri Jul 19 03:47:36 2013
@@ -0,0 +1,60 @@
+#!/bin/bash
+# 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.
+
+##### Remember, this is a velocity template 
+set -x
+umask 0022
+find $localDir/$instanceName/${repositoryName}-source/build -name 'TEST-*.xml' -delete
+find $localDir/$instanceName/${repositoryName}-source/build -name 'hive.log' -delete
+chmod -R u+w $logDir
+rm -rf $logDir
+# makes $logDir and $logDir/tmp
+mkdir -p $logDir/tmp
+if [[ -n "${javaHome}" ]]
+then
+  export JAVA_HOME=$javaHome
+  export PATH=$JAVA_HOME/bin/:$PATH
+fi
+export ANT_OPTS="-Xmx1g -XX:MaxPermSize=256m -Djava.io.tmpdir=$logDir/tmp ${antEnvOpts}"
+export HADOOP_ROOT_LOGGER=INFO,console
+export HADOOP_OPTS="-Dhive.log.dir=$logDir -Dhive.query.id=hadoop -Djava.io.tmpdir=$logDir/tmp"
+cd $localDir/$instanceName/${repositoryName}-source && \
+  timeout 2h ant -Divy.cache.ttl.default=eternal $antArgs \
+   -Divy.default.ivy.user.dir=$localDir/$instanceName/ivy \
+   -Dmvn.local.repo=$localDir/$instanceName/maven \
+   -Dtest.junit.output.format=xml test \
+   $testArguments 1>$logDir/ant-test.txt 2>&1
+ret=$?
+if [[ $ret -ne 0 ]]
+then
+  cp -R $localDir/$instanceName/${repositoryName}-source $logDir/source
+fi
+if [[ -f $localDir/$instanceName/${repositoryName}-source/build/ql/tmp/hive.log ]]
+then
+  mv $localDir/$instanceName/${repositoryName}-source/build/ql/tmp/hive.log $logDir/hive.log
+fi
+batchName=$batchName
+for testOutputFile in $(find $localDir/$instanceName/${repositoryName}-source/ -name 'TEST-*.xml')
+do
+  mv "$testOutputFile" "$logDir/TEST-$batchName-$(basename $testOutputFile)"
+done
+if [[ -f $logDir/.log ]]
+then
+  mv $logDir/.log $logDir/dot.log
+else
+  echo "$logDir/.log does not exist"
+fi
+exit $ret
\ No newline at end of file

Added: hive/trunk/testutils/ptest2/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/resources/log4j.properties?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/resources/log4j.properties (added)
+++ hive/trunk/testutils/ptest2/src/main/resources/log4j.properties Fri Jul 19 03:47:36 2013
@@ -0,0 +1,34 @@
+# 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.
+
+hive.ptest.logdir=target
+
+log4j.rootLogger=DEBUG,FILE
+log4j.threshhold=ALL
+
+log4j.appender.FILE=org.apache.log4j.RollingFileAppender
+log4j.appender.FILE.File=${hive.ptest.logdir}/ptest.log
+log4j.appender.FILE.MaxFileSize=10MB
+log4j.appender.FILE.MaxBackupIndex=1
+log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
+log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
+
+log4j.logger.org.apache.http=INFO
+log4j.logger.org.springframework=INFO
+log4j.logger.org.jclouds=INFO
+log4j.logger.jclouds=INFO
+log4j.logger.jclouds.compute=TRACE
+log4j.logger.org.apache.hive=DEBUG
+log4j.logger.org.apache.http=TRACE
\ No newline at end of file

Added: hive/trunk/testutils/ptest2/src/main/resources/smart-apply-patch.sh
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/resources/smart-apply-patch.sh?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/resources/smart-apply-patch.sh (added)
+++ hive/trunk/testutils/ptest2/src/main/resources/smart-apply-patch.sh Fri Jul 19 03:47:36 2013
@@ -0,0 +1,99 @@
+#!/usr/bin/env bash
+#   Licensed 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.
+
+set -e
+
+PATCH_FILE=$1
+DRY_RUN=$2
+if [ -z "$PATCH_FILE" ]; then
+  echo usage: $0 patch-file
+  exit 1
+fi
+
+PATCH=${PATCH:-patch} # allow overriding patch binary
+
+# Cleanup handler for temporary files
+TOCLEAN=""
+cleanup() {
+  rm $TOCLEAN
+  exit $1
+}
+trap "cleanup 1" HUP INT QUIT TERM
+
+# Allow passing "-" for stdin patches
+if [ "$PATCH_FILE" == "-" ]; then
+  PATCH_FILE=/tmp/tmp.in.$$
+  cat /dev/fd/0 > $PATCH_FILE
+  TOCLEAN="$TOCLEAN $PATCH_FILE"
+fi
+
+# Come up with a list of changed files into $TMP
+TMP=/tmp/tmp.paths.$$
+TOCLEAN="$TOCLEAN $TMP"
+
+if $PATCH -p0 -E --dry-run < $PATCH_FILE 2>&1 > $TMP; then
+  PLEVEL=0
+  #if the patch applied at P0 there is the possability that all we are doing
+  # is adding new files and they would apply anywhere. So try to guess the
+  # correct place to put those files.
+
+  TMP2=/tmp/tmp.paths.2.$$
+  TOCLEAN="$TOCLEAN $TMP2"
+
+  egrep '^patching file |^checking file ' $TMP | awk '{print $3}' | grep -v /dev/null | sort | uniq > $TMP2
+
+  if [ ! -s $TMP2 ]; then
+    echo "Error: Patch dryrun couldn't detect changes the patch would make. Exiting."
+    cleanup 1
+  fi
+
+  #first off check that all of the files do not exist
+  FOUND_ANY=0
+  for CHECK_FILE in $(cat $TMP2)
+  do
+    if [[ -f $CHECK_FILE ]]; then
+      FOUND_ANY=1
+    fi
+  done
+
+  if [[ "$FOUND_ANY" = "0" ]]; then
+    #all of the files are new files so we have to guess where the correct place to put it is.
+
+    # if all of the lines start with a/ or b/, then this is a git patch that
+    # was generated without --no-prefix
+    if ! grep -qv '^a/\|^b/' $TMP2 ; then
+      echo Looks like this is a git patch. Stripping a/ and b/ prefixes
+      echo and incrementing PLEVEL
+      PLEVEL=$[$PLEVEL + 1]
+      sed -i -e 's,^[ab]/,,' $TMP2
+    fi
+
+  fi
+elif $PATCH -p1 -E --dry-run < $PATCH_FILE 2>&1 > /dev/null; then
+  PLEVEL=1
+elif $PATCH -p2 -E --dry-run < $PATCH_FILE 2>&1 > /dev/null; then
+  PLEVEL=2
+else
+  echo "The patch does not appear to apply with p0 to p2";
+  cleanup 1;
+fi
+
+# If this is a dry run then exit instead of applying the patch
+if [[ -n $DRY_RUN ]]; then
+  cleanup 0;
+fi
+
+echo Going to apply patch with: $PATCH -p$PLEVEL
+$PATCH -p$PLEVEL -E < $PATCH_FILE
+
+cleanup $?
\ No newline at end of file

Added: hive/trunk/testutils/ptest2/src/main/resources/source-prep.vm
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/resources/source-prep.vm?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/main/resources/source-prep.vm (added)
+++ hive/trunk/testutils/ptest2/src/main/resources/source-prep.vm Fri Jul 19 03:47:36 2013
@@ -0,0 +1,83 @@
+# 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.
+
+##### Remember this is a velocity template
+set -e
+set -x
+if [[ -n "${javaHome}" ]]
+then
+  export JAVA_HOME=$javaHome
+  export PATH=$JAVA_HOME/bin/:$PATH
+fi
+export ANT_OPTS="-Xmx1g -XX:MaxPermSize=256m ${antEnvOpts}"
+cd $workingDir/
+(
+  mkdir -p {maven,ivy}
+  if [[ "${repositoryType}" = "svn" ]]
+  then
+    if [[ -n "$branch" ]]
+    then
+      echo "Illegal argument for svn: branch '${branch}'."
+      exit 1
+    fi
+    if [[ -d ${repositoryName}-source ]] && [[ ! -d ${repositoryName}-source/.svn ]]
+    then
+      rm -rf ${repositoryName}-source
+    fi
+    if [[ ! -d ${repositoryName}-source ]]
+    then
+      svn co ${repository} ${repositoryName}-source
+    fi
+    cd ${repositoryName}-source
+    svn revert -R .
+    rm -rf $(svn status --no-ignore)
+    svn update
+  elif [[ "${repositoryType}" = "git" ]]
+  then
+     if [[ -z "$branch" ]]
+    then
+      echo "Illegal argument for git: branch name is required."
+      exit 1
+    fi
+    if [[ -d ${repositoryName}-source ]] && [[ ! -d ${repositoryName}-source/.git ]]
+    then
+      rm -rf ${repositoryName}-source	  
+    fi
+    if [[ ! -d ${repositoryName}-source ]]
+    then
+      git clone $repository ${repositoryName}-source
+    fi
+    cd ${repositoryName}-source
+    git fetch origin
+    git reset --hard HEAD && git clean -f -d
+    git checkout $branch || git checkout -b $branch origin/$branch
+    git reset --hard origin/$branch
+    git merge --ff-only origin/$branch
+    git gc
+  else
+    echo "Unknown repository type '${repositoryType}'"
+    exit 1
+  fi
+  patchCommandPath=$workingDir/scratch/smart-apply-patch.sh
+  patchFilePath=$workingDir/scratch/build.patch
+  if [[ -f $patchFilePath ]]
+  then
+    chmod +x $patchCommandPath
+    $patchCommandPath $patchFilePath
+  fi
+  ant $antArgs -Divy.default.ivy.user.dir=$workingDir/ivy -Dmvn.local.repo=$workingDir/maven clean package
+  ant $antArgs -Divy.default.ivy.user.dir=$workingDir/ivy -Dmvn.local.repo=$workingDir/maven -Dtestcase=nothing test
+) 2>&1 | tee $logDir/source-prep.txt
+exit ${PIPESTATUS[0]}
\ No newline at end of file

Added: hive/trunk/testutils/ptest2/src/main/webapp/WEB-INF/config/web-application-config.xml
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/webapp/WEB-INF/config/web-application-config.xml?rev=1504759&view=auto
==============================================================================
Binary file - no diff available.

Propchange: hive/trunk/testutils/ptest2/src/main/webapp/WEB-INF/config/web-application-config.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: hive/trunk/testutils/ptest2/src/main/webapp/WEB-INF/config/webmvc-config.xml
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/webapp/WEB-INF/config/webmvc-config.xml?rev=1504759&view=auto
==============================================================================
Binary file - no diff available.

Propchange: hive/trunk/testutils/ptest2/src/main/webapp/WEB-INF/config/webmvc-config.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: hive/trunk/testutils/ptest2/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/main/webapp/WEB-INF/web.xml?rev=1504759&view=auto
==============================================================================
Binary file - no diff available.

Propchange: hive/trunk/testutils/ptest2/src/main/webapp/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/api/server/TestTestExecutor.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/api/server/TestTestExecutor.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/api/server/TestTestExecutor.java (added)
+++ hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/api/server/TestTestExecutor.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,142 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.api.server;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.util.Set;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.Assert;
+
+import org.apache.hive.ptest.api.Status;
+import org.apache.hive.ptest.api.request.TestStartRequest;
+import org.apache.hive.ptest.execution.LocalCommandFactory;
+import org.apache.hive.ptest.execution.PTest;
+import org.apache.hive.ptest.execution.conf.ExecutionContextConfiguration;
+import org.apache.hive.ptest.execution.conf.Host;
+import org.apache.hive.ptest.execution.conf.TestConfiguration;
+import org.apache.hive.ptest.execution.context.ExecutionContext;
+import org.apache.hive.ptest.execution.context.ExecutionContextProvider;
+import org.apache.hive.ptest.execution.ssh.RSyncCommandExecutor;
+import org.apache.hive.ptest.execution.ssh.SSHCommandExecutor;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
+import org.slf4j.Logger;
+
+import com.google.common.collect.Sets;
+import com.google.common.io.Resources;
+public class TestTestExecutor {
+
+  private static final String TEST_HANDLE = "myhandle";
+  private static final String PRIVATE_KEY = "mykey";
+  private static final String PROFILE = "myprole";
+  @Rule
+  public TemporaryFolder baseDir = new TemporaryFolder();
+  private TestExecutor testExecutor;
+  private BlockingQueue<Test> testQueue;
+  private ExecutionContextConfiguration executionContextConfiguration;
+  private ExecutionContextProvider executionContextProvider;
+  private ExecutionContext executionContext;
+  private PTest.Builder ptestBuilder;
+  private PTest ptest;
+  private Test test;
+  private TestStartRequest startRequest;
+  private File profileProperties;
+
+
+  @Before
+  public void setup() throws Exception {
+    startRequest = new TestStartRequest();
+    startRequest.setProfile(PROFILE);
+    startRequest.setTestHandle(TEST_HANDLE);
+    test = new Test(startRequest, Status.pending(), System.currentTimeMillis());
+    testQueue = new ArrayBlockingQueue<Test>(1);
+    executionContextConfiguration = mock(ExecutionContextConfiguration.class);
+    executionContextProvider = mock(ExecutionContextProvider.class);
+    ptest = mock(PTest.class);
+    Set<Host> hosts = Sets.newHashSet();
+    String baseDirPath = baseDir.getRoot().getAbsolutePath();
+    executionContext = new ExecutionContext(executionContextProvider, hosts, baseDirPath, PRIVATE_KEY);
+    profileProperties = new File(baseDirPath, PROFILE + ".properties");
+    when(executionContextConfiguration.getProfileDirectory()).thenReturn(baseDirPath);
+    when(executionContextConfiguration.getGlobalLogDirectory()).thenReturn(baseDirPath);
+    when(executionContextProvider.createExecutionContext()).thenReturn(executionContext);
+    Assert.assertTrue(profileProperties.toString(), profileProperties.createNewFile());
+    OutputStream profilePropertiesOutputStream = new FileOutputStream(profileProperties);
+    Resources.copy(Resources.getResource("test-configuration.properties"), profilePropertiesOutputStream);
+    profilePropertiesOutputStream.close();
+    ptestBuilder = new PTest.Builder() {
+      @Override
+    public PTest build(TestConfiguration configuration, ExecutionContext executionContext,
+          String buildTag, File logDir, LocalCommandFactory localCommandFactory, SSHCommandExecutor sshCommandExecutor,
+          RSyncCommandExecutor rsyncCommandExecutor, Logger logger) throws Exception {
+        return ptest;
+      }
+    };
+    testExecutor = new TestExecutor(executionContextConfiguration, executionContextProvider,
+        testQueue, ptestBuilder);
+    testExecutor.setDaemon(true);
+    testExecutor.start();
+    TimeUnit.MILLISECONDS.sleep(100);
+  }
+  @After
+  public void teardown() {
+    if(testExecutor != null) {
+      testExecutor.shutdown();
+    }
+  }
+  @org.junit.Test
+  public void testSuccess() throws Exception {
+    Assert.assertTrue(String.valueOf(test.getStatus()),
+        Status.isPending(test.getStatus()));
+    testQueue.add(test);
+    TimeUnit.SECONDS.sleep(1);
+    Assert.assertTrue(String.valueOf(test.getStatus()),
+        Status.isOK(test.getStatus()));
+  }
+  @org.junit.Test
+  public void testTestFailure() throws Exception {
+    Assert.assertTrue(String.valueOf(test.getStatus()),
+        Status.isPending(test.getStatus()));
+    when(ptest.run()).thenReturn(1);
+    testQueue.add(test);
+    TimeUnit.SECONDS.sleep(1);
+    Assert.assertTrue(String.valueOf(test.getStatus()),
+        Status.isFailed(test.getStatus()));
+  }
+  @org.junit.Test
+  public void testNoProfileProperties() throws Exception {
+    Assert.assertTrue(String.valueOf(test.getStatus()),
+        Status.isPending(test.getStatus()));
+    Assert.assertTrue(profileProperties.toString(), profileProperties.delete());
+    testQueue.add(test);
+    TimeUnit.SECONDS.sleep(1);
+    Assert.assertTrue(String.valueOf(test.getStatus()),
+        Status.isIllegalArgument(test.getStatus()));
+  }
+}

Added: hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/api/server/TestTestLogger.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/api/server/TestTestLogger.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/api/server/TestTestLogger.java (added)
+++ hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/api/server/TestTestLogger.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.api.server;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.StringReader;
+
+import junit.framework.Assert;
+
+import com.google.common.base.Charsets;
+
+public class TestTestLogger {
+
+  @org.junit.Test
+  public void basicTest() throws IOException {
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    PrintStream logFile = new PrintStream(out);
+    TestLogger logger = new TestLogger(logFile, TestLogger.LEVEL.INFO);
+    logger.trace("trace");
+    logger.debug("debug");
+    logger.info("info");
+    logger.warn("warn");
+    logger.error("error");
+    logFile.flush();
+    logFile.close();
+    BufferedReader reader = new BufferedReader(new StringReader(new String(out.toByteArray(), Charsets.UTF_8)));
+    String info = reader.readLine();
+    String warn = reader.readLine();
+    String error = reader.readLine();
+    Assert.assertNull(reader.readLine());
+    Assert.assertTrue(info, info.endsWith("info"));
+    Assert.assertTrue(warn, warn.endsWith("warn"));
+    Assert.assertTrue(error, error.endsWith("error"));
+  }
+}

Added: hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/AbstractTestPhase.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/AbstractTestPhase.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/AbstractTestPhase.java (added)
+++ hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/AbstractTestPhase.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,133 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Executors;
+
+import junit.framework.Assert;
+
+import org.apache.hive.ptest.execution.conf.Host;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+
+public abstract class AbstractTestPhase {
+
+  private static final Logger LOG = LoggerFactory
+      .getLogger(AbstractTestPhase.class);
+
+  protected static final String LOCAL_DIR = "/some/local/dir";
+  protected static final String WORKING_DIR = "/some/working/dir";
+  protected static final String PRIVATE_KEY = "some.private.key";
+  protected static final String USER = "someuser";
+  protected static final String HOST = "somehost";
+  protected static final int INSTANCE = 13;
+  protected static final String INSTANCE_NAME = HOST + "-" + USER + "-" + INSTANCE;
+  protected static final String INSTANCE_DIR =  LOCAL_DIR + "/" + INSTANCE_NAME;
+  protected static final String BRANCH = "branch";
+  protected static final String REPOSITORY = "repository";
+  protected static final String REPOSITORY_NAME = "repositoryName";
+
+  protected Host host;
+  protected File baseDir;
+  protected File scratchDir;
+  protected File logDir;
+  protected File succeededLogDir;
+  protected File failedLogDir;
+  protected ListeningExecutorService executor;
+  protected MockLocalCommandFactory localCommandFactory;
+  protected LocalCommand localCommand;
+  protected MockSSHCommandExecutor sshCommandExecutor;
+  protected MockRSyncCommandExecutor rsyncCommandExecutor;
+  protected ImmutableMap<String, String> templateDefaults;
+  protected ImmutableList<HostExecutor> hostExecutors;
+  protected HostExecutor hostExecutor;
+  protected Logger logger;
+
+  public void initialize(String name) throws Exception {
+    baseDir = createBaseDir(name);
+    logDir = Dirs.create(new File(baseDir, "logs"));
+    scratchDir = Dirs.create(new File(baseDir, "scratch"));
+    succeededLogDir = Dirs.create(new File(logDir, "succeeded"));
+    failedLogDir = Dirs.create(new File(logDir, "failed"));
+    executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
+    localCommandFactory = new MockLocalCommandFactory(LOG);
+    localCommand = mock(LocalCommand.class);
+    localCommandFactory.setInstance(localCommand);
+    sshCommandExecutor = spy(new MockSSHCommandExecutor(LOG));
+    rsyncCommandExecutor = spy(new MockRSyncCommandExecutor(LOG));
+    logger = LOG;
+    templateDefaults = ImmutableMap.<String, String>builder()
+        .put("localDir", LOCAL_DIR)
+        .put("workingDir", WORKING_DIR)
+        .put("instanceName", INSTANCE_NAME)
+        .put("branch", BRANCH)
+        .put("logDir", logDir.getAbsolutePath())
+        .put("repository", REPOSITORY)
+        .put("repositoryName", REPOSITORY_NAME)
+        .build();
+    host = new Host(HOST, USER, new String[] { LOCAL_DIR }, 2);
+  }
+
+  protected void createHostExecutor() {
+    hostExecutor = new HostExecutor(host, PRIVATE_KEY, executor, sshCommandExecutor,
+        rsyncCommandExecutor, templateDefaults, scratchDir, succeededLogDir, failedLogDir, 1, logger);
+    hostExecutors = ImmutableList.of(hostExecutor);
+  }
+
+  private static boolean isOSX() {
+    String osName = System.getProperty("os.name");
+    return osName.contains("OS X");
+  }
+  static File createBaseDir(String name) throws IOException {
+    File baseDir;
+    if(isOSX()) {
+      // else osx gives ugly temp path which screws up approvals
+      baseDir = new File("/tmp/hive-ptest-units", name);
+    } else {
+      baseDir = new File(new File(System.getProperty("java.io.tmpdir"), "hive-ptest-units"), name);
+    }
+    return Dirs.create(baseDir);
+  }
+  protected String getExecutedCommands() {
+    List<String> result = Lists.newArrayList();
+    result.addAll(returnNotNull(sshCommandExecutor.getCommands()));
+    result.addAll(returnNotNull(localCommandFactory.getCommands()));
+    result.addAll(returnNotNull(rsyncCommandExecutor.getCommands()));
+    Collections.sort(result);
+    return Joiner.on("\n").join(result);
+  }
+  static <V> V returnNotNull(V value) {
+    Assert.assertNotNull(value);
+    return value;
+  }
+}

Added: hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/ExtendedAssert.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/ExtendedAssert.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/ExtendedAssert.java (added)
+++ hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/ExtendedAssert.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+
+public final class ExtendedAssert {
+
+  private ExtendedAssert() {
+  }
+
+  /**
+   * Asserts that all the elements of the list are equivalent under equals()
+   *
+   * @param expected
+   *          a list full of expected values
+   * @param actual
+   *          a list full of actual test values
+   */
+  public static void assertListEquals(String msg, final List<?> expected,
+      final List<?> actual) {
+    String cleanMsg = msg == null ? "" : msg;
+    if (expected.size() != actual.size()) {
+      fail(cleanMsg + ": Expected list of size " + expected.size() + "; actual size is "
+          + actual.size());
+    }
+    for (int i = 0; i < expected.size(); i++) {
+      final Object t1 = expected.get(i);
+      final Object t2 = actual.get(i);
+
+      assertEquals(cleanMsg + ": Index " + i,t1, t2);
+    }
+  }
+}

Added: hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/MockLocalCommandFactory.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/MockLocalCommandFactory.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/MockLocalCommandFactory.java (added)
+++ hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/MockLocalCommandFactory.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.slf4j.Logger;
+
+import com.google.common.collect.Lists;
+
+public class MockLocalCommandFactory extends LocalCommandFactory {
+  protected final List<String> commands = Lists.newArrayList();
+  private LocalCommand instance;
+
+  public MockLocalCommandFactory(Logger logger) {
+    super(logger);
+  }
+  public void setInstance(LocalCommand instance) {
+    this.instance = instance;
+  }
+  public List<String> getCommands() {
+    return commands;
+  }
+  @Override
+public LocalCommand create(LocalCommand.CollectPolicy policy, String command)
+      throws IOException {
+    commands.add(command);
+    return this.instance;
+  }
+}

Added: hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/MockRSyncCommandExecutor.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/MockRSyncCommandExecutor.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/MockRSyncCommandExecutor.java (added)
+++ hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/MockRSyncCommandExecutor.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+
+import org.apache.hive.ptest.execution.ssh.RSyncCommand;
+import org.apache.hive.ptest.execution.ssh.RSyncCommandExecutor;
+import org.slf4j.Logger;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class MockRSyncCommandExecutor extends RSyncCommandExecutor {
+  private final List<String> mCommands;
+  private final Map<String, Queue<Integer>> mFailures;
+  public MockRSyncCommandExecutor(Logger logger) {
+    super(logger);
+    mCommands = Lists.newArrayList();
+    mFailures = Maps.newHashMap();
+  }
+  public List<String> getCommands() {
+    return mCommands;
+  }
+  public synchronized void putFailure(String command, Integer... exitCodes) {
+    Queue<Integer> queue = mFailures.get(command);
+    if(queue == null) {
+      queue = new LinkedList<Integer>();
+      mFailures.put(command, queue);
+    } else {
+      queue = mFailures.get(command);
+    }
+    for(Integer exitCode : exitCodes) {
+      queue.add(exitCode);
+    }
+  }
+  @Override
+  public synchronized void execute(RSyncCommand command) {
+    String filePair = command.getLocalFile() + " " + command.getRemoteFile();
+    mCommands.add(filePair);
+    command.setOutput("");
+    Queue<Integer> queue = mFailures.get(filePair);
+    if(queue == null || queue.isEmpty()) {
+      command.setExitCode(0);
+    } else {
+     command.setExitCode(queue.remove());
+    }
+  }
+
+
+}

Added: hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/MockSSHCommandExecutor.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/MockSSHCommandExecutor.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/MockSSHCommandExecutor.java (added)
+++ hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/MockSSHCommandExecutor.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+
+import org.apache.hive.ptest.execution.ssh.SSHCommand;
+import org.apache.hive.ptest.execution.ssh.SSHCommandExecutor;
+import org.slf4j.Logger;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class MockSSHCommandExecutor extends SSHCommandExecutor {
+  private final List<String> mCommands;
+  private final Map<String, Queue<Integer>> mFailures;
+  public MockSSHCommandExecutor(Logger logger) {
+    super(logger);
+    mCommands = Lists.newArrayList();
+    mFailures = Maps.newHashMap();
+  }
+  public List<String> getCommands() {
+    return mCommands;
+  }
+  public synchronized void putFailure(String command, Integer... exitCodes) {
+    Queue<Integer> queue = mFailures.get(command);
+    if(queue == null) {
+      queue = new LinkedList<Integer>();
+      mFailures.put(command, queue);
+    } else {
+      queue = mFailures.get(command);
+    }
+    for(Integer exitCode : exitCodes) {
+      queue.add(exitCode);
+    }
+  }
+  @Override
+public synchronized void execute(SSHCommand command) {
+    mCommands.add(command.getCommand());
+    command.setOutput("");
+    Queue<Integer> queue = mFailures.get(command.getCommand());
+    if(queue == null || queue.isEmpty()) {
+      command.setExitCode(0);
+    } else {
+     command.setExitCode(queue.remove());
+    }
+  }
+}

Added: hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestCleanupPhase.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestCleanupPhase.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestCleanupPhase.java (added)
+++ hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestCleanupPhase.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution;
+
+import org.approvaltests.Approvals;
+import org.approvaltests.reporters.JunitReporter;
+import org.approvaltests.reporters.UseReporter;
+import org.junit.Before;
+import org.junit.Test;
+
+@UseReporter(JunitReporter.class)
+public class TestCleanupPhase extends AbstractTestPhase {
+  private CleanupPhase phase;
+
+  @Before
+  public void setup() throws Exception {
+    initialize(getClass().getSimpleName());
+    createHostExecutor();
+  }
+  @Test
+  public void testExecute() throws Exception {
+    phase = new CleanupPhase(hostExecutors, localCommandFactory,
+        templateDefaults, logger);
+    phase.execute();
+    Approvals.verify(getExecutedCommands());
+  }
+}

Added: hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestCleanupPhase.testExecute.approved.txt
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestCleanupPhase.testExecute.approved.txt?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestCleanupPhase.testExecute.approved.txt (added)
+++ hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestCleanupPhase.testExecute.approved.txt Fri Jul 19 03:47:36 2013
@@ -0,0 +1,4 @@
+killall -q -9 -f java || true
+rm -rf /some/local/dir/somehost-someuser-0/scratch /some/local/dir/somehost-someuser-0/logs
+rm -rf /some/local/dir/somehost-someuser-1/scratch /some/local/dir/somehost-someuser-1/logs
+rm -rf /some/working/dir/scratch
\ No newline at end of file

Added: hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.java
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.java?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.java (added)
+++ hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.java Fri Jul 19 03:47:36 2013
@@ -0,0 +1,121 @@
+/*
+ * 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.
+ */
+package org.apache.hive.ptest.execution;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.hive.ptest.execution.conf.QFileTestBatch;
+import org.apache.hive.ptest.execution.conf.TestBatch;
+import org.apache.hive.ptest.execution.conf.UnitTestBatch;
+import org.approvaltests.Approvals;
+import org.approvaltests.reporters.JunitReporter;
+import org.approvaltests.reporters.UseReporter;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Suppliers;
+import com.google.common.collect.Sets;
+import com.google.common.io.Files;
+
+@UseReporter(JunitReporter.class)
+public class TestExecutionPhase extends AbstractTestPhase {
+
+  private static final String DRIVER = "driver";
+  private static final String QFILENAME = "sometest";
+  private ExecutionPhase phase;
+  private File testDir;
+  private Set<String> failedTests;
+  private List<TestBatch> testBatches;
+  private TestBatch testBatch;
+
+  @Before
+  public void setup() throws Exception {
+    initialize(getClass().getSimpleName());
+    failedTests = Sets.newHashSet();
+  }
+  private ExecutionPhase getPhase() throws IOException {
+    createHostExecutor();
+    phase = new ExecutionPhase(hostExecutors, localCommandFactory, templateDefaults,
+        failedLogDir, Suppliers.ofInstance(testBatches),
+        failedTests, logger);
+    return phase;
+  }
+  private void setupQFile(boolean isParallel) throws Exception {
+    testDir = Dirs.create( new File(baseDir, "test"));
+    Assert.assertTrue(new File(testDir, QFILENAME).createNewFile());
+    testBatch = new QFileTestBatch(DRIVER, "qfile", Sets.newHashSet(QFILENAME), isParallel);
+    testBatches = Collections.singletonList(testBatch);
+  }
+  private void setupUnitTest() throws Exception {
+    testBatch = new UnitTestBatch(DRIVER, false);
+    testBatches = Collections.singletonList(testBatch);
+  }
+  @After
+  public void teardown() {
+    FileUtils.deleteQuietly(baseDir);
+  }
+  @Test
+  public void testPassingQFileTest() throws Throwable {
+    setupQFile(true);
+    getPhase().execute();
+    Approvals.verify(getExecutedCommands());
+    Assert.assertEquals(Sets.newHashSet(), failedTests);
+  }
+  @Test
+  public void testFailingQFile() throws Throwable {
+    setupQFile(true);
+    sshCommandExecutor.putFailure("bash " + LOCAL_DIR + "/" + HOST + "-" + USER +
+        "-0/scratch/hiveptest-" + DRIVER + "-" + QFILENAME + ".sh", 1);
+    String junitOutput = Templates.readResource("TEST-SomeTest-failure.xml");
+    File driverFailureDir = Dirs.create(new File(failedLogDir, testBatch.getName()));
+    File junitOutputFile = new File(driverFailureDir, "TEST-SomeTest-failure.xml");
+    Files.write(junitOutput.getBytes(Charsets.UTF_8), junitOutputFile);
+    getPhase().execute();
+    Approvals.verify(getExecutedCommands());
+    Assert.assertEquals(Sets.newHashSet("SomeTest." + QFILENAME), failedTests);
+  }
+  @Test
+  public void testPassingUnitTest() throws Throwable {
+    setupUnitTest();
+    getPhase().execute();
+    Approvals.verify(getExecutedCommands());
+    Assert.assertEquals(Sets.newHashSet(), failedTests);
+  }
+  @Test
+  public void testFailingUnitTest() throws Throwable {
+    setupUnitTest();
+    sshCommandExecutor.putFailure("bash " + LOCAL_DIR + "/" + HOST + "-" + USER +
+        "-0/scratch/hiveptest-" + DRIVER + ".sh", 1);
+    String junitOutput = Templates.readResource("TEST-SomeTest-failure.xml");
+    File driverFailureDir = Dirs.create(new File(failedLogDir, testBatch.getName()));
+    File junitOutputFile = new File(driverFailureDir, "TEST-SomeTest-failure.xml");
+    Files.write(junitOutput.getBytes(Charsets.UTF_8), junitOutputFile);
+    getPhase().execute();
+    Approvals.verify(getExecutedCommands());
+    Assert.assertEquals(Sets.newHashSet("SomeTest." + QFILENAME), failedTests);
+  }
+}
\ No newline at end of file

Added: hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testFailingQFile.approved.txt
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testFailingQFile.approved.txt?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testFailingQFile.approved.txt (added)
+++ hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testFailingQFile.approved.txt Fri Jul 19 03:47:36 2013
@@ -0,0 +1,3 @@
+/tmp/hive-ptest-units/TestExecutionPhase/logs/failed/driver-sometest /some/local/dir/somehost-someuser-0/logs/
+/tmp/hive-ptest-units/TestExecutionPhase/scratch/hiveptest-driver-sometest.sh /some/local/dir/somehost-someuser-0/scratch/hiveptest-driver-sometest.sh
+bash /some/local/dir/somehost-someuser-0/scratch/hiveptest-driver-sometest.sh
\ No newline at end of file

Added: hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testFailingUnitTest.approved.txt
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testFailingUnitTest.approved.txt?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testFailingUnitTest.approved.txt (added)
+++ hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testFailingUnitTest.approved.txt Fri Jul 19 03:47:36 2013
@@ -0,0 +1,3 @@
+/tmp/hive-ptest-units/TestExecutionPhase/logs/failed/driver /some/local/dir/somehost-someuser-0/logs/
+/tmp/hive-ptest-units/TestExecutionPhase/scratch/hiveptest-driver.sh /some/local/dir/somehost-someuser-0/scratch/hiveptest-driver.sh
+bash /some/local/dir/somehost-someuser-0/scratch/hiveptest-driver.sh
\ No newline at end of file

Added: hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testPassingQFileTest.approved.txt
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testPassingQFileTest.approved.txt?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testPassingQFileTest.approved.txt (added)
+++ hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testPassingQFileTest.approved.txt Fri Jul 19 03:47:36 2013
@@ -0,0 +1,3 @@
+/tmp/hive-ptest-units/TestExecutionPhase/logs/succeeded/driver-sometest /some/local/dir/somehost-someuser-0/logs/
+/tmp/hive-ptest-units/TestExecutionPhase/scratch/hiveptest-driver-sometest.sh /some/local/dir/somehost-someuser-0/scratch/hiveptest-driver-sometest.sh
+bash /some/local/dir/somehost-someuser-0/scratch/hiveptest-driver-sometest.sh
\ No newline at end of file

Added: hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testPassingUnitTest.approved.txt
URL: http://svn.apache.org/viewvc/hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testPassingUnitTest.approved.txt?rev=1504759&view=auto
==============================================================================
--- hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testPassingUnitTest.approved.txt (added)
+++ hive/trunk/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestExecutionPhase.testPassingUnitTest.approved.txt Fri Jul 19 03:47:36 2013
@@ -0,0 +1,3 @@
+/tmp/hive-ptest-units/TestExecutionPhase/logs/succeeded/driver /some/local/dir/somehost-someuser-0/logs/
+/tmp/hive-ptest-units/TestExecutionPhase/scratch/hiveptest-driver.sh /some/local/dir/somehost-someuser-0/scratch/hiveptest-driver.sh
+bash /some/local/dir/somehost-someuser-0/scratch/hiveptest-driver.sh
\ No newline at end of file