SyncOptimizeManager { public void start(final SyncOptimizeManagerResultCallBack callback) { if (isRunning()) { throw new IllegalStateException( "The start() method cannot be called when the sync optimize process is running."); } running = true; new Thread(new Runnable() { public void run() { SyncOptimizeManager.this.reset(); SyncOptimizeConfig config = new SyncOptimizeConfig(); DuracloudConfiguration duracloudConfig = syncConfigurationManager.retrieveDuracloudConfiguration(); config.setHost(duracloudConfig.getHost()); config.setPort(duracloudConfig.getPort()); config.setNumFiles(10); config.setSizeFiles(5); config.setSpaceId(duracloudConfig.getSpaceId()); config.setUsername(duracloudConfig.getUsername()); config.setPassword(duracloudConfig.getPassword()); config.setContext(SyncOptimizeConfigParser.DEFAULT_CONTEXT); try { int threadCount = syncOptimizeDriver.getOptimalThreads(config); syncConfigurationManager.setThreadCount(threadCount); status = MessageFormat.format("The optimizer last ran to completion at {0}. " + "The optimal thread count under the prevailing system conditions at that" + " time was {1}. " + " The system has been updated with the new thread count.", new Date(), threadCount); running = false; try { callback.onSuccess(); } catch (Exception e) { log.error(e.getMessage()); } } catch (Exception e) { log.error(e.getMessage(), e); status = "The optimizer failed: " + e.getMessage() + ". Please try again or contact DuraCloud support."; failed = true; running = false; callback.onFailure(e, status); } } }).start(); } SyncOptimizeManager(
        SyncConfigurationManager syncConfigurationManager,
        SyncOptimizeDriver syncOptimizeDriver); @Autowired  SyncOptimizeManager(SyncConfigurationManager syncConfigurationManager); boolean isRunning(); String getStatus(); boolean isFailed(); void start(final SyncOptimizeManagerResultCallBack callback);  }
@Test public void testStart() throws Exception { setupStart(); setupDriver(); this.syncConfigurationManager.setThreadCount(threadCount); expectLastCall().once(); this.callback.onSuccess(); expectLastCall().once(); replayAll(); this.syncOptimizeManager.start(callback); Thread.sleep(500); assertFalse(this.syncOptimizeManager.isRunning()); assertFalse(this.syncOptimizeManager.isFailed()); }