sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [1/2] sqoop git commit: SQOOP-2461: Sqoop2: Add MySQL support for the metadata repository
Date Thu, 20 Aug 2015 01:41:23 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 1c24ecbde -> 668703cfe


http://git-wip-us.apache.org/repos/asf/sqoop/blob/668703cf/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestJobHandling.java
----------------------------------------------------------------------
diff --git a/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestJobHandling.java b/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestJobHandling.java
new file mode 100644
index 0000000..0614d7a
--- /dev/null
+++ b/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestJobHandling.java
@@ -0,0 +1,302 @@
+/**
+ * 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.mysql;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.common.test.db.TableName;
+import org.apache.sqoop.model.MConfig;
+import org.apache.sqoop.model.MConnector;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MLink;
+import org.apache.sqoop.model.MMapInput;
+import org.apache.sqoop.model.MStringInput;
+import org.apache.sqoop.model.MSubmission;
+import org.apache.sqoop.submission.SubmissionStatus;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Test driver methods on MySql repository.
+ */
+@Test(groups = "mysql")
+public class TestJobHandling extends MySqlTestCase {
+
+  public static final String CONNECTOR_A_NAME = "A";
+  public static final String CONNECTOR_A_CLASSNAME = "org.apache.sqoop.test.A";
+  public static final String CONNECTOR_A_VERSION = "1.0-test";
+  public static final String CONNECTOR_B_NAME = "B";
+  public static final String CONNECTOR_B_CLASSNAME = "org.apache.sqoop.test.B";
+  public static final String CONNECTOR_B_VERSION = "1.0-test";
+  public static final String LINK_A_NAME = "Link-A";
+  public static final String LINK_B_NAME = "Link-B";
+  public static final String JOB_A_NAME = "Job-A";
+  public static final String JOB_B_NAME = "Job-B";
+
+  @BeforeMethod(alwaysRun = true)
+  public void setUp() throws Exception {
+    super.setUp();
+
+    handler.registerDriver(getDriver(), provider.getConnection());
+    MConnector connectorA = getConnector(CONNECTOR_A_NAME,
+        CONNECTOR_A_CLASSNAME, CONNECTOR_A_VERSION, true, true);
+    MConnector connectorB = getConnector(CONNECTOR_B_NAME,
+        CONNECTOR_B_CLASSNAME, CONNECTOR_B_VERSION, true, true);
+    handler.registerConnector(connectorA, provider.getConnection());
+    handler.registerConnector(connectorB, provider.getConnection());
+    MLink linkA = getLink(LINK_A_NAME, connectorA);
+    MLink linkB = getLink(LINK_B_NAME, connectorB);
+    handler.createLink(linkA, provider.getConnection());
+    handler.createLink(linkB, provider.getConnection());
+    handler.createJob(getJob(JOB_A_NAME, connectorA, connectorB, linkA, linkB),
+        provider.getConnection());
+    handler.createJob(getJob(JOB_B_NAME, connectorB, connectorA, linkB, linkA),
+        provider.getConnection());
+  }
+
+  @Test
+  public void testFindJobFail() throws Exception {
+    for (MJob job : handler.findJobs(provider.getConnection())) {
+      handler.deleteJob(job.getPersistenceId(), provider.getConnection());
+    }
+
+    // Let's try to find non existing job
+    assertNull(handler.findJob(1, provider.getConnection()));
+  }
+
+  @Test
+  public void testFindJobSuccess() throws Exception {
+    MJob firstJob = handler.findJob(1, provider.getConnection());
+    assertNotNull(firstJob);
+    assertEquals(1, firstJob.getPersistenceId());
+    assertEquals(JOB_A_NAME, firstJob.getName());
+
+    List<MConfig> configs;
+
+    configs = firstJob.getFromJobConfig().getConfigs();
+    assertEquals(2, configs.size());
+    assertEquals("Value1", configs.get(0).getInputs().get(0).getValue());
+    assertNull(configs.get(0).getInputs().get(1).getValue());
+    assertEquals("Value2", configs.get(1).getInputs().get(0).getValue());
+    assertNull(configs.get(1).getInputs().get(1).getValue());
+
+    configs = firstJob.getToJobConfig().getConfigs();
+    assertEquals(2, configs.size());
+    assertEquals("Value1", configs.get(0).getInputs().get(0).getValue());
+    assertNull(configs.get(0).getInputs().get(1).getValue());
+    assertEquals("Value2", configs.get(1).getInputs().get(0).getValue());
+    assertNull(configs.get(1).getInputs().get(1).getValue());
+
+    configs = firstJob.getDriverConfig().getConfigs();
+    assertEquals(2, configs.size());
+    assertEquals("Value1", configs.get(0).getInputs().get(0).getValue());
+    assertNull(configs.get(0).getInputs().get(1).getValue());
+    assertEquals("Value2", configs.get(1).getInputs().get(0).getValue());
+    assertNull(configs.get(1).getInputs().get(1).getValue());
+  }
+
+  @Test
+  public void testFindJobs() throws Exception {
+    List<MJob> list;
+
+    list = handler.findJobs(provider.getConnection());
+    assertEquals(2, list.size());
+    assertEquals(JOB_A_NAME, list.get(0).getName());
+    assertEquals(JOB_B_NAME, list.get(1).getName());
+
+    // Delete jobs
+    for (MJob job : handler.findJobs(provider.getConnection())) {
+      handler.deleteJob(job.getPersistenceId(), provider.getConnection());
+    }
+
+    // Load all two links on loaded repository
+    list = handler.findJobs(provider.getConnection());
+    assertEquals(0, list.size());
+  }
+
+  @Test
+  public void testFindJobsByConnector() throws Exception {
+    List<MJob> list = handler
+        .findJobsForConnector(
+            handler.findConnector("A", provider.getConnection())
+                .getPersistenceId(), provider.getConnection());
+    assertEquals(2, list.size());
+    assertEquals(JOB_A_NAME, list.get(0).getName());
+    assertEquals(JOB_B_NAME, list.get(1).getName());
+  }
+
+  @Test
+  public void testFindJobsForNonExistingConnector() throws Exception {
+    List<MJob> list = handler
+        .findJobsForConnector(11, provider.getConnection());
+    assertEquals(0, list.size());
+  }
+
+  @Test
+  public void testExistsJob() throws Exception {
+    assertTrue(handler.existsJob(1, provider.getConnection()));
+    assertTrue(handler.existsJob(2, provider.getConnection()));
+    assertFalse(handler.existsJob(3, provider.getConnection()));
+
+    // Delete jobs
+    for (MJob job : handler.findJobs(provider.getConnection())) {
+      handler.deleteJob(job.getPersistenceId(), provider.getConnection());
+    }
+
+    // There shouldn't be anything on empty repository
+    assertFalse(handler.existsJob(1, provider.getConnection()));
+    assertFalse(handler.existsJob(2, provider.getConnection()));
+    assertFalse(handler.existsJob(3, provider.getConnection()));
+  }
+
+  @Test
+  public void testInUseJob() throws Exception {
+    MSubmission submission = getSubmission(
+        handler.findJob(1, provider.getConnection()), SubmissionStatus.RUNNING);
+    handler.createSubmission(submission, provider.getConnection());
+
+    assertTrue(handler.inUseJob(1, provider.getConnection()));
+    assertFalse(handler.inUseJob(2, provider.getConnection()));
+    assertFalse(handler.inUseJob(3, provider.getConnection()));
+  }
+
+  @Test
+  public void testCreateJob() throws Exception {
+    Assert.assertEquals(provider.rowCount(new TableName("SQOOP", "SQ_JOB")), 2);
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_JOB_INPUT")), 12);
+
+    MJob retrieved = handler.findJob(1, provider.getConnection());
+    assertEquals(1, retrieved.getPersistenceId());
+
+    List<MConfig> configs;
+    configs = retrieved.getFromJobConfig().getConfigs();
+    assertEquals("Value1", configs.get(0).getInputs().get(0).getValue());
+    assertNull(configs.get(0).getInputs().get(1).getValue());
+    configs = retrieved.getToJobConfig().getConfigs();
+    assertEquals("Value2", configs.get(1).getInputs().get(0).getValue());
+    assertNull(configs.get(0).getInputs().get(1).getValue());
+
+    configs = retrieved.getDriverConfig().getConfigs();
+    assertEquals("Value1", configs.get(0).getInputs().get(0).getValue());
+    assertNull(configs.get(0).getInputs().get(1).getValue());
+    assertEquals("Value2", configs.get(1).getInputs().get(0).getValue());
+    assertNull(configs.get(1).getInputs().get(1).getValue());
+  }
+
+  @Test
+  public void testCreateDuplicateJob() throws Exception {
+    // Duplicate jobs
+    MJob job = handler.findJob(JOB_A_NAME, provider.getConnection());
+    job.setPersistenceId(MJob.PERSISTANCE_ID_DEFAULT);
+    try {
+      handler.createJob(job, provider.getConnection());
+      Assert.fail("SqoopException should be thrown.");
+    } catch (SqoopException se) {
+      // ignore the excepted exception.
+    }
+  }
+
+  @Test
+  public void testUpdateJob() throws Exception {
+    Assert.assertEquals(provider.rowCount(new TableName("SQOOP", "SQ_JOB")), 2);
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_JOB_INPUT")), 12);
+
+    MJob job = handler.findJob(1, provider.getConnection());
+
+    List<MConfig> configs;
+
+    configs = job.getFromJobConfig().getConfigs();
+    ((MStringInput) configs.get(0).getInputs().get(0)).setValue("Updated");
+    ((MMapInput) configs.get(0).getInputs().get(1)).setValue(null);
+
+    configs = job.getToJobConfig().getConfigs();
+    ((MStringInput) configs.get(0).getInputs().get(0)).setValue("Updated");
+    ((MMapInput) configs.get(0).getInputs().get(1)).setValue(null);
+
+    configs = job.getDriverConfig().getConfigs();
+    ((MStringInput) configs.get(0).getInputs().get(0)).setValue("Updated");
+    ((MMapInput) configs.get(0).getInputs().get(1))
+        .setValue(new HashMap<String, String>()); // inject new map value
+    ((MStringInput) configs.get(1).getInputs().get(0)).setValue("Updated");
+    ((MMapInput) configs.get(1).getInputs().get(1))
+        .setValue(new HashMap<String, String>()); // inject new map value
+
+    job.setName("name");
+
+    handler.updateJob(job, provider.getConnection());
+
+    assertEquals(1, job.getPersistenceId());
+    Assert.assertEquals(provider.rowCount(new TableName("SQOOP", "SQ_JOB")), 2);
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_JOB_INPUT")), 14);
+
+    MJob retrieved = handler.findJob(1, provider.getConnection());
+    assertEquals("name", retrieved.getName());
+
+    configs = job.getFromJobConfig().getConfigs();
+    assertEquals(2, configs.size());
+    assertEquals("Updated", configs.get(0).getInputs().get(0).getValue());
+    assertNull(configs.get(0).getInputs().get(1).getValue());
+    configs = job.getToJobConfig().getConfigs();
+    assertEquals(2, configs.size());
+    assertEquals("Updated", configs.get(0).getInputs().get(0).getValue());
+    assertNull(configs.get(0).getInputs().get(1).getValue());
+
+    configs = retrieved.getDriverConfig().getConfigs();
+    assertEquals(2, configs.size());
+    assertEquals("Updated", configs.get(0).getInputs().get(0).getValue());
+    assertNotNull(configs.get(0).getInputs().get(1).getValue());
+    assertEquals(((Map) configs.get(0).getInputs().get(1).getValue()).size(), 0);
+  }
+
+  @Test
+  public void testEnableAndDisableJob() throws Exception {
+    // disable job 1
+    handler.enableJob(1, false, provider.getConnection());
+
+    MJob retrieved = handler.findJob(1, provider.getConnection());
+    assertNotNull(retrieved);
+    assertEquals(false, retrieved.getEnabled());
+
+    // enable job 1
+    handler.enableJob(1, true, provider.getConnection());
+
+    retrieved = handler.findJob(1, provider.getConnection());
+    assertNotNull(retrieved);
+    assertEquals(true, retrieved.getEnabled());
+  }
+
+  @Test
+  public void testDeleteJob() throws Exception {
+    handler.deleteJob(1, provider.getConnection());
+    Assert.assertEquals(provider.rowCount(new TableName("SQOOP", "SQ_JOB")), 1);
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_JOB_INPUT")), 6);
+
+    handler.deleteJob(2, provider.getConnection());
+    Assert.assertEquals(provider.rowCount(new TableName("SQOOP", "SQ_JOB")), 0);
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_JOB_INPUT")), 0);
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/668703cf/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestLinkHandling.java
----------------------------------------------------------------------
diff --git a/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestLinkHandling.java b/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestLinkHandling.java
new file mode 100644
index 0000000..cceef09
--- /dev/null
+++ b/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestLinkHandling.java
@@ -0,0 +1,297 @@
+/**
+ * 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.mysql;
+
+import java.util.List;
+
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.common.test.db.TableName;
+import org.apache.sqoop.model.MConfig;
+import org.apache.sqoop.model.MConnector;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MLink;
+import org.apache.sqoop.model.MMapInput;
+import org.apache.sqoop.model.MStringInput;
+import org.apache.sqoop.model.MSubmission;
+import org.apache.sqoop.submission.SubmissionStatus;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Test driver methods on MySql repository.
+ */
+@Test(groups = "mysql")
+public class TestLinkHandling extends MySqlTestCase {
+
+  public static final String CONNECTOR_A_NAME = "A";
+  public static final String CONNECTOR_A_CLASSNAME = "org.apache.sqoop.test.A";
+  public static final String CONNECTOR_A_VERSION = "1.0-test";
+  public static final String CONNECTOR_B_NAME = "B";
+  public static final String CONNECTOR_B_CLASSNAME = "org.apache.sqoop.test.B";
+  public static final String CONNECTOR_B_VERSION = "1.0-test";
+  public static final String LINK_A_NAME = "Link-A";
+  public static final String LINK_B_NAME = "Link-B";
+
+  @BeforeMethod(alwaysRun = true)
+  public void setUp() throws Exception {
+    super.setUp();
+
+    handler.registerDriver(getDriver(), provider.getConnection());
+    MConnector connectorA = getConnector(CONNECTOR_A_NAME,
+        CONNECTOR_A_CLASSNAME, CONNECTOR_A_VERSION, true, true);
+    MConnector connectorB = getConnector(CONNECTOR_B_NAME,
+        CONNECTOR_B_CLASSNAME, CONNECTOR_B_VERSION, true, true);
+    handler.registerConnector(connectorA, provider.getConnection());
+    handler.registerConnector(connectorB, provider.getConnection());
+    MLink linkA = getLink(LINK_A_NAME, connectorA);
+    MLink linkB = getLink(LINK_B_NAME, connectorB);
+    handler.createLink(linkA, provider.getConnection());
+    handler.createLink(linkB, provider.getConnection());
+  }
+
+  @Test
+  public void testFindLinkFail() {
+    // Delete links
+    for (MLink link : handler.findLinks(provider.getConnection())) {
+      handler.deleteLink(link.getPersistenceId(), provider.getConnection());
+    }
+
+    assertNull(handler.findLink(1, provider.getConnection()));
+  }
+
+  @Test
+  public void testFindLinkSuccess() throws Exception {
+    MLink linkA = handler.findLink(1, provider.getConnection());
+    assertNotNull(linkA);
+    assertEquals(1, linkA.getPersistenceId());
+    assertEquals(LINK_A_NAME, linkA.getName());
+
+    // Check connector link config
+    List<MConfig> configs = linkA.getConnectorLinkConfig().getConfigs();
+    assertEquals("Value1", configs.get(0).getInputs().get(0).getValue());
+    assertNull(configs.get(0).getInputs().get(1).getValue());
+    assertEquals("Value2", configs.get(1).getInputs().get(0).getValue());
+    assertNull(configs.get(1).getInputs().get(1).getValue());
+  }
+
+  @Test
+  public void testFindLinkByName() throws Exception {
+    // Load non-existing
+    assertNull(handler.findLink("non-existing", provider.getConnection()));
+
+    MLink linkA = handler.findLink(LINK_A_NAME, provider.getConnection());
+    assertNotNull(linkA);
+    assertEquals(1, linkA.getPersistenceId());
+    assertEquals(LINK_A_NAME, linkA.getName());
+
+    // Check connector link config
+    List<MConfig> configs = linkA.getConnectorLinkConfig().getConfigs();
+    assertEquals("Value1", configs.get(0).getInputs().get(0).getValue());
+    assertNull(configs.get(0).getInputs().get(1).getValue());
+    assertEquals("Value2", configs.get(1).getInputs().get(0).getValue());
+    assertNull(configs.get(1).getInputs().get(1).getValue());
+  }
+
+  @Test
+  public void testFindLinks() throws Exception {
+    List<MLink> list;
+
+    // Load all two links on loaded repository
+    list = handler.findLinks(provider.getConnection());
+    assertEquals(2, list.size());
+    assertEquals(LINK_A_NAME, list.get(0).getName());
+    assertEquals(LINK_B_NAME, list.get(1).getName());
+
+    // Delete links
+    for (MLink link : handler.findLinks(provider.getConnection())) {
+      handler.deleteLink(link.getPersistenceId(), provider.getConnection());
+    }
+
+    // Load empty list on empty repository
+    list = handler.findLinks(provider.getConnection());
+    assertEquals(0, list.size());
+  }
+
+  @Test
+  public void testFindLinksByConnector() throws Exception {
+    List<MLink> list;
+    Long connectorId = handler.findConnector("A", provider.getConnection())
+        .getPersistenceId();
+
+    // Load all two links on loaded repository
+    list = handler.findLinksForConnector(connectorId, provider.getConnection());
+    assertEquals(1, list.size());
+    assertEquals(LINK_A_NAME, list.get(0).getName());
+
+    // Delete links
+    for (MLink link : handler.findLinks(provider.getConnection())) {
+      handler.deleteLink(link.getPersistenceId(), provider.getConnection());
+    }
+
+    // Load empty list on empty repository
+    list = handler.findLinksForConnector(connectorId, provider.getConnection());
+    assertEquals(0, list.size());
+  }
+
+  @Test
+  public void testFindLinksByNonExistingConnector() throws Exception {
+    List<MLink> list = handler.findLinksForConnector(11,
+        provider.getConnection());
+    assertEquals(0, list.size());
+  }
+
+  @Test
+  public void testExistsLink() throws Exception {
+    assertTrue(handler.existsLink(1, provider.getConnection()));
+    assertTrue(handler.existsLink(2, provider.getConnection()));
+    assertFalse(handler.existsLink(3, provider.getConnection()));
+
+    // Delete links
+    for (MLink link : handler.findLinks(provider.getConnection())) {
+      handler.deleteLink(link.getPersistenceId(), provider.getConnection());
+    }
+
+    assertFalse(handler.existsLink(1, provider.getConnection()));
+    assertFalse(handler.existsLink(2, provider.getConnection()));
+    assertFalse(handler.existsLink(3, provider.getConnection()));
+  }
+
+  @Test
+  public void testCreateLink() throws Exception {
+    List<MConfig> configs;
+
+    MLink retrieved = handler.findLink(1, provider.getConnection());
+    assertEquals(1, retrieved.getPersistenceId());
+
+    configs = retrieved.getConnectorLinkConfig().getConfigs();
+    assertEquals("Value1", configs.get(0).getInputs().get(0).getValue());
+    assertNull(configs.get(0).getInputs().get(1).getValue());
+    assertEquals("Value2", configs.get(1).getInputs().get(0).getValue());
+    assertNull(configs.get(1).getInputs().get(1).getValue());
+
+    retrieved = handler.findLink(2, provider.getConnection());
+    assertEquals(2, retrieved.getPersistenceId());
+
+    configs = retrieved.getConnectorLinkConfig().getConfigs();
+    assertEquals("Value1", configs.get(0).getInputs().get(0).getValue());
+    assertNull(configs.get(0).getInputs().get(1).getValue());
+    assertEquals("Value2", configs.get(1).getInputs().get(0).getValue());
+    assertNull(configs.get(1).getInputs().get(1).getValue());
+
+    Assert
+        .assertEquals(provider.rowCount(new TableName("SQOOP", "SQ_LINK")), 2);
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_LINK_INPUT")), 4);
+  }
+
+  @Test
+  public void testCreateDuplicateLink() throws SqoopException {
+    MLink link = handler.findLink(LINK_A_NAME, provider.getConnection());
+    link.setPersistenceId(MLink.PERSISTANCE_ID_DEFAULT);
+    try {
+      handler.createLink(link, provider.getConnection());
+      Assert.fail("SqoopException should be thrown.");
+    } catch (SqoopException se) {
+      // ignore the excepted exception.
+    }
+  }
+
+  @Test
+  public void testInUseLink() throws Exception {
+    assertFalse(handler.inUseLink(1, provider.getConnection()));
+
+    // Create job and submission and make that job in use to make sure link is
+    // in use.
+    MLink linkA = handler.findLink(LINK_A_NAME, provider.getConnection());
+    MJob job = getJob("Job-A",
+        handler.findConnector("A", provider.getConnection()),
+        handler.findConnector("B", provider.getConnection()), linkA,
+        handler.findLink(LINK_B_NAME, provider.getConnection()));
+    handler.createJob(job, provider.getConnection());
+    MSubmission submission = getSubmission(job, SubmissionStatus.RUNNING);
+    handler.createSubmission(submission, provider.getConnection());
+
+    assertTrue(handler.inUseLink(linkA.getPersistenceId(),
+        provider.getConnection()));
+  }
+
+  @Test
+  public void testUpdateLink() throws Exception {
+    MLink link = handler.findLink(1, provider.getConnection());
+
+    List<MConfig> configs;
+
+    configs = link.getConnectorLinkConfig().getConfigs();
+    ((MStringInput) configs.get(0).getInputs().get(0)).setValue("Updated");
+    ((MMapInput) configs.get(0).getInputs().get(1)).setValue(null);
+    ((MStringInput) configs.get(1).getInputs().get(0)).setValue("Updated");
+    ((MMapInput) configs.get(1).getInputs().get(1)).setValue(null);
+
+    link.setName("name");
+
+    handler.updateLink(link, provider.getConnection());
+
+    assertEquals(1, link.getPersistenceId());
+    Assert
+        .assertEquals(provider.rowCount(new TableName("SQOOP", "SQ_LINK")), 2);
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_LINK_INPUT")), 4);
+
+    MLink retrieved = handler.findLink(1, provider.getConnection());
+    assertEquals("name", link.getName());
+
+    configs = retrieved.getConnectorLinkConfig().getConfigs();
+    assertEquals("Updated", configs.get(0).getInputs().get(0).getValue());
+    assertNull(configs.get(0).getInputs().get(1).getValue());
+    assertEquals("Updated", configs.get(1).getInputs().get(0).getValue());
+    assertNull(configs.get(1).getInputs().get(1).getValue());
+  }
+
+  @Test
+  public void testEnableAndDisableLink() throws Exception {
+    // disable link 1
+    handler.enableLink(1, false, provider.getConnection());
+
+    MLink retrieved = handler.findLink(1, provider.getConnection());
+    assertNotNull(retrieved);
+    assertEquals(false, retrieved.getEnabled());
+
+    // enable link 1
+    handler.enableLink(1, true, provider.getConnection());
+
+    retrieved = handler.findLink(1, provider.getConnection());
+    assertNotNull(retrieved);
+    assertEquals(true, retrieved.getEnabled());
+  }
+
+  @Test
+  public void testDeleteLink() throws Exception {
+    handler.deleteLink(1, provider.getConnection());
+    Assert
+        .assertEquals(provider.rowCount(new TableName("SQOOP", "SQ_LINK")), 1);
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_LINK_INPUT")), 2);
+
+    handler.deleteLink(2, provider.getConnection());
+    Assert
+        .assertEquals(provider.rowCount(new TableName("SQOOP", "SQ_LINK")), 0);
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_LINK_INPUT")), 0);
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/668703cf/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestStructure.java
----------------------------------------------------------------------
diff --git a/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestStructure.java b/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestStructure.java
new file mode 100644
index 0000000..3dec58c
--- /dev/null
+++ b/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestStructure.java
@@ -0,0 +1,81 @@
+/**
+ * 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.mysql;
+
+import org.testng.annotations.Test;
+
+/**
+ * Test driver methods on MySql repository.
+ */
+@Test(groups = "mysql")
+public class TestStructure extends MySqlTestCase {
+
+  @Test
+  public void testTables() throws Exception {
+    utils.assertTableExists("SQOOP", "SQ_SYSTEM");
+    utils.assertTableExists("SQOOP", "SQ_DIRECTION");
+    utils.assertTableExists("SQOOP", "SQ_CONFIGURABLE");
+    utils.assertTableExists("SQOOP", "SQ_CONNECTOR_DIRECTIONS");
+    utils.assertTableExists("SQOOP", "SQ_CONFIG");
+    utils.assertTableExists("SQOOP", "SQ_CONNECTOR_DIRECTIONS");
+    utils.assertTableExists("SQOOP", "SQ_INPUT");
+    utils.assertTableExists("SQOOP", "SQ_INPUT_RELATION");
+    utils.assertTableExists("SQOOP", "SQ_LINK");
+    utils.assertTableExists("SQOOP", "SQ_JOB");
+    utils.assertTableExists("SQOOP", "SQ_LINK_INPUT");
+    utils.assertTableExists("SQOOP", "SQ_JOB_INPUT");
+    utils.assertTableExists("SQOOP", "SQ_SUBMISSION");
+    utils.assertTableExists("SQOOP", "SQ_COUNTER_GROUP");
+    utils.assertTableExists("SQOOP", "SQ_COUNTER");
+    utils.assertTableExists("SQOOP", "SQ_COUNTER_SUBMISSION");
+  }
+
+  @Test
+  public void testForeignKeys() throws Exception {
+    utils.assertForeignKey("SQOOP", "SQ_CONFIGURABLE", "SQC_ID", "SQ_CONNECTOR_DIRECTIONS", "SQCD_CONNECTOR");
+    utils.assertForeignKey("SQOOP", "SQ_DIRECTION", "SQD_ID", "SQ_CONNECTOR_DIRECTIONS", "SQCD_DIRECTION");
+    utils.assertForeignKey("SQOOP", "SQ_CONFIGURABLE", "SQC_ID", "SQ_CONFIG", "SQ_CFG_CONFIGURABLE");
+    utils.assertForeignKey("SQOOP", "SQ_CONFIG", "SQ_CFG_ID", "SQ_CONFIG_DIRECTIONS", "SQ_CFG_DIR_CONFIG");
+    utils.assertForeignKey("SQOOP", "SQ_DIRECTION", "SQD_ID", "SQ_CONFIG_DIRECTIONS", "SQ_CFG_DIR_DIRECTION");
+    utils.assertForeignKey("SQOOP", "SQ_CONFIG", "SQ_CFG_ID", "SQ_INPUT", "SQI_CONFIG");
+    utils.assertForeignKey("SQOOP", "SQ_CONFIGURABLE", "SQC_ID", "SQ_LINK", "SQ_LNK_CONFIGURABLE");
+    utils.assertForeignKey("SQOOP", "SQ_LINK", "SQ_LNK_ID", "SQ_JOB", "SQB_FROM_LINK");
+    utils.assertForeignKey("SQOOP", "SQ_LINK", "SQ_LNK_ID", "SQ_JOB", "SQB_TO_LINK");
+    utils.assertForeignKey("SQOOP", "SQ_LINK", "SQ_LNK_ID", "SQ_LINK_INPUT", "SQ_LNKI_LINK");
+    utils.assertForeignKey("SQOOP", "SQ_INPUT", "SQI_ID", "SQ_LINK_INPUT", "SQ_LNKI_INPUT");
+    utils.assertForeignKey("SQOOP", "SQ_INPUT", "SQI_ID", "SQ_INPUT_RELATION", "SQIR_PARENT_ID");
+    utils.assertForeignKey("SQOOP", "SQ_INPUT", "SQI_ID", "SQ_INPUT_RELATION", "SQIR_CHILD_ID");
+    utils.assertForeignKey("SQOOP", "SQ_JOB", "SQB_ID", "SQ_JOB_INPUT", "SQBI_JOB");
+    utils.assertForeignKey("SQOOP", "SQ_INPUT", "SQI_ID", "SQ_JOB_INPUT", "SQBI_INPUT");
+    utils.assertForeignKey("SQOOP", "SQ_JOB", "SQB_ID", "SQ_SUBMISSION", "SQS_JOB");
+    utils.assertForeignKey("SQOOP", "SQ_COUNTER", "SQR_ID", "SQ_COUNTER_SUBMISSION", "SQRS_COUNTER");
+    utils.assertForeignKey("SQOOP", "SQ_COUNTER_GROUP", "SQG_ID", "SQ_COUNTER_SUBMISSION", "SQRS_GROUP");
+    utils.assertForeignKey("SQOOP", "SQ_SUBMISSION", "SQS_ID", "SQ_COUNTER_SUBMISSION", "SQRS_SUBMISSION");
+  }
+
+  @Test
+  public void testUniqueConstraints() throws Exception {
+    utils.assertUniqueConstraints("SQOOP", "SQ_CONFIGURABLE", "SQC_NAME");
+    utils.assertUniqueConstraints("SQOOP", "SQ_LINK", "SQ_LNK_NAME");
+    utils.assertUniqueConstraints("SQOOP", "SQ_JOB", "SQB_NAME");
+    utils.assertUniqueConstraints("SQOOP", "SQ_CONFIG", "SQ_CFG_NAME", "SQ_CFG_CONFIGURABLE", "SQ_CFG_TYPE");
+    utils.assertUniqueConstraints("SQOOP", "SQ_INPUT", "SQI_NAME", "SQI_TYPE", "SQI_CONFIG");
+    utils.assertUniqueConstraints("SQOOP", "SQ_COUNTER", "SQR_NAME");
+    utils.assertUniqueConstraints("SQOOP", "SQ_COUNTER_GROUP", "SQG_NAME");
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/668703cf/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestSubmissionHandling.java
----------------------------------------------------------------------
diff --git a/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestSubmissionHandling.java b/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestSubmissionHandling.java
new file mode 100644
index 0000000..e2a3011
--- /dev/null
+++ b/repository/repository-mysql/src/test/java/org/apache/sqoop/integration/repository/mysql/TestSubmissionHandling.java
@@ -0,0 +1,406 @@
+/**
+ * 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.mysql;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.sqoop.common.MutableContext;
+import org.apache.sqoop.common.MutableMapContext;
+import org.apache.sqoop.common.test.db.TableName;
+import org.apache.sqoop.model.MConnector;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MLink;
+import org.apache.sqoop.model.MSubmission;
+import org.apache.sqoop.submission.SubmissionStatus;
+import org.apache.sqoop.submission.counter.Counter;
+import org.apache.sqoop.submission.counter.CounterGroup;
+import org.apache.sqoop.submission.counter.Counters;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Test driver methods on MySql repository.
+ */
+@Test(groups = "mysql")
+public class TestSubmissionHandling extends MySqlTestCase {
+  public static final String CONNECTOR_A_NAME = "A";
+  public static final String CONNECTOR_A_CLASSNAME = "org.apache.sqoop.test.A";
+  public static final String CONNECTOR_A_VERSION = "1.0-test";
+  public static final String CONNECTOR_B_NAME = "B";
+  public static final String CONNECTOR_B_CLASSNAME = "org.apache.sqoop.test.B";
+  public static final String CONNECTOR_B_VERSION = "1.0-test";
+  public static final String LINK_A_NAME = "Link-A";
+  public static final String LINK_B_NAME = "Link-B";
+  public static final String JOB_A_NAME = "Job-A";
+  public static final String JOB_B_NAME = "Job-B";
+
+  @BeforeMethod(alwaysRun = true)
+  public void setUp() throws Exception {
+    super.setUp();
+
+    handler.registerDriver(getDriver(), provider.getConnection());
+    MConnector connectorA = getConnector(CONNECTOR_A_NAME,
+        CONNECTOR_A_CLASSNAME, CONNECTOR_A_VERSION, true, true);
+    MConnector connectorB = getConnector(CONNECTOR_B_NAME,
+        CONNECTOR_B_CLASSNAME, CONNECTOR_B_VERSION, true, true);
+    handler.registerConnector(connectorA, provider.getConnection());
+    handler.registerConnector(connectorB, provider.getConnection());
+    MLink linkA = getLink(LINK_A_NAME, connectorA);
+    MLink linkB = getLink(LINK_B_NAME, connectorB);
+    handler.createLink(linkA, provider.getConnection());
+    handler.createLink(linkB, provider.getConnection());
+    MJob jobA = getJob(JOB_A_NAME, connectorA, connectorB, linkA, linkB);
+    MJob jobB = getJob(JOB_B_NAME, connectorB, connectorA, linkB, linkA);
+    handler.createJob(jobA, provider.getConnection());
+    handler.createJob(jobB, provider.getConnection());
+  }
+
+  private void loadSubmissions() throws Exception {
+    MJob jobA = handler.findJob(JOB_A_NAME, provider.getConnection());
+    MJob jobB = handler.findJob(JOB_B_NAME, provider.getConnection());
+
+    MSubmission submissionA = getSubmission(jobA, SubmissionStatus.RUNNING);
+    submissionA.getCounters().getCounterGroup("test-1")
+        .addCounter(new Counter("counter-1"));
+    submissionA.getCounters().getCounterGroup("test-1")
+        .addCounter(new Counter("counter-2"));
+    submissionA.getCounters().getCounterGroup("test-1").getCounter("counter-1")
+        .setValue(300);
+    MSubmission submissionB = getSubmission(jobA, SubmissionStatus.SUCCEEDED);
+    MSubmission submissionC = getSubmission(jobB, SubmissionStatus.FAILED);
+    MSubmission submissionD = getSubmission(jobB, SubmissionStatus.UNKNOWN);
+    handler.createSubmission(submissionA, provider.getConnection());
+    handler.createSubmission(submissionB, provider.getConnection());
+    handler.createSubmission(submissionC, provider.getConnection());
+    handler.createSubmission(submissionD, provider.getConnection());
+  }
+
+  @Test
+  public void testFindSubmissionsUnfinished() throws Exception {
+    List<MSubmission> submissions;
+
+    submissions = handler.findUnfinishedSubmissions(provider.getConnection());
+    assertNotNull(submissions);
+    assertEquals(0, submissions.size());
+
+    loadSubmissions();
+
+    submissions = handler.findUnfinishedSubmissions(provider.getConnection());
+    assertNotNull(submissions);
+    assertEquals(1, submissions.size());
+  }
+
+  @Test
+  public void testExistsSubmission() throws Exception {
+    // There shouldn't be anything on empty repository
+    assertFalse(handler.existsSubmission(1, provider.getConnection()));
+    assertFalse(handler.existsSubmission(2, provider.getConnection()));
+    assertFalse(handler.existsSubmission(3, provider.getConnection()));
+    assertFalse(handler.existsSubmission(4, provider.getConnection()));
+    assertFalse(handler.existsSubmission(5, provider.getConnection()));
+
+    loadSubmissions();
+
+    assertTrue(handler.existsSubmission(1, provider.getConnection()));
+    assertTrue(handler.existsSubmission(2, provider.getConnection()));
+    assertTrue(handler.existsSubmission(3, provider.getConnection()));
+    assertTrue(handler.existsSubmission(4, provider.getConnection()));
+    assertFalse(handler.existsSubmission(5, provider.getConnection()));
+  }
+
+  @Test
+  public void testCreateSubmission() throws Exception {
+    Date creationDate = new Date();
+    Date updateDate = new Date();
+
+    CounterGroup firstGroup = new CounterGroup("ga");
+    CounterGroup secondGroup = new CounterGroup("gb");
+    firstGroup.addCounter(new Counter("ca", 100));
+    firstGroup.addCounter(new Counter("cb", 200));
+    secondGroup.addCounter(new Counter("ca", 300));
+    secondGroup.addCounter(new Counter("cd", 400));
+    Counters counters = new Counters();
+    counters.addCounterGroup(firstGroup);
+    counters.addCounterGroup(secondGroup);
+
+    MutableContext fromContext = new MutableMapContext();
+    MutableContext toContext = new MutableMapContext();
+    MutableContext driverContext = new MutableMapContext();
+    fromContext.setString("from1", "value1");
+    fromContext.setString("from2", "value2");
+    toContext.setString("to1", "value1");
+    toContext.setString("to2", "value2");
+    driverContext.setString("driver1", "value1");
+    driverContext.setString("driver2", "value2");
+
+    MSubmission submission = new MSubmission();
+    submission.setJobId(1);
+    submission.setStatus(SubmissionStatus.RUNNING);
+    submission.setCreationDate(creationDate);
+    submission.setLastUpdateDate(updateDate);
+    submission.setExternalJobId("job-x");
+    submission.setExternalLink("http://somewhere");
+    submission.getError().setErrorSummary("RuntimeException");
+    submission.getError().setErrorDetails("Yeah it happens");
+    submission.setCounters(counters);
+    submission.setFromConnectorContext(fromContext);
+    submission.setToConnectorContext(toContext);
+    submission.setDriverContext(driverContext);
+
+    handler.createSubmission(submission, provider.getConnection());
+
+    assertEquals(1, submission.getPersistenceId());
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_SUBMISSION")), 1);
+
+    List<MSubmission> submissions = handler.findUnfinishedSubmissions(provider
+        .getConnection());
+    assertNotNull(submissions);
+    assertEquals(1, submissions.size());
+
+    submission = submissions.get(0);
+
+    assertEquals(1, submission.getJobId());
+    assertEquals(SubmissionStatus.RUNNING, submission.getStatus());
+    long exceptedData = creationDate.getTime();
+    long actualData = submission.getCreationDate().getTime();
+    long diff = Math.abs(exceptedData - actualData);
+    // the date is saved as Timestamp, there maybe 1 sec diff between the set
+    // value and get value
+    assertTrue(diff < 2000);
+    exceptedData = updateDate.getTime();
+    actualData = submission.getLastUpdateDate().getTime();
+    diff = Math.abs(exceptedData - actualData);
+    assertTrue(diff < 2000);
+    assertEquals("job-x", submission.getExternalJobId());
+    assertEquals("http://somewhere", submission.getExternalLink());
+    assertEquals("RuntimeException", submission.getError().getErrorSummary());
+    assertEquals("Yeah it happens", submission.getError().getErrorDetails());
+
+    CounterGroup group;
+    Counter counter;
+    Counters retrievedCounters = submission.getCounters();
+    assertNotNull(retrievedCounters);
+
+    group = counters.getCounterGroup("ga");
+    assertNotNull(group);
+
+    counter = group.getCounter("ca");
+    assertNotNull(counter);
+    assertEquals(100, counter.getValue());
+
+    counter = group.getCounter("cb");
+    assertNotNull(counter);
+    assertEquals(200, counter.getValue());
+
+    group = counters.getCounterGroup("gb");
+    assertNotNull(group);
+
+    counter = group.getCounter("ca");
+    assertNotNull(counter);
+    assertEquals(300, counter.getValue());
+
+    counter = group.getCounter("cd");
+    assertNotNull(counter);
+    assertEquals(400, counter.getValue());
+
+    assertNotNull(submission.getFromConnectorContext());
+    assertNotNull(submission.getToConnectorContext());
+    assertNotNull(submission.getDriverContext());
+    assertEquals(submission.getFromConnectorContext().getString("from1"),
+        "value1");
+    assertEquals(submission.getFromConnectorContext().getString("from2"),
+        "value2");
+    assertEquals(submission.getToConnectorContext().getString("to1"), "value1");
+    assertEquals(submission.getToConnectorContext().getString("to2"), "value2");
+    assertEquals(submission.getDriverContext().getString("driver1"), "value1");
+    assertEquals(submission.getDriverContext().getString("driver2"), "value2");
+
+    // Let's create second (simpler) connection
+    submission = new MSubmission(1, new Date(), SubmissionStatus.SUCCEEDED,
+        "job-x");
+    handler.createSubmission(submission, provider.getConnection());
+
+    assertEquals(2, submission.getPersistenceId());
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_SUBMISSION")), 2);
+  }
+
+  @Test
+  public void testUpdateSubmission() throws Exception {
+    loadSubmissions();
+
+    List<MSubmission> submissions = handler.findUnfinishedSubmissions(provider
+        .getConnection());
+    assertNotNull(submissions);
+    assertEquals(1, submissions.size());
+
+    MSubmission submission = submissions.get(0);
+    submission.setStatus(SubmissionStatus.SUCCEEDED);
+
+    handler.updateSubmission(submission, provider.getConnection());
+
+    submissions = handler.findUnfinishedSubmissions(provider.getConnection());
+    assertNotNull(submissions);
+    assertEquals(0, submissions.size());
+  }
+
+  @Test
+  public void testCreateSubmissionExceptionDetailsMoreThanMaxLimit()
+      throws Exception {
+
+    String externalLink = "http://somewheresomewheresomewheresomewheresomewheresomewheresomewheresomewheresomewheresomewheresomewheresom"
+        + "ewheresomewheresomewheresomewheresomewher";
+
+    String errorSummary = "RuntimeExceptionRuntimeExceptionRuntimeExceptionRuntimeExceptionRuntimeExceptionRuntimeExceptions"
+        + "RuntimeExceptionRuntimeExceptionRuntimeExceptiontests";
+    String errorDetail = "Yeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah"
+        + " it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it hap"
+        + "pensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYea"
+        + "h it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it ha"
+        + "ppensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah"
+        + " it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happe"
+        + "nsYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happens";
+    MSubmission submission = new MSubmission();
+    submission.setJobId(1);
+    submission.setStatus(SubmissionStatus.RUNNING);
+    submission.setCreationDate(new Date());
+    submission.setLastUpdateDate(new Date());
+    submission.setExternalJobId("job-x");
+    submission.setExternalLink(externalLink + "more than 150");
+    submission.getError().setErrorSummary("RuntimeException");
+    submission.getError().setErrorDetails(errorDetail + "morethan750");
+    submission.getError().setErrorSummary(errorSummary + "morethan150");
+
+    handler.createSubmission(submission, provider.getConnection());
+    List<MSubmission> submissions = handler.findSubmissionsForJob(1,
+        provider.getConnection());
+    assertNotNull(submissions);
+
+    assertEquals(errorDetail, submissions.get(0).getError().getErrorDetails());
+    assertEquals(errorSummary, submissions.get(0).getError().getErrorSummary());
+    assertEquals(externalLink, submissions.get(0).getExternalLink());
+
+  }
+
+  @Test
+  public void testUpdateSubmissionExceptionDetailsMoreThanMaxLimit()
+      throws Exception {
+    loadSubmissions();
+
+    List<MSubmission> submissions = handler.findUnfinishedSubmissions(provider
+        .getConnection());
+    assertNotNull(submissions);
+    assertEquals(1, submissions.size());
+
+    String errorSummary = "RuntimeExceptionRuntimeExceptionRuntimeExceptionRuntimeExceptionRuntimeExceptionRuntimeExceptions"
+        + "RuntimeExceptionRuntimeExceptionRuntimeExceptiontests";
+
+    String errorDetail = "Yeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah"
+        + " it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it hap"
+        + "pensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYea"
+        + "h it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it ha"
+        + "ppensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah"
+        + " it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happe"
+        + "nsYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happensYeah it happens";
+    MSubmission submission = submissions.get(0);
+    String externalLink = submission.getExternalLink();
+    submission.getError().setErrorDetails(errorDetail + "morethan750");
+    submission.getError().setErrorSummary(errorSummary + "morethan150");
+    submission.setExternalLink("cantupdate");
+
+    handler.updateSubmission(submission, provider.getConnection());
+
+    submissions = handler.findUnfinishedSubmissions(provider.getConnection());
+
+    assertNotNull(submissions);
+    assertEquals(errorDetail, submissions.get(0).getError().getErrorDetails());
+    assertEquals(errorSummary, submissions.get(0).getError().getErrorSummary());
+    // note we dont allow external link update
+    assertEquals(externalLink, submissions.get(0).getExternalLink());
+
+  }
+
+  @Test
+  public void testPurgeSubmissions() throws Exception {
+    loadSubmissions();
+    List<MSubmission> submissions;
+
+    submissions = handler.findUnfinishedSubmissions(provider.getConnection());
+    assertNotNull(submissions);
+    assertEquals(1, submissions.size());
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_SUBMISSION")), 4);
+
+    Calendar calendar = Calendar.getInstance();
+    // 2012-01-03 05:05:05
+    calendar.set(2012, Calendar.JANUARY, 3, 5, 5, 5);
+    handler.purgeSubmissions(calendar.getTime(), provider.getConnection());
+
+    submissions = handler.findUnfinishedSubmissions(provider.getConnection());
+    assertNotNull(submissions);
+    assertEquals(1, submissions.size());
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_SUBMISSION")), 4);
+
+    calendar.setTime(new Date());
+    calendar.add(Calendar.DATE, 1);
+    handler.purgeSubmissions(calendar.getTime(), provider.getConnection());
+
+    submissions = handler.findUnfinishedSubmissions(provider.getConnection());
+    assertNotNull(submissions);
+    assertEquals(0, submissions.size());
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_SUBMISSION")), 0);
+
+    handler.purgeSubmissions(new Date(), provider.getConnection());
+
+    submissions = handler.findUnfinishedSubmissions(provider.getConnection());
+    assertNotNull(submissions);
+    assertEquals(0, submissions.size());
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_SUBMISSION")), 0);
+  }
+
+  /**
+   * Test that by directly removing jobs we will also remove associated
+   * submissions and counters.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testDeleteJobs() throws Exception {
+    MJob jobA = handler.findJob(JOB_A_NAME, provider.getConnection());
+    MJob jobB = handler.findJob(JOB_B_NAME, provider.getConnection());
+
+    loadSubmissions();
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_SUBMISSION")), 4);
+
+    handler.deleteJob(jobA.getPersistenceId(), provider.getConnection());
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_SUBMISSION")), 2);
+
+    handler.deleteJob(jobB.getPersistenceId(), provider.getConnection());
+    Assert.assertEquals(
+        provider.rowCount(new TableName("SQOOP", "SQ_SUBMISSION")), 0);
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/668703cf/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index aabefc0..59663fa 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -74,6 +74,11 @@ limitations under the License.
     </dependency>
 
     <dependency>
+      <groupId>org.apache.sqoop.repository</groupId>
+      <artifactId>sqoop-repository-mysql</artifactId>
+    </dependency>
+
+    <dependency>
       <groupId>org.apache.sqoop.connector</groupId>
       <artifactId>sqoop-connector-generic-jdbc</artifactId>
     </dependency>


Mime
View raw message