5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-08 06:01:55 +08:00

SQOOP-2539: Sqoop2: Enforce resource name not null when creating table

(Dian Fu via Jarek Jarcec Cecho)
This commit is contained in:
Jarek Jarcec Cecho 2015-09-08 12:48:01 +02:00
parent a13343b345
commit 933839f0f7
14 changed files with 419 additions and 5 deletions

View File

@ -27,6 +27,8 @@ public class CommonRepoUtils {
public static final String QUOTE_CHARACTER = "\"";
public static final String SINGLE_QUOTO_CHARACTER = "\'";
public static final String escapeTableName(String tableName) {
return QUOTE_CHARACTER + tableName + QUOTE_CHARACTER;
}
@ -47,6 +49,10 @@ public static final String escapeConstraintName(String constraintName) {
return QUOTE_CHARACTER + constraintName + QUOTE_CHARACTER;
}
public static final String escapeLiteralString(String literalString) {
return SINGLE_QUOTO_CHARACTER + literalString + SINGLE_QUOTO_CHARACTER;
}
public static final String getTableName(String schemaName, String tableName) {
if (schemaName != null) {
return escapeSchemaName(schemaName) + "." + escapeTableName(tableName);

View File

@ -312,6 +312,12 @@ public void createOrUpgradeRepository(Connection conn) {
runQuery(QUERY_CREATE_TABLE_SQ_CONTEXT_TYPE, conn);
runQuery(QUERY_CREATE_TABLE_SQ_CONTEXT_PROPERTY, conn);
runQuery(QUERY_CREATE_TABLE_SQ_CONTEXT, conn);
runQuery(QUERY_UPGRADE_TABLE_SQ_LINK_UPDATE_COLUMN_SQ_LINK_NAME, conn);
runQuery(QUERY_UPGRADE_TABLE_SQ_LINK_ALTER_COLUMN_SQ_LINK_NAME_NOT_NULL, conn);
runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_COLUMN_SQB_NAME, conn);
runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ALTER_COLUMN_SQB_NAME_NOT_NULL, conn);
runQuery(QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ALTER_COLUMN_SQB_NAME_NOT_NULL, conn);
}
// last step upgrade the repository version to the latest value in the code

View File

@ -633,6 +633,35 @@ public static final String getDropConstraintQuery(String schemaName, String tabl
+ QUERY_SELECT_DIRECTION_CONFIG_BY_DIRECTION_NAME
+ ")";
public static final String QUERY_UPGRADE_TABLE_SQ_LINK_UPDATE_COLUMN_SQ_LINK_NAME =
"UPDATE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_LINK_NAME)
+ " SET " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME)
+ " = " + CommonRepoUtils.escapeLiteralString("link_") + " || "
+ "TRIM(CHAR(" + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_ID) + "))"
+ " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME) + " IS NULL";
public static final String QUERY_UPGRADE_TABLE_SQ_LINK_ALTER_COLUMN_SQ_LINK_NAME_NOT_NULL =
"ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_LINK_NAME)
+ " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME)
+ " NOT NULL";
public static final String QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_COLUMN_SQB_NAME =
"UPDATE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_JOB_NAME)
+ " SET " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME)
+ " = " + CommonRepoUtils.escapeLiteralString("job_") + " || "
+ "TRIM(CHAR(" + CommonRepoUtils.escapeColumnName(COLUMN_SQB_ID) + "))"
+ " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME) + " IS NULL";
public static final String QUERY_UPGRADE_TABLE_SQ_JOB_ALTER_COLUMN_SQB_NAME_NOT_NULL =
"ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_JOB_NAME)
+ " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME)
+ " NOT NULL";
public static final String QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ALTER_COLUMN_SQB_NAME_NOT_NULL =
"ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_CONFIGURABLE_NAME)
+ " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQC_NAME)
+ " NOT NULL";
private DerbySchemaUpgradeQuery() {
// Disable explicit object creation
}

View File

@ -42,7 +42,7 @@ public class MySqlSchemaCreateQuery {
public static final String QUERY_CREATE_TABLE_SQ_CONFIGURABLE =
"CREATE TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, CommonRepositorySchemaConstants.TABLE_SQ_CONFIGURABLE_NAME) + " ("
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_ID) + " BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_NAME) + " VARCHAR(64),"
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_NAME) + " VARCHAR(64) NOT NULL,"
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_TYPE) + " VARCHAR(32), "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_CLASS) + " VARCHAR(255), "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_VERSION) + " VARCHAR(64), "
@ -135,7 +135,7 @@ public class MySqlSchemaCreateQuery {
"CREATE TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, CommonRepositorySchemaConstants.TABLE_SQ_LINK_NAME) + " ("
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_ID) + " BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_CONFIGURABLE) + " BIGINT, "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_NAME) + " VARCHAR(32), "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_NAME) + " VARCHAR(32) NOT NULL, "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_CREATION_DATE) + " TIMESTAMP, "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_CREATION_USER) + " VARCHAR(32) DEFAULT NULL, "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_UPDATE_DATE) + " TIMESTAMP, "
@ -154,7 +154,7 @@ public class MySqlSchemaCreateQuery {
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_ID) + " BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_FROM_LINK) + " BIGINT, "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_TO_LINK) + " BIGINT, "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_NAME) + " VARCHAR(64), "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_NAME) + " VARCHAR(64) NOT NULL, "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_CREATION_DATE) + " TIMESTAMP, "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_CREATION_USER) + " VARCHAR(32) DEFAULT NULL, "
+ CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_UPDATE_DATE) + " TIMESTAMP, "

View File

@ -139,6 +139,12 @@ public void createOrUpgradeRepository(Connection conn) {
runQuery(PostgresqlSchemaCreateQuery.QUERY_CREATE_TABLE_SQ_CONTEXT_TYPE, conn);
runQuery(PostgresqlSchemaCreateQuery.QUERY_CREATE_TABLE_SQ_CONTEXT_PROPERTY, conn);
runQuery(PostgresqlSchemaCreateQuery.QUERY_CREATE_TABLE_SQ_CONTEXT, conn);
runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_LINK_UPDATE_COLUMN_SQ_LINK_NAME, conn);
runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_LINK_ALTER_COLUMN_SQ_LINK_NAME_NOT_NULL, conn);
runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_COLUMN_SQB_NAME, conn);
runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_JOB_ALTER_COLUMN_SQB_NAME_NOT_NULL, conn);
runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ALTER_COLUMN_SQB_NAME_NOT_NULL, conn);
}
try (PreparedStatement stmtDel = conn.prepareStatement(PostgresqlSchemaQuery.STMT_DELETE_SYSTEM);

View File

@ -0,0 +1,61 @@
/**
* 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.repository.postgresql;
import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQB_ID;
import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQC_NAME;
import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQ_LNK_ID;
import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQ_LNK_NAME;
import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQB_NAME;
import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.SCHEMA_SQOOP;
import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.TABLE_SQ_CONFIGURABLE_NAME;
import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.TABLE_SQ_JOB_NAME;
import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.TABLE_SQ_LINK_NAME;
import org.apache.sqoop.repository.common.CommonRepoUtils;
public class PostgresqlSchemaUpgradeQuery {
public static final String QUERY_UPGRADE_TABLE_SQ_LINK_UPDATE_COLUMN_SQ_LINK_NAME =
"UPDATE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_LINK_NAME)
+ " SET " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME)
+ " = " + CommonRepoUtils.escapeLiteralString("link_") + " || "
+ CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_ID)
+ " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME) + " IS NULL";
public static final String QUERY_UPGRADE_TABLE_SQ_LINK_ALTER_COLUMN_SQ_LINK_NAME_NOT_NULL =
"ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_LINK_NAME)
+ " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME)
+ " SET NOT NULL";
public static final String QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_COLUMN_SQB_NAME =
"UPDATE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_JOB_NAME)
+ " SET " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME)
+ " = " + CommonRepoUtils.escapeLiteralString("job_") + " || "
+ CommonRepoUtils.escapeColumnName(COLUMN_SQB_ID)
+ " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME) + " IS NULL";
public static final String QUERY_UPGRADE_TABLE_SQ_JOB_ALTER_COLUMN_SQB_NAME_NOT_NULL =
"ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_JOB_NAME)
+ " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME)
+ " SET NOT NULL";
public static final String QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ALTER_COLUMN_SQB_NAME_NOT_NULL =
"ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_CONFIGURABLE_NAME)
+ " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQC_NAME)
+ " SET NOT NULL";
}

View File

@ -888,7 +888,13 @@ static String getName(ConsoleReader reader, String name) throws IOException {
nameInput.setValue(name);
}
fillInputStringWithBundle(nameInput, reader, getResourceBundle());
do {
fillInputStringWithBundle(nameInput, reader, getResourceBundle());
if (StringUtils.isEmpty(nameInput.getValue())) {
errorMessage(nameInput, "Job name or link name cannot be null");
continue;
}
} while (false);
return nameInput.getValue();
}

View File

@ -40,6 +40,7 @@
import org.apache.sqoop.test.infrastructure.providers.InfrastructureProvider;
import org.apache.sqoop.test.infrastructure.providers.SqoopInfrastructureProvider;
import org.apache.sqoop.test.utils.HdfsUtils;
import org.apache.sqoop.test.utils.SqoopUtils;
import org.apache.sqoop.validation.Status;
import org.testng.ITest;
import org.testng.ITestContext;
@ -330,6 +331,7 @@ public SqoopClient getClient() {
* @param link
*/
public void saveLink(MLink link) {
SqoopUtils.fillObjectName(link);
assertEquals(Status.OK, getClient().saveLink(link));
assertNotSame(MPersistableEntity.PERSISTANCE_ID_DEFAULT, link.getPersistenceId());
}
@ -340,6 +342,7 @@ public void saveLink(MLink link) {
* @param job
*/
public void saveJob(MJob job) {
SqoopUtils.fillObjectName(job);
assertEquals(Status.OK, getClient().saveJob(job));
assertNotSame(MPersistableEntity.PERSISTANCE_ID_DEFAULT, job.getPersistenceId());
}

View File

@ -36,6 +36,7 @@
import org.apache.sqoop.test.data.Cities;
import org.apache.sqoop.test.data.ShortStories;
import org.apache.sqoop.test.data.UbuntuReleases;
import org.apache.sqoop.test.utils.SqoopUtils;
import org.apache.sqoop.validation.Status;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
@ -253,6 +254,7 @@ protected void assertRowInCities(Object... values) {
* @param link
*/
protected void saveLink(MLink link) {
SqoopUtils.fillObjectName(link);
assertEquals(getClient().saveLink(link), Status.OK);
assertNotSame(link.getPersistenceId(), MPersistableEntity.PERSISTANCE_ID_DEFAULT);
}
@ -265,7 +267,8 @@ protected void saveLink(MLink link) {
* @param job
*/
protected void saveJob(MJob job) {
assertEquals(getClient().saveJob(job), Status.OK);
SqoopUtils.fillObjectName(job);
assertEquals(getClient().saveJob(job), Status.OK);
assertNotSame(job.getPersistenceId(), MPersistableEntity.PERSISTANCE_ID_DEFAULT);
}

View File

@ -0,0 +1,43 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.sqoop.test.utils;
import java.util.Random;
import org.apache.sqoop.model.MAccountableEntity;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MLink;
public class SqoopUtils {
private static final Random rand = new Random();
public static void fillObjectName(MAccountableEntity object) {
String objectName = object.getName();
if (objectName != null && !objectName.isEmpty()) {
return;
}
String prefix = "";
if (object instanceof MLink) {
prefix = "link_";
} else if (object instanceof MJob) {
prefix = "job_";
}
object.setName(prefix + rand.nextLong());
}
}

View File

@ -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.repository.derby.upgrade;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import java.util.HashMap;
import java.util.Map;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MLink;
import org.apache.sqoop.validation.Status;
import org.testng.annotations.Test;
/**
* This version contains the following structures:
* Generic JDBC Connector link with name "Link1" and id 1
* Generic JDBC Connector link with blank name and id 2
* HDFS Connector link with name "Link3" and id 3
* HDFS Connector link with blank name and id 4
* HDFS Connector link with blank name and id 5
* HDFS Connector link with blank name and id 6
* Job (-f 1 -t 3) with name "Import" and id 1
* Job (-f 1 -t 3) with name "Query" and id 2
* Job (-f 3 -t 1) with name "Export" and id 3
* Job (-f 3 -t 1) with blank name and id 4
* Job (-f 3 -t 1) with blank name and id 5
* Job (-f 1 -t 1) with name "SameConnector" and id 6
* Job with id 1 has been executed 3 times
* Job with id 2 has been executed 3 times
* Job with id 3 has been executed 1 times
* Link with id 4 has been disabled
* Link with id 5 has been disabled
* Job with id 4 has been disabled
* Job with id 5 has been disabled
*/
public class Derby1_99_5UpgradeTest extends DerbyRepositoryUpgradeTest {
@Override
public String getPathToRepositoryTarball() {
return "/repository/derby/derby-repository-1.99.5.tar.gz";
}
@Override
public int getNumberOfLinks() {
return 6;
}
@Override
public int getNumberOfJobs() {
return 6;
}
@Override
public Map<Integer, Integer> getNumberOfSubmissions() {
HashMap<Integer, Integer> ret = new HashMap<Integer, Integer>();
ret.put(1, 3);
ret.put(2, 3);
ret.put(3, 1);
ret.put(4, 0);
ret.put(5, 0);
return ret;
}
@Override
public Integer[] getDisabledLinkIds() {
return new Integer[] {4, 5};
}
@Override
public Integer[] getDisabledJobIds() {
return new Integer[] {4, 5};
}
@Override
public Integer[] getDeleteLinkIds() {
return new Integer[] {1, 2, 3, 4, 5, 6};
}
@Override
public Integer[] getDeleteJobIds() {
return new Integer[] {1, 2, 3, 4, 5, 6};
}
@Test
public void testJobNameNotNull() {
assertEquals(getNumberOfJobs(), getClient().getJobs().size());
for(MJob job : getClient().getJobs()) {
assertNotNull(job.getName());
}
MJob job = getClient().createJob(1, 1);
assertNull(job.getName());
assertEquals(getClient().saveJob(job), Status.ERROR);
}
@Test
public void testLinkNameNotNull() {
assertEquals(getNumberOfLinks(), getClient().getLinks().size());
for(MLink link : getClient().getLinks()) {
assertNotNull(link.getName());
}
MLink link = getClient().createLink("generic-jdbc-connector");
assertNull(link.getName());
assertEquals(getClient().saveLink(link), Status.ERROR);
}
}

View File

@ -0,0 +1,126 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.sqoop.integration.repository.derby.upgrade;
import static org.testng.Assert.assertEquals;
import java.util.HashMap;
import java.util.Map;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MLink;
import org.apache.sqoop.validation.Status;
import org.testng.annotations.Test;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
/**
* This version contains the following structures:
* Generic JDBC Connector link with name "Link1" and id 1
* Generic JDBC Connector link with blank name and id 2
* HDFS Connector link with name "Link3" and id 3
* HDFS Connector link with blank name and id 4
* HDFS Connector link with blank name and id 5
* HDFS Connector link with blank name and id 6
* Job (-f 1 -t 3) with name "Import" and id 1
* Job (-f 1 -t 3) with name "Query" and id 2
* Job (-f 3 -t 1) with name "Export" and id 3
* Job (-f 3 -t 1) with blank name and id 4
* Job (-f 3 -t 1) with blank name and id 5
* Job (-f 1 -t 1) with name "SameConnector" and id 6
* Job with id 1 has been executed 3 times
* Job with id 2 has been executed 3 times
* Job with id 3 has been executed 1 times
* Link with id 4 has been disabled
* Link with id 5 has been disabled
* Job with id 4 has been disabled
* Job with id 5 has been disabled
*/
public class Derby1_99_6UpgradeTest extends DerbyRepositoryUpgradeTest {
@Override
public String getPathToRepositoryTarball() {
return "/repository/derby/derby-repository-1.99.6.tar.gz";
}
@Override
public int getNumberOfLinks() {
return 6;
}
@Override
public int getNumberOfJobs() {
return 6;
}
@Override
public Map<Integer, Integer> getNumberOfSubmissions() {
HashMap<Integer, Integer> ret = new HashMap<Integer, Integer>();
ret.put(1, 3);
ret.put(2, 3);
ret.put(3, 1);
ret.put(4, 0);
ret.put(5, 0);
return ret;
}
@Override
public Integer[] getDisabledLinkIds() {
return new Integer[] {4, 5};
}
@Override
public Integer[] getDisabledJobIds() {
return new Integer[] {4, 5};
}
@Override
public Integer[] getDeleteLinkIds() {
return new Integer[] {1, 2, 3, 4, 5, 6};
}
@Override
public Integer[] getDeleteJobIds() {
return new Integer[] {1, 2, 3, 4, 5, 6};
}
@Test
public void testJobNameNotNull() {
assertEquals(getNumberOfJobs(), getClient().getJobs().size());
for(MJob job : getClient().getJobs()) {
assertNotNull(job.getName());
}
MJob job = getClient().createJob(1, 1);
assertNull(job.getName());
assertEquals(getClient().saveJob(job), Status.ERROR);
}
@Test
public void testLinkNameNotNull() {
assertEquals(getNumberOfLinks(), getClient().getLinks().size());
for(MLink link : getClient().getLinks()) {
assertNotNull(link.getName());
}
MLink link = getClient().createLink("generic-jdbc-connector");
assertNull(link.getName());
assertEquals(getClient().saveLink(link), Status.ERROR);
}
}