@Nullable public TaskDescriptor<IndexCommandResult> getIndexTask(long taskId) { TaskDescriptor<IndexCommandResult> indexingTask = null; final TaskDescriptor<?> task = taskManager.getTask(taskId); if (task != null && task.getTaskContext() instanceof IndexTaskContext) { indexingTask = (TaskDescriptor<IndexCommandResult>) task; } return indexingTask; }
@Nullable public TaskDescriptor<IndexCommandResult> getLastindexTask() { final Collection<TaskDescriptor<?>> indexingTasks = taskManager.findTasks( new TaskMatcher() { @Override public boolean match(final TaskDescriptor<?> descriptor) { return descriptor.getTaskContext() instanceof IndexTaskContext; } }); if (indexingTasks.size() > 0) { return (TaskDescriptor<IndexCommandResult>) byIdOrdering.max(indexingTasks); } else { return null; } }
@Nullable public TaskDescriptor<IndexCommandResult> getActiveIndexTask() { return taskManager.getLiveTask(new IndexTaskContext()); }
@Test public void testExecuteBuildNumberMissing() throws Exception { expect(mockBarrier.await(20, TimeUnit.SECONDS)).andReturn(true); expect(mockBeanFactory.getInstance(currentUser)).andReturn(new MockI18nHelper()).anyTimes(); // called during validation! expect(mockPermissionManager.hasPermission(Permissions.SYSTEM_ADMIN, currentUser)) .andReturn(true); // This is called during the first parse of the XML file. At this stage nothing should have // been created yet! final MockGenericValue mockGv = new MockGenericValue("someentity"); expect(mockOfBizDelegator.makeValue(EasyMock.<String>anyObject())).andReturn(mockGv).anyTimes(); expect(mockAttachmentPathManager.getDefaultAttachmentPath()) .andReturn(directories.get(0).getAbsolutePath()) .anyTimes(); expect(mockIndexPathManager.getDefaultIndexRootPath()) .andReturn(directories.get(1).getAbsolutePath()) .anyTimes(); expect( mockLicenseStringFactory.create( EasyMock.<String>anyObject(), EasyMock.<String>anyObject())) .andStubReturn(""); // after the first parse check the build number. expect(mockBuildUtilsInfo.getCurrentBuildNumber()).andStubReturn("1"); expect(mockBuildUtilsInfo.getMinimumUpgradableBuildNumber()).andStubReturn("0"); // after the first parse we also verify the license is good. expect( mockJiraLicenseService.validate( EasyMock.<I18nHelper>anyObject(), EasyMock.<String>anyObject())) .andStubReturn(mockValidationResult); expect(mockValidationResult.getLicenseVersion()).andStubReturn(2); expect(mockValidationResult.getErrorCollection()).andStubReturn(new SimpleErrorCollection()); // this gets called during shutdownAndFlushAsyncServices. After parse and before the import. // This shuts down // the scheduler expect(mockScheduler.isShutdown()).andReturn(false); mockScheduler.shutdown(); mockMailQueue.sendBuffer(); expect(mockTaskManager.shutdownAndWait(5)).andReturn(true); // Expect AO to be cleared. backup.clear(); // Once the import is running one of the first things to do is to clear out the old database // values. expect(mockOfBizDelegator.getModelReader()).andReturn(mockModelReader); expect(mockModelReader.getEntityNames()) .andReturn(CollectionBuilder.<String>list("Issue", "User")); expect(mockModelReader.getModelEntity("Issue")).andReturn(new ModelEntity()); expect(mockOfBizDelegator.removeByAnd("Issue", Collections.<String, Object>emptyMap())) .andReturn(10); expect(mockModelReader.getModelEntity("User")).andReturn(new ModelEntity()); expect(mockOfBizDelegator.removeByAnd("User", Collections.<String, Object>emptyMap())) .andReturn(5); // then we go through and create all our GVs (already mocked out during the first parse above) // once everything's been imported need to refresh the ofbiz sequencer and check for data // consistency. mockOfBizDelegator.refreshSequencer(); mockConsistencyChecker.checkDataConsistency(); // after the consistency check lets do the upgrade expect(mockUpgradeManager.doUpgradeIfNeededAndAllowed(null)) .andReturn(Collections.<String>emptyList()); // now do a reindex mockIndexManager.deactivate(); expect(mockIndexManager.size()).andReturn(5); expect(mockIndexManager.activate((Context) notNull())).andReturn(1L); // raise the JiraStartedEvent mockPluginEventManager.broadcast(EasyMock.<JiraStartedEvent>anyObject()); // finally we can restart the scheduler! expect( mockScheduler.scheduleJob( EasyMock.<JobDetail>anyObject(), EasyMock.<Trigger>anyObject())) .andReturn(new Date()) .anyTimes(); mockScheduler.start(); final String filePath = getDataFilePath("jira-export-test-no-build-number.xml"); final DataImportParams params = new DataImportParams.Builder(filePath).build(); // Finally everything's mocked out. Run the import! executeTest(params, true, DataImportService.ImportError.NONE); // create() should have been called on our GVs assertTrue(mockGv.isCreated()); // the world should have been rebuilt! assertTrue(((MockDataImportDependencies) mockDependencies).globalRefreshCalled); }