DirEntryCacheUpdater implements RepositoryChangeListener { public void update(final RevisionUpdate revisionUpdate) { final RepositoryName repositoryName = revisionUpdate.getRepositoryName(); LOGGER.info("Listener got [" + revisionUpdate.getRevisions().size() + "] updated revision(s) for repository: " + repositoryName); final StopWatch stopWatch = new StopWatch(); stopWatch.start(); SVNConnection connection = null; try { final DirEntryCache entryCache = cacheManager.getCache(repositoryName); final RepositoryConfiguration configuration = application.getConfiguration(repositoryName); connection = connectionFactory.createConnection(repositoryName, configuration.getSVNURL(), configuration.getCacheCredentials()); updateInternal(entryCache, connection, revisionUpdate); } catch (final Exception ex) { LOGGER.warn("Could not update cache instance [" + repositoryName + "]", ex); } finally { if (connection != null) { connection.closeSession(); } } stopWatch.stop(); LOGGER.info("Update completed in [" + stopWatch.getTotalTimeSeconds() + "] seconds"); } DirEntryCacheUpdater(final DirEntryCacheManager cacheManager, final Application application); void update(final RevisionUpdate revisionUpdate); @Autowired void setConnectionFactory(final SVNConnectionFactory connectionFactory); @Autowired void setRepositoryService(final RepositoryService repositoryService);  }
@Test public void testUpdate() throws Exception { final RepositoryService serviceMock = mock(RepositoryService.class); assertEquals(0, entryCache.getSize()); final List<LogEntry> logEntries = new ArrayList<LogEntry>(); final SortedSet<ChangedPath> changedPaths1 = new TreeSet<ChangedPath>(); changedPaths1.add(new ChangedPath("/file1.java", null, -1, ChangeType.MODIFIED)); changedPaths1.add(new ChangedPath("/file2.abc", null, -1, ChangeType.ADDED)); changedPaths1.add(new ChangedPath("/trunk/file3.def", null, -1, ChangeType.REPLACED)); logEntries.add(createLogEntry(123, "author", new Date(), "Log message for revision 123.", changedPaths1)); final SortedSet<ChangedPath> changedPaths2 = new TreeSet<ChangedPath>(); changedPaths2.add(new ChangedPath("/branch", "/trunk", 123, ChangeType.ADDED)); changedPaths2.add(new ChangedPath("/trunk/file3.def", null, -1, ChangeType.DELETED)); logEntries.add(createLogEntry(124, "author", new Date(), "Log message for revision 124.", changedPaths2)); 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); when(serviceMock.getLatestRevision(null)).thenReturn(124L); when(serviceMock.getEntryInfo(null, "/file1.java", 123)).thenReturn(new DirEntry( "/", "file1.java", "author", new Date(), DirEntry.Kind.FILE, 123, 12345)); when(serviceMock.getEntryInfo(null, "/file2.abc", 123)).thenReturn(new DirEntry( "/", "file2.abc", "author", new Date(), DirEntry.Kind.FILE, 123, 12345)); when(serviceMock.getEntryInfo(null, "/trunk/file3.def", 123)).thenReturn(new DirEntry( "/trunk", "file3.def", "author", new Date(), DirEntry.Kind.FILE, 123, 12345)); when(serviceMock.getEntryInfo(null, "/branch", 124)).thenReturn(new DirEntry( "/", "branch", "author", new Date(), DirEntry.Kind.DIR, 123, 12345)); when(serviceMock.list(null, "/branch/", 124)).thenReturn(new DirList(Collections.<DirEntry>emptyList(), new Properties())); when(serviceMock.getEntryInfo(null, "/trunk/file3.def", 123)).thenReturn(new DirEntry( "/trunk", "file3.def", "author", new Date(), DirEntry.Kind.FILE, 123, 12345)); final RepositoryName repositoryName = new RepositoryName("defaultsvn"); final RevisionUpdate revisionUpdate = new RevisionUpdate(repositoryName, logEntries, false); final DirEntryCacheUpdater cacheUpdater = new DirEntryCacheUpdater(null, application); cacheUpdater.setRepositoryService(serviceMock); cacheUpdater.updateInternal(entryCache, null, revisionUpdate); Thread.sleep(500L); assertEquals(4, entryCache.getSize()); }