1 package org.apache.helix;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.concurrent.TimeoutException;
25
26 import org.apache.log4j.Logger;
27 import org.testng.Assert;
28
29 public class ScriptTestHelper
30 {
31 private static final Logger LOG = Logger.getLogger(ScriptTestHelper.class);
32
33 public static final String INTEGRATION_SCRIPT_DIR = "src/main/scripts/integration-test/script";
34 public static final String INTEGRATION_TEST_DIR = "src/main/scripts/integration-test/testcases";
35 public static final String INTEGRATION_LOG_DIR = "src/main/scripts/integration-test/var/log";
36
37 public static final long EXEC_TIMEOUT = 1200;
38
39 public static String getPrefix()
40 {
41 StringBuilder prefixBuilder = new StringBuilder("");
42 String prefix = "";
43 String filepath = INTEGRATION_SCRIPT_DIR;
44 File integrationScriptDir = new File(filepath);
45
46 while (!integrationScriptDir.exists())
47 {
48 prefixBuilder.append("../");
49 prefix = prefixBuilder.toString();
50
51 integrationScriptDir = new File(prefix + filepath);
52
53
54 if (prefix.length() > 30)
55 {
56 return "";
57 }
58 }
59 return new File(prefix).getAbsolutePath() + "/";
60 }
61
62 public static ExternalCommand runCommandLineTest(String testName, String... arguments) throws IOException, InterruptedException,
63 TimeoutException
64 {
65 ExternalCommand cmd = ExternalCommand.executeWithTimeout(new File(getPrefix() + INTEGRATION_TEST_DIR),
66 testName, EXEC_TIMEOUT, arguments);
67 int exitValue = cmd.exitValue();
68 String output = cmd.getStringOutput("UTF8");
69
70 if (0 == exitValue)
71 {
72 LOG.info("Test " + testName + " has run. ExitCode=" + exitValue + ". Command output: " + output);
73 }
74 else
75 {
76 LOG.warn("Test " + testName + " is FAILING. ExitCode=" + exitValue + ". Command output: " + output);
77 Assert.fail(output);
78
79 }
80 return cmd;
81 }
82 }
83