JobManager implements ModeChangeListener { public synchronized void shutdown() throws StateManagementException { this.validateStateTransition(ManagerState.SHUTDOWN); try { log.info("Shutting down job manager"); if (this.state == ManagerState.RUNNING || this.state == ManagerState.SUSPENDED) { this.dispatcher.shutdown(); this.receiver.shutdown(); if (this.isSchedulerEnabled()) { this.scheduler.shutdown(true); } } log.info("Job manager shut down"); this.state = ManagerState.SHUTDOWN; } catch (Exception e) { String errmsg = "Unexpected exception occurred while shutting down job manager"; log.error(errmsg, e); throw new StateManagementException(this.state, ManagerState.SHUTDOWN, errmsg, e); } } @Inject  JobManager(
        Configuration configuration,
        SchedulerFactory schedulerFactory,
        CandlepinModeManager modeManager,
        AsyncJobStatusCurator jobCurator,
        OwnerCurator ownerCurator,
        JobMessageDispatcher dispatcher,
        JobMessageReceiver receiver,
        PrincipalProvider principalProvider,
        CandlepinRequestScope scope,
        Injector injector); static Class<? extends AsyncJob> registerJob(String jobKey, Class<? extends AsyncJob> jobClass); static Class<? extends AsyncJob> unregisterJob(String jobKey); static Class<? extends AsyncJob> getJobClass(String jobKey); synchronized void initialize(); void start(); synchronized void start(Object key); void resume(); void resume(Object key); void suspend(); synchronized void suspend(Object key); synchronized void shutdown(); synchronized ManagerState getManagerState(); boolean isJobEnabled(String jobKey); boolean isSchedulerEnabled(); AsyncJobStatus findJob(String jobId); List<AsyncJobStatus> findJobs(AsyncJobStatusQueryBuilder queryBuilder); @Transactional AsyncJobStatus queueJob(JobConfig config); AsyncJobStatus executeJob(JobMessage message); @Transactional AsyncJobStatus cancelJob(String jobId); @Transactional int cleanupJobs(AsyncJobStatusQueryBuilder queryBuilder); @Transactional int abortNonTerminalJobs(AsyncJobStatusQueryBuilder queryBuilder); @Override void handleModeChange(CandlepinModeManager modeManager, Mode previousMode, Mode currentMode);  }
@Test public void testManagerCanBeShutdownAfterCreation() { JobManager manager = this.createJobManager(); manager.shutdown(); }
@Test public void testManagerCannotBeInitializedAfterShutdown() { JobManager manager = this.createJobManager(); manager.shutdown(); assertThrows(IllegalStateException.class, manager::initialize); }
@Test public void testManagerCannotBeSuspendedAfterShutdown() { JobManager manager = this.createJobManager(); manager.shutdown(); assertThrows(IllegalStateException.class, manager::suspend); }
@Test public void testManagerCannotBeResumedAfterShutdown() { JobManager manager = this.createJobManager(); manager.shutdown(); assertThrows(IllegalStateException.class, manager::resume); }