Review Board 1.7.22


SQOOP-1153 Sqoop2: Integration: Add test for enabling and disabling connections and objects

Review Request #13945 - Created Sept. 3, 2013 and updated

Jarek Cecho
SQOOP-1153
Reviewers
Sqoop
sqoop-sqoop2
Added integration test that is submitting job that have disabled either the corresponding connection, the job or both objects.
New test seems to be passing.
test/src/test/java/org/apache/sqoop/integration/server/SubmissionWithDisabledModelObjectsTest.java
New File

    
   
1
/**

    
   
2
 * Licensed to the Apache Software Foundation (ASF) under one

    
   
3
 * or more contributor license agreements.  See the NOTICE file

    
   
4
 * distributed with this work for additional information

    
   
5
 * regarding copyright ownership.  The ASF licenses this file

    
   
6
 * to you under the Apache License, Version 2.0 (the

    
   
7
 * "License"); you may not use this file except in compliance

    
   
8
 * with the License.  You may obtain a copy of the License at

    
   
9
 *

    
   
10
 *     http://www.apache.org/licenses/LICENSE-2.0

    
   
11
 *

    
   
12
 * Unless required by applicable law or agreed to in writing, software

    
   
13
 * distributed under the License is distributed on an "AS IS" BASIS,

    
   
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

    
   
15
 * See the License for the specific language governing permissions and

    
   
16
 * limitations under the License.

    
   
17
 */

    
   
18
package org.apache.sqoop.integration.server;

    
   
19

   

    
   
20
import org.apache.sqoop.client.ClientError;

    
   
21
import org.apache.sqoop.common.SqoopException;

    
   
22
import org.apache.sqoop.framework.FrameworkError;

    
   
23
import org.apache.sqoop.framework.configuration.OutputFormat;

    
   
24
import org.apache.sqoop.framework.configuration.StorageType;

    
   
25
import org.apache.sqoop.model.MConnection;

    
   
26
import org.apache.sqoop.model.MFormList;

    
   
27
import org.apache.sqoop.model.MJob;

    
   
28
import org.apache.sqoop.test.testcases.ConnectorTestCase;

    
   
29
import org.junit.Test;

    
   
30
import org.junit.runner.RunWith;

    
   
31
import org.junit.runners.Parameterized;

    
   
32

   

    
   
33
import java.util.Arrays;

    
   
34

   

    
   
35
import static org.junit.Assert.assertEquals;

    
   
36
import static org.junit.Assert.assertNotNull;

    
   
37
import static org.junit.Assert.assertTrue;

    
   
38
import static org.junit.Assert.fail;

    
   
39

   

    
   
40
/**

    
   
41
 * Ensure that server will reject starting job when either job itself

    
   
42
 * or corresponding connection is disabled.

    
   
43
 */

    
   
44
@RunWith(Parameterized.class)

    
   
45
public class SubmissionWithDisabledModelObjectsTest extends ConnectorTestCase {

    
   
46

   

    
   
47
  @Parameterized.Parameters(name = "con({0}) job({1})")

    
   
48
  public static Iterable<Object[]> data() {

    
   
49
    return Arrays.asList(new Object[][] {

    
   
50
      { true, false },

    
   
51
      { false, true },

    
   
52
      { false, false },

    
   
53
    });

    
   
54
  }

    
   
55

   

    
   
56
  private boolean enabledConnection;

    
   
57
  private boolean enabledJob;

    
   
58

   

    
   
59
  public SubmissionWithDisabledModelObjectsTest(boolean enabledConnection, boolean enabledJob) {

    
   
60
    this.enabledConnection = enabledConnection;

    
   
61
    this.enabledJob = enabledJob;

    
   
62
  }

    
   
63

   

    
   
64
  @Test

    
   
65
  public void testWithDisabledObjects() throws Exception {

    
   
66
    createAndLoadTableCities();

    
   
67

   

    
   
68
    // Connection creation

    
   
69
    MConnection connection = getClient().newConnection("generic-jdbc-connector");

    
   
70
    fillConnectionForm(connection);

    
   
71
    createConnection(connection);

    
   
72

   

    
   
73
    // Job creation

    
   
74
    MJob job = getClient().newJob(connection.getPersistenceId(), MJob.Type.IMPORT);

    
   
75

   

    
   
76
    // Connector values

    
   
77
    MFormList forms = job.getConnectorPart();

    
   
78
    forms.getStringInput("table.tableName").setValue(provider.escapeTableName(getTableName()));

    
   
79
    forms.getStringInput("table.partitionColumn").setValue(provider.escapeColumnName("id"));

    
   
80
    // Framework values

    
   
81
    fillOutputForm(job, StorageType.HDFS, OutputFormat.TEXT_FILE);

    
   
82
    createJob(job);

    
   
83

   

    
   
84
    // Disable model entities as per parametrized run

    
   
85
    getClient().enableConnection(connection.getPersistenceId(), enabledConnection);

    
   
86
    getClient().enableJob(job.getPersistenceId(), enabledJob);

    
   
87

   

    
   
88
    // Try to run the job and verify that the it was not executed

    
   
89
    try {

    
   
90
      runJob(job);

    
   
91
      fail("Expected exception as the model classes are disabled.");

    
   
92
    } catch(SqoopException ex) {

    
   
93
      // Top level exception should be CLIENT_0001

    
   
94
      assertEquals(ClientError.CLIENT_0001, ex.getErrorCode());

    
   
95

   

    
   
96
      // We can directly verify the ErrorCode from SqoopException as client side

    
   
97
      // is not rebuilding SqoopExceptions per missing ErrorCodes. E.g. the cause

    
   
98
      // will be generic Throwable and not SqoopException instance.

    
   
99
      Throwable cause = ex.getCause();

    
   
100
      assertNotNull(cause);

    
   
101

   

    
   
102
      if(!enabledJob) {

    
   
103
        assertTrue(cause.getMessage().startsWith(FrameworkError.FRAMEWORK_0009.toString()));

    
   
104
      } else if(!enabledConnection) {

    
   
105
        assertTrue(cause.getMessage().startsWith(FrameworkError.FRAMEWORK_0010.toString()));

    
   
106
      } else {

    
   
107
        fail("Unexpected expception retrieved from server " + cause);

    
   
108
      }

    
   
109
    } finally {

    
   
110
      dropTable();

    
   
111
    }

    
   
112
  }

    
   
113
}
  1. test/src/test/java/org/apache/sqoop/integration/server/SubmissionWithDisabledModelObjectsTest.java: Loading...