diff options
author | Thomas Wolf | 2015-12-05 23:29:18 +0000 |
---|---|---|
committer | Matthias Sohn | 2016-01-20 21:44:59 +0000 |
commit | 5c74ba8f5cf75602794eb3d27eceda408b836951 (patch) | |
tree | f2408f232d16b8e0aa1f6aca7234cbb290eb1966 /org.eclipse.egit.ui.test | |
parent | 6728df2e58f0c296922072cd08795369d4746a6f (diff) | |
download | egit-5c74ba8f5cf75602794eb3d27eceda408b836951.tar.gz egit-5c74ba8f5cf75602794eb3d27eceda408b836951.tar.xz egit-5c74ba8f5cf75602794eb3d27eceda408b836951.zip |
Properly clean up caches when a configured repository is removed
When a repository is removed, it was never removed from the
IndexDiffCache, which in fact has no operation to remove anything. Only
the preference in ResourceUtil is updated. This of course in turn means
there's a hard reference in IndexDiffCache to the repo, and it thus also
remains in the RepositoryCache indefinitely (unless it is really
deleted, not just removed from the view).
Clean this up:
1. IndexDiffCache listens on changes to the preference storing the
configured repositories and removes any stale cache entries upon
changes.
2. Individual cache entries really clear all listeners, and cancel
their jobs when disposed.
3. The RepositoryCache also listens on that preference and also removes
stale entries proactively.
Bug: 483664
Change-Id: I8c20d4e8821e6c5d9fa7e62191a79275bef58bce
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui.test')
-rw-r--r-- | org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoDeletionTest.java | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoDeletionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoDeletionTest.java index 10aab87669..8f5342cf73 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoDeletionTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRepoDeletionTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013, 2015 Matthias Sohn <matthias.sohn@sap.com> and others. + * Copyright (c) 2012, 2016 Matthias Sohn <matthias.sohn@sap.com> and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,20 +7,25 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Thomas Wolf <thomas.wolf@paranor.ch> - Bug 479964 + * Thomas Wolf <thomas.wolf@paranor.ch> - Bugs 479964, 483664 *******************************************************************************/ package org.eclipse.egit.ui.view.repositories; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.File; +import java.util.List; +import java.util.concurrent.TimeUnit; +import org.eclipse.egit.core.internal.indexdiff.IndexDiffCache; import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.JobFamilies; import org.eclipse.egit.ui.internal.UIText; import org.eclipse.egit.ui.test.ContextMenuHelper; +import org.eclipse.egit.ui.test.JobJoiner; import org.eclipse.egit.ui.test.TestUtil; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jgit.api.SubmoduleAddCommand; @@ -42,6 +47,8 @@ public class GitRepositoriesViewRepoDeletionTest extends private static final String DELETE_REPOSITORY_CONTEXT_MENU_LABEL = "RepoViewDeleteRepository.label"; + private static final String REMOVE_REPOSITORY_FROM_VIEW_CONTEXT_MENU_LABEL = "RepoViewRemove.label"; + private File repositoryFile; @Before @@ -125,6 +132,44 @@ public class GitRepositoriesViewRepoDeletionTest extends } @Test + public void testRemoveRepositoryRemoveFromCachesBug483664() + throws Exception { + deleteAllProjects(); + assertProjectExistence(PROJ1, false); + clearView(); + refreshAndWait(); + + Activator.getDefault().getRepositoryUtil() + .addConfiguredRepository(repositoryFile); + refreshAndWait(); + assertHasRepo(repositoryFile); + SWTBotTree tree = getOrOpenView().bot().tree(); + tree.getAllItems()[0].select(); + JobJoiner joiner = JobJoiner.startListening( + JobFamilies.REPOSITORY_DELETE, 10, TimeUnit.SECONDS); + ContextMenuHelper.clickContextMenu(tree, myUtil.getPluginLocalizedValue( + REMOVE_REPOSITORY_FROM_VIEW_CONTEXT_MENU_LABEL)); + refreshAndWait(); + joiner.join(); + assertEmpty(); + assertTrue(repositoryFile.exists()); + assertTrue( + new File(repositoryFile.getParentFile(), PROJ1).isDirectory()); + List<String> configuredRepos = org.eclipse.egit.core.Activator + .getDefault().getRepositoryUtil().getConfiguredRepositories(); + assertTrue("Expected no configured repositories", + configuredRepos.isEmpty()); + Repository[] repositories = org.eclipse.egit.core.Activator.getDefault() + .getRepositoryCache().getAllRepositories(); + assertEquals("Expected no cached repositories", 0, repositories.length); + // A pity we can't mock the cache. + IndexDiffCache indexDiffCache = org.eclipse.egit.core.Activator + .getDefault().getIndexDiffCache(); + assertTrue("Expected no IndexDiffCache entries", + indexDiffCache.currentCacheEntries().isEmpty()); + } + + @Test public void testDeleteSubmoduleRepository() throws Exception { deleteAllProjects(); assertProjectExistence(PROJ1, false); @@ -174,4 +219,5 @@ public class GitRepositoriesViewRepoDeletionTest extends assertFalse(subRepo.getDirectory().exists()); assertFalse(subRepo.getWorkTree().exists()); } + } |