Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Baumgart2011-03-22 06:20:31 -0400
committerJens Baumgart2011-03-22 06:21:15 -0400
commite192acc569cfef2a786e0d03bca2e3156e26df19 (patch)
treefd386ad00f56f2a9178f57454a9f71370320ce2f /org.eclipse.egit.core.test
parent4c792027f4a3a988a5a7b755bab57979d4d3730e (diff)
downloadegit-e192acc569cfef2a786e0d03bca2e3156e26df19.tar.gz
egit-e192acc569cfef2a786e0d03bca2e3156e26df19.tar.xz
egit-e192acc569cfef2a786e0d03bca2e3156e26df19.zip
TestRepository: use cached repository instance
TestRepository used its own Repository instance while EGit operations used in the tests use the instances provided by RepositoryCache. This caused update problems. Now TestRepository also uses the instances provided by RepositoryCache. This change is a prerequisite for removing the sleeps in CommitOperationTest. The sleeps were removed. Change-Id: Ib27e2a1f35a4494cf113b220ef57b768f8e61fa2 Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
Diffstat (limited to 'org.eclipse.egit.core.test')
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/DualRepositoryTestCase.java18
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitTestCase.java1
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java8
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/CommitOperationTest.java5
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ListRemoteOperationTest.java10
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/PushOperationTest.java7
6 files changed, 36 insertions, 13 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/DualRepositoryTestCase.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/DualRepositoryTestCase.java
index 73f32ee4e..b7c4ef6e3 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/DualRepositoryTestCase.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/DualRepositoryTestCase.java
@@ -14,7 +14,10 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
+import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.op.ConnectProviderOperation;
+import org.junit.After;
+import org.junit.Before;
public abstract class DualRepositoryTestCase {
@@ -26,6 +29,18 @@ public abstract class DualRepositoryTestCase {
protected IProject testProject;
+ @Before
+ public void beforeTestCase() throws Exception {
+ // ensure there are no shared Repository instances left
+ // when starting a new test
+ Activator.getDefault().getRepositoryCache().clear();
+ }
+
+ @After
+ public void afterTestCase() throws Exception {
+ Activator.getDefault().getRepositoryCache().clear();
+ }
+
protected IProject importProject(TestRepository repo, String projectName)
throws Exception {
IProject firstProject = ResourcesPlugin.getWorkspace().getRoot()
@@ -43,4 +58,7 @@ public abstract class DualRepositoryTestCase {
cop.execute(null);
return firstProject;
}
+
+
+
}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitTestCase.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitTestCase.java
index 4cd502ae3..00e5316c6 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitTestCase.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitTestCase.java
@@ -55,6 +55,7 @@ public abstract class GitTestCase {
@After
public void tearDown() throws Exception {
project.dispose();
+ Activator.getDefault().getRepositoryCache().clear();
if (gitDir.exists())
FileUtils.delete(gitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java
index a7b290b40..d3ae5cc69 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java
@@ -20,6 +20,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
+import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.op.BranchOperation;
import org.eclipse.egit.core.op.ConnectProviderOperation;
import org.eclipse.egit.core.op.DisconnectProviderOperation;
@@ -60,8 +61,11 @@ public class TestRepository {
* @throws IOException
*/
public TestRepository(File gitDir) throws IOException {
- repository = new FileRepository(gitDir);
- repository.create();
+ FileRepository tmpRepository = new FileRepository(gitDir);
+ tmpRepository.create();
+ tmpRepository.close();
+ // use repository instance from RepositoryCache!
+ repository = Activator.getDefault().getRepositoryCache().lookupRepository(gitDir);
try {
workdirPrefix = repository.getWorkTree().getCanonicalPath();
} catch (IOException err) {
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/CommitOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/CommitOperationTest.java
index be69527e5..0ab116317 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/CommitOperationTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/CommitOperationTest.java
@@ -195,13 +195,10 @@ public class CommitOperationTest extends GitTestCase {
ArrayList<IFile> notIndexed = new ArrayList<IFile>();
notIndexed.add(filesToCommit[0]);
ArrayList<IFile> notTracked = new ArrayList<IFile>();
- Thread.sleep(1100); // Trouble in "fresh" detection of something
- // Do this like the commit dialog does it
commitOperation = new CommitOperation(filesToCommit, notIndexed, notTracked, TestUtils.AUTHOR, TestUtils.COMMITTER, "second commit");
commitOperation.setCommitAll(false);
commitOperation.execute(null);
- Thread.sleep(1100); // Trouble in "fresh" detection of something
git = new Git(repository);
commits = git.log().call().iterator();
secondCommit = commits.next();
@@ -250,7 +247,6 @@ public class CommitOperationTest extends GitTestCase {
EMPTY_FILE_LIST, Arrays.asList(filesToCommit),
TestUtils.AUTHOR, TestUtils.COMMITTER, "first commit");
commitOperation.execute(null);
- Thread.sleep(1100); // TODO: remove when GitIndex is no longer used
testUtils.changeContentOfFile(project.getProject(), fileA,
"new content of A");
testUtils.changeContentOfFile(project.getProject(), fileB,
@@ -279,7 +275,6 @@ public class CommitOperationTest extends GitTestCase {
EMPTY_FILE_LIST, Arrays.asList(filesToCommit),
TestUtils.AUTHOR, TestUtils.COMMITTER, "first commit");
commitOperation.execute(null);
- Thread.sleep(1100); // TODO: remove when GitIndex is no longer used
testUtils.changeContentOfFile(project.getProject(), fileA,
"new content of A");
testUtils.changeContentOfFile(project.getProject(), fileB,
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ListRemoteOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ListRemoteOperationTest.java
index 67a6f03bb..f51587d42 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ListRemoteOperationTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ListRemoteOperationTest.java
@@ -31,7 +31,7 @@ import org.eclipse.egit.core.test.TestRepository;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
-import org.eclipse.jgit.storage.file.FileRepository;
+import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.URIish;
import org.junit.After;
import org.junit.Before;
@@ -97,8 +97,12 @@ public class ListRemoteOperationTest extends DualRepositoryTestCase {
master, "origin", 0);
clop.run(null);
- repository2 = new TestRepository(new FileRepository(new File(workdir2,
- Constants.DOT_GIT)));
+ Repository existingRepo = Activator
+ .getDefault()
+ .getRepositoryCache()
+ .lookupRepository(
+ new File(workdir2, Constants.DOT_GIT));
+ repository2 = new TestRepository(existingRepo);
// we push to branch "test" of repository2
RefUpdate createBranch = repository2.getRepository().updateRef(
"refs/heads/test");
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/PushOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/PushOperationTest.java
index ccfef6683..1a2cf05b3 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/PushOperationTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/PushOperationTest.java
@@ -39,7 +39,7 @@ import org.eclipse.egit.core.test.TestUtils;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
-import org.eclipse.jgit.storage.file.FileRepository;
+import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.RemoteRefUpdate;
import org.eclipse.jgit.transport.RemoteRefUpdate.Status;
import org.eclipse.jgit.transport.URIish;
@@ -107,8 +107,9 @@ public class PushOperationTest extends DualRepositoryTestCase {
master, "origin", 0);
clop.run(null);
- repository2 = new TestRepository(new FileRepository(new File(workdir2,
- Constants.DOT_GIT)));
+ Repository repo2 = Activator.getDefault().getRepositoryCache().lookupRepository(new File(workdir2,
+ Constants.DOT_GIT));
+ repository2 = new TestRepository(repo2);
// we push to branch "test" of repository2
RefUpdate createBranch = repository2.getRepository().updateRef(
"refs/heads/test");

Back to the top