You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by ab...@apache.org on 2014/10/10 04:51:42 UTC
[13/52] [abbrv] SQOOP-1497: Sqoop2: Entity Nomenclature Revisited
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/main/java/org/apache/sqoop/repository/Repository.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/sqoop/repository/Repository.java b/core/src/main/java/org/apache/sqoop/repository/Repository.java
index 8e8dd80..ea1608a 100644
--- a/core/src/main/java/org/apache/sqoop/repository/Repository.java
+++ b/core/src/main/java/org/apache/sqoop/repository/Repository.java
@@ -17,36 +17,36 @@
*/
package org.apache.sqoop.repository;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
import org.apache.log4j.Logger;
import org.apache.sqoop.common.Direction;
import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.connector.ConnectorManager;
-import org.apache.sqoop.connector.spi.MetadataUpgrader;
+import org.apache.sqoop.connector.spi.RepositoryUpgrader;
import org.apache.sqoop.connector.spi.SqoopConnector;
-import org.apache.sqoop.framework.FrameworkManager;
+import org.apache.sqoop.driver.Driver;
import org.apache.sqoop.model.FormUtils;
-import org.apache.sqoop.model.MConnection;
import org.apache.sqoop.model.MConnectionForms;
import org.apache.sqoop.model.MConnector;
+import org.apache.sqoop.model.MDriverConfig;
import org.apache.sqoop.model.MForm;
-import org.apache.sqoop.model.MFramework;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MJobForms;
+import org.apache.sqoop.model.MLink;
import org.apache.sqoop.model.MPersistableEntity;
import org.apache.sqoop.model.MSubmission;
import org.apache.sqoop.utils.ClassUtils;
import org.apache.sqoop.validation.Validation;
import org.apache.sqoop.validation.Validator;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
/**
- * Defines the contract of a Repository used by Sqoop. A Repository allows
- * Sqoop to store metadata, statistics and other state relevant to Sqoop
- * Jobs in the system.
+ * Defines the contract for repository used by Sqoop. A Repository allows
+ * Sqoop to store entities such as connectors, links, jobs, submissions and its related configs,
+ * statistics and other state relevant the entities in the store
*/
public abstract class Repository {
@@ -76,11 +76,11 @@ public abstract class Repository {
/**
* Registers given connector in the repository and return registered
- * variant. This method might return an exception in case that metadata for
+ * variant. This method might return an exception in case that
* given connector are already registered with different structure.
*
- * @param mConnector the connector metadata to be registered
- * autoupgrade whether to upgrade framework automatically
+ * @param mConnector the connector to be registered
+ * autoupgrade whether to upgrade driver config automatically
* @return Registered connector structure
*/
public abstract MConnector registerConnector(MConnector mConnector, boolean autoUpgrade);
@@ -88,7 +88,7 @@ public abstract class Repository {
/**
* Search for connector with given name in repository.
*
- * And return corresponding metadata structure.
+ * And return corresponding entity structure.
*
* @param shortName Connector unique name
* @return null if connector is not yet registered in repository or
@@ -105,76 +105,75 @@ public abstract class Repository {
/**
- * Registers given framework in the repository and return registered
- * variant. This method might return an exception in case that metadata for
- * given framework are already registered with different structure.
+ * Registers given driverConfig in the repository and return registered
+ * variant. This method might return an exception in case that the
+ * given driverConfig are already registered with different structure.
*
- * @param mFramework framework metadata to be registered
- * autoupgrade whether to upgrade framework automatically
+ * @param mDriverConfig driverConfig to be registered
+ * autoupgrade whether to upgrade driverConfig automatically
* @return Registered connector structure
*/
- public abstract MFramework registerFramework(MFramework mFramework, boolean autoUpgrade);
+ public abstract MDriverConfig registerDriverConfig(MDriverConfig mDriverConfig, boolean autoUpgrade);
/**
- * Save given connection to repository. This connection must not be already
+ * Save given link to repository. This link must not be already
* present in the repository otherwise exception will be thrown.
*
- * @param connection Connection object to serialize into repository.
+ * @param link link object to serialize into repository.
*/
- public abstract void createConnection(MConnection connection);
+ public abstract void createLink(MLink link);
/**
- * Update given connection representation in repository. This connection
+ * Update given link representation in repository. This link
* object must already exists in the repository otherwise exception will be
* thrown.
*
- * @param connection Connection object that should be updated in repository.
+ * @param link link object that should be updated in repository.
*/
- public abstract void updateConnection(MConnection connection);
+ public abstract void updateLink(MLink link);
/**
- * Update given connection representation in repository. This connection
+ * Update given link representation in repository. This link
* object must already exists in the repository otherwise exception will be
* thrown.
*
- * @param connection Connection object that should be updated in repository.
+ * @param link Link object that should be updated in repository.
* @param tx The repository transaction to use to push the data to the
* repository. If this is null, a new transaction will be created.
* method will not call begin, commit,
* rollback or close on this transaction.
*/
- public abstract void updateConnection(final MConnection connection,
- RepositoryTransaction tx);
+ public abstract void updateLink(final MLink link, RepositoryTransaction tx);
/**
- * Enable or disable connection with given id from metadata repository
+ * Enable or disable Link with given id from the repository
*
- * @param id Connection object that is going to be enabled or disabled
+ * @param id Link object that is going to be enabled or disabled
* @param enabled enable or disable
*/
- public abstract void enableConnection(long id, boolean enabled);
+ public abstract void enableLink(long id, boolean enabled);
/**
- * Delete connection with given id from metadata repository.
+ * Delete Link with given id from the repository.
*
- * @param id Connection object that should be removed from repository
+ * @param id Link object that should be removed from repository
*/
- public abstract void deleteConnection(long id);
+ public abstract void deleteLink(long id);
/**
- * Find connection with given id in repository.
+ * Find link with given id in repository.
*
- * @param id Connection id
- * @return Deserialized form of the connection that is saved in repository
+ * @param id Link id
+ * @return Deserialized form of the link that is saved in repository
*/
- public abstract MConnection findConnection(long id);
+ public abstract MLink findLink(long id);
/**
- * Get all connection objects.
+ * Get all Link objects.
*
- * @return List will all saved connection objects
+ * @return List will all saved link objects
*/
- public abstract List<MConnection> findConnections();
+ public abstract List<MLink> findLinks();
/**
* Save given job to repository. This job object must not be already present
@@ -285,18 +284,18 @@ public abstract class Repository {
public abstract MSubmission findSubmissionLastForJob(long jobId);
/**
- * Retrieve connections which use the given connector.
- * @param connectorID Connector ID whose connections should be fetched
- * @return List of MConnections that use <code>connectorID</code>.
+ * Retrieve links which use the given connector.
+ * @param connectorID Connector ID whose links should be fetched
+ * @return List of MLink that use <code>connectorID</code>.
*/
- public abstract List<MConnection> findConnectionsForConnector(long
+ public abstract List<MLink> findLinksForConnector(long
connectorID);
/**
- * Retrieve jobs which use the given connection.
+ * Retrieve jobs which use the given link.
*
* @param connectorID Connector ID whose jobs should be fetched
- * @return List of MJobs that use <code>connectionID</code>.
+ * @return List of MJobs that use <code>linkID</code>.
*/
public abstract List<MJob> findJobsForConnector(long
connectorID);
@@ -317,29 +316,25 @@ public abstract class Repository {
* method will not call begin, commit,
* rollback or close on this transaction.
*/
- protected abstract void updateConnector(MConnector newConnector,
- RepositoryTransaction tx);
-
+ protected abstract void updateConnector(MConnector newConnector, RepositoryTransaction tx);
/**
- * Update the framework with the new data supplied in the
- * <tt>mFramework</tt>. Also Update all forms associated with the framework
+ * Update the driverConfig with the new data supplied in the
+ * <tt>mDriverConfig</tt>. Also Update all forms associated with the driverConfig
* in the repository with the forms specified in
- * <tt>mFramework</tt>. <tt>mFramework </tt> must
+ * <tt>mDriverConfig</tt>. <tt>mDriverConfig </tt> must
* minimally have the connectorID and all required forms (including ones
* which may not have changed). After this operation the repository is
* guaranteed to only have the new forms specified in this object.
*
- * @param mFramework The new data to be inserted into the repository for
- * the framework.
+ * @param mDriverConfig The new data to be inserted into the repository for
+ * the driverConfig.
* @param tx The repository transaction to use to push the data to the
* repository. If this is null, a new transaction will be created.
* method will not call begin, commit,
* rollback or close on this transaction.
*/
- protected abstract void updateFramework(MFramework mFramework,
- RepositoryTransaction tx);
-
+ protected abstract void updateDriverConfig(MDriverConfig mDriverConfig, RepositoryTransaction tx);
/**
* Delete all inputs for a job
@@ -351,24 +346,22 @@ public abstract class Repository {
protected abstract void deleteJobInputs(long jobId, RepositoryTransaction tx);
/**
- * Delete all inputs for a connection
- * @param connectionID The id of the connection whose inputs are to be
+ * Delete all inputs for a link
+ * @param linkId The id of the link whose inputs are to be
* deleted.
* @param tx The repository transaction to use to push the data to the
* repository. If this is null, a new transaction will be created.
* method will not call begin, commit,
* rollback or close on this transaction.
*/
- protected abstract void deleteConnectionInputs(long connectionID,
- RepositoryTransaction tx);
+ protected abstract void deleteLinkInputs(long linkId, RepositoryTransaction tx);
- private void deleteConnectionsAndJobs(List<MConnection> connections,
- List<MJob> jobs, RepositoryTransaction tx) {
+ private void deletelinksAndJobs(List<MLink> links, List<MJob> jobs, RepositoryTransaction tx) {
for (MJob job : jobs) {
deleteJobInputs(job.getPersistenceId(), tx);
}
- for (MConnection connection : connections) {
- deleteConnectionInputs(connection.getPersistenceId(), tx);
+ for (MLink link : links) {
+ deleteLinkInputs(link.getPersistenceId(), tx);
}
}
@@ -376,7 +369,7 @@ public abstract class Repository {
* Upgrade the connector with the same {@linkplain MConnector#uniqueName}
* in the repository with values from <code>newConnector</code>.
* <p/>
- * All connections and jobs associated with this connector will be upgraded
+ * All links and jobs associated with this connector will be upgraded
* automatically.
*
* @param oldConnector The old connector that should be upgraded.
@@ -389,18 +382,18 @@ public abstract class Repository {
newConnector.setPersistenceId(connectorID);
/* Algorithms:
* 1. Get an upgrader for the connector.
- * 2. Get all connections associated with the connector.
+ * 2. Get all links associated with the connector.
* 3. Get all jobs associated with the connector.
- * 4. Delete the inputs for all of the jobs and connections (in that order)
+ * 4. Delete the inputs for all of the jobs and links (in that order)
* 5. Remove all inputs and forms associated with the connector, and
* register the new forms and inputs.
- * 6. Create new connections and jobs with connector part being the ones
+ * 6. Create new links and jobs with connector part being the ones
* returned by the upgrader.
- * 7. Validate new connections and jobs with connector's validator
- * 8. If any invalid connections or jobs detected, throw an exception
+ * 7. Validate new links and jobs with connector's validator
+ * 8. If any invalid links or jobs detected, throw an exception
* and stop the bootup of Sqoop server
- * 9. Otherwise, Insert the connection inputs followed by job inputs (using
- * updateJob and updateConnection)
+ * 9. Otherwise, Insert the link inputs followed by job inputs (using
+ * updateJob and updatelink)
*/
RepositoryTransaction tx = null;
try {
@@ -412,33 +405,33 @@ public abstract class Repository {
boolean upgradeSuccessful = true;
- MetadataUpgrader upgrader = connector.getMetadataUpgrader();
- List<MConnection> connections = findConnectionsForConnector(
+ RepositoryUpgrader upgrader = connector.getRepositoryUpgrader();
+ List<MLink> links = findLinksForConnector(
connectorID);
List<MJob> jobs = findJobsForConnector(connectorID);
// -- BEGIN TXN --
tx = getTransaction();
tx.begin();
- deleteConnectionsAndJobs(connections, jobs, tx);
+ deletelinksAndJobs(links, jobs, tx);
updateConnector(newConnector, tx);
- for (MConnection connection : connections) {
+ for (MLink link : links) {
// Make a new copy of the forms from the connector,
// else the values will get set in the forms in the connector for
- // each connection.
+ // each link.
List<MForm> forms = newConnector.getConnectionForms().clone(false).getForms();
- MConnectionForms newConnectionForms = new MConnectionForms(forms);
- upgrader.upgrade(connection.getConnectorPart(), newConnectionForms);
- MConnection newConnection = new MConnection(connection, newConnectionForms, connection.getFrameworkPart());
+ MConnectionForms newlinkForms = new MConnectionForms(forms);
+ upgrader.upgrade(link.getConnectorPart(), newlinkForms);
+ MLink newlink = new MLink(link, newlinkForms, link.getFrameworkPart());
// Transform form structures to objects for validations
- Object newConfigurationObject = ClassUtils.instantiate(connector.getConnectionConfigurationClass());
- FormUtils.fromForms(newConnection.getConnectorPart().getForms(), newConfigurationObject);
+ Object newConfigurationObject = ClassUtils.instantiate(connector.getLinkConfigurationClass());
+ FormUtils.fromForms(newlink.getConnectorPart().getForms(), newConfigurationObject);
- Validation validation = validator.validateConnection(newConfigurationObject);
+ Validation validation = validator.validateLink(newConfigurationObject);
if (validation.getStatus().canProceed()) {
- updateConnection(newConnection, tx);
+ updateLink(newlink, tx);
} else {
- logInvalidModelObject("connection", newConnection, validation);
+ logInvalidModelObject("link", newlink, validation);
upgradeSuccessful = false;
}
}
@@ -513,57 +506,57 @@ public abstract class Repository {
}
}
- public final void upgradeFramework(MFramework framework) {
- LOG.info("Upgrading framework metadata");
+ public final void upgradeDriverConfig(MDriverConfig driverConfig) {
+ LOG.info("Upgrading driver config");
RepositoryTransaction tx = null;
try {
- MetadataUpgrader upgrader = FrameworkManager.getInstance()
- .getMetadataUpgrader();
- List<MConnection> connections = findConnections();
+ RepositoryUpgrader upgrader = Driver.getInstance()
+ .getDriverConfigRepositoryUpgrader();
+ List<MLink> links = findLinks();
List<MJob> jobs = findJobs();
- Validator validator = FrameworkManager.getInstance().getValidator();
+ Validator validator = Driver.getInstance().getValidator();
boolean upgradeSuccessful = true;
// -- BEGIN TXN --
tx = getTransaction();
tx.begin();
- deleteConnectionsAndJobs(connections, jobs, tx);
- updateFramework(framework, tx);
- for (MConnection connection : connections) {
+ deletelinksAndJobs(links, jobs, tx);
+ updateDriverConfig(driverConfig, tx);
+ for (MLink link : links) {
// Make a new copy of the forms from the connector,
// else the values will get set in the forms in the connector for
- // each connection.
- // @TODO(Abe): From/To connection forms.
- List<MForm> forms = framework.getConnectionForms().clone(false).getForms();
- MConnectionForms newConnectionForms = new MConnectionForms(forms);
- upgrader.upgrade(connection.getFrameworkPart(), newConnectionForms);
- MConnection newConnection = new MConnection(connection, connection.getConnectorPart(), newConnectionForms);
+ // each link.
+ // @TODO(Abe): From/To link forms.
+ List<MForm> forms = driverConfig.getConnectionForms().clone(false).getForms();
+ MConnectionForms newlinkForms = new MConnectionForms(forms);
+ upgrader.upgrade(link.getFrameworkPart(), newlinkForms);
+ MLink newlink = new MLink(link, link.getConnectorPart(), newlinkForms);
// Transform form structures to objects for validations
- Object newConfigurationObject = ClassUtils.instantiate(FrameworkManager.getInstance().getConnectionConfigurationClass());
- FormUtils.fromForms(newConnection.getFrameworkPart().getForms(), newConfigurationObject);
+ Object newConfigurationObject = ClassUtils.instantiate(Driver.getInstance().getLinkConfigurationClass());
+ FormUtils.fromForms(newlink.getFrameworkPart().getForms(), newConfigurationObject);
- Validation validation = validator.validateConnection(newConfigurationObject);
+ Validation validation = validator.validateLink(newConfigurationObject);
if (validation.getStatus().canProceed()) {
- updateConnection(newConnection, tx);
+ updateLink(newlink, tx);
} else {
- logInvalidModelObject("connection", newConnection, validation);
+ logInvalidModelObject("link", newlink, validation);
upgradeSuccessful = false;
}
}
for (MJob job : jobs) {
// Make a new copy of the forms from the framework,
// else the values will get set in the forms in the connector for
- // each connection.
- List<MForm> forms = framework.getJobForms().clone(false).getForms();
+ // each link.
+ List<MForm> forms = driverConfig.getJobForms().clone(false).getForms();
MJobForms newJobForms = new MJobForms(forms);
upgrader.upgrade(job.getFrameworkPart(), newJobForms);
MJob newJob = new MJob(job, job.getConnectorPart(Direction.FROM), job.getConnectorPart(Direction.TO), newJobForms);
// Transform form structures to objects for validations
- Object newConfigurationObject = ClassUtils.instantiate(FrameworkManager.getInstance().getJobConfigurationClass());
+ Object newConfigurationObject = ClassUtils.instantiate(Driver.getInstance().getJobConfigurationClass());
FormUtils.fromForms(newJob.getFrameworkPart().getForms(), newConfigurationObject);
Validation validation = validator.validateJob(newConfigurationObject);
@@ -594,7 +587,7 @@ public abstract class Repository {
if(tx != null) {
tx.close();
}
- LOG.info("Framework metadata upgrade finished");
+ LOG.info("Driver config upgrade finished");
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java b/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
index 3f3a9e6..54e37d9 100644
--- a/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
+++ b/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
@@ -40,8 +40,8 @@ public enum RepositoryError implements ErrorCode {
/** The system was unable to find or load the JDBC repository handler. */
JDBCREPO_0001("Invalid JDBC Repository Handler specified"),
- /** An invalid JDBC connection URL was specified. */
- JDBCREPO_0002("Invalid JDBC connection URL specified"),
+ /** An invalid JDBC link URL was specified. */
+ JDBCREPO_0002("Invalid JDBC link URL specified"),
/** An invalid JDBC driver class name was specified. */
JDBCREPO_0003("Invalid JDBC driver class specified"),
@@ -49,17 +49,17 @@ public enum RepositoryError implements ErrorCode {
/** An invalid JDBC transaction isolation level was specified. */
JDBCREPO_0004("Invalid JDBC transaction isolation level specified"),
- /** The value specified for maximum connection pool connections is invalid.*/
- JDBCREPO_0005("Invalid maximum connections specified for connection pool"),
+ /** The value specified for maximum link pool links is invalid.*/
+ JDBCREPO_0005("Invalid maximum links specified for link pool"),
/** The system attempted to use an inactive transaction. */
JDBCREPO_0006("Transaction is not active"),
/**
- * The system was unable to obtain a connection lease for the
+ * The system was unable to obtain a link lease for the
* requested transaction.
*/
- JDBCREPO_0007("Unable to lease connection"),
+ JDBCREPO_0007("Unable to lease link"),
/** The system attempted to commit a transaction marked for rollback.*/
JDBCREPO_0008("Attempt to commit a transaction marked for rollback"),
@@ -76,23 +76,23 @@ public enum RepositoryError implements ErrorCode {
*/
JDBCREPO_0011("Attempt to reinitialize JDBC repository context"),
- /** Failure in metadata repository operation. */
- JDBCREPO_0012("Failure in metadata repository operation."),
+ /** Failure in config repository operation. */
+ JDBCREPO_0012("Failure in config repository operation."),
- /** The system found a change in connector metadata that requires upgrade. */
- JDBCREPO_0013("Connector metadata changed - upgrade may be required"),
+ /** The system found a change in connector config that requires upgrade. */
+ JDBCREPO_0013("Connector config changed - upgrade may be required"),
- /** The system found a change in framework metadata that requires upgrade. */
- JDBCREPO_0014("Framework metadata changed - upgrade may be required"),
+ /** The system found a change in driver config that requires upgrade. */
+ JDBCREPO_0014("Driver config changed - upgrade may be required"),
- /** Connection that we're trying to create is already saved in repository **/
- JDBCREPO_0015("Cannot create connection that was already created"),
+ /** link that we're trying to create is already saved in repository **/
+ JDBCREPO_0015("Cannot create link that was already created"),
- /** Connection that we're trying to update is not yet saved **/
- JDBCREPO_0016("Cannot update connection that was not yet created"),
+ /** link that we're trying to update is not yet saved **/
+ JDBCREPO_0016("Cannot update link that was not yet created"),
- /** Invalid connection id **/
- JDBCREPO_0017("Given connection id is invalid"),
+ /** Invalid link id **/
+ JDBCREPO_0017("Given link id is invalid"),
/** Job that we're trying to create is already saved in repository **/
JDBCREPO_0018("Cannot create job that was already created"),
@@ -103,8 +103,8 @@ public enum RepositoryError implements ErrorCode {
/** Invalid job id **/
JDBCREPO_0020("Given job id is invalid"),
- /** Connection ID is in use **/
- JDBCREPO_0021("Given connection id is in use"),
+ /** link ID is in use **/
+ JDBCREPO_0021("Given link id is in use"),
/** Job ID is in use **/
JDBCREPO_0022("Given job id is in use"),
@@ -121,8 +121,8 @@ public enum RepositoryError implements ErrorCode {
/** Upgrade required but not allowed **/
JDBCREPO_0026("Upgrade required but not allowed"),
- /** Invalid connections or jobs when upgrading connector **/
- JDBCREPO_0027("Invalid connections or jobs when upgrading connector");
+ /** Invalid links or jobs when upgrading connector **/
+ JDBCREPO_0027("Invalid links or jobs when upgrading connector");
;
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/main/resources/driver-config.properties
----------------------------------------------------------------------
diff --git a/core/src/main/resources/driver-config.properties b/core/src/main/resources/driver-config.properties
new file mode 100644
index 0000000..9ec5d9e
--- /dev/null
+++ b/core/src/main/resources/driver-config.properties
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Driver Configs
+
+############################
+
+# Throttling From
+#
+throttling.label = Throttling resources
+throttling.help = Set throttling boundaries to not overload your systems
+
+throttling.extractors.label = Extractors
+throttling.extractors.help = Number of extractors that Sqoop will use
+
+throttling.loaders.label = Loaders
+throttling.loaders.help = Number of loaders that Sqoop will use
+
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/main/resources/framework-resources.properties
----------------------------------------------------------------------
diff --git a/core/src/main/resources/framework-resources.properties b/core/src/main/resources/framework-resources.properties
deleted file mode 100644
index 7ecb9ae..0000000
--- a/core/src/main/resources/framework-resources.properties
+++ /dev/null
@@ -1,71 +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.
-
-# Framework Resources
-
-############################
-# Security Form
-#
-security.label = Security related configuration options
-security.help = You must supply the information requested in order to \
- create a job object.
-
-security.maxConnections.label = Max connections
-security.maxConnections.help = Maximal number of connections that this \
- connection object can use at one point in time
-
-# Output From
-#
-output.label = Output configuration
-output.help = You must supply the information requested in order to \
- get information where you want to store your data.
-
-output.storageType.label = Storage type
-output.storageType.help = Target on Hadoop ecosystem where to store data
-
-output.outputFormat.label = Output format
-output.outputFormat.help = Format in which data should be serialized
-
-output.compression.label = Compression format
-output.compression.help = Compression that should be used for the data
-
-output.customCompression.label = Custom compression format
-output.customCompression.help = Full class name of the custom compression
-
-output.outputDirectory.label = Output directory
-output.outputDirectory.help = Output directory for final data
-
-output.ignored.label = Ignored
-output.ignored.help = This value is ignored
-
-# Input Form
-#
-input.label = Input configuration
-input.help = Specifies information required to get data from Hadoop ecosystem
-
-input.inputDirectory.label = Input directory
-input.inputDirectory.help = Directory that should be exported
-
-# Throttling From
-#
-throttling.label = Throttling resources
-throttling.help = Set throttling boundaries to not overload your systems
-
-throttling.extractors.label = Extractors
-throttling.extractors.help = Number of extractors that Sqoop will use
-
-throttling.loaders.label = Loaders
-throttling.loaders.help = Number of loaders that Sqoop will use
-
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/test/java/org/apache/sqoop/core/MockInvalidConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/sqoop/core/MockInvalidConfigurationProvider.java b/core/src/test/java/org/apache/sqoop/core/MockInvalidConfigurationProvider.java
index 4043e3e..550aaee 100644
--- a/core/src/test/java/org/apache/sqoop/core/MockInvalidConfigurationProvider.java
+++ b/core/src/test/java/org/apache/sqoop/core/MockInvalidConfigurationProvider.java
@@ -29,26 +29,19 @@ public class MockInvalidConfigurationProvider implements ConfigurationProvider {
@Override
public void initialize(File configDir, Properties bootstrapCongiruation) {
- // TODO Auto-generated method stub
-
}
@Override
public void registerListener(ConfigurationListener listener) {
- // TODO Auto-generated method stub
-
}
@Override
public Map<String, String> getConfiguration() {
- // TODO Auto-generated method stub
return null;
}
@Override
public void destroy() {
- // TODO Auto-generated method stub
-
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/test/java/org/apache/sqoop/core/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/sqoop/core/TestConfiguration.java b/core/src/test/java/org/apache/sqoop/core/TestConfiguration.java
deleted file mode 100644
index e7fe370..0000000
--- a/core/src/test/java/org/apache/sqoop/core/TestConfiguration.java
+++ /dev/null
@@ -1,165 +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.core;
-
-import java.util.Properties;
-
-import org.apache.sqoop.common.SqoopException;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class TestConfiguration {
-
- @Before
- public void setUp() throws Exception {
- // Unset any configuration dir if it is set by another test
- System.getProperties().remove(ConfigurationConstants.SYSPROP_CONFIG_DIR);
- SqoopConfiguration.getInstance().destroy();
- }
-
- @Test
- public void testConfigurationInitFailure() {
- boolean success = false;
- try {
- SqoopConfiguration.getInstance().initialize();
- } catch (Exception ex) {
- Assert.assertTrue(ex instanceof SqoopException);
- Assert.assertSame(((SqoopException) ex).getErrorCode(),
- CoreError.CORE_0001);
- success = true;
- }
-
- Assert.assertTrue(success);
- }
-
- @Test
- public void testBootstrapConfigurationInitFailure() {
- boolean success = false;
- try {
- String configDirPath = TestUtils.createEmptyConfigDirectory();
- System.setProperty(ConfigurationConstants.SYSPROP_CONFIG_DIR,
- configDirPath);
- SqoopConfiguration.getInstance().initialize();
- } catch (Exception ex) {
- Assert.assertTrue(ex instanceof SqoopException);
- Assert.assertSame(((SqoopException) ex).getErrorCode(),
- CoreError.CORE_0002);
- success = true;
- }
-
- Assert.assertTrue(success);
- }
-
- @Test
- public void testConfigurationProviderNotSet() throws Exception {
- boolean success = false;
- Properties bootProps = new Properties();
- bootProps.setProperty("foo", "bar");
- TestUtils.setupTestConfigurationUsingProperties(bootProps, null);
- try {
- SqoopConfiguration.getInstance().initialize();
- } catch (Exception ex) {
- Assert.assertTrue(ex instanceof SqoopException);
- Assert.assertSame(((SqoopException) ex).getErrorCode(),
- CoreError.CORE_0003);
- success = true;
- }
-
- Assert.assertTrue(success);
- }
-
- @Test
- public void testConfigurationProviderInvalid() throws Exception {
- boolean success = false;
- Properties bootProps = new Properties();
- bootProps.setProperty(ConfigurationConstants.BOOTCFG_CONFIG_PROVIDER,
- "foobar");
- TestUtils.setupTestConfigurationUsingProperties(bootProps, null);
- try {
- SqoopConfiguration.getInstance().initialize();
- } catch (Exception ex) {
- Assert.assertTrue(ex instanceof SqoopException);
- Assert.assertSame(((SqoopException) ex).getErrorCode(),
- CoreError.CORE_0004);
-
- success = true;
- }
-
- Assert.assertTrue(success);
- }
-
- @Test
- public void testConfiugrationProviderCannotLoad() throws Exception {
- boolean success = false;
- Properties bootProps = new Properties();
- bootProps.setProperty(ConfigurationConstants.BOOTCFG_CONFIG_PROVIDER,
- MockInvalidConfigurationProvider.class.getCanonicalName());
- TestUtils.setupTestConfigurationUsingProperties(bootProps, null);
- try {
- SqoopConfiguration.getInstance().initialize();
- } catch (Exception ex) {
- Assert.assertTrue(ex instanceof SqoopException);
- Assert.assertSame(((SqoopException) ex).getErrorCode(),
- CoreError.CORE_0005);
- success = true;
- }
-
- Assert.assertTrue(success);
- }
-
- @Test
- public void testPropertiesConfigProviderNoFile() throws Exception {
- boolean success = false;
- Properties bootProps = new Properties();
- bootProps.setProperty(ConfigurationConstants.BOOTCFG_CONFIG_PROVIDER,
- PropertiesConfigurationProvider.class.getCanonicalName());
- TestUtils.setupTestConfigurationUsingProperties(bootProps, null);
- try {
- SqoopConfiguration.getInstance().initialize();
- } catch (Exception ex) {
- Assert.assertTrue(ex instanceof SqoopException);
- Assert.assertSame(((SqoopException) ex).getErrorCode(),
- CoreError.CORE_0006);
- success = true;
- }
-
- Assert.assertTrue(success);
- }
-
- @Test
- public void testSystemNotInitialized() throws Exception {
- boolean success = false;
- try {
- SqoopConfiguration.getInstance().getContext();
- } catch (Exception ex) {
- Assert.assertTrue(ex instanceof SqoopException);
- Assert.assertSame(((SqoopException) ex).getErrorCode(),
- CoreError.CORE_0007);
- success = true;
- }
-
- Assert.assertTrue(success);
- }
-
- @Test
- public void testConfigurationInitSuccess() throws Exception {
- TestUtils.setupTestConfigurationWithExtraConfig(null, null);
- SqoopConfiguration.getInstance().initialize();
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/test/java/org/apache/sqoop/core/TestSqoopConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/sqoop/core/TestSqoopConfiguration.java b/core/src/test/java/org/apache/sqoop/core/TestSqoopConfiguration.java
new file mode 100644
index 0000000..4d58bd1
--- /dev/null
+++ b/core/src/test/java/org/apache/sqoop/core/TestSqoopConfiguration.java
@@ -0,0 +1,165 @@
+/**
+ * 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.core;
+
+import java.util.Properties;
+
+import org.apache.sqoop.common.SqoopException;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestSqoopConfiguration {
+
+ @Before
+ public void setUp() throws Exception {
+ // Unset any configuration dir if it is set by another test
+ System.getProperties().remove(ConfigurationConstants.SYSPROP_CONFIG_DIR);
+ SqoopConfiguration.getInstance().destroy();
+ }
+
+ @Test
+ public void testConfigurationInitFailure() {
+ boolean success = false;
+ try {
+ SqoopConfiguration.getInstance().initialize();
+ } catch (Exception ex) {
+ Assert.assertTrue(ex instanceof SqoopException);
+ Assert.assertSame(((SqoopException) ex).getErrorCode(),
+ CoreError.CORE_0001);
+ success = true;
+ }
+
+ Assert.assertTrue(success);
+ }
+
+ @Test
+ public void testBootstrapConfigurationInitFailure() {
+ boolean success = false;
+ try {
+ String configDirPath = TestUtils.createEmptyConfigDirectory();
+ System.setProperty(ConfigurationConstants.SYSPROP_CONFIG_DIR,
+ configDirPath);
+ SqoopConfiguration.getInstance().initialize();
+ } catch (Exception ex) {
+ Assert.assertTrue(ex instanceof SqoopException);
+ Assert.assertSame(((SqoopException) ex).getErrorCode(),
+ CoreError.CORE_0002);
+ success = true;
+ }
+
+ Assert.assertTrue(success);
+ }
+
+ @Test
+ public void testConfigurationProviderNotSet() throws Exception {
+ boolean success = false;
+ Properties bootProps = new Properties();
+ bootProps.setProperty("foo", "bar");
+ TestUtils.setupTestConfigurationUsingProperties(bootProps, null);
+ try {
+ SqoopConfiguration.getInstance().initialize();
+ } catch (Exception ex) {
+ Assert.assertTrue(ex instanceof SqoopException);
+ Assert.assertSame(((SqoopException) ex).getErrorCode(),
+ CoreError.CORE_0003);
+ success = true;
+ }
+
+ Assert.assertTrue(success);
+ }
+
+ @Test
+ public void testConfigurationProviderInvalid() throws Exception {
+ boolean success = false;
+ Properties bootProps = new Properties();
+ bootProps.setProperty(ConfigurationConstants.BOOTCFG_CONFIG_PROVIDER,
+ "foobar");
+ TestUtils.setupTestConfigurationUsingProperties(bootProps, null);
+ try {
+ SqoopConfiguration.getInstance().initialize();
+ } catch (Exception ex) {
+ Assert.assertTrue(ex instanceof SqoopException);
+ Assert.assertSame(((SqoopException) ex).getErrorCode(),
+ CoreError.CORE_0004);
+
+ success = true;
+ }
+
+ Assert.assertTrue(success);
+ }
+
+ @Test
+ public void testConfiugrationProviderCannotLoad() throws Exception {
+ boolean success = false;
+ Properties bootProps = new Properties();
+ bootProps.setProperty(ConfigurationConstants.BOOTCFG_CONFIG_PROVIDER,
+ MockInvalidConfigurationProvider.class.getCanonicalName());
+ TestUtils.setupTestConfigurationUsingProperties(bootProps, null);
+ try {
+ SqoopConfiguration.getInstance().initialize();
+ } catch (Exception ex) {
+ Assert.assertTrue(ex instanceof SqoopException);
+ Assert.assertSame(((SqoopException) ex).getErrorCode(),
+ CoreError.CORE_0005);
+ success = true;
+ }
+
+ Assert.assertTrue(success);
+ }
+
+ @Test
+ public void testPropertiesConfigProviderNoFile() throws Exception {
+ boolean success = false;
+ Properties bootProps = new Properties();
+ bootProps.setProperty(ConfigurationConstants.BOOTCFG_CONFIG_PROVIDER,
+ PropertiesConfigurationProvider.class.getCanonicalName());
+ TestUtils.setupTestConfigurationUsingProperties(bootProps, null);
+ try {
+ SqoopConfiguration.getInstance().initialize();
+ } catch (Exception ex) {
+ Assert.assertTrue(ex instanceof SqoopException);
+ Assert.assertSame(((SqoopException) ex).getErrorCode(),
+ CoreError.CORE_0006);
+ success = true;
+ }
+
+ Assert.assertTrue(success);
+ }
+
+ @Test
+ public void testSystemNotInitialized() throws Exception {
+ boolean success = false;
+ try {
+ SqoopConfiguration.getInstance().getContext();
+ } catch (Exception ex) {
+ Assert.assertTrue(ex instanceof SqoopException);
+ Assert.assertSame(((SqoopException) ex).getErrorCode(),
+ CoreError.CORE_0007);
+ success = true;
+ }
+
+ Assert.assertTrue(success);
+ }
+
+ @Test
+ public void testConfigurationInitSuccess() throws Exception {
+ TestUtils.setupTestConfigurationWithExtraConfig(null, null);
+ SqoopConfiguration.getInstance().initialize();
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/test/java/org/apache/sqoop/core/TestUtils.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/sqoop/core/TestUtils.java b/core/src/test/java/org/apache/sqoop/core/TestUtils.java
index 5b230ba..65f07ff 100644
--- a/core/src/test/java/org/apache/sqoop/core/TestUtils.java
+++ b/core/src/test/java/org/apache/sqoop/core/TestUtils.java
@@ -17,13 +17,11 @@
*/
package org.apache.sqoop.core;
-import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.Properties;
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/test/java/org/apache/sqoop/driver/TestDriverConfigUpgrader.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/sqoop/driver/TestDriverConfigUpgrader.java b/core/src/test/java/org/apache/sqoop/driver/TestDriverConfigUpgrader.java
new file mode 100644
index 0000000..9c39d23
--- /dev/null
+++ b/core/src/test/java/org/apache/sqoop/driver/TestDriverConfigUpgrader.java
@@ -0,0 +1,171 @@
+/*
+ * 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.driver;
+
+import org.apache.sqoop.driver.DriverConfigUpgrader;
+import org.apache.sqoop.model.*;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+/**
+ */
+public class TestDriverConfigUpgrader {
+
+ DriverConfigUpgrader upgrader;
+
+ @Before
+ public void initializeUpgrader() {
+ upgrader = new DriverConfigUpgrader();
+ }
+
+ /**
+ * We take the same forms on input and output and we
+ * expect that all values will be correctly transferred.
+ */
+ @Test
+ public void testConnectionUpgrade() {
+ MConnectionForms original = connection1();
+ MConnectionForms target = connection1();
+
+ original.getStringInput("f1.s1").setValue("A");
+ original.getStringInput("f1.s2").setValue("B");
+ original.getIntegerInput("f1.i").setValue(3);
+
+ upgrader.upgrade(original, target);
+
+ assertEquals("A", target.getStringInput("f1.s1").getValue());
+ assertEquals("B", target.getStringInput("f1.s2").getValue());
+ assertEquals(3, (long)target.getIntegerInput("f1.i").getValue());
+ }
+
+ /**
+ * We take the same forms on input and output and we
+ * expect that all values will be correctly transferred.
+ */
+ @Test
+ public void testJobUpgrade() {
+ MJobForms original = job1();
+ MJobForms target = job1();
+
+ original.getStringInput("f1.s1").setValue("A");
+ original.getStringInput("f1.s2").setValue("B");
+ original.getIntegerInput("f1.i").setValue(3);
+
+ upgrader.upgrade(original, target);
+
+ assertEquals("A", target.getStringInput("f1.s1").getValue());
+ assertEquals("B", target.getStringInput("f1.s2").getValue());
+ assertEquals(3, (long)target.getIntegerInput("f1.i").getValue());
+ }
+
+ /**
+ * Upgrade scenario when new input has been added to the target forms.
+ */
+ @Test
+ public void testNonExistingInput() {
+ MConnectionForms original = connection1();
+ MConnectionForms target = connection2();
+
+ original.getStringInput("f1.s1").setValue("A");
+ original.getStringInput("f1.s2").setValue("B");
+ original.getIntegerInput("f1.i").setValue(3);
+
+ upgrader.upgrade(original, target);
+
+ assertEquals("A", target.getStringInput("f1.s1").getValue());
+ assertNull(target.getStringInput("f1.s2_").getValue());
+ assertEquals(3, (long)target.getIntegerInput("f1.i").getValue());
+ }
+
+ /**
+ * Upgrade scenario when entire has been added in the target and
+ * therefore is missing in the original.
+ */
+ @Test
+ public void testNonExistingForm() {
+ MConnectionForms original = connection1();
+ MConnectionForms target = connection3();
+
+ original.getStringInput("f1.s1").setValue("A");
+ original.getStringInput("f1.s2").setValue("B");
+ original.getIntegerInput("f1.i").setValue(3);
+
+ upgrader.upgrade(original, target);
+
+ assertNull(target.getStringInput("f2.s1").getValue());
+ assertNull(target.getStringInput("f2.s2").getValue());
+ assertNull(target.getIntegerInput("f2.i").getValue());
+ }
+
+ MJobForms job1() {
+ return new MJobForms(forms1());
+ }
+
+ MConnectionForms connection1() {
+ return new MConnectionForms(forms1());
+ }
+
+ MConnectionForms connection2() {
+ return new MConnectionForms(forms2());
+ }
+
+ MConnectionForms connection3() {
+ return new MConnectionForms(forms3());
+ }
+
+ List<MForm> forms1() {
+ List<MForm> list = new LinkedList<MForm>();
+ list.add(new MForm("f1", inputs1("f1")));
+ return list;
+ }
+
+ List<MInput<?>> inputs1(String formName) {
+ List<MInput<?>> list = new LinkedList<MInput<?>>();
+ list.add(new MStringInput(formName + ".s1", false, (short)30));
+ list.add(new MStringInput(formName + ".s2", false, (short)30));
+ list.add(new MIntegerInput(formName + ".i", false));
+ return list;
+ }
+
+ List<MForm> forms2() {
+ List<MForm> list = new LinkedList<MForm>();
+ list.add(new MForm("f1", inputs2("f1")));
+ return list;
+ }
+
+ List<MInput<?>> inputs2(String formName) {
+ List<MInput<?>> list = new LinkedList<MInput<?>>();
+ list.add(new MStringInput(formName + ".s1", false, (short)30));
+ list.add(new MStringInput(formName + ".s2_", false, (short)30));
+ list.add(new MIntegerInput(formName + ".i", false));
+ return list;
+ }
+
+ List<MForm> forms3() {
+ List<MForm> list = new LinkedList<MForm>();
+ list.add(new MForm("f2", inputs1("f2")));
+ return list;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/test/java/org/apache/sqoop/driver/TestJobManager.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/sqoop/driver/TestJobManager.java b/core/src/test/java/org/apache/sqoop/driver/TestJobManager.java
new file mode 100644
index 0000000..80f45e5
--- /dev/null
+++ b/core/src/test/java/org/apache/sqoop/driver/TestJobManager.java
@@ -0,0 +1,190 @@
+/**
+ * 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.driver;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.sqoop.common.Direction;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.connector.ConnectorManager;
+import org.apache.sqoop.connector.spi.SqoopConnector;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MLink;
+import org.apache.sqoop.model.MSubmission;
+import org.apache.sqoop.repository.JdbcRepository;
+import org.apache.sqoop.repository.Repository;
+import org.apache.sqoop.repository.RepositoryManager;
+import org.apache.sqoop.request.HttpEventContext;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestJobManager {
+ private JobManager jobManager;
+ private SqoopConnector sqoopConnectorMock;
+ private ConnectorManager connectorMgrMock;
+ private RepositoryManager repositoryManagerMock;
+ private Repository jdbcRepoMock;
+
+ @Before
+ public void setUp() {
+ jobManager = new JobManager();
+ connectorMgrMock = mock(ConnectorManager.class);
+ sqoopConnectorMock = mock(SqoopConnector.class);
+ ConnectorManager.setInstance(connectorMgrMock);
+ repositoryManagerMock = mock(RepositoryManager.class);
+ RepositoryManager.setInstance(repositoryManagerMock);
+ jdbcRepoMock = mock(JdbcRepository.class);
+ }
+
+ @Test
+ public void testCreateJobSubmission() {
+
+ HttpEventContext testCtx = new HttpEventContext();
+ testCtx.setUsername("testUser");
+ MSubmission jobSubmission = jobManager.createJobSubmission(testCtx, 1234L);
+ assertEquals(jobSubmission.getCreationUser(), "testUser");
+ assertEquals(jobSubmission.getLastUpdateUser(), "testUser");
+ }
+
+ @Test
+ public void testGetConnector() {
+ when(connectorMgrMock.getConnector(123l)).thenReturn(sqoopConnectorMock);
+ when(sqoopConnectorMock.getSupportedDirections()).thenReturn(getSupportedDirections());
+ assertEquals(jobManager.getConnector(123l), sqoopConnectorMock);
+ verify(connectorMgrMock, times(1)).getConnector(123l);
+ }
+
+ @Test
+ public void testUnsupportedDirectionForConnector() {
+ // invalid job id/ direction
+ SqoopException exception = new SqoopException(DriverError.DRIVER_0011, "Connector: "
+ + sqoopConnectorMock.getClass().getCanonicalName());
+ List<Direction> supportedDirections = getSupportedDirections();
+ when(sqoopConnectorMock.getSupportedDirections()).thenReturn(supportedDirections);
+
+ try {
+ // invalid direction
+ jobManager.validateSupportedDirection(sqoopConnectorMock, null);
+ } catch (SqoopException ex) {
+ assertEquals(ex.getMessage(), exception.getMessage());
+ verify(sqoopConnectorMock, times(1)).getSupportedDirections();
+ return;
+ }
+
+ fail("Should throw out an exception with message: " + exception.getMessage());
+ }
+
+ @Test
+ public void testGetLink() {
+ MLink testLink = new MLink(123l, null, null);
+ testLink.setEnabled(true);
+ MLink mConnectionSpy = org.mockito.Mockito.spy(testLink);
+ when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock);
+ when(jdbcRepoMock.findLink(123l)).thenReturn(mConnectionSpy);
+ assertEquals(jobManager.getLink(123l), mConnectionSpy);
+ verify(repositoryManagerMock, times(1)).getRepository();
+ verify(jdbcRepoMock, times(1)).findLink(123l);
+ }
+
+ @Test
+ public void testDisabledLink() {
+ MLink testConnection = new MLink(123l, null, null);
+ testConnection.setPersistenceId(1234);
+ testConnection.setEnabled(false);
+ SqoopException exception = new SqoopException(DriverError.DRIVER_0010, "Connection id: "
+ + testConnection.getPersistenceId());
+
+ MLink mConnectionSpy = org.mockito.Mockito.spy(testConnection);
+ when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock);
+ when(jdbcRepoMock.findLink(123l)).thenReturn(mConnectionSpy);
+ try {
+ jobManager.getLink(123l);
+ } catch (SqoopException ex) {
+ assertEquals(ex.getMessage(), exception.getMessage());
+ verify(repositoryManagerMock, times(1)).getRepository();
+ verify(jdbcRepoMock, times(1)).findLink(123l);
+ }
+ }
+
+ @Test
+ public void testGetJob() {
+ MJob testJob = job(123l, 456l);
+ testJob.setEnabled(true);
+ MJob mJobSpy = org.mockito.Mockito.spy(testJob);
+ when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock);
+ when(jdbcRepoMock.findJob(123l)).thenReturn(mJobSpy);
+ assertEquals(jobManager.getJob(123l), mJobSpy);
+ verify(repositoryManagerMock, times(1)).getRepository();
+ verify(jdbcRepoMock, times(1)).findJob(123l);
+ }
+
+ @Test
+ public void testDisabledJob() {
+ MJob testJob = job(123l, 456l);
+ testJob.setEnabled(false);
+ testJob.setPersistenceId(1111);
+ SqoopException exception = new SqoopException(DriverError.DRIVER_0009, "Job id: "
+ + testJob.getPersistenceId());
+
+ MJob mJobSpy = org.mockito.Mockito.spy(testJob);
+ when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock);
+ when(jdbcRepoMock.findJob(123l)).thenReturn(mJobSpy);
+ try {
+ jobManager.getJob(123l);
+ } catch (SqoopException ex) {
+ assertEquals(ex.getMessage(), exception.getMessage());
+ verify(repositoryManagerMock, times(1)).getRepository();
+ verify(jdbcRepoMock, times(1)).findJob(123l);
+ }
+ }
+
+ @Test
+ public void testUnknownJob() {
+ long testJobId = 555l;
+ SqoopException exception = new SqoopException(DriverError.DRIVER_0004, "Unknown job id: "
+ + testJobId);
+ when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock);
+ when(jdbcRepoMock.findJob(testJobId)).thenReturn(null);
+ try {
+ jobManager.getJob(testJobId);
+ } catch (SqoopException ex) {
+ assertEquals(ex.getMessage(), exception.getMessage());
+ verify(repositoryManagerMock, times(1)).getRepository();
+ verify(jdbcRepoMock, times(1)).findJob(testJobId);
+ }
+ }
+
+ private MJob job(long fromId, long toId) {
+ MJob job = new MJob(fromId, toId, 1L, 2L, null, null, null);
+ job.setName("Vampire");
+ job.setCreationUser("Buffy");
+ return job;
+ }
+
+ public List<Direction> getSupportedDirections() {
+ return Arrays.asList(new Direction[] { Direction.FROM, Direction.TO });
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/test/java/org/apache/sqoop/driver/TestJobRequest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/sqoop/driver/TestJobRequest.java b/core/src/test/java/org/apache/sqoop/driver/TestJobRequest.java
new file mode 100644
index 0000000..768c978
--- /dev/null
+++ b/core/src/test/java/org/apache/sqoop/driver/TestJobRequest.java
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.driver;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import org.apache.sqoop.driver.JobRequest;
+import org.apache.sqoop.utils.ClassUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class TestJobRequest {
+
+ private JobRequest jobRequest;
+
+ @Before
+ public void initializeSubmissionRequest() {
+ jobRequest = new JobRequest();
+ }
+
+ @Test
+ public void testAddJar() {
+ jobRequest.addJar("A");
+ jobRequest.addJar("B");
+ jobRequest.addJar("A");
+
+ assertEquals(2, jobRequest.getJars().size());
+ assertEquals("A", jobRequest.getJars().get(0));
+ assertEquals("B", jobRequest.getJars().get(1));
+ }
+
+ @Test
+ public void testAddJarForClass() {
+ jobRequest.addJarForClass(TestJobRequest.class);
+ assertEquals(1, jobRequest.getJars().size());
+ assertTrue(jobRequest.getJars().contains(ClassUtils.jarForClass(TestJobRequest.class)));
+ }
+
+ @Test
+ public void testAddJars() {
+ jobRequest.addJars(Arrays.asList("A", "B"));
+ jobRequest.addJars(Arrays.asList("B", "C"));
+
+ assertEquals(3, jobRequest.getJars().size());
+ assertEquals("A", jobRequest.getJars().get(0));
+ assertEquals("B", jobRequest.getJars().get(1));
+ assertEquals("C", jobRequest.getJars().get(2));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/test/java/org/apache/sqoop/framework/TestFrameworkMetadataUpgrader.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/sqoop/framework/TestFrameworkMetadataUpgrader.java b/core/src/test/java/org/apache/sqoop/framework/TestFrameworkMetadataUpgrader.java
deleted file mode 100644
index 81d197e..0000000
--- a/core/src/test/java/org/apache/sqoop/framework/TestFrameworkMetadataUpgrader.java
+++ /dev/null
@@ -1,170 +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.framework;
-
-import org.apache.sqoop.model.*;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-/**
- */
-public class TestFrameworkMetadataUpgrader {
-
- FrameworkMetadataUpgrader upgrader;
-
- @Before
- public void initializeUpgrader() {
- upgrader = new FrameworkMetadataUpgrader();
- }
-
- /**
- * We take the same forms on input and output and we
- * expect that all values will be correctly transferred.
- */
- @Test
- public void testConnectionUpgrade() {
- MConnectionForms original = connection1();
- MConnectionForms target = connection1();
-
- original.getStringInput("f1.s1").setValue("A");
- original.getStringInput("f1.s2").setValue("B");
- original.getIntegerInput("f1.i").setValue(3);
-
- upgrader.upgrade(original, target);
-
- assertEquals("A", target.getStringInput("f1.s1").getValue());
- assertEquals("B", target.getStringInput("f1.s2").getValue());
- assertEquals(3, (long)target.getIntegerInput("f1.i").getValue());
- }
-
- /**
- * We take the same forms on input and output and we
- * expect that all values will be correctly transferred.
- */
- @Test
- public void testJobUpgrade() {
- MJobForms original = job1();
- MJobForms target = job1();
-
- original.getStringInput("f1.s1").setValue("A");
- original.getStringInput("f1.s2").setValue("B");
- original.getIntegerInput("f1.i").setValue(3);
-
- upgrader.upgrade(original, target);
-
- assertEquals("A", target.getStringInput("f1.s1").getValue());
- assertEquals("B", target.getStringInput("f1.s2").getValue());
- assertEquals(3, (long)target.getIntegerInput("f1.i").getValue());
- }
-
- /**
- * Upgrade scenario when new input has been added to the target forms.
- */
- @Test
- public void testNonExistingInput() {
- MConnectionForms original = connection1();
- MConnectionForms target = connection2();
-
- original.getStringInput("f1.s1").setValue("A");
- original.getStringInput("f1.s2").setValue("B");
- original.getIntegerInput("f1.i").setValue(3);
-
- upgrader.upgrade(original, target);
-
- assertEquals("A", target.getStringInput("f1.s1").getValue());
- assertNull(target.getStringInput("f1.s2_").getValue());
- assertEquals(3, (long)target.getIntegerInput("f1.i").getValue());
- }
-
- /**
- * Upgrade scenario when entire has been added in the target and
- * therefore is missing in the original.
- */
- @Test
- public void testNonExistingForm() {
- MConnectionForms original = connection1();
- MConnectionForms target = connection3();
-
- original.getStringInput("f1.s1").setValue("A");
- original.getStringInput("f1.s2").setValue("B");
- original.getIntegerInput("f1.i").setValue(3);
-
- upgrader.upgrade(original, target);
-
- assertNull(target.getStringInput("f2.s1").getValue());
- assertNull(target.getStringInput("f2.s2").getValue());
- assertNull(target.getIntegerInput("f2.i").getValue());
- }
-
- MJobForms job1() {
- return new MJobForms(forms1());
- }
-
- MConnectionForms connection1() {
- return new MConnectionForms(forms1());
- }
-
- MConnectionForms connection2() {
- return new MConnectionForms(forms2());
- }
-
- MConnectionForms connection3() {
- return new MConnectionForms(forms3());
- }
-
- List<MForm> forms1() {
- List<MForm> list = new LinkedList<MForm>();
- list.add(new MForm("f1", inputs1("f1")));
- return list;
- }
-
- List<MInput<?>> inputs1(String formName) {
- List<MInput<?>> list = new LinkedList<MInput<?>>();
- list.add(new MStringInput(formName + ".s1", false, (short)30));
- list.add(new MStringInput(formName + ".s2", false, (short)30));
- list.add(new MIntegerInput(formName + ".i", false));
- return list;
- }
-
- List<MForm> forms2() {
- List<MForm> list = new LinkedList<MForm>();
- list.add(new MForm("f1", inputs2("f1")));
- return list;
- }
-
- List<MInput<?>> inputs2(String formName) {
- List<MInput<?>> list = new LinkedList<MInput<?>>();
- list.add(new MStringInput(formName + ".s1", false, (short)30));
- list.add(new MStringInput(formName + ".s2_", false, (short)30));
- list.add(new MIntegerInput(formName + ".i", false));
- return list;
- }
-
- List<MForm> forms3() {
- List<MForm> list = new LinkedList<MForm>();
- list.add(new MForm("f2", inputs1("f2")));
- return list;
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/test/java/org/apache/sqoop/framework/TestFrameworkValidator.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/sqoop/framework/TestFrameworkValidator.java b/core/src/test/java/org/apache/sqoop/framework/TestFrameworkValidator.java
deleted file mode 100644
index 69dd028..0000000
--- a/core/src/test/java/org/apache/sqoop/framework/TestFrameworkValidator.java
+++ /dev/null
@@ -1,156 +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.framework;
-
-
-/**
- * NOTE(VB): This test class will soon be removed with the Validator refactoring
- */
-public class TestFrameworkValidator {
-
-// FrameworkValidator validator;
-//
-// @Before
-// public void setUp() {
-// validator = new FrameworkValidator();
-// }
-//
-// @Test
-// public void testConnectionValidation() {
-// ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration();
-//
-// Validation validation = validator.validateConnection(connectionConfiguration);
-// assertEquals(Status.FINE, validation.getStatus());
-// assertEquals(0, validation.getMessages().size());
-// }
-//
-// @Test
-// public void testExportJobValidation() {
-// ExportJobConfiguration configuration;
-// Validation validation;
-//
-// // Empty form is not allowed
-// configuration = new ExportJobConfiguration();
-// validation = validator.validateJob(MJob.Type.EXPORT, configuration);
-// assertEquals(Status.UNACCEPTABLE, validation.getStatus());
-// assertTrue(validation.getMessages().containsKey(new Validation.FormInput("input.inputDirectory")));
-//
-// // Explicitly setting extractors and loaders
-// configuration = new ExportJobConfiguration();
-// configuration.input.inputDirectory = "/czech/republic";
-// configuration.throttling.extractors = 3;
-// configuration.throttling.loaders = 3;
-//
-// validation = validator.validateJob(MJob.Type.EXPORT, configuration);
-// assertEquals(Status.FINE, validation.getStatus());
-// assertEquals(0, validation.getMessages().size());
-//
-// // Negative and zero values for extractors and loaders
-// configuration = new ExportJobConfiguration();
-// configuration.input.inputDirectory = "/czech/republic";
-// configuration.throttling.extractors = 0;
-// configuration.throttling.loaders = -1;
-//
-// validation = validator.validateJob(MJob.Type.EXPORT, configuration);
-// assertEquals(Status.UNACCEPTABLE, validation.getStatus());
-// assertTrue(validation.getMessages().containsKey(new Validation.FormInput("throttling.extractors")));
-// assertTrue(validation.getMessages().containsKey(new Validation.FormInput("throttling.loaders")));
-// }
-//
-//
-// @Test
-// public void testImportJobValidation() {
-// ImportJobConfiguration configuration;
-// Validation validation;
-//
-// // Empty form is not allowed
-// configuration = new ImportJobConfiguration();
-// validation = validator.validateJob(MJob.Type.IMPORT, configuration);
-// assertEquals(Status.UNACCEPTABLE, validation.getStatus());
-// assertTrue(validation.getMessages().containsKey(new Validation.FormInput("output.outputDirectory")));
-//
-// // Explicitly setting extractors and loaders
-// configuration = new ImportJobConfiguration();
-// configuration.output.outputDirectory = "/czech/republic";
-// configuration.throttling.extractors = 3;
-// configuration.throttling.loaders = 3;
-//
-// validation = validator.validateJob(MJob.Type.IMPORT, configuration);
-// assertEquals(Status.FINE, validation.getStatus());
-// assertEquals(0, validation.getMessages().size());
-//
-// // Negative and zero values for extractors and loaders
-// configuration = new ImportJobConfiguration();
-// configuration.output.outputDirectory = "/czech/republic";
-// configuration.throttling.extractors = 0;
-// configuration.throttling.loaders = -1;
-//
-// validation = validator.validateJob(MJob.Type.IMPORT, configuration);
-// assertEquals(Status.UNACCEPTABLE, validation.getStatus());
-// assertTrue(validation.getMessages().containsKey(new Validation.FormInput("throttling.extractors")));
-// assertTrue(validation.getMessages().containsKey(new Validation.FormInput("throttling.loaders")));
-//
-// // specifying both compression as well as customCompression is
-// // unacceptable
-// configuration = new ImportJobConfiguration();
-// configuration.output.outputDirectory = "/czech/republic";
-// configuration.throttling.extractors = 2;
-// configuration.throttling.loaders = 2;
-// configuration.output.compression = OutputCompression.BZIP2;
-// configuration.output.customCompression = "some.compression.codec";
-//
-// validation = validator.validateJob(MJob.Type.IMPORT, configuration);
-// assertEquals(Status.UNACCEPTABLE, validation.getStatus());
-// assertTrue(validation.getMessages().containsKey(new Validation.FormInput("output.compression")));
-//
-// // specifying a customCompression is fine
-// configuration = new ImportJobConfiguration();
-// configuration.output.outputDirectory = "/czech/republic";
-// configuration.throttling.extractors = 2;
-// configuration.throttling.loaders = 2;
-// configuration.output.compression = OutputCompression.CUSTOM;
-// configuration.output.customCompression = "some.compression.codec";
-//
-// validation = validator.validateJob(MJob.Type.IMPORT, configuration);
-// assertEquals(Status.FINE, validation.getStatus());
-//
-// // specifying a customCompression without codec name is unacceptable
-// configuration = new ImportJobConfiguration();
-// configuration.output.outputDirectory = "/czech/republic";
-// configuration.throttling.extractors = 2;
-// configuration.throttling.loaders = 2;
-// configuration.output.compression = OutputCompression.CUSTOM;
-// configuration.output.customCompression = "";
-//
-// validation = validator.validateJob(MJob.Type.IMPORT, configuration);
-// assertEquals(Status.UNACCEPTABLE, validation.getStatus());
-// assertTrue(validation.getMessages().containsKey(new Validation.FormInput("output.compression")));
-//
-// configuration = new ImportJobConfiguration();
-// configuration.output.outputDirectory = "/czech/republic";
-// configuration.throttling.extractors = 2;
-// configuration.throttling.loaders = 2;
-// configuration.output.compression = OutputCompression.CUSTOM;
-// configuration.output.customCompression = null;
-//
-// validation = validator.validateJob(MJob.Type.IMPORT, configuration);
-// assertEquals(Status.UNACCEPTABLE, validation.getStatus());
-// assertTrue(validation.getMessages().containsKey(new Validation.FormInput("output.compression")));
-//
-// }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/test/java/org/apache/sqoop/framework/TestJobManager.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/sqoop/framework/TestJobManager.java b/core/src/test/java/org/apache/sqoop/framework/TestJobManager.java
deleted file mode 100644
index 2732b1c..0000000
--- a/core/src/test/java/org/apache/sqoop/framework/TestJobManager.java
+++ /dev/null
@@ -1,173 +0,0 @@
-package org.apache.sqoop.framework;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.sqoop.common.Direction;
-import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.connector.ConnectorManager;
-import org.apache.sqoop.connector.spi.SqoopConnector;
-import org.apache.sqoop.model.MConnection;
-import org.apache.sqoop.model.MJob;
-import org.apache.sqoop.model.MSubmission;
-import org.apache.sqoop.repository.JdbcRepository;
-import org.apache.sqoop.repository.Repository;
-import org.apache.sqoop.repository.RepositoryManager;
-import org.apache.sqoop.request.HttpEventContext;
-import org.junit.Before;
-import org.junit.Test;
-
-public class TestJobManager {
- private JobManager jobManager;
- private SqoopConnector sqoopConnectorMock;
- private ConnectorManager connectorMgrMock;
- private RepositoryManager repositoryManagerMock;
- private Repository jdbcRepoMock;
-
- @Before
- public void setUp() {
- jobManager = new JobManager();
- connectorMgrMock = mock(ConnectorManager.class);
- sqoopConnectorMock = mock(SqoopConnector.class);
- ConnectorManager.setInstance(connectorMgrMock);
- repositoryManagerMock = mock(RepositoryManager.class);
- RepositoryManager.setInstance(repositoryManagerMock);
- jdbcRepoMock = mock(JdbcRepository.class);
- }
-
- @Test
- public void testCreateJobSubmission() {
-
- HttpEventContext testCtx = new HttpEventContext();
- testCtx.setUsername("testUser");
- MSubmission jobSubmission = jobManager.createJobSubmission(testCtx, 1234L);
- assertEquals(jobSubmission.getCreationUser(), "testUser");
- assertEquals(jobSubmission.getLastUpdateUser(), "testUser");
- }
-
- @Test
- public void testGetConnector() {
- when(connectorMgrMock.getConnector(123l)).thenReturn(sqoopConnectorMock);
- when(sqoopConnectorMock.getSupportedDirections()).thenReturn(getSupportedDirections());
- assertEquals(jobManager.getConnector(123l), sqoopConnectorMock);
- verify(connectorMgrMock, times(1)).getConnector(123l);
- }
-
- @Test
- public void testUnsupportedDirectionForConnector() {
- // invalid job id/ direction
- SqoopException exception = new SqoopException(FrameworkError.FRAMEWORK_0011, "Connector: "
- + sqoopConnectorMock.getClass().getCanonicalName());
- List<Direction> supportedDirections = getSupportedDirections();
- when(sqoopConnectorMock.getSupportedDirections()).thenReturn(supportedDirections);
-
- try {
- // invalid direction
- jobManager.validateSupportedDirection(sqoopConnectorMock, null);
- } catch (SqoopException ex) {
- assertEquals(ex.getMessage(), exception.getMessage());
- verify(sqoopConnectorMock, times(1)).getSupportedDirections();
- return;
- }
-
- fail("Should throw out an exception with message: " + exception.getMessage());
- }
-
- @Test
- public void testGetConnection() {
- MConnection testConnection = new MConnection(123l, null, null);
- testConnection.setEnabled(true);
- MConnection mConnectionSpy = org.mockito.Mockito.spy(testConnection);
- when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock);
- when(jdbcRepoMock.findConnection(123l)).thenReturn(mConnectionSpy);
- assertEquals(jobManager.getConnection(123l), mConnectionSpy);
- verify(repositoryManagerMock, times(1)).getRepository();
- verify(jdbcRepoMock, times(1)).findConnection(123l);
- }
-
- @Test
- public void testDisabledConnection() {
- MConnection testConnection = new MConnection(123l, null, null);
- testConnection.setPersistenceId(1234);
- testConnection.setEnabled(false);
- SqoopException exception = new SqoopException(FrameworkError.FRAMEWORK_0010, "Connection id: "
- + testConnection.getPersistenceId());
-
- MConnection mConnectionSpy = org.mockito.Mockito.spy(testConnection);
- when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock);
- when(jdbcRepoMock.findConnection(123l)).thenReturn(mConnectionSpy);
- try {
- jobManager.getConnection(123l);
- } catch (SqoopException ex) {
- assertEquals(ex.getMessage(), exception.getMessage());
- verify(repositoryManagerMock, times(1)).getRepository();
- verify(jdbcRepoMock, times(1)).findConnection(123l);
- }
- }
-
- @Test
- public void testGetJob() {
- MJob testJob = job(123l, 456l);
- testJob.setEnabled(true);
- MJob mJobSpy = org.mockito.Mockito.spy(testJob);
- when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock);
- when(jdbcRepoMock.findJob(123l)).thenReturn(mJobSpy);
- assertEquals(jobManager.getJob(123l), mJobSpy);
- verify(repositoryManagerMock, times(1)).getRepository();
- verify(jdbcRepoMock, times(1)).findJob(123l);
- }
-
- @Test
- public void testDisabledJob() {
- MJob testJob = job(123l, 456l);
- testJob.setEnabled(false);
- testJob.setPersistenceId(1111);
- SqoopException exception = new SqoopException(FrameworkError.FRAMEWORK_0009, "Job id: "
- + testJob.getPersistenceId());
-
- MJob mJobSpy = org.mockito.Mockito.spy(testJob);
- when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock);
- when(jdbcRepoMock.findJob(123l)).thenReturn(mJobSpy);
- try {
- jobManager.getJob(123l);
- } catch (SqoopException ex) {
- assertEquals(ex.getMessage(), exception.getMessage());
- verify(repositoryManagerMock, times(1)).getRepository();
- verify(jdbcRepoMock, times(1)).findJob(123l);
- }
- }
-
- @Test
- public void testUnknownJob() {
- long testJobId = 555l;
- SqoopException exception = new SqoopException(FrameworkError.FRAMEWORK_0004, "Unknown job id: "
- + testJobId);
- when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock);
- when(jdbcRepoMock.findJob(testJobId)).thenReturn(null);
- try {
- jobManager.getJob(testJobId);
- } catch (SqoopException ex) {
- assertEquals(ex.getMessage(), exception.getMessage());
- verify(repositoryManagerMock, times(1)).getRepository();
- verify(jdbcRepoMock, times(1)).findJob(testJobId);
- }
- }
-
- private MJob job(long fromId, long toId) {
- MJob job = new MJob(fromId, toId, 1L, 2L, null, null, null);
- job.setName("Vampire");
- job.setCreationUser("Buffy");
- return job;
- }
-
- public List<Direction> getSupportedDirections() {
- return Arrays.asList(new Direction[] { Direction.FROM, Direction.TO });
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/049994a0/core/src/test/java/org/apache/sqoop/framework/TestJobRequest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/sqoop/framework/TestJobRequest.java b/core/src/test/java/org/apache/sqoop/framework/TestJobRequest.java
deleted file mode 100644
index 6ca1c6a..0000000
--- a/core/src/test/java/org/apache/sqoop/framework/TestJobRequest.java
+++ /dev/null
@@ -1,71 +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.framework;
-
-import org.apache.sqoop.utils.ClassUtils;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Arrays;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- *
- */
-public class TestJobRequest {
-
- private JobRequest jobRequest;
-
- @Before
- public void initializeSubmissionRequest() {
- jobRequest = new JobRequest();
- }
-
- @Test
- public void testAddJar() {
- jobRequest.addJar("A");
- jobRequest.addJar("B");
- jobRequest.addJar("A");
-
- assertEquals(2, jobRequest.getJars().size());
- assertEquals("A", jobRequest.getJars().get(0));
- assertEquals("B", jobRequest.getJars().get(1));
- }
-
- @Test
- public void testAddJarForClass() {
- jobRequest.addJarForClass(TestJobRequest.class);
- jobRequest.addJarForClass(TestFrameworkValidator.class);
-
- assertEquals(1, jobRequest.getJars().size());
- assertTrue(jobRequest.getJars().contains(ClassUtils.jarForClass(TestJobRequest.class)));
- }
-
- @Test
- public void testAddJars() {
- jobRequest.addJars(Arrays.asList("A", "B"));
- jobRequest.addJars(Arrays.asList("B", "C"));
-
- assertEquals(3, jobRequest.getJars().size());
- assertEquals("A", jobRequest.getJars().get(0));
- assertEquals("B", jobRequest.getJars().get(1));
- assertEquals("C", jobRequest.getJars().get(2));
- }
-}