You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by pb...@apache.org on 2016/12/13 13:19:47 UTC
[16/48] oozie git commit: OOZIE-2729 OYA: refactor XTestCase.
OOZIE-2729 OYA: refactor XTestCase.
Change-Id: If6b97427dea26eeaecf60bbd0ba43d6eda0effeb
Project: http://git-wip-us.apache.org/repos/asf/oozie/repo
Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/ba68347b
Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/ba68347b
Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/ba68347b
Branch: refs/heads/oya
Commit: ba68347b56d6dd7eec792eb463cc36e9728ddbd5
Parents: d5dcc5c
Author: Andras Piros <an...@cloudera.com>
Authored: Thu Nov 17 20:50:19 2016 +0100
Committer: Andras Piros <an...@cloudera.com>
Committed: Thu Nov 17 20:50:19 2016 +0100
----------------------------------------------------------------------
.../action/hadoop/TestFsActionExecutor.java | 4 +-
.../oozie/action/hadoop/TestShellMain.java | 5 +-
.../command/coord/TestCoordRerunXCommand.java | 4 +-
.../oozie/dependency/TestHCatURIHandler.java | 4 +-
.../oozie/jms/TestDefaultConnectionContext.java | 2 +-
.../oozie/jms/TestHCatMessageHandler.java | 2 +-
.../oozie/jms/TestJMSJobEventListener.java | 9 +-
.../oozie/jms/TestJMSSLAEventListener.java | 4 +-
.../oozie/service/TestJMSAccessorService.java | 7 +-
.../apache/oozie/test/MiniOozieTestCase.java | 3 +-
.../apache/oozie/test/TestCaseDirectories.java | 139 ++++
.../apache/oozie/test/TestConfigurations.java | 111 +++
.../org/apache/oozie/test/TestConstants.java | 96 +++
.../org/apache/oozie/test/TestDbCleaner.java | 126 ++++
.../apache/oozie/test/TestPropertiesLoader.java | 102 +++
.../apache/oozie/test/TestSystemProperties.java | 105 +++
.../org/apache/oozie/test/TestXTestCase.java | 8 +-
.../java/org/apache/oozie/test/XFsTestCase.java | 6 +-
.../java/org/apache/oozie/test/XTestCase.java | 740 ++++---------------
19 files changed, 851 insertions(+), 626 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/action/hadoop/TestFsActionExecutor.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/action/hadoop/TestFsActionExecutor.java b/core/src/test/java/org/apache/oozie/action/hadoop/TestFsActionExecutor.java
index 5618cf8..e7fd9c5 100644
--- a/core/src/test/java/org/apache/oozie/action/hadoop/TestFsActionExecutor.java
+++ b/core/src/test/java/org/apache/oozie/action/hadoop/TestFsActionExecutor.java
@@ -35,7 +35,7 @@ import org.apache.oozie.service.HadoopAccessorService;
import org.apache.oozie.service.Services;
import org.apache.oozie.service.URIHandlerService;
import org.apache.oozie.service.WorkflowAppService;
-import org.apache.oozie.test.XTestCase;
+import org.apache.oozie.test.TestConstants;
import org.apache.oozie.util.XConfiguration;
import org.apache.oozie.util.XmlUtils;
import org.jdom.Element;
@@ -305,7 +305,7 @@ public class TestFsActionExecutor extends ActionExecutorTestCase {
public void testDeleteHcat() throws Exception {
//setting current user as test user because directory structure created by HCat have current user permissions (755).
- setSystemProperty(XTestCase.TEST_USER1_PROP, System.getProperty("user.name"));
+ setSystemProperty(TestConstants.TEST_USER1_PROP, System.getProperty("user.name"));
createTestTable();
addPartition(db, table, "year=2012;month=12;dt=02;country=us");
URI hcatURI = getHCatURI(db, table, "country=us;year=2012;month=12;dt=02");
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/action/hadoop/TestShellMain.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/action/hadoop/TestShellMain.java b/core/src/test/java/org/apache/oozie/action/hadoop/TestShellMain.java
index a7d6c18..d184a5a 100644
--- a/core/src/test/java/org/apache/oozie/action/hadoop/TestShellMain.java
+++ b/core/src/test/java/org/apache/oozie/action/hadoop/TestShellMain.java
@@ -25,6 +25,7 @@ import java.io.FileWriter;
import java.io.Writer;
import java.util.Properties;
+import org.apache.oozie.test.TestConstants;
import org.apache.oozie.util.XConfiguration;
//Test cases are mainly implemented in the Base class
@@ -50,8 +51,8 @@ public class TestShellMain extends ShellTestCase {
jobConf.set("fs.default.name", getNameNodeUri());
- jobConf.set(ShellMain.CONF_OOZIE_SHELL_EXEC, SHELL_COMMAND_NAME);
- String[] args = new String[] { SHELL_COMMAND_SCRIPTFILE_OPTION, script.toString(), "A", "B" };
+ jobConf.set(ShellMain.CONF_OOZIE_SHELL_EXEC, TestConstants.SHELL_COMMAND_NAME);
+ String[] args = new String[] { TestConstants.SHELL_COMMAND_SCRIPTFILE_OPTION, script.toString(), "A", "B" };
ActionUtils.setStrings(jobConf, ShellMain.CONF_OOZIE_SHELL_ARGS, args);
ActionUtils.setStrings(jobConf, ShellMain.CONF_OOZIE_SHELL_ENVS,
new String[] { "var1=value1", "var2=value2" });
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/command/coord/TestCoordRerunXCommand.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/command/coord/TestCoordRerunXCommand.java b/core/src/test/java/org/apache/oozie/command/coord/TestCoordRerunXCommand.java
index 9a05a85..6ae0ae2 100644
--- a/core/src/test/java/org/apache/oozie/command/coord/TestCoordRerunXCommand.java
+++ b/core/src/test/java/org/apache/oozie/command/coord/TestCoordRerunXCommand.java
@@ -59,8 +59,8 @@ import org.apache.oozie.service.Services;
import org.apache.oozie.service.StatusTransitService;
import org.apache.oozie.service.URIHandlerService;
import org.apache.oozie.store.StoreException;
+import org.apache.oozie.test.TestConstants;
import org.apache.oozie.test.XDataTestCase;
-import org.apache.oozie.test.XTestCase;
import org.apache.oozie.util.DateUtils;
import org.apache.oozie.util.IOUtils;
import org.apache.oozie.util.XLog;
@@ -571,7 +571,7 @@ public class TestCoordRerunXCommand extends XDataTestCase {
*/
public void testCoordRerunCleanupForHCat() throws Exception {
//setting current user as test user because directory structure created by HCat have current user permissions (755).
- setSystemProperty(XTestCase.TEST_USER1_PROP, System.getProperty("user.name"));
+ setSystemProperty(TestConstants.TEST_USER1_PROP, System.getProperty("user.name"));
super.setupHCatalogServer();
services = super.setupServicesForHCatalog();
services.init();
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/dependency/TestHCatURIHandler.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/dependency/TestHCatURIHandler.java b/core/src/test/java/org/apache/oozie/dependency/TestHCatURIHandler.java
index 615f5e1..5f62c11 100644
--- a/core/src/test/java/org/apache/oozie/dependency/TestHCatURIHandler.java
+++ b/core/src/test/java/org/apache/oozie/dependency/TestHCatURIHandler.java
@@ -24,8 +24,8 @@ import org.apache.hadoop.mapred.JobConf;
import org.apache.oozie.service.HCatAccessorService;
import org.apache.oozie.service.Services;
import org.apache.oozie.service.URIHandlerService;
+import org.apache.oozie.test.TestConstants;
import org.apache.oozie.test.XHCatTestCase;
-import org.apache.oozie.test.XTestCase;
import org.junit.Test;
public class TestHCatURIHandler extends XHCatTestCase {
@@ -69,7 +69,7 @@ public class TestHCatURIHandler extends XHCatTestCase {
@Test
public void testExists() throws Exception {
//setting current user as test user because directory structure created by HCat have current user permissions (755).
- setSystemProperty(XTestCase.TEST_USER1_PROP, System.getProperty("user.name"));
+ setSystemProperty(TestConstants.TEST_USER1_PROP, System.getProperty("user.name"));
createTestTable();
addPartition(db, table, "year=2012;month=12;dt=02;country=us");
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/jms/TestDefaultConnectionContext.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/jms/TestDefaultConnectionContext.java b/core/src/test/java/org/apache/oozie/jms/TestDefaultConnectionContext.java
index e941a8e..5346a91 100644
--- a/core/src/test/java/org/apache/oozie/jms/TestDefaultConnectionContext.java
+++ b/core/src/test/java/org/apache/oozie/jms/TestDefaultConnectionContext.java
@@ -44,7 +44,7 @@ public class TestDefaultConnectionContext extends XTestCase {
conf.set(Services.CONF_SERVICE_EXT_CLASSES,
JMSAccessorService.class.getName() + "," + JMSTopicService.class.getName());
conf.set(JMSJobEventListener.JMS_CONNECTION_PROPERTIES, "java.naming.factory.initial#"
- + ActiveMQConnFactory + ";" + "java.naming.provider.url#" + localActiveMQBroker
+ + ACTIVE_MQ_CONN_FACTORY + ";" + "java.naming.provider.url#" + LOCAL_ACTIVE_MQ_BROKER
+ ";connectionFactoryNames#" + "ConnectionFactory");
services.init();
}
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/jms/TestHCatMessageHandler.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/jms/TestHCatMessageHandler.java b/core/src/test/java/org/apache/oozie/jms/TestHCatMessageHandler.java
index 1a1a44e..2ce5431 100644
--- a/core/src/test/java/org/apache/oozie/jms/TestHCatMessageHandler.java
+++ b/core/src/test/java/org/apache/oozie/jms/TestHCatMessageHandler.java
@@ -66,7 +66,7 @@ public class TestHCatMessageHandler extends XDataTestCase {
super.setUp();
services = super.setupServicesForHCatalog();
services.init();
- connFac = new ActiveMQConnectionFactory(localActiveMQBroker);
+ connFac = new ActiveMQConnectionFactory(LOCAL_ACTIVE_MQ_BROKER);
conn = connFac.createConnection();
conn.start();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/jms/TestJMSJobEventListener.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/jms/TestJMSJobEventListener.java b/core/src/test/java/org/apache/oozie/jms/TestJMSJobEventListener.java
index 728916e..913112f 100644
--- a/core/src/test/java/org/apache/oozie/jms/TestJMSJobEventListener.java
+++ b/core/src/test/java/org/apache/oozie/jms/TestJMSJobEventListener.java
@@ -38,9 +38,6 @@ import org.apache.oozie.client.event.jms.JMSHeaderConstants;
import org.apache.oozie.client.event.message.CoordinatorActionMessage;
import org.apache.oozie.client.event.message.WorkflowJobMessage;
import org.apache.oozie.event.*;
-import org.apache.oozie.jms.ConnectionContext;
-import org.apache.oozie.jms.JMSConnectionInfo;
-import org.apache.oozie.jms.JMSJobEventListener;
import org.apache.oozie.service.JMSAccessorService;
import org.apache.oozie.service.JMSTopicService;
import org.apache.oozie.service.Services;
@@ -63,8 +60,8 @@ public class TestJMSJobEventListener extends XTestCase {
conf = services.getConf();
conf.set(Services.CONF_SERVICE_EXT_CLASSES,
JMSAccessorService.class.getName() + "," + JMSTopicService.class.getName());
- conf.set(JMSJobEventListener.JMS_CONNECTION_PROPERTIES, "java.naming.factory.initial#" + ActiveMQConnFactory
- + ";" + "java.naming.provider.url#" + localActiveMQBroker + ";connectionFactoryNames#"
+ conf.set(JMSJobEventListener.JMS_CONNECTION_PROPERTIES, "java.naming.factory.initial#" + ACTIVE_MQ_CONN_FACTORY
+ + ";" + "java.naming.provider.url#" + LOCAL_ACTIVE_MQ_BROKER + ";connectionFactoryNames#"
+ "ConnectionFactory");
services.init();
}
@@ -329,7 +326,7 @@ public class TestJMSJobEventListener extends XTestCase {
int randomPort = 30000 + random.nextInt(10000);
String brokerURl = "tcp://localhost:" + randomPort;
conf.set(JMSJobEventListener.JMS_CONNECTION_PROPERTIES, "java.naming.factory.initial#"
- + ActiveMQConnFactory + ";" + "java.naming.provider.url#" + brokerURl + ";connectionFactoryNames#"
+ + ACTIVE_MQ_CONN_FACTORY + ";" + "java.naming.provider.url#" + brokerURl + ";connectionFactoryNames#"
+ "ConnectionFactory");
services.init();
JMSJobEventListener wfEventListener = new JMSJobEventListener();
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/jms/TestJMSSLAEventListener.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/jms/TestJMSSLAEventListener.java b/core/src/test/java/org/apache/oozie/jms/TestJMSSLAEventListener.java
index 30fd151..7b9e64b 100644
--- a/core/src/test/java/org/apache/oozie/jms/TestJMSSLAEventListener.java
+++ b/core/src/test/java/org/apache/oozie/jms/TestJMSSLAEventListener.java
@@ -56,8 +56,8 @@ public class TestJMSSLAEventListener extends XTestCase {
conf = services.getConf();
conf.set(Services.CONF_SERVICE_EXT_CLASSES,
JMSAccessorService.class.getName() + "," + JMSTopicService.class.getName());
- conf.set(JMSJobEventListener.JMS_CONNECTION_PROPERTIES, "java.naming.factory.initial#" + ActiveMQConnFactory
- + ";" + "java.naming.provider.url#" + localActiveMQBroker + ";" + "connectionFactoryNames#"
+ conf.set(JMSJobEventListener.JMS_CONNECTION_PROPERTIES, "java.naming.factory.initial#" + ACTIVE_MQ_CONN_FACTORY
+ + ";" + "java.naming.provider.url#" + LOCAL_ACTIVE_MQ_BROKER + ";" + "connectionFactoryNames#"
+ "ConnectionFactory");
services.init();
}
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/service/TestJMSAccessorService.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/service/TestJMSAccessorService.java b/core/src/test/java/org/apache/oozie/service/TestJMSAccessorService.java
index 505049d..96803db 100644
--- a/core/src/test/java/org/apache/oozie/service/TestJMSAccessorService.java
+++ b/core/src/test/java/org/apache/oozie/service/TestJMSAccessorService.java
@@ -21,7 +21,6 @@ package org.apache.oozie.service;
import java.net.URI;
import java.util.Random;
-import javax.jms.JMSException;
import javax.jms.Session;
import org.apache.activemq.broker.BrokerService;
@@ -161,7 +160,7 @@ public class TestJMSAccessorService extends XTestCase {
servicesConf.set(JMSAccessorService.CONF_RETRY_INITIAL_DELAY, "1");
servicesConf.set(JMSAccessorService.CONF_RETRY_MAX_ATTEMPTS, "3");
servicesConf.set(HCatAccessorService.JMS_CONNECTIONS_PROPERTIES, "default=java.naming.factory.initial#"
- + ActiveMQConnFactory + ";" + "java.naming.provider.url#" + brokerURl + ";" + "connectionFactoryNames#"
+ + ACTIVE_MQ_CONN_FACTORY + ";" + "java.naming.provider.url#" + brokerURl + ";" + "connectionFactoryNames#"
+ "ConnectionFactory");
services.init();
HCatAccessorService hcatService = Services.get().get(HCatAccessorService.class);
@@ -193,7 +192,7 @@ public class TestJMSAccessorService extends XTestCase {
services = super.setupServicesForHCatalog();
int randomPort = 30000 + random.nextInt(10000);
String brokerURL = "tcp://localhost:" + randomPort;
- String jndiPropertiesString = "java.naming.factory.initial#" + ActiveMQConnFactory + ";"
+ String jndiPropertiesString = "java.naming.factory.initial#" + ACTIVE_MQ_CONN_FACTORY + ";"
+ "java.naming.provider.url#" + brokerURL + ";" + "connectionFactoryNames#" + "ConnectionFactory";
Configuration servicesConf = services.getConf();
servicesConf.set(JMSAccessorService.CONF_RETRY_INITIAL_DELAY, "1");
@@ -242,7 +241,7 @@ public class TestJMSAccessorService extends XTestCase {
public void testConnectionRetryMaxAttempt() throws Exception {
services.destroy();
services = super.setupServicesForHCatalog();
- String jndiPropertiesString = "java.naming.factory.initial#" + ActiveMQConnFactory + ";"
+ String jndiPropertiesString = "java.naming.factory.initial#" + ACTIVE_MQ_CONN_FACTORY + ";"
+ "java.naming.provider.url#" + "tcp://localhost:12345;connectionFactoryNames#ConnectionFactory";
Configuration servicesConf = services.getConf();
servicesConf.set(JMSAccessorService.CONF_RETRY_INITIAL_DELAY, "1");
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/test/MiniOozieTestCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/test/MiniOozieTestCase.java b/core/src/test/java/org/apache/oozie/test/MiniOozieTestCase.java
index 12ede02..93b9cd0 100644
--- a/core/src/test/java/org/apache/oozie/test/MiniOozieTestCase.java
+++ b/core/src/test/java/org/apache/oozie/test/MiniOozieTestCase.java
@@ -18,7 +18,6 @@
package org.apache.oozie.test;
-import org.apache.oozie.test.XFsTestCase;
import org.apache.oozie.client.OozieClient;
import org.apache.oozie.local.LocalOozie;
@@ -39,7 +38,7 @@ import org.apache.oozie.local.LocalOozie;
* 'hdfs://localhost:9000'.
* <p/>
* The test working directory is created in the specified FS URI, under the current user name home directory, under the
- * subdirectory name specified wit the system property {@link XTestCase#OOZIE_TEST_DIR}. The default value is '/tmp'.
+ * subdirectory name specified wit the system property {@link TestConstants#OOZIE_TEST_DIR}. The default value is '/tmp'.
* <p/> The path of the test working directory is: '$FS_URI/user/$USER/$OOZIE_TEST_DIR/oozietest/$TEST_CASE_CLASS/$TEST_CASE_METHOD/'
* <p/> For example: 'hdfs://localhost:9000/user/tucu/tmp/oozietest/org.apache.oozie.service.TestELService/testEL/'
* <p/>
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/test/TestCaseDirectories.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/test/TestCaseDirectories.java b/core/src/test/java/org/apache/oozie/test/TestCaseDirectories.java
new file mode 100644
index 0000000..36be4da
--- /dev/null
+++ b/core/src/test/java/org/apache/oozie/test/TestCaseDirectories.java
@@ -0,0 +1,139 @@
+/**
+ * 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.oozie.test;
+
+import junit.framework.TestCase;
+import org.apache.oozie.util.ParamChecker;
+import org.apache.oozie.util.XLog;
+
+import java.io.File;
+import java.io.IOException;
+
+class TestCaseDirectories {
+
+ /**
+ * Create the test working directory.
+ *
+ * @param testCase testcase instance to obtain the working directory.
+ * @param cleanup indicates if the directory should be cleaned up if it exists.
+ * @return return the path of the test working directory, it is always an absolute path.
+ * @throws Exception if the test working directory could not be created or cleaned up.
+ */
+ String createTestCaseDir(final TestCase testCase, final boolean cleanup) throws Exception {
+ final String testCaseDir = getTestCaseDirInternal(testCase);
+ System.out.println();
+ System.out.println(XLog.format("Setting testcase work dir[{0}]", testCaseDir));
+ if (cleanup) {
+ delete(new File(testCaseDir));
+ }
+ final File dir = new File(testCaseDir);
+ if (!dir.mkdirs()) {
+ throw new RuntimeException(XLog.format("Could not create testcase dir[{0}]", testCaseDir));
+ }
+ return testCaseDir;
+ }
+
+ /**
+ * Return the test working directory.
+ * <p/>
+ * It returns <code>${oozie.test.dir}/oozietests/TESTCLASSNAME/TESTMETHODNAME</code>.
+ *
+ * @param testCase testcase instance to obtain the working directory.
+ * @return the test working directory.
+ */
+ private String getTestCaseDirInternal(final TestCase testCase) {
+ ParamChecker.notNull(testCase, "testCase");
+
+ File dir = new File(System.getProperty(TestConstants.OOZIE_TEST_DIR, "target/test-data"));
+
+ dir = new File(dir, "oozietests").getAbsoluteFile();
+ dir = new File(dir, testCase.getClass().getName());
+ dir = new File(dir, testCase.getName());
+
+ return dir.getAbsolutePath();
+ }
+
+ protected void delete(final File file) throws IOException {
+ ParamChecker.notNull(file, "file");
+ if (file.getAbsolutePath().length() < 5) {
+ throw new RuntimeException(XLog.format("path [{0}] is too short, not deleting", file.getAbsolutePath()));
+ }
+ if (file.exists()) {
+ if (file.isDirectory()) {
+ final File[] children = file.listFiles();
+ if (children != null) {
+ for (final File child : children) {
+ delete(child);
+ }
+ }
+ }
+ if (!file.delete()) {
+ throw new RuntimeException(XLog.format("could not delete path [{0}]", file.getAbsolutePath()));
+ }
+ }
+ else {
+ // With a dangling symlink, exists() doesn't return true so try to delete it anyway; we fail silently in case the file
+ // truely doesn't exist
+ file.delete();
+ }
+ }
+
+ String createTestCaseSubdir(String testCaseDir, String[] subDirNames) {
+ ParamChecker.notNull(subDirNames, "subDirName");
+ if (subDirNames.length == 0) {
+ throw new RuntimeException(XLog.format("Could not create testcase subdir ''; it already exists"));
+ }
+
+ File dir = new File(testCaseDir);
+ for (int i = 0; i < subDirNames.length; i++) {
+ ParamChecker.notNull(subDirNames[i], "subDirName[" + i + "]");
+ dir = new File(dir, subDirNames[i]);
+ }
+
+ if (!dir.mkdirs()) {
+ throw new RuntimeException(XLog.format("Could not create testcase subdir[{0}]", dir));
+ }
+ return dir.getAbsolutePath();
+ }
+
+ void createTestDirOrError() {
+ final String baseDir = System.getProperty(TestConstants.OOZIE_TEST_DIR, new File("target/test-data").getAbsolutePath());
+ String msg = null;
+ final File testDir = new File(baseDir);
+ if (!testDir.isAbsolute()) {
+ msg = XLog.format("System property [{0}]=[{1}] must be set to an absolute path", TestConstants.OOZIE_TEST_DIR, baseDir);
+ }
+ else {
+ if (baseDir.length() < 4) {
+ msg = XLog.format("System property [{0}]=[{1}] path must be at least 4 chars", TestConstants.OOZIE_TEST_DIR, baseDir);
+ }
+ }
+ if (msg != null) {
+ System.err.println();
+ System.err.println(msg);
+ System.exit(-1);
+ }
+ testDir.mkdirs();
+ if (!testDir.exists() || !testDir.isDirectory()) {
+ System.err.println();
+ System.err.println(XLog.format("Could not create test dir [{0}]", baseDir));
+ System.exit(-1);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/test/TestConfigurations.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/test/TestConfigurations.java b/core/src/test/java/org/apache/oozie/test/TestConfigurations.java
new file mode 100644
index 0000000..c6c1d23
--- /dev/null
+++ b/core/src/test/java/org/apache/oozie/test/TestConfigurations.java
@@ -0,0 +1,111 @@
+/**
+ * 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.oozie.test;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.oozie.dependency.FSURIHandler;
+import org.apache.oozie.dependency.HCatURIHandler;
+import org.apache.oozie.service.*;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Map;
+
+class TestConfigurations {
+
+ Configuration createYarnConfig(final Configuration parentConfig) {
+ final Configuration yarnConfig = new YarnConfiguration(parentConfig);
+
+ yarnConfig.setBoolean(YarnConfiguration.AUTO_FAILOVER_ENABLED, false);
+ yarnConfig.set(YarnConfiguration.RM_WEBAPP_ADDRESS, "localhost:0");
+
+ return yarnConfig;
+ }
+
+ @SuppressWarnings("deprecation")
+ JobConf createJobConfFromYarnCluster(final Configuration yarnConfiguration) {
+ final JobConf jobConf = new JobConf();
+ final JobConf jobConfYarn = new JobConf(yarnConfiguration);
+
+ for (final Map.Entry<String, String> entry : jobConfYarn) {
+ // MiniMRClientClusterFactory sets the job jar in Hadoop 2.0 causing tests to fail
+ // TODO call conf.unset after moving completely to Hadoop 2.x
+ if (!(entry.getKey().equals("mapreduce.job.jar") || entry.getKey().equals("mapred.jar"))) {
+ jobConf.set(entry.getKey(), entry.getValue());
+ }
+ }
+
+ return jobConf;
+ }
+
+ JobConf createPristineJobConf(final String jobTrackerUri, final String nameNodeUri) {
+ final JobConf jobConf = new JobConf();
+
+ jobConf.set("mapred.job.tracker", jobTrackerUri);
+ jobConf.set("fs.default.name", nameNodeUri);
+
+ return jobConf;
+ }
+
+ JobConf createDFSConfig(String oozieUser, String testGroup) throws UnknownHostException {
+ final JobConf conf = new JobConf();
+ conf.set("dfs.block.access.token.enable", "false");
+ conf.set("dfs.permissions", "true");
+ conf.set("hadoop.security.authentication", "simple");
+
+ //Doing this because Hadoop 1.x does not support '*' if the value is '*,127.0.0.1'
+ final StringBuilder sb = new StringBuilder();
+ sb.append("127.0.0.1,localhost");
+ for (final InetAddress i : InetAddress.getAllByName(InetAddress.getLocalHost().getHostName())) {
+ sb.append(",").append(i.getCanonicalHostName());
+ }
+ conf.set("hadoop.proxyuser." + oozieUser + ".hosts", sb.toString());
+
+ conf.set("hadoop.proxyuser." + oozieUser + ".groups", testGroup);
+ conf.set("mapred.tasktracker.map.tasks.maximum", "4");
+ conf.set("mapred.tasktracker.reduce.tasks.maximum", "4");
+
+ conf.set("hadoop.tmp.dir", "target/test-data" + "/minicluster");
+
+ // Scheduler properties required for YARN CapacityScheduler to work
+ conf.set("yarn.scheduler.capacity.root.queues", "default");
+ conf.set("yarn.scheduler.capacity.root.default.capacity", "100");
+ // Required to prevent deadlocks with YARN CapacityScheduler
+ conf.set("yarn.scheduler.capacity.maximum-am-resource-percent", "0.5");
+
+ return conf;
+ }
+
+ void setConfigurationForHCatalog(final Services services) {
+ final Configuration conf = services.getConf();
+
+ conf.set(Services.CONF_SERVICE_EXT_CLASSES,
+ JMSAccessorService.class.getName() + "," +
+ PartitionDependencyManagerService.class.getName() + "," +
+ HCatAccessorService.class.getName());
+ conf.set(HCatAccessorService.JMS_CONNECTIONS_PROPERTIES,
+ "default=java.naming.factory.initial#" + XTestCase.ACTIVE_MQ_CONN_FACTORY + ";" +
+ "java.naming.provider.url#" + XTestCase.LOCAL_ACTIVE_MQ_BROKER +
+ "connectionFactoryNames#" + "ConnectionFactory");
+ conf.set(URIHandlerService.URI_HANDLERS,
+ FSURIHandler.class.getName() + "," + HCatURIHandler.class.getName());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/test/TestConstants.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/test/TestConstants.java b/core/src/test/java/org/apache/oozie/test/TestConstants.java
new file mode 100644
index 0000000..f7d4580
--- /dev/null
+++ b/core/src/test/java/org/apache/oozie/test/TestConstants.java
@@ -0,0 +1,96 @@
+/**
+ * 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.oozie.test;
+
+import org.apache.hadoop.util.Shell;
+
+public class TestConstants {
+ /**
+ * System property that specifies the default test user name used by
+ * the tests. The defalt value of this property is <tt>test</tt>.
+ */
+ public static final String TEST_USER1_PROP = "oozie.test.user.test";
+ /**
+ * System property that specifies the test groiup used by the tests.
+ * The default value of this property is <tt>testg</tt>.
+ */
+ public static final String TEST_GROUP_PROP2 = "oozie.test.group2";
+ /**
+ * Name of the shell command
+ */
+ public static final String SHELL_COMMAND_NAME = (Shell.WINDOWS) ? "cmd" : "bash";
+ /**
+ * Extension for shell script files
+ */
+ protected static final String SHELL_COMMAND_SCRIPTFILE_EXTENSION = (Shell.WINDOWS) ? "cmd" : "sh";
+ /**
+ * Option for shell command to pass script files
+ */
+ public static final String SHELL_COMMAND_SCRIPTFILE_OPTION = (Shell.WINDOWS) ? "/c" : "-c";
+ /**
+ * System property to specify the parent directory for the 'oozietests' directory to be used as base for all test
+ * working directories. </p> If this property is not set, the assumed value is '/tmp'.
+ */
+ static final String OOZIE_TEST_DIR = "oozie.test.dir";
+ /**
+ * System property to specify the Hadoop Job Tracker to use for testing. </p> If this property is not set, the
+ * assumed value is 'locahost:9001'.
+ */
+ static final String OOZIE_TEST_JOB_TRACKER = "oozie.test.job.tracker";
+ /**
+ * System property to specify the Hadoop Name Node to use for testing. </p> If this property is not set, the assumed
+ * value is 'locahost:9000'.
+ */
+ static final String OOZIE_TEST_NAME_NODE = "oozie.test.name.node";
+ /**
+ * System property to specify the second Hadoop Name Node to use for testing. </p> If this property is not set, the assumed
+ * value is 'locahost:9100'.
+ */
+ static final String OOZIE_TEST_NAME_NODE2 = "oozie.test.name.node2";
+ /**
+ * System property to specify the Hadoop Version to use for testing. </p> If this property is not set, the assumed
+ * value is "0.20.0"
+ */
+ static final String HADOOP_VERSION = "hadoop.version";
+ /**
+ * System property that specifies the user that test oozie instance runs as.
+ * The value of this property defaults to the "${user.name} system property.
+ */
+ static final String TEST_OOZIE_USER_PROP = "oozie.test.user.oozie";
+ /**
+ * System property that specifies an auxilliary test user name used by the
+ * tests. The default value of this property is <tt>test2</tt>.
+ */
+ static final String TEST_USER2_PROP = "oozie.test.user.test2";
+ /**
+ * System property that specifies another auxilliary test user name used by
+ * the tests. The default value of this property is <tt>test3</tt>.
+ */
+ static final String TEST_USER3_PROP = "oozie.test.user.test3";
+ /**
+ * System property that specifies the test groiup used by the tests.
+ * The default value of this property is <tt>testg</tt>.
+ */
+ static final String TEST_GROUP_PROP = "oozie.test.group";
+ /**
+ * System property that specifies the wait time, in seconds, between testcases before
+ * triggering a shutdown. The default value is 10 sec.
+ */
+ static final String TEST_MINICLUSTER_MONITOR_SHUTDOWN_WAIT = "oozie.test.minicluster.monitor.shutdown.wait";
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/test/TestDbCleaner.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/test/TestDbCleaner.java b/core/src/test/java/org/apache/oozie/test/TestDbCleaner.java
new file mode 100644
index 0000000..318274c
--- /dev/null
+++ b/core/src/test/java/org/apache/oozie/test/TestDbCleaner.java
@@ -0,0 +1,126 @@
+/**
+ * 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.oozie.test;
+
+import org.apache.commons.logging.LogFactory;
+import org.apache.oozie.*;
+import org.apache.oozie.service.JPAService;
+import org.apache.oozie.service.ServiceException;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.service.StoreService;
+import org.apache.oozie.sla.SLARegistrationBean;
+import org.apache.oozie.sla.SLASummaryBean;
+import org.apache.oozie.store.StoreException;
+import org.apache.oozie.util.XLog;
+
+import javax.persistence.EntityManager;
+import javax.persistence.FlushModeType;
+import javax.persistence.TypedQuery;
+import java.util.List;
+
+public class TestDbCleaner {
+ private static final XLog log = new XLog(LogFactory.getLog(TestDbCleaner.class));
+
+ /**
+ * Minimal set of require Services for cleaning up the database ({@link JPAService} and {@link StoreService})
+ */
+ private static final String MINIMAL_SERVICES_FOR_DB_CLEANUP = JPAService.class.getName() + "," + StoreService.class.getName();
+
+ private EntityManager entityManager;
+
+ void cleanDbTables() throws StoreException, ServiceException {
+ // If the Services are already loaded, then a test is likely calling this for something specific and we shouldn't mess with
+ // the Services; so just cleanup the database
+ if (Services.get() != null) {
+ performCleanDbTables();
+ }
+ else {
+ // Otherwise, this is probably being called during setup() and we should just load the minimal set of required Services
+ // needed to cleanup the database and shut them down when done; the test will likely start its own Services later and
+ // we don't want to interfere
+ try {
+ final Services services = new Services();
+ services.getConf().set(Services.CONF_SERVICE_CLASSES, MINIMAL_SERVICES_FOR_DB_CLEANUP);
+ services.init();
+ performCleanDbTables();
+ } finally {
+ if (Services.get() != null) {
+ Services.get().destroy();
+ }
+ }
+ }
+ }
+
+ private void performCleanDbTables() throws StoreException {
+ ensureEntityManager().setFlushMode(FlushModeType.COMMIT);
+ ensureEntityManager().getTransaction().begin();
+
+ final int wfjSize = removeAllByQueryName("GET_WORKFLOWS", WorkflowJobBean.class);
+ final int wfaSize = removeAllByQueryName("GET_ACTIONS", WorkflowActionBean.class);
+ final int cojSize = removeAllByQueryName("GET_COORD_JOBS", CoordinatorJobBean.class);
+ final int coaSize = removeAllByQueryName("GET_COORD_ACTIONS", CoordinatorActionBean.class);
+ final int bjSize = removeAllByQueryName("GET_BUNDLE_JOBS", BundleJobBean.class);
+ final int baSize = removeAllByQueryName("GET_BUNDLE_ACTIONS", BundleActionBean.class);
+ final int slaSize = removeAllByQueryName("GET_SLA_EVENTS", SLAEventBean.class);
+ final int ssSize = removeAllByQueryName("GET_SLA_EVENTS", SLAEventBean.class);
+ final int slaRegSize = removeAllByHql("select OBJECT(w) from SLARegistrationBean w", SLARegistrationBean.class);
+ final int slaSumSize = removeAllByHql("select OBJECT(w) from SLASummaryBean w", SLASummaryBean.class);
+
+ ensureEntityManager().getTransaction().commit();
+ ensureEntityManager().close();
+
+ log.info(wfjSize + " entries in WF_JOBS removed from DB!");
+ log.info(wfaSize + " entries in WF_ACTIONS removed from DB!");
+ log.info(cojSize + " entries in COORD_JOBS removed from DB!");
+ log.info(coaSize + " entries in COORD_ACTIONS removed from DB!");
+ log.info(bjSize + " entries in BUNDLE_JOBS removed from DB!");
+ log.info(baSize + " entries in BUNDLE_ACTIONS removed from DB!");
+ log.info(slaSize + " entries in SLA_EVENTS removed from DB!");
+ log.info(ssSize + " entries in SLA_SUMMARY removed from DB!");
+ log.info(slaRegSize + " entries in SLA_REGISTRATION removed from DB!");
+ log.info(slaSumSize + " entries in SLA_SUMMARY removed from DB!");
+ }
+
+ private <E> int removeAllByQueryName(final String queryName, final Class<E> entityClass) {
+ return removeAll(ensureEntityManager().createNamedQuery(queryName, entityClass));
+ }
+
+ private <E> int removeAllByHql(final String hql, final Class<E> entityClass) {
+ return removeAll(ensureEntityManager().createQuery(hql, entityClass));
+ }
+
+ private <E> int removeAll(final TypedQuery<E> query) {
+ final List<E> entitiesToRemove = query.getResultList();
+ final int removedEntitiedCount = entitiesToRemove.size();
+
+ for (final E entityToRemove : entitiesToRemove) {
+ ensureEntityManager().remove(entityToRemove);
+ }
+
+ return removedEntitiedCount;
+ }
+
+ private EntityManager ensureEntityManager() {
+ if (entityManager == null) {
+ entityManager = Services.get().get(JPAService.class).getEntityManager();
+ }
+
+ return entityManager;
+ }
+}
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/test/TestPropertiesLoader.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/test/TestPropertiesLoader.java b/core/src/test/java/org/apache/oozie/test/TestPropertiesLoader.java
new file mode 100644
index 0000000..97057f8
--- /dev/null
+++ b/core/src/test/java/org/apache/oozie/test/TestPropertiesLoader.java
@@ -0,0 +1,102 @@
+/**
+ * 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.oozie.test;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+
+public class TestPropertiesLoader {
+
+ public File loadTestPropertiesOrThrow() {
+ try {
+ final File oozieSrcDir = findOozieSrcDir();
+
+ final String testPropsFile = System.getProperty(XTestCase.OOZIE_TEST_PROPERTIES, "test.properties");
+ final File file = new File(testPropsFile).isAbsolute()
+ ? new File(testPropsFile) : new File(oozieSrcDir, testPropsFile);
+ if (file.exists()) {
+ loadTestProperties(file);
+ }
+ else {
+ checkTestPropertiesAndError();
+ }
+
+ return oozieSrcDir;
+ } catch (final IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private File findOozieSrcDir() {
+ File oozieSrcDir = new File("core").getAbsoluteFile();
+
+ if (!oozieSrcDir.exists()) {
+ oozieSrcDir = oozieSrcDir.getParentFile().getParentFile();
+ oozieSrcDir = new File(oozieSrcDir, "core");
+ }
+ if (!oozieSrcDir.exists()) {
+ oozieSrcDir = oozieSrcDir.getParentFile().getParentFile();
+ oozieSrcDir = new File(oozieSrcDir, "core");
+ }
+ if (!oozieSrcDir.exists()) {
+ // We're probably being run from outside of Oozie (e.g. MiniOozie), so just use a dummy location here.
+ // Anything that uses this location should have a fallback anyway.
+ oozieSrcDir = new File(".");
+ }
+ else {
+ oozieSrcDir = oozieSrcDir.getParentFile();
+ }
+
+ return oozieSrcDir;
+ }
+
+ private void loadTestProperties(final File file) throws IOException {
+ System.out.println();
+ System.out.println("*********************************************************************************");
+ System.out.println("Loading test system properties from: " + file.getAbsolutePath());
+ System.out.println();
+ final Properties props = new Properties();
+ props.load(new FileReader(file));
+ for (final Map.Entry entry : props.entrySet()) {
+ if (!System.getProperties().containsKey(entry.getKey())) {
+ System.setProperty((String) entry.getKey(), (String) entry.getValue());
+ System.out.println(entry.getKey() + " = " + entry.getValue());
+ }
+ else {
+ System.out.println(entry.getKey() + " IGNORED, using command line value = " +
+ System.getProperty((String) entry.getKey()));
+ }
+ }
+ System.out.println("*********************************************************************************");
+ System.out.println();
+ }
+
+ private void checkTestPropertiesAndError() {
+ if (System.getProperty(XTestCase.OOZIE_TEST_PROPERTIES) != null) {
+ System.err.println();
+ System.err.println("ERROR: Specified test file does not exist: " +
+ System.getProperty(XTestCase.OOZIE_TEST_PROPERTIES));
+ System.err.println();
+ System.exit(-1);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/test/TestSystemProperties.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/test/TestSystemProperties.java b/core/src/test/java/org/apache/oozie/test/TestSystemProperties.java
new file mode 100644
index 0000000..dcc770a
--- /dev/null
+++ b/core/src/test/java/org/apache/oozie/test/TestSystemProperties.java
@@ -0,0 +1,105 @@
+/**
+ * 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.oozie.test;
+
+import org.apache.oozie.service.ConfigurationService;
+import org.apache.oozie.service.HadoopAccessorService;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class TestSystemProperties {
+ private Map<String, String> sysProps;
+
+ private boolean embeddedHadoop = false;
+
+ private boolean embeddedHadoop2 = false;
+
+ void setupSystemProperties(final String testCaseDir) throws Exception {
+ if (System.getProperty("oozielocal.log") == null) {
+ setSystemProperty("oozielocal.log", "/tmp/oozielocal.log");
+ }
+ if (System.getProperty("oozie.test.hadoop.security", "simple").equals("kerberos")) {
+ System.setProperty("oozie.service.HadoopAccessorService.kerberos.enabled", "true");
+ }
+ if (System.getProperty("oozie.test.hadoop.minicluster", "true").equals("true")) {
+ embeddedHadoop = true;
+ // Second cluster is not necessary without the first one
+ if (System.getProperty("oozie.test.hadoop.minicluster2", "false").equals("true")) {
+ embeddedHadoop2 = true;
+ }
+ }
+
+ if (System.getProperty("oozie.test.db.host") == null) {
+ System.setProperty("oozie.test.db.host", "localhost");
+ }
+ setSystemProperty(ConfigurationService.OOZIE_DATA_DIR, testCaseDir);
+
+ setSystemProperty(HadoopAccessorService.SUPPORTED_FILESYSTEMS, "*");
+ }
+
+ /**
+ * Reset changed system properties to their original values. <p/> Called from {@link XTestCase#tearDown}.
+ */
+ void resetSystemProperties() {
+ if (sysProps != null) {
+ for (final Map.Entry<String, String> entry : sysProps.entrySet()) {
+ if (entry.getValue() != null) {
+ System.setProperty(entry.getKey(), entry.getValue());
+ }
+ else {
+ System.getProperties().remove(entry.getKey());
+ }
+ }
+ sysProps.clear();
+ }
+ }
+
+ /**
+ * Set a system property for the duration of the method test case.
+ * <p/>
+ * After the test method ends the original value is restored.
+ *
+ * @param name system property name.
+ * @param value value to set.
+ */
+ protected void setSystemProperty(final String name, final String value) {
+ if (sysProps == null) {
+ sysProps = new HashMap<String, String>();
+ }
+ if (!sysProps.containsKey(name)) {
+ final String currentValue = System.getProperty(name);
+ sysProps.put(name, currentValue);
+ }
+ if (value != null) {
+ System.setProperty(name, value);
+ }
+ else {
+ System.getProperties().remove(name);
+ }
+ }
+
+ boolean isEmbeddedHadoop() {
+ return embeddedHadoop;
+ }
+
+ boolean isEmbeddedHadoop2() {
+ return embeddedHadoop2;
+ }
+}
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/test/TestXTestCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/test/TestXTestCase.java b/core/src/test/java/org/apache/oozie/test/TestXTestCase.java
index 7a2d70d..735f80a 100644
--- a/core/src/test/java/org/apache/oozie/test/TestXTestCase.java
+++ b/core/src/test/java/org/apache/oozie/test/TestXTestCase.java
@@ -37,7 +37,7 @@ public class TestXTestCase extends TestCase {
}
public void testBaseDir() throws Exception {
- testBaseDir = System.getProperty(XTestCase.OOZIE_TEST_DIR);
+ testBaseDir = System.getProperty(TestConstants.OOZIE_TEST_DIR);
try {
MyXTestCase testcase = new MyXTestCase();
testcase.setName(getName());
@@ -47,7 +47,7 @@ public class TestXTestCase extends TestCase {
}
finally {
if (testBaseDir != null) {
- System.getProperties().setProperty(XTestCase.OOZIE_TEST_DIR, testBaseDir);
+ System.getProperties().setProperty(TestConstants.OOZIE_TEST_DIR, testBaseDir);
}
}
}
@@ -190,8 +190,8 @@ public class TestXTestCase extends TestCase {
public void testHadoopSysProps() {
if (TESTING) {
- setSystemProperty(XTestCase.OOZIE_TEST_NAME_NODE, "hdfs://xyz:9000");
- setSystemProperty(XTestCase.OOZIE_TEST_JOB_TRACKER, "xyz:9001");
+ setSystemProperty(TestConstants.OOZIE_TEST_NAME_NODE, "hdfs://xyz:9000");
+ setSystemProperty(TestConstants.OOZIE_TEST_JOB_TRACKER, "xyz:9001");
assertEquals("hdfs://xyz:9000", getNameNodeUri());
assertEquals("xyz:9001", getJobTrackerUri());
}
http://git-wip-us.apache.org/repos/asf/oozie/blob/ba68347b/core/src/test/java/org/apache/oozie/test/XFsTestCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/test/XFsTestCase.java b/core/src/test/java/org/apache/oozie/test/XFsTestCase.java
index 20529e8..7a419d1 100644
--- a/core/src/test/java/org/apache/oozie/test/XFsTestCase.java
+++ b/core/src/test/java/org/apache/oozie/test/XFsTestCase.java
@@ -28,7 +28,6 @@ import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.oozie.util.XConfiguration;
import org.apache.oozie.util.XLog;
-import org.apache.oozie.client.WorkflowAction;
import org.apache.oozie.client.WorkflowJob;
import org.apache.oozie.command.wf.ActionXCommand.ActionExecutorContext;
import org.apache.oozie.service.HadoopAccessorException;
@@ -37,16 +36,15 @@ import org.apache.oozie.service.Services;
import java.io.IOException;
import java.net.URI;
-import java.net.URISyntaxException;
/**
* Base JUnit <code>TestCase</code> subclass used by all Oozie testcases that need Hadoop FS access. <p/> As part of its
* setup, this testcase class creates a unique test working directory per test method in the FS. <p/> The URI of the FS
- * namenode must be specified via the {@link XTestCase#OOZIE_TEST_NAME_NODE} system property. The default value is
+ * namenode must be specified via the {@link TestConstants#OOZIE_TEST_NAME_NODE} system property. The default value is
* 'hdfs://localhost:9000'.
*
* The test working directory is created in the specified FS URI, under the current user name home directory, under the
- * subdirectory name specified wit the system property {@link XTestCase#OOZIE_TEST_DIR}. The default value is '/tmp'.
+ * subdirectory name specified wit the system property {@link TestConstants#OOZIE_TEST_DIR}. The default value is '/tmp'.
* <p/> The path of the test working directory is: '$FS_URI/user/$USER/$OOZIE_TEST_DIR/oozietest/$TEST_CASE_CLASS/$TEST_CASE_METHOD/'
* <p/> For example: 'hdfs://localhost:9000/user/tucu/tmp/oozietest/org.apache.oozie.service.TestELService/testEL/'
*/