SQOOP-2758: Sqoop2: Add integration test for shell
(Colin Ma via Jarek Jarcec Cecho)
Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/67214a48
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/67214a48
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/67214a48
Branch: refs/heads/sqoop2
Commit: 67214a48c5278811da93b7d0a26d2f93eef1f6df
Parents: 88654b9
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Thu Jan 14 12:06:21 2016 -0800
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Thu Jan 14 12:06:21 2016 -0800
----------------------------------------------------------------------
.../java/org/apache/sqoop/shell/SetCommand.java | 2 +-
.../org/apache/sqoop/shell/ShowCommand.java | 2 +-
.../org/apache/sqoop/shell/StartCommand.java | 2 +-
.../org/apache/sqoop/shell/StatusCommand.java | 2 +-
.../org/apache/sqoop/shell/StopCommand.java | 2 +-
test/pom.xml | 20 ++
.../test/infrastructure/SqoopTestCase.java | 28 +-
.../providers/SqoopInfrastructureProvider.java | 8 +-
...SqoopInfrastructureProviderForShellTest.java | 37 +++
...tySqoopMiniClusterWithExternalConnector.java | 82 +++++
.../testcases/ConnectorClasspathTestCase.java | 235 ---------------
.../sqoop/test/testcases/ShellTestCase.java | 94 ++++++
.../apache/sqoop/test/utils/ConnectorUtils.java | 236 +++++++++++++++
.../connectorloading/ClasspathTest.java | 25 +-
.../ConnectorClasspathIsolationTest.java | 11 +-
.../SubmissionWithDisabledModelObjectsTest.java | 2 +-
.../integration/shell/CloneCommandTest.java | 125 ++++++++
.../integration/shell/CreateCommandTest.java | 117 ++++++++
.../integration/shell/DeleteCommandTest.java | 97 ++++++
.../integration/shell/DisableCommandTest.java | 97 ++++++
.../integration/shell/EnableCommandTest.java | 99 ++++++
.../sqoop/integration/shell/SetCommandTest.java | 152 ++++++++++
.../integration/shell/ShowCommandTest.java | 300 +++++++++++++++++++
.../integration/shell/StartCommandTest.java | 77 +++++
.../integration/shell/StatusCommandTest.java | 80 +++++
.../integration/shell/StopCommandTest.java | 63 ++++
.../integration/shell/UpdateCommandTest.java | 127 ++++++++
.../TestConnectorForShell.java | 85 ++++++
.../TestExtractorForShell.java | 35 +++
.../TestFromDestroyerForShell.java | 27 ++
.../TestFromInitializerForShell.java | 27 ++
.../TestFromJobConfigForShell.java | 28 ++
.../TestFromJobConfigurationForShell.java | 29 ++
.../TestLinkConfigForShell.java | 32 ++
.../TestLinkConfigurationForShell.java | 29 ++
.../TestLoaderForShell.java | 33 ++
.../TestPartitionForShell.java | 36 +++
.../TestPartitionerForShell.java | 37 +++
.../TestToDestroyerForShell.java | 27 ++
.../TestToInitializerForShell.java | 27 ++
.../TestToJobConfigForShell.java | 30 ++
.../TestToJobConfigurationForShell.java | 29 ++
.../sqoopconnector.properties | 18 ++
.../test-connector-for-shell.properties | 48 +++
test/src/test/resources/shell-tests-suite.xml | 33 ++
45 files changed, 2465 insertions(+), 267 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/shell/src/main/java/org/apache/sqoop/shell/SetCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/SetCommand.java b/shell/src/main/java/org/apache/sqoop/shell/SetCommand.java
index 0a04e3d..3feaac3 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/SetCommand.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/SetCommand.java
@@ -23,7 +23,7 @@ import org.codehaus.groovy.tools.shell.Groovysh;
public class SetCommand extends SqoopCommand {
- protected SetCommand(Groovysh shell) {
+ public SetCommand(Groovysh shell) {
super(shell,
Constants.CMD_SET,
Constants.CMD_SET_SC,
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/shell/src/main/java/org/apache/sqoop/shell/ShowCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowCommand.java b/shell/src/main/java/org/apache/sqoop/shell/ShowCommand.java
index c148eeb..eb8522a 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/ShowCommand.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShowCommand.java
@@ -23,7 +23,7 @@ import org.codehaus.groovy.tools.shell.Groovysh;
public class ShowCommand extends SqoopCommand {
- protected ShowCommand(Groovysh shell) {
+ public ShowCommand(Groovysh shell) {
super(shell,
Constants.CMD_SHOW,
Constants.CMD_SHOW_SC,
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/shell/src/main/java/org/apache/sqoop/shell/StartCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/StartCommand.java b/shell/src/main/java/org/apache/sqoop/shell/StartCommand.java
index 679c1f7..28abc3d 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/StartCommand.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/StartCommand.java
@@ -23,7 +23,7 @@ import org.codehaus.groovy.tools.shell.Groovysh;
public class StartCommand extends SqoopCommand {
- protected StartCommand(Groovysh shell) {
+ public StartCommand(Groovysh shell) {
super(shell,
Constants.CMD_START,
Constants.CMD_START_SC,
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/shell/src/main/java/org/apache/sqoop/shell/StatusCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/StatusCommand.java b/shell/src/main/java/org/apache/sqoop/shell/StatusCommand.java
index 6082799..618b79d 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/StatusCommand.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/StatusCommand.java
@@ -23,7 +23,7 @@ import org.codehaus.groovy.tools.shell.Groovysh;
public class StatusCommand extends SqoopCommand {
- protected StatusCommand(Groovysh shell) {
+ public StatusCommand(Groovysh shell) {
super(shell,
Constants.CMD_STATUS,
Constants.CMD_STATUS_SC,
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/shell/src/main/java/org/apache/sqoop/shell/StopCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/StopCommand.java b/shell/src/main/java/org/apache/sqoop/shell/StopCommand.java
index 83c571a..0afba26 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/StopCommand.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/StopCommand.java
@@ -23,7 +23,7 @@ import org.codehaus.groovy.tools.shell.Groovysh;
public class StopCommand extends SqoopCommand {
- protected StopCommand(Groovysh shell) {
+ public StopCommand(Groovysh shell) {
super(shell,
Constants.CMD_STOP,
Constants.CMD_STOP_SC,
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/pom.xml
----------------------------------------------------------------------
diff --git a/test/pom.xml b/test/pom.xml
index bd1680f..644a9c7 100644
--- a/test/pom.xml
+++ b/test/pom.xml
@@ -42,6 +42,11 @@ limitations under the License.
<dependency>
<groupId>org.apache.sqoop</groupId>
+ <artifactId>sqoop-shell</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.sqoop</groupId>
<artifactId>sqoop-core</artifactId>
</dependency>
@@ -272,6 +277,21 @@ limitations under the License.
</properties>
</configuration>
</execution>
+ <execution>
+ <id>shell-test</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <phase>integration-test</phase>
+ <configuration>
+ <suiteXmlFiles>
+ <suiteXmlFile>src/test/resources/shell-tests-suite.xml</suiteXmlFile>
+ </suiteXmlFiles>
+ <properties>
+ <suitename>shell-tests</suitename>
+ </properties>
+ </configuration>
+ </execution>
</executions>
</plugin>
<plugin>
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java b/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java
index becfa6b..74fe29b 100644
--- a/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java
+++ b/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java
@@ -18,9 +18,9 @@
package org.apache.sqoop.test.infrastructure;
import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.fs.FileSystem;
import org.apache.log4j.Logger;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL;
@@ -225,7 +225,14 @@ public class SqoopTestCase implements ITest {
providerObject.start();
// Add for recall later.
- PROVIDERS.put(providerClass.getCanonicalName(), providerObject);
+ if (providerObject instanceof SqoopInfrastructureProvider) {
+ // there will be some child class of SqoopInfrastructureProvider,
+ // put all these kind of the providers with key SqoopInfrastructureProvider.class.getCanonicalName()
+ // then, getSqoopServerUrl() will get the correct value
+ PROVIDERS.put(SqoopInfrastructureProvider.class.getCanonicalName(), providerObject);
+ } else {
+ PROVIDERS.put(providerClass.getCanonicalName(), providerObject);
+ }
System.out.println("Infrastructure Provider " + providerClass.getCanonicalName());
@@ -405,14 +412,17 @@ public class SqoopTestCase implements ITest {
* @param jobName Job name
* @throws Exception
*/
- public void executeJob(String jobName) throws Exception {
+ public void executeJob(String jobName, boolean isAssertStatus) throws Exception {
MSubmission finalSubmission = getClient().startJob(jobName, DEFAULT_SUBMISSION_CALLBACKS, 100);
if(finalSubmission.getStatus().isFailure()) {
LOG.error("Submission has failed: " + finalSubmission.getError().getErrorSummary());
LOG.error("Corresponding error details: " + finalSubmission.getError().getErrorDetails());
}
- assertEquals(SubmissionStatus.SUCCEEDED, finalSubmission.getStatus(), "Submission finished with error: " + finalSubmission.getError().getErrorSummary());
+ if (isAssertStatus) {
+ assertEquals(finalSubmission.getStatus(), SubmissionStatus.SUCCEEDED,
+ "Submission finished with error: " + finalSubmission.getError().getErrorSummary());
+ }
}
/**
@@ -422,7 +432,7 @@ public class SqoopTestCase implements ITest {
* @throws Exception
*/
protected void executeJob(MJob job) throws Exception {
- executeJob(job.getName());
+ executeJob(job.getName(), true);
}
/**
@@ -651,4 +661,12 @@ public class SqoopTestCase implements ITest {
}
return hadoopConf;
}
+
+ protected MLink createLink(String linkName, String connectorName) {
+ MLink link = getClient().createLink(connectorName);
+ link.setName(linkName);
+ saveLink(link);
+ return link;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/SqoopInfrastructureProvider.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/SqoopInfrastructureProvider.java b/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/SqoopInfrastructureProvider.java
index 4d51ed6..5c8d733 100644
--- a/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/SqoopInfrastructureProvider.java
+++ b/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/SqoopInfrastructureProvider.java
@@ -30,10 +30,10 @@ import org.apache.sqoop.test.minicluster.SqoopMiniClusterFactory;
public class SqoopInfrastructureProvider extends InfrastructureProvider {
private static final Logger LOG = Logger.getLogger(SqoopInfrastructureProvider.class);
- private SqoopMiniCluster instance;
- private String rootPath;
- private Configuration hadoopConf;
- private KdcRunner kdc;
+ protected SqoopMiniCluster instance;
+ protected String rootPath;
+ protected Configuration hadoopConf;
+ protected KdcRunner kdc;
public SqoopInfrastructureProvider() {}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/SqoopInfrastructureProviderForShellTest.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/SqoopInfrastructureProviderForShellTest.java b/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/SqoopInfrastructureProviderForShellTest.java
new file mode 100644
index 0000000..3562722
--- /dev/null
+++ b/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/SqoopInfrastructureProviderForShellTest.java
@@ -0,0 +1,37 @@
+/**
+ * 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.sqoop.test.infrastructure.providers;
+
+import org.apache.log4j.Logger;
+import org.apache.sqoop.test.minicluster.JettySqoopMiniClusterWithExternalConnector;
+import org.apache.sqoop.test.minicluster.SqoopMiniClusterFactory;
+
+public class SqoopInfrastructureProviderForShellTest extends SqoopInfrastructureProvider {
+ private static final Logger LOG = Logger.getLogger(SqoopInfrastructureProviderForShellTest.class);
+
+ @Override
+ public void start() {
+ try {
+ instance = SqoopMiniClusterFactory.getSqoopMiniCluster(System.getProperties(),
+ JettySqoopMiniClusterWithExternalConnector.class, rootPath, hadoopConf, kdc);
+ instance.start();
+ } catch (Exception e) {
+ LOG.error("Could not start Sqoop mini cluster.", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/main/java/org/apache/sqoop/test/minicluster/JettySqoopMiniClusterWithExternalConnector.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/sqoop/test/minicluster/JettySqoopMiniClusterWithExternalConnector.java b/test/src/main/java/org/apache/sqoop/test/minicluster/JettySqoopMiniClusterWithExternalConnector.java
new file mode 100644
index 0000000..1a19e83
--- /dev/null
+++ b/test/src/main/java/org/apache/sqoop/test/minicluster/JettySqoopMiniClusterWithExternalConnector.java
@@ -0,0 +1,82 @@
+/**
+ * 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.sqoop.test.minicluster;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.sqoop.core.ConfigurationConstants;
+import org.apache.sqoop.test.utils.ConnectorUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class JettySqoopMiniClusterWithExternalConnector extends JettySqoopMiniCluster {
+
+ private String extraClasspath;
+
+ /** {@inheritDoc} */
+ public JettySqoopMiniClusterWithExternalConnector(String temporaryPath,
+ Configuration configuration) throws Exception {
+ super(temporaryPath, configuration);
+ prepareConnector();
+ }
+
+ private void prepareConnector() throws Exception {
+ String[] connectorSourceFiles = {
+ "TestConnectorForShell/TestConnectorForShell.java",
+ "TestConnectorForShell/TestExtractorForShell.java",
+ "TestConnectorForShell/TestFromDestroyerForShell.java",
+ "TestConnectorForShell/TestFromInitializerForShell.java",
+ "TestConnectorForShell/TestFromJobConfigForShell.java",
+ "TestConnectorForShell/TestFromJobConfigurationForShell.java",
+ "TestConnectorForShell/TestLinkConfigForShell.java",
+ "TestConnectorForShell/TestLinkConfigurationForShell.java",
+ "TestConnectorForShell/TestLoaderForShell.java",
+ "TestConnectorForShell/TestPartitionerForShell.java",
+ "TestConnectorForShell/TestPartitionForShell.java",
+ "TestConnectorForShell/TestToDestroyerForShell.java",
+ "TestConnectorForShell/TestToInitializerForShell.java",
+ "TestConnectorForShell/TestToJobConfigForShell.java",
+ "TestConnectorForShell/TestToJobConfigurationForShell.java"
+ };
+ String[] connectorPropertyFiles = {
+ "TestConnectorForShell/sqoopconnector.properties",
+ "TestConnectorForShell/test-connector-for-shell.properties"
+ };
+
+ String testConnectorJarName = "test-connector-for-shell.jar";
+
+ Map<String, String> connectorJarMap = ConnectorUtils.compileTestConnectorAndDependency(
+ connectorSourceFiles,
+ new String[]{},
+ connectorPropertyFiles,
+ testConnectorJarName,
+ "", false);
+ extraClasspath = connectorJarMap.get(testConnectorJarName);
+ }
+
+ @Override
+ protected Map<String, String> getClasspathConfiguration() {
+ Map<String, String> properties = new HashMap<>();
+
+ if (extraClasspath != null) {
+ properties.put(ConfigurationConstants.CLASSPATH, extraClasspath);
+ }
+
+ return properties;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorClasspathTestCase.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorClasspathTestCase.java b/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorClasspathTestCase.java
deleted file mode 100644
index 6db1db8..0000000
--- a/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorClasspathTestCase.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/**
- * 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.sqoop.test.testcases;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.jar.Attributes;
-import java.util.jar.JarEntry;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-
-import javax.tools.JavaCompiler;
-import javax.tools.JavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.StandardLocation;
-import javax.tools.ToolProvider;
-
-import org.apache.commons.collections.ListUtils;
-
-public class ConnectorClasspathTestCase extends ConnectorTestCase {
-
- static class JarContents {
- private List<File> sourceFiles;
- private List<File> properitesFiles;
- private List<String> dependencyJarFiles;
-
- public JarContents(List<File> sourceFiles, List<File> properitesFiles, List<String> dependencyJarFiles) {
- this.sourceFiles = sourceFiles;
- this.properitesFiles = properitesFiles;
- this.dependencyJarFiles = dependencyJarFiles;
- }
-
- public List<File> getSourceFiles() {
- return sourceFiles;
- }
-
- public List<File> getProperitesFiles() {
- return properitesFiles;
- }
-
- public List<String> getDependencyJarFiles() {
- return dependencyJarFiles;
- }
- }
-
- @SuppressWarnings("unchecked")
- protected Map<String, String> compileTestConnectorAndDependency(String[] connectorSourceFiles,
- String[] connectorDependencySourceFiles, String[] connectorPropertyFiles, String connectorJarName,
- String connectorDependencyJarName, boolean dependencyBuiltInsideConnectorJar) throws Exception {
- JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
- if (compiler == null) {
- throw new IllegalStateException(
- "Cannot find the system Java compiler. "
- + "Check that your class path includes tools.jar");
- }
-
- Path outputDir = Files.createTempDirectory(null);
-
- Map<String, JarContents> sourceFileToJarMap = new LinkedHashMap<>();
-
- ClassLoader classLoader = getClass().getClassLoader();
- List<File> sourceFiles = new ArrayList<>();
-
- for (String connectorDependencySourceFile : connectorDependencySourceFiles) {
- File file = new File(classLoader.getResource(connectorDependencySourceFile).getFile());
- sourceFiles.add(file);
- }
- sourceFileToJarMap.put(connectorDependencyJarName, new JarContents(sourceFiles, ListUtils.EMPTY_LIST, ListUtils.EMPTY_LIST));
-
- sourceFiles = new ArrayList<>();
- for (String connectorSourceFile : connectorSourceFiles) {
- File file = new File(classLoader.getResource(connectorSourceFile).getFile());
- sourceFiles.add(file);
- }
-
- List<File> propertiesFiles = new ArrayList<>();
- for (String connectorPropertyFile : connectorPropertyFiles) {
- File file = new File(classLoader.getResource(connectorPropertyFile).getFile());
- propertiesFiles.add(file);
- }
-
- List<String> dependencyFiles = new ArrayList<>();
- if (dependencyBuiltInsideConnectorJar) {
- dependencyFiles.add(connectorDependencyJarName);
- }
- sourceFileToJarMap.put(connectorJarName, new JarContents(sourceFiles, propertiesFiles, dependencyFiles));
-
- buildJar(outputDir.toString(), sourceFileToJarMap);
-
- Map<String, String> jarMap = new HashMap<>();
- jarMap.put(connectorJarName, outputDir.toString() + File.separator + connectorJarName);
- jarMap.put(connectorDependencyJarName, outputDir.toString() + File.separator + connectorDependencyJarName);
- return jarMap;
- }
-
- @edu.umd.cs.findbugs.annotations.SuppressWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
- private void buildJar(String outputDir, Map<String, JarContents> sourceFileToJarMap) throws IOException {
- JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
- StandardJavaFileManager fileManager = compiler.getStandardFileManager
- (null, null, null);
-
- List<File> sourceFiles = new ArrayList<>();
- for(JarContents jarContents : sourceFileToJarMap.values()) {
- sourceFiles.addAll(jarContents.sourceFiles);
- }
-
- fileManager.setLocation(StandardLocation.CLASS_OUTPUT,
- Arrays.asList(new File(outputDir)));
-
- Iterable<? extends JavaFileObject> compilationUnits1 =
- fileManager.getJavaFileObjectsFromFiles(sourceFiles);
-
- boolean compiled = compiler.getTask(null, fileManager, null, null, null, compilationUnits1).call();
- if (!compiled) {
- throw new RuntimeException("failed to compile");
- }
-
- for(Map.Entry<String, JarContents> jarNameAndContents : sourceFileToJarMap.entrySet()) {
- Manifest manifest = new Manifest();
- manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
- manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, ".");
-
- JarOutputStream target = new JarOutputStream(new FileOutputStream(outputDir + File.separator + jarNameAndContents.getKey()), manifest);
- List<String> classesForJar = new ArrayList<>();
- for(File sourceFile : jarNameAndContents.getValue().getSourceFiles()) {
- //split the file on dot to get the filename from FILENAME.java
- String fileName = sourceFile.getName().split("\\.")[0];
- classesForJar.add(fileName);
- }
-
- File dir = new File(outputDir);
- File[] directoryListing = dir.listFiles();
- if (directoryListing != null) {
- for (File compiledClass : directoryListing) {
- String classFileName = compiledClass.getName().split("\\$")[0].split("\\.")[0];
- if (classesForJar.contains(classFileName)){
- addFileToJar(compiledClass, target);
- }
- }
- }
-
- for (File propertiesFile : jarNameAndContents.getValue().getProperitesFiles()) {
- addFileToJar(propertiesFile, target);
- }
-
- for (String dependencyJarFileName : jarNameAndContents.getValue().getDependencyJarFiles()) {
- File dependencyJarFile = new File(dir, dependencyJarFileName);
- addFileToJar(dependencyJarFile, target);
- }
-
- target.close();
- }
- //delete non jar files
- File dir = new File(outputDir);
- File[] directoryListing = dir.listFiles();
- if (directoryListing != null) {
- for (File file : directoryListing) {
- String extension = file.getName().split("\\.")[1];
- if (!extension.equals("jar")) {
- file.delete();
- }
- }
- }
- }
-
- @edu.umd.cs.findbugs.annotations.SuppressWarnings("OS_OPEN_STREAM_EXCEPTION_PATH")
- private void addFileToJar(File source, JarOutputStream target) throws IOException {
- String entryName;
- if (source.getName().endsWith(".jar")) {
- // put dependency jars into directory "lib"
- entryName = "lib/" + source.getName();
- } else {
- entryName = source.getName();
- }
- JarEntry entry = new JarEntry(entryName);
- entry.setTime(source.lastModified());
- target.putNextEntry(entry);
- BufferedInputStream in = null;
- try {
- in = new BufferedInputStream(new FileInputStream(source));
-
- long bufferSize = source.length();
- if (bufferSize < Integer.MIN_VALUE || bufferSize > Integer.MAX_VALUE) {
- throw new RuntimeException("file to large to be added to jar");
- }
-
- byte[] buffer = new byte[(int) bufferSize];
- while (true) {
- int count = in.read(buffer);
- if (count == -1)
- break;
- target.write(buffer, 0, count);
- }
- } finally {
- target.closeEntry();
- if (in != null) {
- in.close();
- }
- }
- }
-
- @edu.umd.cs.findbugs.annotations.SuppressWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
- protected void deleteJars(Map<String, String> jarMap) {
- for (String jarPath : jarMap.values()) {
- (new File(jarPath)).delete();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/main/java/org/apache/sqoop/test/testcases/ShellTestCase.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/sqoop/test/testcases/ShellTestCase.java b/test/src/main/java/org/apache/sqoop/test/testcases/ShellTestCase.java
new file mode 100644
index 0000000..bfae595
--- /dev/null
+++ b/test/src/main/java/org/apache/sqoop/test/testcases/ShellTestCase.java
@@ -0,0 +1,94 @@
+/**
+ * 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.sqoop.test.testcases;
+
+import jline.console.ConsoleReader;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MLink;
+import org.apache.sqoop.shell.ShellEnvironment;
+import org.apache.sqoop.shell.SqoopCommand;
+import org.apache.sqoop.test.infrastructure.SqoopTestCase;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+abstract public class ShellTestCase extends SqoopTestCase {
+
+ protected SqoopCommand command = null;
+ protected ConsoleReader reader = null;
+ protected ByteArrayInputStream in = null;
+ protected byte[] data = null;
+ private final static String TEST_CONNECTOR_NAME = "test-connector-for-shell";
+
+ @BeforeMethod
+ public void setup() throws Exception {
+ Groovysh shell = new Groovysh();
+ command = createCommand(shell);
+ ShellEnvironment.setIo(shell.getIo());
+ ShellEnvironment.setClient(getClient());
+
+ data = new byte[1024];
+ in = new ByteArrayInputStream(data);
+ reader = new ConsoleReader(in, System.out);
+ ShellEnvironment.setConsoleReader(reader);
+ }
+
+ @AfterMethod
+ public void cleanup() throws IOException {
+ clearJob();
+ clearLink();
+ }
+
+ protected Object execute(List args) {
+ return command.execute(args);
+ }
+
+ protected void initData(String destData) throws UnsupportedEncodingException {
+ byte[] destDataBytes = destData.getBytes("UTF-8");
+ System.arraycopy(destDataBytes, 0, data, 0, destDataBytes.length);
+ in.reset();
+ }
+
+ protected void initEnv() {
+ in.reset();
+ for (int i = 0; i < data.length; i++) {
+ data[i] = '\0';
+ }
+ }
+
+ protected MLink createLink(String linkName) {
+ return createLink(linkName, TEST_CONNECTOR_NAME);
+ }
+
+ protected void createJob(String fromLinkName, String toLinkName, String jobName) {
+ // create link for test
+ createLink(fromLinkName, TEST_CONNECTOR_NAME);
+ createLink(toLinkName, TEST_CONNECTOR_NAME);
+ MJob mjob = getClient().createJob(fromLinkName, toLinkName);
+ mjob.setName(jobName);
+ saveJob(mjob);
+ }
+
+ // the method should be override by sub class
+ abstract protected SqoopCommand createCommand(Groovysh shell);
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/main/java/org/apache/sqoop/test/utils/ConnectorUtils.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/sqoop/test/utils/ConnectorUtils.java b/test/src/main/java/org/apache/sqoop/test/utils/ConnectorUtils.java
new file mode 100644
index 0000000..b63bcf8
--- /dev/null
+++ b/test/src/main/java/org/apache/sqoop/test/utils/ConnectorUtils.java
@@ -0,0 +1,236 @@
+/**
+ * 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.sqoop.test.utils;
+
+import org.apache.commons.collections.ListUtils;
+
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+import javax.tools.ToolProvider;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+public class ConnectorUtils {
+
+ static class JarContents {
+ private List<File> sourceFiles;
+ private List<File> properitesFiles;
+ private List<String> dependencyJarFiles;
+
+ public JarContents(List<File> sourceFiles, List<File> properitesFiles, List<String> dependencyJarFiles) {
+ this.sourceFiles = sourceFiles;
+ this.properitesFiles = properitesFiles;
+ this.dependencyJarFiles = dependencyJarFiles;
+ }
+
+ public List<File> getSourceFiles() {
+ return sourceFiles;
+ }
+
+ public List<File> getProperitesFiles() {
+ return properitesFiles;
+ }
+
+ public List<String> getDependencyJarFiles() {
+ return dependencyJarFiles;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static Map<String, String> compileTestConnectorAndDependency(String[] connectorSourceFiles,
+ String[] connectorDependencySourceFiles, String[] connectorPropertyFiles, String connectorJarName,
+ String connectorDependencyJarName, boolean dependencyBuiltInsideConnectorJar) throws Exception {
+ ClassLoader classLoader = ConnectorUtils.class.getClassLoader();
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ throw new IllegalStateException(
+ "Cannot find the system Java compiler. "
+ + "Check that your class path includes tools.jar");
+ }
+
+ Path outputDir = Files.createTempDirectory(null);
+
+ Map<String, JarContents> sourceFileToJarMap = new LinkedHashMap<>();
+
+ List<File> sourceFiles = new ArrayList<>();
+
+ for (String connectorDependencySourceFile : connectorDependencySourceFiles) {
+ File file = new File(classLoader.getResource(connectorDependencySourceFile).getFile());
+ sourceFiles.add(file);
+ }
+ if (connectorDependencySourceFiles.length > 0) {
+ sourceFileToJarMap.put(connectorDependencyJarName, new JarContents(sourceFiles, ListUtils.EMPTY_LIST, ListUtils.EMPTY_LIST));
+ }
+
+ sourceFiles = new ArrayList<>();
+ for (String connectorSourceFile : connectorSourceFiles) {
+ File file = new File(classLoader.getResource(connectorSourceFile).getFile());
+ sourceFiles.add(file);
+ }
+
+ List<File> propertiesFiles = new ArrayList<>();
+ for (String connectorPropertyFile : connectorPropertyFiles) {
+ File file = new File(classLoader.getResource(connectorPropertyFile).getFile());
+ propertiesFiles.add(file);
+ }
+
+ List<String> dependencyFiles = new ArrayList<>();
+ if (dependencyBuiltInsideConnectorJar) {
+ dependencyFiles.add(connectorDependencyJarName);
+ }
+ sourceFileToJarMap.put(connectorJarName, new JarContents(sourceFiles, propertiesFiles, dependencyFiles));
+
+ buildJar(outputDir.toString(), sourceFileToJarMap);
+
+ Map<String, String> jarMap = new HashMap<>();
+ jarMap.put(connectorJarName, outputDir.toString() + File.separator + connectorJarName);
+ jarMap.put(connectorDependencyJarName, outputDir.toString() + File.separator + connectorDependencyJarName);
+ return jarMap;
+ }
+
+ @edu.umd.cs.findbugs.annotations.SuppressWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
+ private static void buildJar(String outputDir, Map<String, JarContents> sourceFileToJarMap) throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ StandardJavaFileManager fileManager = compiler.getStandardFileManager
+ (null, null, null);
+
+ List<File> sourceFiles = new ArrayList<>();
+ for(JarContents jarContents : sourceFileToJarMap.values()) {
+ sourceFiles.addAll(jarContents.sourceFiles);
+ }
+
+ fileManager.setLocation(StandardLocation.CLASS_OUTPUT,
+ Arrays.asList(new File(outputDir)));
+
+ Iterable<? extends JavaFileObject> compilationUnits1 =
+ fileManager.getJavaFileObjectsFromFiles(sourceFiles);
+
+ boolean compiled = compiler.getTask(null, fileManager, null, null, null, compilationUnits1).call();
+ if (!compiled) {
+ throw new RuntimeException("failed to compile");
+ }
+
+ for(Map.Entry<String, JarContents> jarNameAndContents : sourceFileToJarMap.entrySet()) {
+ Manifest manifest = new Manifest();
+ manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
+ manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, ".");
+
+ JarOutputStream target = new JarOutputStream(new FileOutputStream(outputDir + File.separator + jarNameAndContents.getKey()), manifest);
+ List<String> classesForJar = new ArrayList<>();
+ for(File sourceFile : jarNameAndContents.getValue().getSourceFiles()) {
+ //split the file on dot to get the filename from FILENAME.java
+ String fileName = sourceFile.getName().split("\\.")[0];
+ classesForJar.add(fileName);
+ }
+
+ File dir = new File(outputDir);
+ File[] directoryListing = dir.listFiles();
+ if (directoryListing != null) {
+ for (File compiledClass : directoryListing) {
+ String classFileName = compiledClass.getName().split("\\$")[0].split("\\.")[0];
+ if (classesForJar.contains(classFileName)){
+ addFileToJar(compiledClass, target);
+ }
+ }
+ }
+
+ for (File propertiesFile : jarNameAndContents.getValue().getProperitesFiles()) {
+ addFileToJar(propertiesFile, target);
+ }
+
+ for (String dependencyJarFileName : jarNameAndContents.getValue().getDependencyJarFiles()) {
+ File dependencyJarFile = new File(dir, dependencyJarFileName);
+ addFileToJar(dependencyJarFile, target);
+ }
+
+ target.close();
+ }
+ //delete non jar files
+ File dir = new File(outputDir);
+ File[] directoryListing = dir.listFiles();
+ if (directoryListing != null) {
+ for (File file : directoryListing) {
+ String extension = file.getName().split("\\.")[1];
+ if (!extension.equals("jar")) {
+ file.delete();
+ }
+ }
+ }
+ }
+
+ @edu.umd.cs.findbugs.annotations.SuppressWarnings("OS_OPEN_STREAM_EXCEPTION_PATH")
+ private static void addFileToJar(File source, JarOutputStream target) throws IOException {
+ String entryName;
+ if (source.getName().endsWith(".jar")) {
+ // put dependency jars into directory "lib"
+ entryName = "lib/" + source.getName();
+ } else {
+ entryName = source.getName();
+ }
+ JarEntry entry = new JarEntry(entryName);
+ entry.setTime(source.lastModified());
+ target.putNextEntry(entry);
+ BufferedInputStream in = null;
+ try {
+ in = new BufferedInputStream(new FileInputStream(source));
+
+ long bufferSize = source.length();
+ if (bufferSize < Integer.MIN_VALUE || bufferSize > Integer.MAX_VALUE) {
+ throw new RuntimeException("file to large to be added to jar");
+ }
+
+ byte[] buffer = new byte[(int) bufferSize];
+ while (true) {
+ int count = in.read(buffer);
+ if (count == -1)
+ break;
+ target.write(buffer, 0, count);
+ }
+ } finally {
+ target.closeEntry();
+ if (in != null) {
+ in.close();
+ }
+ }
+ }
+
+ @edu.umd.cs.findbugs.annotations.SuppressWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
+ public static void deleteJars(Map<String, String> jarMap) {
+ for (String jarPath : jarMap.values()) {
+ (new File(jarPath)).delete();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/test/java/org/apache/sqoop/integration/connectorloading/ClasspathTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/connectorloading/ClasspathTest.java b/test/src/test/java/org/apache/sqoop/integration/connectorloading/ClasspathTest.java
index 4bb6aa1..4aed991 100644
--- a/test/src/test/java/org/apache/sqoop/integration/connectorloading/ClasspathTest.java
+++ b/test/src/test/java/org/apache/sqoop/integration/connectorloading/ClasspathTest.java
@@ -25,7 +25,8 @@ import org.apache.sqoop.model.MDriverConfig;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MLink;
import org.apache.sqoop.test.minicluster.JettySqoopMiniCluster;
-import org.apache.sqoop.test.testcases.ConnectorClasspathTestCase;
+import org.apache.sqoop.test.testcases.ConnectorTestCase;
+import org.apache.sqoop.test.utils.ConnectorUtils;
import org.apache.sqoop.test.utils.HdfsUtils;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -37,7 +38,7 @@ import java.util.List;
import java.util.Map;
@Test(groups = "no-real-cluster")
-public class ClasspathTest extends ConnectorClasspathTestCase {
+public class ClasspathTest extends ConnectorTestCase {
private static final String TEST_CONNECTOR_JAR_NAME = "test-connector.jar";
private static final String TEST_DEPENDENCY_JAR_NAME = "test-dependency.jar";
@@ -111,13 +112,13 @@ public class ClasspathTest extends ConnectorClasspathTestCase {
@Test
public void testClasspathSqoopProperties() throws Exception {
- Map<String, String> jarMap = compileTestConnectorAndDependency(
- CONNECTOR_SOURCE_FILES,
- CONNECTOR_DEPENDENCY_SOURCE_FILES,
- CONNECTOR_PROPERTY_FILES,
- TEST_CONNECTOR_JAR_NAME,
- TEST_DEPENDENCY_JAR_NAME,
- false);
+ Map<String, String> jarMap = ConnectorUtils.compileTestConnectorAndDependency(
+ CONNECTOR_SOURCE_FILES,
+ CONNECTOR_DEPENDENCY_SOURCE_FILES,
+ CONNECTOR_PROPERTY_FILES,
+ TEST_CONNECTOR_JAR_NAME,
+ TEST_DEPENDENCY_JAR_NAME,
+ false);
startSqoopMiniCluster(jarMap.get(TEST_CONNECTOR_JAR_NAME), jarMap.get
(TEST_DEPENDENCY_JAR_NAME));
createAndLoadTableCities();
@@ -131,12 +132,12 @@ public class ClasspathTest extends ConnectorClasspathTestCase {
executeJob(job);
stopSqoop();
- deleteJars(jarMap);
+ ConnectorUtils.deleteJars(jarMap);
}
@Test
public void testClasspathDriverInput() throws Exception{
- Map<String, String> jarMap = compileTestConnectorAndDependency(
+ Map<String, String> jarMap = ConnectorUtils.compileTestConnectorAndDependency(
CONNECTOR_SOURCE_FILES,
CONNECTOR_DEPENDENCY_SOURCE_FILES,
CONNECTOR_PROPERTY_FILES,
@@ -159,7 +160,7 @@ public class ClasspathTest extends ConnectorClasspathTestCase {
executeJob(job);
stopSqoop();
- deleteJars(jarMap);
+ ConnectorUtils.deleteJars(jarMap);
}
private MJob prepareJob() {
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/test/java/org/apache/sqoop/integration/connectorloading/ConnectorClasspathIsolationTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/connectorloading/ConnectorClasspathIsolationTest.java b/test/src/test/java/org/apache/sqoop/integration/connectorloading/ConnectorClasspathIsolationTest.java
index 5b95631..295e049 100644
--- a/test/src/test/java/org/apache/sqoop/integration/connectorloading/ConnectorClasspathIsolationTest.java
+++ b/test/src/test/java/org/apache/sqoop/integration/connectorloading/ConnectorClasspathIsolationTest.java
@@ -30,14 +30,15 @@ import org.apache.sqoop.model.MDriverConfig;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MLink;
import org.apache.sqoop.test.minicluster.JettySqoopMiniCluster;
-import org.apache.sqoop.test.testcases.ConnectorClasspathTestCase;
+import org.apache.sqoop.test.testcases.ConnectorTestCase;
+import org.apache.sqoop.test.utils.ConnectorUtils;
import org.apache.sqoop.test.utils.HdfsUtils;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@Test(groups = "no-real-cluster")
-public class ConnectorClasspathIsolationTest extends ConnectorClasspathTestCase {
+public class ConnectorClasspathIsolationTest extends ConnectorTestCase {
private static final String TEST_FROM_CONNECTOR_JAR_NAME = "test-from-connector.jar";
private static final String TEST_TO_CONNECTOR_JAR_NAME = "test-to-connector.jar";
@@ -126,14 +127,14 @@ public class ConnectorClasspathIsolationTest extends ConnectorClasspathTestCase
@Test
public void testConnectorClasspathIsolation() throws Exception {
- Map<String, String> fromConnectorJarMap = compileTestConnectorAndDependency(
+ Map<String, String> fromConnectorJarMap = ConnectorUtils.compileTestConnectorAndDependency(
FROM_CONNECTOR_SOURCE_FILES,
FROM_CONNECTOR_DEPENDENCY_SOURCE_FILES,
FROM_CONNECTOR_PROPERTY_FILES,
TEST_FROM_CONNECTOR_JAR_NAME,
TEST_FROM_DEPENDENCY_JAR_NAME,
true);
- Map<String, String> toConnectorJarMap = compileTestConnectorAndDependency(
+ Map<String, String> toConnectorJarMap = ConnectorUtils.compileTestConnectorAndDependency(
TO_CONNECTOR_SOURCE_FILES,
TO_CONNECTOR_DEPENDENCY_SOURCE_FILES,
TO_CONNECTOR_PROPERTY_FILES,
@@ -152,7 +153,7 @@ public class ConnectorClasspathIsolationTest extends ConnectorClasspathTestCase
executeJob(job);
stopSqoop();
- deleteJars(fromConnectorJarMap);
+ ConnectorUtils.deleteJars(fromConnectorJarMap);
}
private MJob prepareJob() {
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/test/java/org/apache/sqoop/integration/server/SubmissionWithDisabledModelObjectsTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/server/SubmissionWithDisabledModelObjectsTest.java b/test/src/test/java/org/apache/sqoop/integration/server/SubmissionWithDisabledModelObjectsTest.java
index 9adebea..83baa22 100644
--- a/test/src/test/java/org/apache/sqoop/integration/server/SubmissionWithDisabledModelObjectsTest.java
+++ b/test/src/test/java/org/apache/sqoop/integration/server/SubmissionWithDisabledModelObjectsTest.java
@@ -110,7 +110,7 @@ public class SubmissionWithDisabledModelObjectsTest extends SqoopTestCase {
// Try to execute the job and verify that the it was not executed
try {
- executeJob(jobName);
+ executeJob(jobName, true);
fail("Expected exception as the model classes are disabled.");
} catch(SqoopException ex) {
// Top level exception should be CLIENT_0001
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/test/java/org/apache/sqoop/integration/shell/CloneCommandTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/shell/CloneCommandTest.java b/test/src/test/java/org/apache/sqoop/integration/shell/CloneCommandTest.java
new file mode 100644
index 0000000..bcf6334
--- /dev/null
+++ b/test/src/test/java/org/apache/sqoop/integration/shell/CloneCommandTest.java
@@ -0,0 +1,125 @@
+/**
+ * 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.sqoop.integration.shell;
+
+import org.apache.sqoop.client.ClientError;
+import org.apache.sqoop.common.SqoopException;
+
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MLink;
+import org.apache.sqoop.shell.CloneCommand;
+import org.apache.sqoop.shell.ShellEnvironment;
+import org.apache.sqoop.shell.SqoopCommand;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.test.infrastructure.Infrastructure;
+import org.apache.sqoop.test.infrastructure.providers.DatabaseInfrastructureProvider;
+import org.apache.sqoop.test.infrastructure.providers.SqoopInfrastructureProviderForShellTest;
+import org.apache.sqoop.test.testcases.ShellTestCase;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.annotations.Test;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+@Infrastructure(dependencies = {SqoopInfrastructureProviderForShellTest.class, DatabaseInfrastructureProvider.class})
+public class CloneCommandTest extends ShellTestCase {
+
+ protected SqoopCommand createCommand(Groovysh shell) {
+ return new CloneCommand(shell);
+ }
+
+ @Test
+ public void testCloneLink() throws UnsupportedEncodingException {
+ ShellEnvironment.setInteractive(true);
+ initEnv();
+
+ // create link
+ createLink("linkName");
+
+ // do the clone test
+ initData("Clone\n" + // link name: append to the old link name
+ "linkConfig1\n" + // link config1
+ "linkConfig2\n"); // link config2
+ Status status = (Status) execute(Arrays.asList(Constants.FN_LINK, "-name", "linkName"));
+ assertTrue(status != null && status != Status.ERROR);
+ // the origin link is still there
+ MLink orginLink = getClient().getLink("linkName");
+ assertEquals(orginLink.getName(), "linkName");
+
+ MLink link = getClient().getLink("linkNameClone");
+ assertEquals(link.getName(), "linkNameClone");
+ assertEquals(link.getConnectorLinkConfig("testLinkConfigForShell").getInput("testLinkConfigForShell.linkConfig1").getValue(),
+ "linkConfig1");
+ assertEquals(link.getConnectorLinkConfig("testLinkConfigForShell").getInput("testLinkConfigForShell.linkConfig2").getValue(),
+ "linkConfig2");
+ }
+
+ @Test
+ public void testCloneNonExistingLink() {
+ ShellEnvironment.setInteractive(false);
+ try {
+ execute(Arrays.asList(Constants.FN_LINK, "-name", "non-exist-link"));
+ fail("Clone Link should fail as link doesn't exist!");
+ } catch (SqoopException e) {
+ assertEquals(e.getErrorCode(), ClientError.CLIENT_0001);
+ }
+ }
+
+ @Test
+ public void testCloneJob() throws UnsupportedEncodingException {
+ ShellEnvironment.setInteractive(true);
+ initEnv();
+
+ createJob("fromLink", "toLink", "jobName");
+
+ // create job -f link_from -to link_to
+ initData("Clone\n" + // job name
+ "fromJobConfig1\n" + // from job config1
+ "fromJobConfig2\n" + // from job config2
+ "toJobConfig1\n" + // to job config1
+ "toJobConfig2\n\n\n\n\n\n"); // to job config2 and nothing for driver
+ Status status = (Status) execute(Arrays.asList(Constants.FN_JOB, "-name", "jobName"));
+ assertTrue(status != null && status != Status.ERROR);
+ // the origin job is still there
+ MJob originJob = getClient().getJob("jobName");
+ assertEquals(originJob.getName(), "jobName");
+
+ MJob job = getClient().getJob("jobNameClone");
+ assertEquals(job.getName(), "jobNameClone");
+ assertEquals(job.getFromJobConfig().getInput("testFromJobConfigForShell.fromJobConfig1").getValue(), "fromJobConfig1");
+ assertEquals(job.getFromJobConfig().getInput("testFromJobConfigForShell.fromJobConfig2").getValue(), "fromJobConfig2");
+ assertEquals(job.getToJobConfig().getInput("testToJobConfigForShell.toJobConfig1").getValue(), "toJobConfig1");
+ assertEquals(job.getToJobConfig().getInput("testToJobConfigForShell.toJobConfig2").getValue(), "toJobConfig2");
+ }
+
+ @Test
+ public void testCloneNonExistingJob() {
+ ShellEnvironment.setInteractive(false);
+ try {
+ execute(Arrays.asList(Constants.FN_JOB, "-name", "non-exist-jobName"));
+ fail("Clone Job should fail as job doesn't exist!");
+ } catch (SqoopException e) {
+ assertEquals(e.getErrorCode(), ClientError.CLIENT_0001);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/test/java/org/apache/sqoop/integration/shell/CreateCommandTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/shell/CreateCommandTest.java b/test/src/test/java/org/apache/sqoop/integration/shell/CreateCommandTest.java
new file mode 100644
index 0000000..81b7c8a
--- /dev/null
+++ b/test/src/test/java/org/apache/sqoop/integration/shell/CreateCommandTest.java
@@ -0,0 +1,117 @@
+/**
+ * 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.sqoop.integration.shell;
+
+import org.apache.sqoop.client.ClientError;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.*;
+import org.apache.sqoop.shell.CreateCommand;
+import org.apache.sqoop.shell.ShellEnvironment;
+import org.apache.sqoop.shell.SqoopCommand;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.test.infrastructure.Infrastructure;
+import org.apache.sqoop.test.infrastructure.providers.DatabaseInfrastructureProvider;
+import org.apache.sqoop.test.infrastructure.providers.SqoopInfrastructureProviderForShellTest;
+import org.apache.sqoop.test.testcases.ShellTestCase;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.annotations.Test;
+
+import java.io.UnsupportedEncodingException;
+import java.util.*;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+@Infrastructure(dependencies = {SqoopInfrastructureProviderForShellTest.class, DatabaseInfrastructureProvider.class})
+public class CreateCommandTest extends ShellTestCase {
+
+ protected SqoopCommand createCommand(Groovysh shell) {
+ return new CreateCommand(shell);
+ }
+
+ @Test
+ public void testCreateLink() throws UnsupportedEncodingException {
+ ShellEnvironment.setInteractive(true);
+ initEnv();
+
+ // create link -c generic-jdbc-connector
+ initData("linkname\n" + // link name
+ "linkConfig1\n" + // link config1
+ "linkConfig2\n"); // link config2
+
+ Status status = (Status) execute(Arrays.asList(Constants.FN_LINK, "-c", "test-connector-for-shell"));
+ MLink link = getClient().getLink("linkname");
+ // the status should be warning because of the validation of jdbc connection string
+ assertTrue(status != null && status != Status.ERROR);
+ assertEquals(link.getName(), "linkname");
+ assertEquals(link.getConnectorLinkConfig("testLinkConfigForShell").getInput("testLinkConfigForShell.linkConfig1").getValue(),
+ "linkConfig1");
+ assertEquals(link.getConnectorLinkConfig("testLinkConfigForShell").getInput("testLinkConfigForShell.linkConfig2").getValue(),
+ "linkConfig2");
+ }
+
+ @Test
+ public void testCreateLinkWithNonExistingConnector() {
+ ShellEnvironment.setInteractive(false);
+ try {
+ execute(Arrays.asList(Constants.FN_LINK, "-c", "non-exist-connector"));
+ fail("Create Link should fail as connector doesn't exist!");
+ } catch (SqoopException e) {
+ assertEquals(e.getErrorCode(), ClientError.CLIENT_0003);
+ }
+ }
+
+ @Test
+ public void testCreateJob() throws UnsupportedEncodingException {
+ ShellEnvironment.setInteractive(true);
+ initEnv();
+
+ // create link for test
+ createLink("fromLink");
+ createLink("toLink");
+
+ // create job -f link_from -to link_to
+ initData("jobname\n" + // job name
+ "fromJobConfig1\n" + // from job config1
+ "fromJobConfig2\n" + // from job config2
+ "toJobConfig1\n" + // to job config1
+ "toJobConfig2\n\n\n\n\n\n"); // to job config2 and nothing for driver
+ Status status = (Status) execute(Arrays.asList(Constants.FN_JOB, "-f", "fromLink", "-to", "toLink"));
+
+ assertTrue(status != null && status != Status.ERROR);
+ MJob job = getClient().getJob("jobname");
+ assertEquals(job.getName(), "jobname");
+ assertEquals(job.getFromJobConfig().getInput("testFromJobConfigForShell.fromJobConfig1").getValue(), "fromJobConfig1");
+ assertEquals(job.getFromJobConfig().getInput("testFromJobConfigForShell.fromJobConfig2").getValue(), "fromJobConfig2");
+ assertEquals(job.getToJobConfig().getInput("testToJobConfigForShell.toJobConfig1").getValue(), "toJobConfig1");
+ assertEquals(job.getToJobConfig().getInput("testToJobConfigForShell.toJobConfig2").getValue(), "toJobConfig2");
+ }
+
+ @Test
+ public void testCreateJobWithNonExistingLink() {
+ ShellEnvironment.setInteractive(false);
+ try {
+ execute(Arrays.asList(Constants.FN_JOB, "-f", "link_from", "-to", "link_to"));
+ fail("Create Job should fail as from link doesn't exist!");
+ } catch (SqoopException e) {
+ assertEquals(e.getErrorCode(), ClientError.CLIENT_0001);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/test/java/org/apache/sqoop/integration/shell/DeleteCommandTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/shell/DeleteCommandTest.java b/test/src/test/java/org/apache/sqoop/integration/shell/DeleteCommandTest.java
new file mode 100644
index 0000000..8ed8570
--- /dev/null
+++ b/test/src/test/java/org/apache/sqoop/integration/shell/DeleteCommandTest.java
@@ -0,0 +1,97 @@
+/**
+ * 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.sqoop.integration.shell;
+
+import org.apache.sqoop.client.ClientError;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.DeleteCommand;
+import org.apache.sqoop.shell.SqoopCommand;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.test.infrastructure.Infrastructure;
+import org.apache.sqoop.test.infrastructure.providers.DatabaseInfrastructureProvider;
+import org.apache.sqoop.test.infrastructure.providers.SqoopInfrastructureProviderForShellTest;
+import org.apache.sqoop.test.testcases.ShellTestCase;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.util.Arrays;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.fail;
+
+@Infrastructure(dependencies = {SqoopInfrastructureProviderForShellTest.class, DatabaseInfrastructureProvider.class})
+public class DeleteCommandTest extends ShellTestCase {
+
+ protected SqoopCommand createCommand(Groovysh shell) {
+ return new DeleteCommand(shell);
+ }
+
+ @Test
+ public void testDeleteLink() {
+ // creaet link
+ createLink("linkName");
+
+ // delete link -name linkName
+ Status status = (Status) execute(Arrays.asList(Constants.FN_LINK, "-name", "linkName"));
+ Assert.assertTrue(status != null && status == Status.OK);
+
+ // verify the link is deleted
+ try {
+ getClient().getLink("linkName");
+ fail("Link doesn't exist!");
+ } catch (SqoopException e) {
+ assertEquals(e.getErrorCode(), ClientError.CLIENT_0001);
+ }
+
+ // delete the non-exist link
+ try {
+ execute(Arrays.asList(Constants.FN_LINK, "-name", "non-exist-link"));
+ fail("Delete link should fail as link doesn't exist!");
+ } catch (SqoopException e) {
+ assertEquals(e.getErrorCode(), ClientError.CLIENT_0001);
+ }
+ }
+
+ @Test
+ public void testDeleteJob() {
+ // creaet job
+ createJob("fromLink", "toLink", "jobName");
+
+ // delete job -name jobName
+ Status status = (Status) execute(Arrays.asList(Constants.FN_JOB, "-name", "jobName"));
+ Assert.assertTrue(status != null && status == Status.OK);
+
+ // verify the job is deleted
+ try {
+ getClient().getJob("jobName");
+ fail("Job doesn't exist!");
+ } catch (SqoopException e) {
+ assertEquals(e.getErrorCode(), ClientError.CLIENT_0001);
+ }
+
+ // delete the non-exist job
+ try {
+ execute(Arrays.asList(Constants.FN_JOB, "-name", "non-exist-job"));
+ fail("Delete job should fail as job doesn't exist!");
+ } catch (SqoopException e) {
+ assertEquals(e.getErrorCode(), ClientError.CLIENT_0001);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/test/java/org/apache/sqoop/integration/shell/DisableCommandTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/shell/DisableCommandTest.java b/test/src/test/java/org/apache/sqoop/integration/shell/DisableCommandTest.java
new file mode 100644
index 0000000..e524312
--- /dev/null
+++ b/test/src/test/java/org/apache/sqoop/integration/shell/DisableCommandTest.java
@@ -0,0 +1,97 @@
+/**
+ * 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.sqoop.integration.shell;
+
+import org.apache.sqoop.client.ClientError;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MLink;
+import org.apache.sqoop.shell.DisableCommand;
+import org.apache.sqoop.shell.SqoopCommand;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.test.infrastructure.Infrastructure;
+import org.apache.sqoop.test.infrastructure.providers.DatabaseInfrastructureProvider;
+import org.apache.sqoop.test.infrastructure.providers.SqoopInfrastructureProviderForShellTest;
+import org.apache.sqoop.test.testcases.ShellTestCase;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.annotations.Test;
+
+import java.util.Arrays;
+
+import static org.testng.Assert.*;
+
+@Infrastructure(dependencies = {SqoopInfrastructureProviderForShellTest.class, DatabaseInfrastructureProvider.class})
+public class DisableCommandTest extends ShellTestCase {
+
+ protected SqoopCommand createCommand(Groovysh shell) {
+ return new DisableCommand(shell);
+ }
+
+ @Test
+ public void testDisableLink() {
+ // creaet link
+ createLink("linkName");
+
+ // the link is enable
+ MLink link = getClient().getLink("linkName");
+ assertTrue(link.getEnabled());
+
+ // disable link -name linkName
+ Status status = (Status) execute(Arrays.asList(Constants.FN_LINK, "-name", "linkName"));
+ assertTrue(status != null && status == Status.OK);
+
+ // the link is disable
+ link = getClient().getLink("linkName");
+ assertFalse(link.getEnabled());
+
+ // disable the non-exist link
+ try {
+ execute(Arrays.asList(Constants.FN_LINK, "-name", "non-exist-link"));
+ fail("Disable link should fail as link doesn't exist!");
+ } catch (SqoopException e) {
+ assertEquals(e.getErrorCode(), ClientError.CLIENT_0001);
+ }
+ }
+
+ @Test
+ public void testDisableJob() {
+ // creaet job
+ createJob("fromLink", "toLink", "jobName");
+
+ // the job is enable
+ MJob job = getClient().getJob("jobName");
+ assertTrue(job.getEnabled());
+
+ // disable job -name jobName
+ Status status = (Status) execute(Arrays.asList(Constants.FN_JOB, "-name", "jobName"));
+ assertTrue(status != null && status == Status.OK);
+
+ // the job is disable
+ job = getClient().getJob("jobName");
+ assertFalse(job.getEnabled());
+
+ // disable the non-exist job
+ try {
+ execute(Arrays.asList(Constants.FN_JOB, "-name", "non-exist-job"));
+ fail("Disable job should fail as job doesn't exist!");
+ } catch (SqoopException e) {
+ assertEquals(e.getErrorCode(), ClientError.CLIENT_0001);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/test/java/org/apache/sqoop/integration/shell/EnableCommandTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/shell/EnableCommandTest.java b/test/src/test/java/org/apache/sqoop/integration/shell/EnableCommandTest.java
new file mode 100644
index 0000000..b104348
--- /dev/null
+++ b/test/src/test/java/org/apache/sqoop/integration/shell/EnableCommandTest.java
@@ -0,0 +1,99 @@
+/**
+ * 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.sqoop.integration.shell;
+
+import org.apache.sqoop.client.ClientError;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MLink;
+import org.apache.sqoop.shell.EnableCommand;
+import org.apache.sqoop.shell.SqoopCommand;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.test.infrastructure.Infrastructure;
+import org.apache.sqoop.test.infrastructure.providers.DatabaseInfrastructureProvider;
+import org.apache.sqoop.test.infrastructure.providers.SqoopInfrastructureProviderForShellTest;
+import org.apache.sqoop.test.testcases.ShellTestCase;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.annotations.Test;
+
+import java.util.Arrays;
+
+import static org.testng.Assert.*;
+
+@Infrastructure(dependencies = {SqoopInfrastructureProviderForShellTest.class, DatabaseInfrastructureProvider.class})
+public class EnableCommandTest extends ShellTestCase {
+
+ protected SqoopCommand createCommand(Groovysh shell) {
+ return new EnableCommand(shell);
+ }
+
+ @Test
+ public void testEnableLink() {
+ // creaet link
+ createLink("linkName");
+ getClient().enableLink("linkName", false);
+
+ // the link is disable
+ MLink link = getClient().getLink("linkName");
+ assertFalse(link.getEnabled());
+
+ // enable link -name linkName
+ Status status = (Status) execute(Arrays.asList(Constants.FN_LINK, "-name", "linkName"));
+ assertTrue(status != null && status == Status.OK);
+
+ // the link is enable
+ link = getClient().getLink("linkName");
+ assertTrue(link.getEnabled());
+
+ // enable the non-exist link
+ try {
+ execute(Arrays.asList(Constants.FN_LINK, "-name", "non-exist-link"));
+ fail("Enable link should fail as link doesn't exist!");
+ } catch (SqoopException e) {
+ assertEquals(e.getErrorCode(), ClientError.CLIENT_0001);
+ }
+ }
+
+ @Test
+ public void testEnableJob() {
+ // creaet job
+ createJob("fromLink", "toLink", "jobName");
+ getClient().enableJob("jobName", false);
+
+ // the job is disable
+ MJob job = getClient().getJob("jobName");
+ assertFalse(job.getEnabled());
+
+ // enable job -name jobName
+ Status status = (Status) execute(Arrays.asList(Constants.FN_JOB, "-name", "jobName"));
+ assertTrue(status != null && status == Status.OK);
+
+ // the job is disable
+ job = getClient().getJob("jobName");
+ assertTrue(job.getEnabled());
+
+ // enable the non-exist job
+ try {
+ execute(Arrays.asList(Constants.FN_JOB, "-name", "non-exist-job"));
+ fail("Enable job should fail as job doesn't exist!");
+ } catch (SqoopException e) {
+ assertEquals(e.getErrorCode(), ClientError.CLIENT_0001);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/67214a48/test/src/test/java/org/apache/sqoop/integration/shell/SetCommandTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/sqoop/integration/shell/SetCommandTest.java b/test/src/test/java/org/apache/sqoop/integration/shell/SetCommandTest.java
new file mode 100644
index 0000000..f673a58
--- /dev/null
+++ b/test/src/test/java/org/apache/sqoop/integration/shell/SetCommandTest.java
@@ -0,0 +1,152 @@
+/**
+ * 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.sqoop.integration.shell;
+
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.SetCommand;
+import org.apache.sqoop.shell.ShellEnvironment;
+import org.apache.sqoop.shell.SqoopCommand;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.test.infrastructure.Infrastructure;
+import org.apache.sqoop.test.infrastructure.providers.DatabaseInfrastructureProvider;
+import org.apache.sqoop.test.infrastructure.providers.SqoopInfrastructureProviderForShellTest;
+import org.apache.sqoop.test.testcases.ShellTestCase;
+import org.apache.sqoop.validation.Status;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.util.Arrays;
+
+@Infrastructure(dependencies = {SqoopInfrastructureProviderForShellTest.class, DatabaseInfrastructureProvider.class})
+public class SetCommandTest extends ShellTestCase {
+
+ protected SqoopCommand createCommand(Groovysh shell) {
+ return new SetCommand(shell);
+ }
+
+ @Test
+ public void testSetServer() {
+ ShellEnvironment.cleanup();
+ // set server -url http://host-test:7070/sqoop-test
+ Status status = (Status) execute(Arrays.asList(Constants.FN_SERVER, "-url", "http://host-test:7070/sqoop-test"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertEquals(getClient().getServerUrl(), "http://host-test:7070/sqoop-test/");
+
+ // use the default webapp path if not specified
+ status = (Status) execute(Arrays.asList(Constants.FN_SERVER, "-url", "http://host-test:7070/"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertTrue(getClient().getServerUrl().equals("http://host-test:7070/sqoop/"));
+
+ // use the default webapp and port if not specified
+ status = (Status) execute(Arrays.asList(Constants.FN_SERVER, "-url", "http://host-test/"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertTrue(getClient().getServerUrl().equals("http://host-test:12000/sqoop/"));
+
+ // option host is ignored when option url is specified
+ status = (Status) execute(Arrays.asList(Constants.FN_SERVER, "-url", "http://host-test:7070/sqoop-test", "-host", "host2-test"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertEquals(getClient().getServerUrl(), "http://host-test:7070/sqoop-test/");
+
+ // option port is ignored when option url is specified
+ status = (Status) execute(Arrays.asList(Constants.FN_SERVER, "-url", "http://host-test:7070/sqoop-test", "-port", "12000"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertEquals(getClient().getServerUrl(), "http://host-test:7070/sqoop-test/");
+
+ // option webapp is ignored when option url is specified
+ status = (Status) execute(Arrays.asList(Constants.FN_SERVER, "-url", "http://host-test:7070/sqoop-test", "-webapp", "sqoop2-test"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertEquals(getClient().getServerUrl(), "http://host-test:7070/sqoop-test/");
+
+ // Missing argument for option url
+ try {
+ execute(Arrays.asList(Constants.FN_SERVER, "-url"));
+ Assert.fail("Set server should fail as url is missing!");
+ } catch (SqoopException e) {
+ Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
+ Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
+ }
+ }
+
+ @Test
+ public void testSetServerWithoutOptionURL() {
+ ShellEnvironment.cleanup();
+ // use option host, port, webapp when option url is not specified
+ Status status = (Status) execute(Arrays.asList(Constants.FN_SERVER, "-host", "host2-test", "-port", "7070", "-webapp", "sqoop2-test"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertEquals(getClient().getServerUrl(), "http://host2-test:7070/sqoop2-test/");
+
+ ShellEnvironment.cleanup();
+ // use default host if option host is not specified
+ status = (Status) execute(Arrays.asList(Constants.FN_SERVER, "-port", "7070", "-webapp", "sqoop2-test"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertEquals(getClient().getServerUrl(), "http://localhost:7070/sqoop2-test/");
+
+ ShellEnvironment.cleanup();
+ // use default port if option port is not specified
+ status = (Status) execute(Arrays.asList(Constants.FN_SERVER, "-host", "host2-test", "-webapp", "sqoop2-test"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertEquals(getClient().getServerUrl(), "http://host2-test:12000/sqoop2-test/");
+
+ ShellEnvironment.cleanup();
+ // use default webapp if option webapp is not specified
+ status = (Status) execute(Arrays.asList(Constants.FN_SERVER, "-host", "host2-test", "-port", "7070"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertEquals(getClient().getServerUrl(), "http://host2-test:7070/sqoop/");
+ }
+
+ @Test
+ public void testSetOption() {
+ // set option -name verbose -value true
+ Status status = (Status) execute(Arrays.asList(Constants.FN_OPTION, "-name", "verbose", "-value", "true"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertTrue(ShellEnvironment.isVerbose());
+
+ // set option -name verbose -value 1
+ status = (Status) execute(Arrays.asList(Constants.FN_OPTION, "-name", "verbose", "-value", "1"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertTrue(ShellEnvironment.isVerbose());
+
+ // set option -name verbose -value 0
+ status = (Status) execute(Arrays.asList(Constants.FN_OPTION, "-name", "verbose", "-value", "0"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertFalse(ShellEnvironment.isVerbose());
+
+ // set option -name poll-timeout -value 12345
+ status = (Status) execute(Arrays.asList(Constants.FN_OPTION, "-name", "poll-timeout", "-value", "12345"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertEquals(ShellEnvironment.getPollTimeout(), 12345);
+
+ // when value of poll-timeout is not number, poll-timeout should stay the old value
+ status = (Status) execute(Arrays.asList(Constants.FN_OPTION, "-name", "poll-timeout", "-value", "abc"));
+ Assert.assertTrue(status != null && status == Status.OK);
+ Assert.assertEquals(ShellEnvironment.getPollTimeout(), 12345);
+
+ // skip non exist options, options already set should stay the old value
+ status = (Status) execute(Arrays.asList(Constants.FN_OPTION, "-name", "non-exist-option", "-value", "opt-value"));
+ Assert.assertTrue(status == null);
+ Assert.assertFalse(ShellEnvironment.isVerbose());
+ Assert.assertEquals(ShellEnvironment.getPollTimeout(), 12345);
+ }
+
+ @Override
+ public void cleanup() {
+ // this test don't need to cleanup the repository
+ }
+}
|