DefaultRepositoryChangeMonitor implements RepositoryChangeMonitor { @Override public void update(final RepositoryName repositoryName) { if (application.isConfigured()) { final RepositoryConfiguration configuration = application.getConfiguration(repositoryName); synchronized (this) { if (configuration.isCacheUsed() && !application.isUpdating(repositoryName)) { final Thread updaterThread = new Thread(new Runnable() { @Override public void run() { application.setUpdatingCache(repositoryName, true); SVNConnection connection = null; try { connection = connectionFactory.createConnection(configuration.getName(), configuration.getSVNURL(), configuration.getCacheCredentials()); final ObjectCache objectCache = objectCacheManager.getCache(repositoryName); update(repositoryName, connection, objectCache); } catch (final Exception ex) { logger.warn("Unable to establish repository connection", ex); } finally { if (connection != null) { connection.closeSession(); } application.setUpdatingCache(repositoryName, false); } } }, "Updater-" + repositoryName.toString()); updaterThread.start(); } } } } DefaultRepositoryChangeMonitor(); synchronized void setListeners(final List<RepositoryChangeListener> listeners); @Override void update(final RepositoryName repositoryName); @Override @ManagedOperation void updateAll(); @Autowired void setRepositoryService(final RepositoryService repositoryService); @Autowired void setConnectionFactory(final SVNConnectionFactory connectionFactory); void setMaxRevisionCountPerUpdate(final int count); @Autowired void setApplication(final Application application); @Autowired void setObjectCacheManager(final ObjectCacheManager objectCacheManager);  }
@Test public void testUpdate() throws Exception { final ConfigDirectory configDirectory = TestUtils.getTestConfigDirectory(); configDirectory.setCreateDirectories(false); final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setServletContext(servletContext); final Application application = new Application(configDirectory); final RepositoryConfiguration configuration = new RepositoryConfiguration("name"); configuration.setCacheUsed(true); application.addConfiguration(configuration); application.setConfigured(true); final ObjectCache cache = createMemoryCache(); try { final List<RepositoryChangeListener> listeners = new ArrayList<RepositoryChangeListener>(); listeners.add(repositoryChangeListenerMock); final DefaultRepositoryChangeMonitor changeMonitor = new DefaultRepositoryChangeMonitor(); changeMonitor.setListeners(listeners); changeMonitor.setMaxRevisionCountPerUpdate(3); changeMonitor.setApplication(application); changeMonitor.setRepositoryService(repositoryServiceMock); assertFalse(application.isUpdating(configuration.getName())); expect(repositoryServiceMock.getLatestRevision(null)).andReturn(6L); expect(repositoryServiceMock.getLogEntriesFromRepositoryRoot(null, 1L, 3L)).andReturn(firstBatchOfRevisions); repositoryChangeListenerMock.update(isA(RevisionUpdate.class)); expect(repositoryServiceMock.getLogEntriesFromRepositoryRoot(null, 4L, 6L)).andReturn(secondBatchOfRevisions); repositoryChangeListenerMock.update(isA(RevisionUpdate.class)); replay(repositoryServiceMock); replay(repositoryChangeListenerMock); changeMonitor.update(configuration.getName(), null, cache); verify(repositoryServiceMock); verify(repositoryChangeListenerMock); assertFalse(application.isUpdating(configuration.getName())); } finally { cache.shutdown(); } }