@Test(priority = 3) public void testSearchStoreJob() throws Exception { // Store more jobs with the one user and search XJob job = getTestJob(); long currentTime = System.currentTimeMillis(); SchedulerJobInfo info = new SchedulerJobInfo( SchedulerJobHandle.fromString(UUID.randomUUID().toString()), job, "lens", SchedulerJobState.NEW, currentTime, currentTime); // Store the job schedulerDAO.storeJob(info); info = new SchedulerJobInfo( SchedulerJobHandle.fromString(UUID.randomUUID().toString()), job, "lens", SchedulerJobState.NEW, currentTime, currentTime); schedulerDAO.storeJob(info); // There should be 3 jobs till now. Assert.assertEquals(schedulerDAO.getJobs("lens", null, null, null).size(), 3); Assert.assertEquals( schedulerDAO.getJobs("lens", SchedulerJobState.NEW, 1L, System.currentTimeMillis()).size(), 2); Assert.assertEquals(schedulerDAO.getJobs("Alice", SchedulerJobState.NEW, null, null).size(), 0); }
@Test(priority = 3) public void testUpdateJobInstance() { SchedulerJobInstanceHandle handle = instances.keySet().iterator().next(); SchedulerJobInstanceInfo info = instances.get(handle); SchedulerJobInstanceRun run = info.getInstanceRunList().get(0); run.setInstanceState(SchedulerJobInstanceState.LAUNCHED); schedulerDAO.updateJobInstanceRun(run); // Get the instance Assert.assertEquals(schedulerDAO.getSchedulerJobInstanceInfo(handle), info); }
@Test(priority = 2) public void testStoreInstance() throws Exception { long currentTime = System.currentTimeMillis(); SchedulerJobInstanceHandle instanceHandle = new SchedulerJobInstanceHandle(UUID.randomUUID()); SchedulerJobInstanceInfo firstInstance = new SchedulerJobInstanceInfo( instanceHandle, jobHandle, currentTime, new ArrayList<SchedulerJobInstanceRun>()); SchedulerJobInstanceRun run1 = new SchedulerJobInstanceRun( instanceHandle, 1, new LensSessionHandle(UUID.randomUUID(), UUID.randomUUID()), currentTime, currentTime, "/tmp/", QueryHandle.fromString(UUID.randomUUID().toString()), SchedulerJobInstanceState.WAITING); instances.put(firstInstance.getId(), firstInstance); schedulerDAO.storeJobInstance(firstInstance); schedulerDAO.storeJobInstanceRun(run1); // Put run in the instance firstInstance.getInstanceRunList().add(run1); currentTime = System.currentTimeMillis(); instanceHandle = new SchedulerJobInstanceHandle(UUID.randomUUID()); SchedulerJobInstanceInfo secondInstance = new SchedulerJobInstanceInfo( instanceHandle, jobHandle, currentTime, new ArrayList<SchedulerJobInstanceRun>()); SchedulerJobInstanceRun run2 = new SchedulerJobInstanceRun( instanceHandle, 1, new LensSessionHandle(UUID.randomUUID(), UUID.randomUUID()), currentTime, currentTime, "/tmp/", QueryHandle.fromString(UUID.randomUUID().toString()), SchedulerJobInstanceState.WAITING); instances.put(secondInstance.getId(), secondInstance); schedulerDAO.storeJobInstance(secondInstance); schedulerDAO.storeJobInstanceRun(run2); secondInstance.getInstanceRunList().add(run2); List<SchedulerJobInstanceInfo> handleList = schedulerDAO.getJobInstances(jobHandle); // Size should be 2 Assert.assertEquals(handleList.size(), 2); // Get the definition of instance from the store. SchedulerJobInstanceInfo instance1 = handleList.get(0); Assert.assertEquals(instances.get(handleList.get(0).getId()), instance1); SchedulerJobInstanceInfo instance2 = handleList.get(1); Assert.assertEquals(instances.get(handleList.get(1).getId()), instance2); }
@Test(priority = 1) public void testStoreJob() throws Exception { XJob job = getTestJob(); long currentTime = System.currentTimeMillis(); jobHandle = new SchedulerJobHandle(UUID.randomUUID()); SchedulerJobInfo info = new SchedulerJobInfo( jobHandle, job, "lens", SchedulerJobState.NEW, currentTime, currentTime); // Store the job schedulerDAO.storeJob(info); // Retrive the stored job XJob outJob = schedulerDAO.getJob(info.getId()); Assert.assertEquals(job, outJob); }
@Test(priority = 2) public void testUpdateJob() throws Exception { // Get all the stored jobs. // update one and check if it successful. SchedulerJobInfo jobInfo = schedulerDAO.getSchedulerJobInfo(jobHandle); XJob newJob = getTestJob(); jobInfo.setJob(newJob); schedulerDAO.updateJob(jobInfo); XJob storedJob = schedulerDAO.getJob(jobInfo.getId()); Assert.assertEquals(storedJob, newJob); // Change SchedulerJobInstanceState jobInfo.setJobState(jobInfo.getJobState().nextTransition(SchedulerJobEvent.ON_SCHEDULE)); schedulerDAO.updateJobStatus(jobInfo); Assert.assertEquals(schedulerDAO.getJobState(jobInfo.getId()), SchedulerJobState.SCHEDULED); }