Repository: sqoop Updated Branches: refs/heads/sqoop2 b345b4654 -> 6ae93e6ad
http://git-wip-us.apache.org/repos/asf/sqoop/blob/6ae93e6a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java ---------------------------------------------------------------------- diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java index 01a05b2..a15bda9 100644 --- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java +++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestJobHandling.java @@ -17,6 +17,13 @@ */ package org.apache.sqoop.repository.derby; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.sql.Connection; import java.util.HashMap; import java.util.List; @@ -31,8 +38,6 @@ import org.apache.sqoop.model.MStringInput; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.*; - /** * Test job methods on Derby repository. */ @@ -44,17 +49,12 @@ public class TestJobHandling extends DerbyTestCase { @Before public void setUp() throws Exception { super.setUp(); - derbyConnection = getDerbyDatabaseConnection(); handler = new DerbyRepositoryHandler(); - - // We always needs schema for this test case - createSchema(); - - loadConnectorLinkConfig(); - - // We always needs connection metadata in place - loadLinks(); + // We always needs create/ upgrade schema for this test case + createOrUpgradeSchemaForLatestVersion(); + loadConnectorAndDriverConfig(); + loadLinksForLatestVersion(); } @Test @@ -67,7 +67,7 @@ public class TestJobHandling extends DerbyTestCase { assertEquals(DerbyRepoError.DERBYREPO_0030, ex.getErrorCode()); } - loadJobs(); + loadJobsForLatestVersion(); MJob firstJob = handler.findJob(1, derbyConnection); assertNotNull(firstJob); @@ -104,7 +104,7 @@ public class TestJobHandling extends DerbyTestCase { // Load empty list on empty repository list = handler.findJobs(derbyConnection); assertEquals(0, list.size()); - loadJobs(); + loadJobsForLatestVersion(); // Load all two connections on loaded repository list = handler.findJobs(derbyConnection); @@ -128,7 +128,7 @@ public class TestJobHandling extends DerbyTestCase { assertFalse(handler.existsJob(4, derbyConnection)); assertFalse(handler.existsJob(5, derbyConnection)); - loadJobs(); + loadJobsForLatestVersion(); assertTrue(handler.existsJob(1, derbyConnection)); assertTrue(handler.existsJob(2, derbyConnection)); @@ -139,7 +139,7 @@ public class TestJobHandling extends DerbyTestCase { @Test public void testInUseJob() throws Exception { - loadJobs(); + loadJobsForLatestVersion(); loadSubmissions(); assertTrue(handler.inUseJob(1, derbyConnection)); @@ -204,7 +204,7 @@ public class TestJobHandling extends DerbyTestCase { @Test public void testUpdateJob() throws Exception { - loadJobs(); + loadJobsForLatestVersion(); assertCountForTable("SQOOP.SQ_JOB", 4); assertCountForTable("SQOOP.SQ_JOB_INPUT", 24); @@ -256,7 +256,7 @@ public class TestJobHandling extends DerbyTestCase { @Test public void testEnableAndDisableJob() throws Exception { - loadJobs(); + loadJobsForLatestVersion(); // disable job 1 handler.enableJob(1, false, derbyConnection); @@ -275,7 +275,7 @@ public class TestJobHandling extends DerbyTestCase { @Test public void testDeleteJob() throws Exception { - loadJobs(); + loadJobsForLatestVersion(); handler.deleteJob(1, derbyConnection); assertCountForTable("SQOOP.SQ_JOB", 3); @@ -301,4 +301,4 @@ public class TestJobHandling extends DerbyTestCase { handler.findDriver(derbyConnection).getDriverConfig() ); } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/sqoop/blob/6ae93e6a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestLinkHandling.java ---------------------------------------------------------------------- diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestLinkHandling.java b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestLinkHandling.java index bbfe5bb..37343d3 100644 --- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestLinkHandling.java +++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestLinkHandling.java @@ -17,6 +17,13 @@ */ package org.apache.sqoop.repository.derby; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.util.List; import org.apache.sqoop.common.SqoopException; @@ -27,12 +34,6 @@ import org.apache.sqoop.model.MStringInput; import org.junit.Before; import org.junit.Test; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.*; - /** * Test link methods on Derby repository. */ @@ -45,12 +46,10 @@ public class TestLinkHandling extends DerbyTestCase { super.setUp(); handler = new DerbyRepositoryHandler(); - // We always needs schema for this test case - createSchema(); - + createOrUpgradeSchemaForLatestVersion(); // We always needs connector and framework structures in place - loadConnectorLinkConfig(); + loadConnectorAndDriverConfig(); } @Test @@ -64,7 +63,7 @@ public class TestLinkHandling extends DerbyTestCase { } // Load prepared connections into database - loadLinks(); + loadLinksForLatestVersion(); MLink linkA = handler.findLink(1, getDerbyDatabaseConnection()); assertNotNull(linkA); @@ -89,7 +88,7 @@ public class TestLinkHandling extends DerbyTestCase { list = handler.findLinks(getDerbyDatabaseConnection()); assertEquals(0, list.size()); - loadLinks(); + loadLinksForLatestVersion(); // Load all two connections on loaded repository list = handler.findLinks(getDerbyDatabaseConnection()); @@ -106,7 +105,7 @@ public class TestLinkHandling extends DerbyTestCase { assertFalse(handler.existsLink(2, getDerbyDatabaseConnection())); assertFalse(handler.existsLink(3, getDerbyDatabaseConnection())); - loadLinks(); + loadLinksForLatestVersion(); assertTrue(handler.existsLink(1, getDerbyDatabaseConnection())); assertTrue(handler.existsLink(2, getDerbyDatabaseConnection())); @@ -161,18 +160,18 @@ public class TestLinkHandling extends DerbyTestCase { @Test public void testInUseLink() throws Exception { - loadLinks(); + loadLinksForLatestVersion(); assertFalse(handler.inUseLink(1, getDerbyDatabaseConnection())); - loadJobs(); + loadJobsForLatestVersion(); assertTrue(handler.inUseLink(1, getDerbyDatabaseConnection())); } @Test public void testUpdateLink() throws Exception { - loadLinks(); + loadLinksForLatestVersion(); MLink link = handler.findLink(1, getDerbyDatabaseConnection()); @@ -204,7 +203,7 @@ public class TestLinkHandling extends DerbyTestCase { @Test public void testEnableAndDisableLink() throws Exception { - loadLinks(); + loadLinksForLatestVersion(); // disable link 1 handler.enableLink(1, false, getDerbyDatabaseConnection()); @@ -223,7 +222,7 @@ public class TestLinkHandling extends DerbyTestCase { @Test public void testDeleteLink() throws Exception { - loadLinks(); + loadLinksForLatestVersion(); handler.deleteLink(1, getDerbyDatabaseConnection()); assertCountForTable("SQOOP.SQ_LINK", 1); http://git-wip-us.apache.org/repos/asf/sqoop/blob/6ae93e6a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestRespositorySchemaUpgrade.java ---------------------------------------------------------------------- diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestRespositorySchemaUpgrade.java b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestRespositorySchemaUpgrade.java new file mode 100644 index 0000000..d4c4009 --- /dev/null +++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestRespositorySchemaUpgrade.java @@ -0,0 +1,104 @@ +/** + * 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.derby; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.sql.Connection; + +import org.apache.sqoop.common.SqoopException; +import org.junit.Before; +import org.junit.Test; + +public class TestRespositorySchemaUpgrade extends DerbyTestCase { + + DerbyRepositoryHandler handler; + + @Before + public void setUp() throws Exception { + super.setUp(); + handler = new TestDerbyRepositoryHandler(); + } + + @Test + public void testHasLatestRepositoryVersion() throws Exception { + assertFalse(handler.isRespositorySuitableForUse(getDerbyDatabaseConnection())); + createOrUpgradeSchemaForLatestVersion(); // Test code is building the structures + assertTrue(handler.isRespositorySuitableForUse(getDerbyDatabaseConnection())); + } + + @Test + public void testCreateorUpdateRepositorySchema() throws Exception { + assertFalse(handler.isRespositorySuitableForUse(getDerbyDatabaseConnection())); + handler.createOrUpgradeRepository(getDerbyDatabaseConnection()); + assertTrue(handler.isRespositorySuitableForUse(getDerbyDatabaseConnection())); + } + + // TODO(VB): This should really test for a specific SQL exception that violates the constraints + @Test(expected=SqoopException.class) + public void testUpgradeVersion4WithLinkNameAndJobNameDuplicateFailure() throws Exception { + super.createOrUpgradeSchema(4); + super.loadConnectorAndDriverConfig(4); + super.loadConnectionsOrLinks(4); + super.loadJobs(4); + // no removing of dupes for job name and link names, hence there should be a exception due to the unique name constraint + handler.createOrUpgradeRepository(getDerbyDatabaseConnection()); + assertTrue(handler.isRespositorySuitableForUse(getDerbyDatabaseConnection())); + } + // TODO: VB: follow up with the constraint code, which really does not test with examples that has + // duplicate names, the id list is always of size 1 + //@Test + public void testUpgradeVersion4WithLinkNameAndJobNameWithNoDuplication() throws Exception { + super.createOrUpgradeSchema(4); + super.loadConnectorAndDriverConfig(4); + super.loadConnectionsOrLinks(4); + super.loadJobs(4); + super.removeDuplicateLinkNames(4); + super.removeDuplicateJobNames(4); + // removing duplicate job name and link name, hence there should be no exception with unique name constraint + handler.createOrUpgradeRepository(getDerbyDatabaseConnection()); + assertTrue(handler.isRespositorySuitableForUse(getDerbyDatabaseConnection())); + } + + @Test + public void testUpgradeRepoVersion2ToVersion4() throws Exception { + super.createOrUpgradeSchema(2); + assertFalse(handler.isRespositorySuitableForUse(getDerbyDatabaseConnection())); + loadConnectorAndDriverConfig(2); + super.loadConnectionsOrLinks(2); + super.loadJobs(2); + super.removeDuplicateLinkNames(2); + super.removeDuplicateJobNames(2); + // in case of version 2 schema there is no unique job/ link constraint + handler.createOrUpgradeRepository(getDerbyDatabaseConnection()); + assertTrue(handler.isRespositorySuitableForUse(getDerbyDatabaseConnection())); + } + + private class TestDerbyRepositoryHandler extends DerbyRepositoryHandler { + protected long registerHdfsConnector(Connection conn) { + try { + runQuery("INSERT INTO SQOOP.SQ_CONNECTOR(SQC_NAME, SQC_CLASS, SQC_VERSION)" + + "VALUES('hdfs-connector', 'org.apache.sqoop.test.B', '1.0-test')"); + return 2L; + } catch(Exception e) { + return -1L; + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/sqoop/blob/6ae93e6a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestSubmissionHandling.java ---------------------------------------------------------------------- diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestSubmissionHandling.java b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestSubmissionHandling.java index 8402d8c..4c2d062 100644 --- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestSubmissionHandling.java +++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestSubmissionHandling.java @@ -43,18 +43,17 @@ public class TestSubmissionHandling extends DerbyTestCase { super.setUp(); handler = new DerbyRepositoryHandler(); - // We always needs schema for this test case - createSchema(); + super.createOrUpgradeSchemaForLatestVersion(); // We always needs connector and framework structures in place - loadConnectorLinkConfig(); + loadConnectorAndDriverConfig(); // We also always needs connection metadata in place - loadLinks(); + loadLinksForLatestVersion(); // And finally we always needs job metadata in place - loadJobs(); + loadJobsForLatestVersion(); } @Test @@ -252,4 +251,4 @@ public class TestSubmissionHandling extends DerbyTestCase { handler.deleteJob(4, getDerbyDatabaseConnection()); assertCountForTable("SQOOP.SQ_SUBMISSION", 0); } -} +} \ No newline at end of file
