Repository: sqoop Updated Branches: refs/heads/SQOOP-1367 0cfcce5aa -> d7e049043 (forced update)
http://git-wip-us.apache.org/repos/asf/sqoop/blob/51a07bc3/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 2260a45..e658c11 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,7 @@ */ package org.apache.sqoop.repository.derby; +import org.apache.sqoop.common.Direction; import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.model.MForm; import org.apache.sqoop.model.MJob; @@ -32,242 +33,249 @@ import java.util.Map; */ public class TestJobHandling extends DerbyTestCase { -// DerbyRepositoryHandler handler; -// -// @Override -// public void setUp() throws Exception { -// super.setUp(); -// -// handler = new DerbyRepositoryHandler(); -// -// // We always needs schema for this test case -// createSchema(); -// -// // We always needs connector and framework structures in place -// loadConnectorAndFramework(); -// -// // We always needs connection metadata in place -// loadConnections(); -// } -// -// public void testFindJob() throws Exception { -// // Let's try to find non existing job -// try { -// handler.findJob(1, getDerbyConnection()); -// fail(); -// } catch(SqoopException ex) { -// assertEquals(DerbyRepoError.DERBYREPO_0030, ex.getErrorCode()); -// } -// -// // Load prepared connections into database -// loadJobs(); -// -// MJob jobImport = handler.findJob(1, getDerbyConnection()); -// assertNotNull(jobImport); -// assertEquals(1, jobImport.getPersistenceId()); -// assertEquals("JA", jobImport.getName()); -// assertEquals(MJob.Type.IMPORT, jobImport.getType()); -// -// List<MForm> forms; -// -// // Check connector part -// forms = jobImport.getFromPart().getForms(); -// assertEquals("Value5", forms.get(0).getInputs().get(0).getValue()); -// assertNull(forms.get(0).getInputs().get(1).getValue()); -// assertEquals("Value7", forms.get(1).getInputs().get(0).getValue()); -// assertNull(forms.get(1).getInputs().get(1).getValue()); -// -// // Check framework part -// forms = jobImport.getFrameworkPart().getForms(); -// assertEquals("Value17", forms.get(0).getInputs().get(0).getValue()); -// assertNull(forms.get(0).getInputs().get(1).getValue()); -// assertEquals("Value19", forms.get(1).getInputs().get(0).getValue()); -// assertNull(forms.get(1).getInputs().get(1).getValue()); -// } -// -// public void testFindJobs() throws Exception { -// List<MJob> list; -// -// // Load empty list on empty repository -// list = handler.findJobs(getDerbyConnection()); -// assertEquals(0, list.size()); -// -// loadJobs(); -// -// // Load all two connections on loaded repository -// list = handler.findJobs(getDerbyConnection()); -// assertEquals(4, list.size()); -// -// assertEquals("JA", list.get(0).getName()); -// assertEquals(MJob.Type.IMPORT, list.get(0).getType()); -// -// assertEquals("JB", list.get(1).getName()); -// assertEquals(MJob.Type.IMPORT, list.get(1).getType()); -// -// assertEquals("JA", list.get(2).getName()); -// assertEquals(MJob.Type.EXPORT, list.get(2).getType()); -// -// assertEquals("JB", list.get(3).getName()); -// assertEquals(MJob.Type.EXPORT, list.get(3).getType()); -// } -// -// public void testExistsJob() throws Exception { -// // There shouldn't be anything on empty repository -// assertFalse(handler.existsJob(1, getDerbyConnection())); -// assertFalse(handler.existsJob(2, getDerbyConnection())); -// assertFalse(handler.existsJob(3, getDerbyConnection())); -// assertFalse(handler.existsJob(4, getDerbyConnection())); -// assertFalse(handler.existsJob(5, getDerbyConnection())); -// -// loadJobs(); -// -// assertTrue(handler.existsJob(1, getDerbyConnection())); -// assertTrue(handler.existsJob(2, getDerbyConnection())); -// assertTrue(handler.existsJob(3, getDerbyConnection())); -// assertTrue(handler.existsJob(4, getDerbyConnection())); -// assertFalse(handler.existsJob(5, getDerbyConnection())); -// } -// -// public void testInUseJob() throws Exception { -// loadJobs(); -// loadSubmissions(); -// -// assertTrue(handler.inUseJob(1, getDerbyConnection())); -// assertFalse(handler.inUseJob(2, getDerbyConnection())); -// assertFalse(handler.inUseJob(3, getDerbyConnection())); -// assertFalse(handler.inUseJob(4, getDerbyConnection())); -// } -// -// public void testCreateJob() throws Exception { -// MJob job = getJob(); -// -// // Load some data -// fillJob(job); -// -// handler.createJob(job, getDerbyConnection()); -// -// assertEquals(1, job.getPersistenceId()); -// assertCountForTable("SQOOP.SQ_JOB", 1); -// assertCountForTable("SQOOP.SQ_JOB_INPUT", 4); -// -// MJob retrieved = handler.findJob(1, getDerbyConnection()); -// assertEquals(1, retrieved.getPersistenceId()); -// -// List<MForm> forms; -// forms = job.getFromPart().getForms(); -// assertEquals("Value1", forms.get(0).getInputs().get(0).getValue()); -// assertNull(forms.get(0).getInputs().get(1).getValue()); -// assertEquals("Value2", forms.get(1).getInputs().get(0).getValue()); -// assertNull(forms.get(1).getInputs().get(1).getValue()); -// -// forms = job.getFrameworkPart().getForms(); -// assertEquals("Value13", forms.get(0).getInputs().get(0).getValue()); -// assertNull(forms.get(0).getInputs().get(1).getValue()); -// assertEquals("Value15", forms.get(1).getInputs().get(0).getValue()); -// assertNull(forms.get(1).getInputs().get(1).getValue()); -// -// // Let's create second job -// job = getJob(); -// fillJob(job); -// -// handler.createJob(job, getDerbyConnection()); -// -// assertEquals(2, job.getPersistenceId()); -// assertCountForTable("SQOOP.SQ_JOB", 2); -// assertCountForTable("SQOOP.SQ_JOB_INPUT", 8); -// } -// -// public void testUpdateJob() throws Exception { -// loadJobs(); -// -// MJob job = handler.findJob(1, getDerbyConnection()); -// -// List<MForm> forms; -// -// forms = job.getFromPart().getForms(); -// ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Updated"); -// ((MMapInput)forms.get(0).getInputs().get(1)).setValue(null); -// ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Updated"); -// ((MMapInput)forms.get(1).getInputs().get(1)).setValue(null); -// -// forms = job.getFrameworkPart().getForms(); -// ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Updated"); -// ((MMapInput)forms.get(0).getInputs().get(1)).setValue(new HashMap<String, String>()); // inject new map value -// ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Updated"); -// ((MMapInput)forms.get(1).getInputs().get(1)).setValue(new HashMap<String, String>()); // inject new map value -// -// job.setName("name"); -// -// handler.updateJob(job, getDerbyConnection()); -// -// assertEquals(1, job.getPersistenceId()); -// assertCountForTable("SQOOP.SQ_JOB", 4); -// assertCountForTable("SQOOP.SQ_JOB_INPUT", 18); -// -// MJob retrieved = handler.findJob(1, getDerbyConnection()); -// assertEquals("name", retrieved.getName()); -// -// forms = retrieved.getFromPart().getForms(); -// assertEquals("Updated", forms.get(0).getInputs().get(0).getValue()); -// assertNull(forms.get(0).getInputs().get(1).getValue()); -// assertEquals("Updated", forms.get(1).getInputs().get(0).getValue()); -// assertNull(forms.get(1).getInputs().get(1).getValue()); -// -// forms = retrieved.getFrameworkPart().getForms(); -// assertEquals("Updated", forms.get(0).getInputs().get(0).getValue()); -// assertNotNull(forms.get(0).getInputs().get(1).getValue()); -// assertEquals(((Map)forms.get(0).getInputs().get(1).getValue()).size(), 0); -// assertEquals("Updated", forms.get(1).getInputs().get(0).getValue()); -// assertNotNull(forms.get(1).getInputs().get(1).getValue()); -// assertEquals(((Map)forms.get(1).getInputs().get(1).getValue()).size(), 0); -// } -// -// public void testEnableAndDisableJob() throws Exception { -// loadJobs(); -// -// // disable job 1 -// handler.enableJob(1, false, getDerbyConnection()); -// -// MJob retrieved = handler.findJob(1, getDerbyConnection()); -// assertNotNull(retrieved); -// assertEquals(false, retrieved.getEnabled()); -// -// // enable job 1 -// handler.enableJob(1, true, getDerbyConnection()); -// -// retrieved = handler.findJob(1, getDerbyConnection()); -// assertNotNull(retrieved); -// assertEquals(true, retrieved.getEnabled()); -// } -// -// public void testDeleteJob() throws Exception { -// loadJobs(); -// -// handler.deleteJob(1, getDerbyConnection()); -// assertCountForTable("SQOOP.SQ_JOB", 3); -// assertCountForTable("SQOOP.SQ_JOB_INPUT", 12); -// -// handler.deleteJob(2, getDerbyConnection()); -// assertCountForTable("SQOOP.SQ_JOB", 2); -// assertCountForTable("SQOOP.SQ_JOB_INPUT", 8); -// -// handler.deleteJob(3, getDerbyConnection()); -// assertCountForTable("SQOOP.SQ_JOB", 1); -// assertCountForTable("SQOOP.SQ_JOB_INPUT", 4); -// -// handler.deleteJob(4, getDerbyConnection()); -// assertCountForTable("SQOOP.SQ_JOB", 0); -// assertCountForTable("SQOOP.SQ_JOB_INPUT", 0); -// } -// -// public MJob getJob() { -// return new MJob(1, 1, MJob.Type.IMPORT, -// handler.findConnector("A", -// getDerbyConnection()).getJobForms(MJob.Type.IMPORT -// ), -// handler.findFramework( -// getDerbyConnection()).getJobForms(MJob.Type.IMPORT -// ) -// ); -// } + DerbyRepositoryHandler handler; + + @Override + public void setUp() throws Exception { + super.setUp(); + + handler = new DerbyRepositoryHandler(); + + // We always needs schema for this test case + createSchema(); + + // We always needs connector and framework structures in place + loadConnectorAndFramework(); + + // We always needs connection metadata in place + loadConnections(); + } + + public void testFindJob() throws Exception { + // Let's try to find non existing job + try { + handler.findJob(1, getDerbyConnection()); + fail(); + } catch(SqoopException ex) { + assertEquals(DerbyRepoError.DERBYREPO_0030, ex.getErrorCode()); + } + + // Load prepared connections into database + loadJobs(); + + MJob jobImport = handler.findJob(1, getDerbyConnection()); + assertNotNull(jobImport); + assertEquals(1, jobImport.getPersistenceId()); + assertEquals("JA", jobImport.getName()); + + List<MForm> forms; + + // Check connector parts + forms = jobImport.getConnectorPart(Direction.FROM).getForms(); + assertEquals(2, forms.size()); + assertEquals("Value5", forms.get(0).getInputs().get(0).getValue()); + assertNull(forms.get(0).getInputs().get(1).getValue()); + assertEquals("Value5", forms.get(0).getInputs().get(0).getValue()); + assertNull(forms.get(1).getInputs().get(1).getValue()); + + forms = jobImport.getConnectorPart(Direction.TO).getForms(); + assertEquals(2, forms.size()); + assertEquals("Value9", forms.get(0).getInputs().get(0).getValue()); + assertNull(forms.get(0).getInputs().get(1).getValue()); + assertEquals("Value9", forms.get(0).getInputs().get(0).getValue()); + assertNull(forms.get(1).getInputs().get(1).getValue()); + + // Check framework part + forms = jobImport.getFrameworkPart().getForms(); + assertEquals(2, forms.size()); + assertEquals("Value17", forms.get(0).getInputs().get(0).getValue()); + assertNull(forms.get(0).getInputs().get(1).getValue()); + assertEquals("Value19", forms.get(1).getInputs().get(0).getValue()); + assertNull(forms.get(1).getInputs().get(1).getValue()); + } + + public void testFindJobs() throws Exception { + List<MJob> list; + + // Load empty list on empty repository + list = handler.findJobs(getDerbyConnection()); + assertEquals(0, list.size()); + + loadJobs(); + + // Load all two connections on loaded repository + list = handler.findJobs(getDerbyConnection()); + assertEquals(4, list.size()); + + assertEquals("JA", list.get(0).getName()); + + assertEquals("JB", list.get(1).getName()); + + assertEquals("JC", list.get(2).getName()); + + assertEquals("JD", list.get(3).getName()); + } + + public void testExistsJob() throws Exception { + // There shouldn't be anything on empty repository + assertFalse(handler.existsJob(1, getDerbyConnection())); + assertFalse(handler.existsJob(2, getDerbyConnection())); + assertFalse(handler.existsJob(3, getDerbyConnection())); + assertFalse(handler.existsJob(4, getDerbyConnection())); + assertFalse(handler.existsJob(5, getDerbyConnection())); + + loadJobs(); + + assertTrue(handler.existsJob(1, getDerbyConnection())); + assertTrue(handler.existsJob(2, getDerbyConnection())); + assertTrue(handler.existsJob(3, getDerbyConnection())); + assertTrue(handler.existsJob(4, getDerbyConnection())); + assertFalse(handler.existsJob(5, getDerbyConnection())); + } + + public void testInUseJob() throws Exception { + loadJobs(); + loadSubmissions(); + + assertTrue(handler.inUseJob(1, getDerbyConnection())); + assertFalse(handler.inUseJob(2, getDerbyConnection())); + assertFalse(handler.inUseJob(3, getDerbyConnection())); + assertFalse(handler.inUseJob(4, getDerbyConnection())); + } + + public void testCreateJob() throws Exception { + MJob job = getJob(); + + // Load some data + fillJob(job); + + handler.createJob(job, getDerbyConnection()); + + assertEquals(1, job.getPersistenceId()); + assertCountForTable("SQOOP.SQ_JOB", 1); + assertCountForTable("SQOOP.SQ_JOB_INPUT", 6); + + MJob retrieved = handler.findJob(1, getDerbyConnection()); + assertEquals(1, retrieved.getPersistenceId()); + + List<MForm> forms; + forms = job.getConnectorPart(Direction.FROM).getForms(); + assertEquals("Value1", forms.get(0).getInputs().get(0).getValue()); + assertNull(forms.get(0).getInputs().get(1).getValue()); + forms = job.getConnectorPart(Direction.TO).getForms(); + assertEquals("Value1", forms.get(0).getInputs().get(0).getValue()); + assertNull(forms.get(0).getInputs().get(1).getValue()); + + forms = job.getFrameworkPart().getForms(); + assertEquals("Value13", forms.get(0).getInputs().get(0).getValue()); + assertNull(forms.get(0).getInputs().get(1).getValue()); + assertEquals("Value15", forms.get(1).getInputs().get(0).getValue()); + assertNull(forms.get(1).getInputs().get(1).getValue()); + + // Let's create second job + job = getJob(); + fillJob(job); + + handler.createJob(job, getDerbyConnection()); + + assertEquals(2, job.getPersistenceId()); + assertCountForTable("SQOOP.SQ_JOB", 2); + assertCountForTable("SQOOP.SQ_JOB_INPUT", 12); + } + + public void testUpdateJob() throws Exception { + loadJobs(); + + assertCountForTable("SQOOP.SQ_JOB", 4); + assertCountForTable("SQOOP.SQ_JOB_INPUT", 24); + + MJob job = handler.findJob(1, getDerbyConnection()); + + List<MForm> forms; + + forms = job.getConnectorPart(Direction.FROM).getForms(); + ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Updated"); + ((MMapInput)forms.get(0).getInputs().get(1)).setValue(null); + forms = job.getConnectorPart(Direction.TO).getForms(); + ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Updated"); + ((MMapInput)forms.get(0).getInputs().get(1)).setValue(null); + + forms = job.getFrameworkPart().getForms(); + ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Updated"); + ((MMapInput)forms.get(0).getInputs().get(1)).setValue(new HashMap<String, String>()); // inject new map value + ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Updated"); + ((MMapInput)forms.get(1).getInputs().get(1)).setValue(new HashMap<String, String>()); // inject new map value + + job.setName("name"); + + handler.updateJob(job, getDerbyConnection()); + + assertEquals(1, job.getPersistenceId()); + assertCountForTable("SQOOP.SQ_JOB", 4); + assertCountForTable("SQOOP.SQ_JOB_INPUT", 26); + + MJob retrieved = handler.findJob(1, getDerbyConnection()); + assertEquals("name", retrieved.getName()); + + forms = job.getConnectorPart(Direction.FROM).getForms(); + assertEquals(2, forms.size()); + assertEquals("Updated", forms.get(0).getInputs().get(0).getValue()); + assertNull(forms.get(0).getInputs().get(1).getValue()); + forms = job.getConnectorPart(Direction.TO).getForms(); + assertEquals(2, forms.size()); + assertEquals("Updated", forms.get(0).getInputs().get(0).getValue()); + assertNull(forms.get(0).getInputs().get(1).getValue()); + + forms = retrieved.getFrameworkPart().getForms(); + assertEquals(2, forms.size()); + assertEquals("Updated", forms.get(0).getInputs().get(0).getValue()); + assertNotNull(forms.get(0).getInputs().get(1).getValue()); + assertEquals(((Map)forms.get(0).getInputs().get(1).getValue()).size(), 0); + } + + public void testEnableAndDisableJob() throws Exception { + loadJobs(); + + // disable job 1 + handler.enableJob(1, false, getDerbyConnection()); + + MJob retrieved = handler.findJob(1, getDerbyConnection()); + assertNotNull(retrieved); + assertEquals(false, retrieved.getEnabled()); + + // enable job 1 + handler.enableJob(1, true, getDerbyConnection()); + + retrieved = handler.findJob(1, getDerbyConnection()); + assertNotNull(retrieved); + assertEquals(true, retrieved.getEnabled()); + } + + public void testDeleteJob() throws Exception { + loadJobs(); + + handler.deleteJob(1, getDerbyConnection()); + assertCountForTable("SQOOP.SQ_JOB", 3); + assertCountForTable("SQOOP.SQ_JOB_INPUT", 18); + + handler.deleteJob(2, getDerbyConnection()); + assertCountForTable("SQOOP.SQ_JOB", 2); + assertCountForTable("SQOOP.SQ_JOB_INPUT", 12); + + handler.deleteJob(3, getDerbyConnection()); + assertCountForTable("SQOOP.SQ_JOB", 1); + assertCountForTable("SQOOP.SQ_JOB_INPUT", 6); + + handler.deleteJob(4, getDerbyConnection()); + assertCountForTable("SQOOP.SQ_JOB", 0); + assertCountForTable("SQOOP.SQ_JOB_INPUT", 0); + } + + public MJob getJob() { + return new MJob(1, 1, 1, 1, + handler.findConnector("A", getDerbyConnection()).getJobForms(Direction.FROM), + handler.findConnector("A", getDerbyConnection()).getJobForms(Direction.TO), + handler.findFramework(getDerbyConnection()).getJobForms() + ); + } } http://git-wip-us.apache.org/repos/asf/sqoop/blob/51a07bc3/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 8cfe076..8fce0dd 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 @@ -32,214 +32,214 @@ import java.util.List; */ public class TestSubmissionHandling extends DerbyTestCase { -// DerbyRepositoryHandler handler; -// -// @Override -// public void setUp() throws Exception { -// super.setUp(); -// -// handler = new DerbyRepositoryHandler(); -// -// // We always needs schema for this test case -// createSchema(); -// -// // We always needs connector and framework structures in place -// loadConnectorAndFramework(); -// -// // We also always needs connection metadata in place -// loadConnections(); -// -// // And finally we always needs job metadata in place -// loadJobs(); -// } -// -// public void testFindSubmissionsUnfinished() throws Exception { -// List<MSubmission> submissions; -// -// submissions = handler.findSubmissionsUnfinished(getDerbyConnection()); -// assertNotNull(submissions); -// assertEquals(0, submissions.size()); -// -// loadSubmissions(); -// -// submissions = handler.findSubmissionsUnfinished(getDerbyConnection()); -// assertNotNull(submissions); -// assertEquals(2, submissions.size()); -// } -// -// public void testExistsSubmission() throws Exception { -// // There shouldn't be anything on empty repository -// assertFalse(handler.existsSubmission(1, getDerbyConnection())); -// assertFalse(handler.existsSubmission(2, getDerbyConnection())); -// assertFalse(handler.existsSubmission(3, getDerbyConnection())); -// assertFalse(handler.existsSubmission(4, getDerbyConnection())); -// assertFalse(handler.existsSubmission(5, getDerbyConnection())); -// assertFalse(handler.existsSubmission(6, getDerbyConnection())); -// -// loadSubmissions(); -// -// assertTrue(handler.existsSubmission(1, getDerbyConnection())); -// assertTrue(handler.existsSubmission(2, getDerbyConnection())); -// assertTrue(handler.existsSubmission(3, getDerbyConnection())); -// assertTrue(handler.existsSubmission(4, getDerbyConnection())); -// assertTrue(handler.existsSubmission(5, getDerbyConnection())); -// assertFalse(handler.existsSubmission(6, getDerbyConnection())); -// } -// -// 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); -// -// MSubmission submission = new MSubmission(); -// submission.setJobId(1); -// submission.setStatus(SubmissionStatus.RUNNING); -// submission.setCreationDate(creationDate); -// submission.setLastUpdateDate(updateDate); -// submission.setExternalId("job-x"); -// submission.setExternalLink("http://somewhere"); -// submission.setExceptionInfo("RuntimeException"); -// submission.setExceptionStackTrace("Yeah it happens"); -// submission.setCounters(counters); -// -// handler.createSubmission(submission, getDerbyConnection()); -// -// assertEquals(1, submission.getPersistenceId()); -// assertCountForTable("SQOOP.SQ_SUBMISSION", 1); -// -// List<MSubmission> submissions = -// handler.findSubmissionsUnfinished(getDerbyConnection()); -// assertNotNull(submissions); -// assertEquals(1, submissions.size()); -// -// submission = submissions.get(0); -// -// assertEquals(1, submission.getJobId()); -// assertEquals(SubmissionStatus.RUNNING, submission.getStatus()); -// assertEquals(creationDate, submission.getCreationDate()); -// assertEquals(updateDate, submission.getLastUpdateDate()); -// assertEquals("job-x", submission.getExternalId()); -// assertEquals("http://somewhere", submission.getExternalLink()); -// assertEquals("RuntimeException", submission.getExceptionInfo()); -// assertEquals("Yeah it happens", submission.getExceptionStackTrace()); -// -// 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()); -// -// // Let's create second (simpler) connection -// submission = -// new MSubmission(1, new Date(), SubmissionStatus.SUCCEEDED, "job-x"); -// handler.createSubmission(submission, getDerbyConnection()); -// -// assertEquals(2, submission.getPersistenceId()); -// assertCountForTable("SQOOP.SQ_SUBMISSION", 2); -// } -// -// public void testUpdateConnection() throws Exception { -// loadSubmissions(); -// -// List<MSubmission> submissions = -// handler.findSubmissionsUnfinished(getDerbyConnection()); -// assertNotNull(submissions); -// assertEquals(2, submissions.size()); -// -// MSubmission submission = submissions.get(0); -// submission.setStatus(SubmissionStatus.SUCCEEDED); -// -// handler.updateSubmission(submission, getDerbyConnection()); -// -// submissions = handler.findSubmissionsUnfinished(getDerbyConnection()); -// assertNotNull(submissions); -// assertEquals(1, submissions.size()); -// } -// -// public void testPurgeSubmissions() throws Exception { -// loadSubmissions(); -// List<MSubmission> submissions; -// -// submissions = handler.findSubmissionsUnfinished(getDerbyConnection()); -// assertNotNull(submissions); -// assertEquals(2, submissions.size()); -// assertCountForTable("SQOOP.SQ_SUBMISSION", 5); -// -// Calendar calendar = Calendar.getInstance(); -// // 2012-01-03 05:05:05 -// calendar.set(2012, Calendar.JANUARY, 3, 5, 5, 5); -// handler.purgeSubmissions(calendar.getTime(), getDerbyConnection()); -// -// submissions = handler.findSubmissionsUnfinished(getDerbyConnection()); -// assertNotNull(submissions); -// assertEquals(1, submissions.size()); -// assertCountForTable("SQOOP.SQ_SUBMISSION", 2); -// -// handler.purgeSubmissions(new Date(), getDerbyConnection()); -// -// submissions = handler.findSubmissionsUnfinished(getDerbyConnection()); -// assertNotNull(submissions); -// assertEquals(0, submissions.size()); -// assertCountForTable("SQOOP.SQ_SUBMISSION", 0); -// -// handler.purgeSubmissions(new Date(), getDerbyConnection()); -// -// submissions = handler.findSubmissionsUnfinished(getDerbyConnection()); -// assertNotNull(submissions); -// assertEquals(0, submissions.size()); -// assertCountForTable("SQOOP.SQ_SUBMISSION", 0); -// } -// -// /** -// * Test that by directly removing jobs we will also remove associated -// * submissions and counters. -// * -// * @throws Exception -// */ -// public void testDeleteJobs() throws Exception { -// loadSubmissions(); -// assertCountForTable("SQOOP.SQ_SUBMISSION", 5); -// -// handler.deleteJob(1, getDerbyConnection()); -// assertCountForTable("SQOOP.SQ_SUBMISSION", 3); -// -// handler.deleteJob(2, getDerbyConnection()); -// assertCountForTable("SQOOP.SQ_SUBMISSION", 2); -// -// handler.deleteJob(3, getDerbyConnection()); -// assertCountForTable("SQOOP.SQ_SUBMISSION", 1); -// -// handler.deleteJob(4, getDerbyConnection()); -// assertCountForTable("SQOOP.SQ_SUBMISSION", 0); -// } + DerbyRepositoryHandler handler; + + @Override + public void setUp() throws Exception { + super.setUp(); + + handler = new DerbyRepositoryHandler(); + + // We always needs schema for this test case + createSchema(); + + // We always needs connector and framework structures in place + loadConnectorAndFramework(); + + // We also always needs connection metadata in place + loadConnections(); + + // And finally we always needs job metadata in place + loadJobs(); + } + + public void testFindSubmissionsUnfinished() throws Exception { + List<MSubmission> submissions; + + submissions = handler.findSubmissionsUnfinished(getDerbyConnection()); + assertNotNull(submissions); + assertEquals(0, submissions.size()); + + loadSubmissions(); + + submissions = handler.findSubmissionsUnfinished(getDerbyConnection()); + assertNotNull(submissions); + assertEquals(2, submissions.size()); + } + + public void testExistsSubmission() throws Exception { + // There shouldn't be anything on empty repository + assertFalse(handler.existsSubmission(1, getDerbyConnection())); + assertFalse(handler.existsSubmission(2, getDerbyConnection())); + assertFalse(handler.existsSubmission(3, getDerbyConnection())); + assertFalse(handler.existsSubmission(4, getDerbyConnection())); + assertFalse(handler.existsSubmission(5, getDerbyConnection())); + assertFalse(handler.existsSubmission(6, getDerbyConnection())); + + loadSubmissions(); + + assertTrue(handler.existsSubmission(1, getDerbyConnection())); + assertTrue(handler.existsSubmission(2, getDerbyConnection())); + assertTrue(handler.existsSubmission(3, getDerbyConnection())); + assertTrue(handler.existsSubmission(4, getDerbyConnection())); + assertTrue(handler.existsSubmission(5, getDerbyConnection())); + assertFalse(handler.existsSubmission(6, getDerbyConnection())); + } + + 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); + + MSubmission submission = new MSubmission(); + submission.setJobId(1); + submission.setStatus(SubmissionStatus.RUNNING); + submission.setCreationDate(creationDate); + submission.setLastUpdateDate(updateDate); + submission.setExternalId("job-x"); + submission.setExternalLink("http://somewhere"); + submission.setExceptionInfo("RuntimeException"); + submission.setExceptionStackTrace("Yeah it happens"); + submission.setCounters(counters); + + handler.createSubmission(submission, getDerbyConnection()); + + assertEquals(1, submission.getPersistenceId()); + assertCountForTable("SQOOP.SQ_SUBMISSION", 1); + + List<MSubmission> submissions = + handler.findSubmissionsUnfinished(getDerbyConnection()); + assertNotNull(submissions); + assertEquals(1, submissions.size()); + + submission = submissions.get(0); + + assertEquals(1, submission.getJobId()); + assertEquals(SubmissionStatus.RUNNING, submission.getStatus()); + assertEquals(creationDate, submission.getCreationDate()); + assertEquals(updateDate, submission.getLastUpdateDate()); + assertEquals("job-x", submission.getExternalId()); + assertEquals("http://somewhere", submission.getExternalLink()); + assertEquals("RuntimeException", submission.getExceptionInfo()); + assertEquals("Yeah it happens", submission.getExceptionStackTrace()); + + 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()); + + // Let's create second (simpler) connection + submission = + new MSubmission(1, new Date(), SubmissionStatus.SUCCEEDED, "job-x"); + handler.createSubmission(submission, getDerbyConnection()); + + assertEquals(2, submission.getPersistenceId()); + assertCountForTable("SQOOP.SQ_SUBMISSION", 2); + } + + public void testUpdateConnection() throws Exception { + loadSubmissions(); + + List<MSubmission> submissions = + handler.findSubmissionsUnfinished(getDerbyConnection()); + assertNotNull(submissions); + assertEquals(2, submissions.size()); + + MSubmission submission = submissions.get(0); + submission.setStatus(SubmissionStatus.SUCCEEDED); + + handler.updateSubmission(submission, getDerbyConnection()); + + submissions = handler.findSubmissionsUnfinished(getDerbyConnection()); + assertNotNull(submissions); + assertEquals(1, submissions.size()); + } + + public void testPurgeSubmissions() throws Exception { + loadSubmissions(); + List<MSubmission> submissions; + + submissions = handler.findSubmissionsUnfinished(getDerbyConnection()); + assertNotNull(submissions); + assertEquals(2, submissions.size()); + assertCountForTable("SQOOP.SQ_SUBMISSION", 5); + + Calendar calendar = Calendar.getInstance(); + // 2012-01-03 05:05:05 + calendar.set(2012, Calendar.JANUARY, 3, 5, 5, 5); + handler.purgeSubmissions(calendar.getTime(), getDerbyConnection()); + + submissions = handler.findSubmissionsUnfinished(getDerbyConnection()); + assertNotNull(submissions); + assertEquals(1, submissions.size()); + assertCountForTable("SQOOP.SQ_SUBMISSION", 2); + + handler.purgeSubmissions(new Date(), getDerbyConnection()); + + submissions = handler.findSubmissionsUnfinished(getDerbyConnection()); + assertNotNull(submissions); + assertEquals(0, submissions.size()); + assertCountForTable("SQOOP.SQ_SUBMISSION", 0); + + handler.purgeSubmissions(new Date(), getDerbyConnection()); + + submissions = handler.findSubmissionsUnfinished(getDerbyConnection()); + assertNotNull(submissions); + assertEquals(0, submissions.size()); + assertCountForTable("SQOOP.SQ_SUBMISSION", 0); + } + + /** + * Test that by directly removing jobs we will also remove associated + * submissions and counters. + * + * @throws Exception + */ + public void testDeleteJobs() throws Exception { + loadSubmissions(); + assertCountForTable("SQOOP.SQ_SUBMISSION", 5); + + handler.deleteJob(1, getDerbyConnection()); + assertCountForTable("SQOOP.SQ_SUBMISSION", 3); + + handler.deleteJob(2, getDerbyConnection()); + assertCountForTable("SQOOP.SQ_SUBMISSION", 2); + + handler.deleteJob(3, getDerbyConnection()); + assertCountForTable("SQOOP.SQ_SUBMISSION", 1); + + handler.deleteJob(4, getDerbyConnection()); + assertCountForTable("SQOOP.SQ_SUBMISSION", 0); + } } http://git-wip-us.apache.org/repos/asf/sqoop/blob/51a07bc3/spi/src/main/java/org/apache/sqoop/connector/spi/MetadataUpgrader.java ---------------------------------------------------------------------- diff --git a/spi/src/main/java/org/apache/sqoop/connector/spi/MetadataUpgrader.java b/spi/src/main/java/org/apache/sqoop/connector/spi/MetadataUpgrader.java index d840a78..328f9b0 100644 --- a/spi/src/main/java/org/apache/sqoop/connector/spi/MetadataUpgrader.java +++ b/spi/src/main/java/org/apache/sqoop/connector/spi/MetadataUpgrader.java @@ -18,9 +18,7 @@ */ package org.apache.sqoop.connector.spi; -import org.apache.sqoop.model.MConnection; import org.apache.sqoop.model.MConnectionForms; -import org.apache.sqoop.model.MJob; import org.apache.sqoop.model.MJobForms; public abstract class MetadataUpgrader { @@ -45,3 +43,4 @@ public abstract class MetadataUpgrader { */ public abstract void upgrade(MJobForms original, MJobForms upgradeTarget); } +