Github user szvasas commented on a diff in the pull request:

    https://github.com/apache/sqoop/pull/38#discussion_r130082318
  
    --- Diff: src/test/com/cloudera/sqoop/metastore/SavedJobsTest.java ---
    @@ -0,0 +1,379 @@
    +/**
    + * 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 com.cloudera.sqoop.metastore;
    +
    +import java.sql.SQLException;
    +import java.sql.Statement;
    +
    +import java.util.*;
    +
    +import com.cloudera.sqoop.manager.ConnManager;
    +import com.cloudera.sqoop.manager.MySQLTestUtils;
    +import com.cloudera.sqoop.manager.OracleUtils;
    +import org.apache.hadoop.conf.Configuration;
    +
    +import com.cloudera.sqoop.SqoopOptions;
    +import com.cloudera.sqoop.tool.VersionTool;
    +import org.apache.sqoop.manager.*;
    +import org.apache.sqoop.manager.sqlserver.MSSQLTestUtils;
    +import org.apache.sqoop.tool.ImportTool;
    +import org.junit.*;
    +import org.junit.rules.ExpectedException;
    +import org.junit.runner.RunWith;
    +import org.junit.runners.Parameterized;
    +
    +import java.io.IOException;
    +import java.sql.Connection;
    +
    +import static org.apache.sqoop.metastore.GenericJobStorage.*;
    +import static org.hamcrest.core.IsCollectionContaining.hasItems;
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertThat;
    +
    +/**
    + * Test the metastore and job-handling features.
    + *
    + * These all make use of the auto-connect hsqldb-based metastore.
    + * The metastore URL is configured to be in-memory, and drop all
    + * state between individual tests.
    + */
    +@RunWith(Parameterized.class)
    +public class SavedJobsTest {
    +
    +  private static MySQLTestUtils mySQLTestUtils = new MySQLTestUtils();
    +  private static MSSQLTestUtils msSQLTestUtils = new MSSQLTestUtils();
    +
    +  @Parameterized.Parameters(name = "metaConnect = {0}, metaUser = {1}, 
metaPassword = {2}, driverClass = {3}")
    +  public static Iterable<? extends Object> dbConnectParameters() {
    +    return Arrays.asList(
    +            new Object[] {
    +                    mySQLTestUtils.getHostUrl(), 
mySQLTestUtils.getUserName(),
    +                    mySQLTestUtils.getUserPass(), MySQLManager.DRIVER_CLASS
    +            },
    +            new Object[] {
    +                   OracleUtils.CONNECT_STRING, 
OracleUtils.ORACLE_USER_NAME,
    +                    OracleUtils.ORACLE_USER_PASS, 
OracleManager.DRIVER_CLASS
    +            },
    +            new Object[] {
    +                   msSQLTestUtils.getDBConnectString(), 
msSQLTestUtils.getDBUserName(),
    +                    msSQLTestUtils.getDBPassWord(), 
SQLServerManager.DRIVER_CLASS
    +            },
    +            new Object[] {
    +                    System.getProperty(
    +                            "sqoop.test.postgresql.connectstring.host_url",
    +                            "jdbc:postgresql://localhost/"),
    +                    System.getProperty(
    +                            "sqoop.test.postgresql.connectstring.username",
    +                            "sqooptest"),
    +                    System.getProperty(
    +                            
"sqoop.test.postgresql.connectstring.password"),
    +                    PostgresqlManager.DRIVER_CLASS
    +            },
    +            new Object[] {
    +                    System.getProperty(
    +                            "sqoop.test.db2.connectstring.host_url",
    +                            "jdbc:db2://db2host:50000"),
    +                    System.getProperty(
    +                            "sqoop.test.db2.connectstring.username",
    +                            "SQOOP"),
    +                    System.getProperty(
    +                            "sqoop.test.db2.connectstring.password",
    +                            "SQOOP"),
    +                    Db2Manager.DRIVER_CLASS
    +            },
    +            new Object[] { "jdbc:hsqldb:mem:sqoopmetastore", "SA" , "", 
HsqldbManager.DRIVER_CLASS }
    +            );
    +  }
    +
    +  private String metaConnect;
    +  private String metaUser;
    +  private String metaPassword;
    +  private String driverClass;
    +  private JobStorage storage;
    +
    +  private Configuration conf;
    +  private Map<String, String> descriptor;
    +
    +  public String INVALID_KEY = "INVALID_KEY";
    +
    +
    +
    +  public SavedJobsTest(String metaConnect, String metaUser, String 
metaPassword, String driverClass){
    +    this.metaConnect = metaConnect;
    +    this.metaUser = metaUser;
    +    this.metaPassword = metaPassword;
    +    this.driverClass = driverClass;
    +    descriptor = new TreeMap<String, String>();
    +  }
    +
    +  @Rule
    +  public ExpectedException thrown = ExpectedException.none();
    +
    +  @Before
    +  public void setUp() throws Exception {
    +    // Delete db state between tests.
    +    resetJobSchema();
    +    conf = newConf();
    +
    +    descriptor.put(META_CONNECT_KEY, metaConnect);
    +    descriptor.put(META_USERNAME_KEY, metaUser);
    +    descriptor.put(META_PASSWORD_KEY, metaPassword);
    +    descriptor.put(META_DRIVER_KEY, driverClass);
    +
    +    JobStorageFactory ssf = new JobStorageFactory(conf);
    +    storage = ssf.getJobStorage(descriptor);
    +    storage.open(descriptor);
    +  }
    +
    +  @After
    +  public void tearDown() throws Exception {
    +    descriptor.clear();
    +    storage.close();
    +  }
    +
    +  public void resetJobSchema()
    +          throws SQLException {
    +    SqoopOptions options = new SqoopOptions();
    +    options.setConnectString(metaConnect);
    +    options.setUsername(metaUser);
    +    options.setPassword(metaPassword);
    +    options.setDriverClassName(driverClass);
    +
    +    resetSchema(options);
    +  }
    +
    +  /**
    +   * Drop all tables in the configured HSQLDB-based schema/user/pass.
    +   */
    +  public static void resetSchema(SqoopOptions options) throws SQLException 
{
    +    JobData jd = new JobData();
    +    jd.setSqoopOptions(options);
    +    DefaultManagerFactory dmf = new DefaultManagerFactory();
    +    ConnManager manager = dmf.accept(jd);
    +    Connection c = manager.getConnection();
    +    Statement s = c.createStatement();
    +    try {
    +      String [] tables = manager.listTables();
    +      for (String table : tables) {
    +        if(table.equalsIgnoreCase("SQOOP_ROOT") || 
table.equalsIgnoreCase("SQOOP_SESSIONS")){
    +          s.execute("DROP TABLE " + table);
    +        }
    +      }
    +
    +      c.commit();
    +    } finally {
    +      s.close();
    +    }
    +  }
    +
    +  public Configuration newConf() {
    +    Configuration conf = new Configuration();
    +    conf.set(META_CONNECT_KEY, metaConnect);
    +    conf.set(META_USERNAME_KEY, metaUser);
    +    conf.set(META_PASSWORD_KEY, metaPassword);
    +    conf.set(META_DRIVER_KEY, driverClass);
    +
    +    return conf;
    +  }
    +
    +  @Test
    +  public void canAcceptInvalidKeyFalseTest() throws Exception {
    +    TreeMap<String,String> t = new TreeMap<>();
    --- End diff --
    
    Use the superinterface in the variable decalaration.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to