diff options
author | James Moger <james.moger@gitblit.com> | 2012-03-15 18:02:14 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2012-03-15 18:02:14 -0400 |
commit | d896e62505a429ee27237b3302d7c04e7ff8e6df (patch) | |
tree | 7ab9f88b8e83cfe198e9750642e82c390251b01b /tests/com | |
parent | 68ce2ce77157b2fda9c4f4a0893ece499e747320 (diff) | |
download | gitblit-d896e62505a429ee27237b3302d7c04e7ff8e6df.tar.gz gitblit-d896e62505a429ee27237b3302d7c04e7ff8e6df.zip |
Refactored Lucene integration and fixed two index deleteDocument bugs
Diffstat (limited to 'tests/com')
-rw-r--r-- | tests/com/gitblit/tests/GitBlitSuite.java | 5 | ||||
-rw-r--r-- | tests/com/gitblit/tests/IssuesTest.java | 15 | ||||
-rw-r--r-- | tests/com/gitblit/tests/LuceneExecutorTest.java (renamed from tests/com/gitblit/tests/LuceneUtilsTest.java) | 100 |
3 files changed, 72 insertions, 48 deletions
diff --git a/tests/com/gitblit/tests/GitBlitSuite.java b/tests/com/gitblit/tests/GitBlitSuite.java index 4a70964b..af18083d 100644 --- a/tests/com/gitblit/tests/GitBlitSuite.java +++ b/tests/com/gitblit/tests/GitBlitSuite.java @@ -52,7 +52,7 @@ import com.gitblit.utils.JGitUtils; ObjectCacheTest.class, UserServiceTest.class, MarkdownUtilsTest.class, JGitUtilsTest.class,
SyndicationUtilsTest.class, DiffUtilsTest.class, MetricUtilsTest.class,
TicgitUtilsTest.class, GitBlitTest.class, FederationTests.class, RpcTests.class,
- GitServletTest.class, GroovyScriptTest.class, LuceneUtilsTest.class, IssuesTest.class })
+ GitServletTest.class, GroovyScriptTest.class, LuceneExecutorTest.class, IssuesTest.class })
public class GitBlitSuite {
public static final File REPOSITORIES = new File("git");
@@ -87,6 +87,7 @@ public class GitBlitSuite { }
public static Repository getIssuesTestRepository() throws Exception {
+ JGitUtils.createRepository(REPOSITORIES, "gb-issues.git").close();
return new FileRepository(new File(REPOSITORIES, "gb-issues.git"));
}
@@ -137,8 +138,6 @@ public class GitBlitSuite { cloneOrFetch("test/theoretical-physics.git", "https://github.com/certik/theoretical-physics.git");
cloneOrFetch("test/gitective.git", "https://github.com/kevinsawicki/gitective.git");
- JGitUtils.createRepository(REPOSITORIES, "gb-issues.git").close();
-
enableTickets("ticgit.git");
enableDocs("ticgit.git");
showRemoteBranches("ticgit.git");
diff --git a/tests/com/gitblit/tests/IssuesTest.java b/tests/com/gitblit/tests/IssuesTest.java index eb7b66dd..9133f9b1 100644 --- a/tests/com/gitblit/tests/IssuesTest.java +++ b/tests/com/gitblit/tests/IssuesTest.java @@ -26,6 +26,7 @@ import org.bouncycastle.util.Arrays; import org.eclipse.jgit.lib.Repository;
import org.junit.Test;
+import com.gitblit.LuceneExecutor;
import com.gitblit.models.IssueModel;
import com.gitblit.models.IssueModel.Attachment;
import com.gitblit.models.IssueModel.Change;
@@ -35,7 +36,6 @@ import com.gitblit.models.IssueModel.Status; import com.gitblit.models.SearchResult;
import com.gitblit.utils.IssueUtils;
import com.gitblit.utils.IssueUtils.IssueFilter;
-import com.gitblit.utils.LuceneUtils;
import com.gitblit.utils.StringUtils;
/**
@@ -123,17 +123,18 @@ public class IssuesTest { return issue.status.isClosed();
}
});
-
+
assertTrue(allIssues.size() > 0);
assertEquals(1, openIssues.size());
assertEquals(1, closedIssues.size());
// build a new Lucene index
- LuceneUtils.deleteIndex(repository);
+ LuceneExecutor lucene = new LuceneExecutor(null, GitBlitSuite.REPOSITORIES);
+ lucene.deleteIndex(name);
for (IssueModel anIssue : allIssues) {
- LuceneUtils.index(name, repository, anIssue);
+ lucene.index(name, anIssue);
}
- List<SearchResult> hits = LuceneUtils.search("working", 10, repository);
+ List<SearchResult> hits = lucene.search("working", 10, name);
assertTrue(hits.size() > 0);
// reindex an issue
@@ -142,14 +143,14 @@ public class IssuesTest { change.comment("this is a test of reindexing an issue");
IssueUtils.updateIssue(repository, issue.id, change);
issue = IssueUtils.getIssue(repository, issue.id);
- LuceneUtils.index(name, repository, issue);
+ lucene.index(name, issue);
// delete all issues
for (IssueModel anIssue : allIssues) {
assertTrue(IssueUtils.deleteIssue(repository, anIssue.id, "D"));
}
- LuceneUtils.close();
+ lucene.close();
repository.close();
}
diff --git a/tests/com/gitblit/tests/LuceneUtilsTest.java b/tests/com/gitblit/tests/LuceneExecutorTest.java index 01858f50..ddc9bf85 100644 --- a/tests/com/gitblit/tests/LuceneUtilsTest.java +++ b/tests/com/gitblit/tests/LuceneExecutorTest.java @@ -17,13 +17,14 @@ package com.gitblit.tests; import static org.junit.Assert.assertEquals;
+import java.util.ArrayList;
import java.util.List;
import org.eclipse.jgit.lib.Repository;
import org.junit.Test;
+import com.gitblit.LuceneExecutor;
import com.gitblit.models.SearchResult;
-import com.gitblit.utils.LuceneUtils;
import com.gitblit.utils.StringUtils;
/**
@@ -32,95 +33,118 @@ import com.gitblit.utils.StringUtils; * @author James Moger
*
*/
-public class LuceneUtilsTest {
+public class LuceneExecutorTest {
+ private LuceneExecutor newLuceneExecutor() {
+ return new LuceneExecutor(null, GitBlitSuite.REPOSITORIES);
+ }
+
+ private String getName(Repository repository) {
+ return StringUtils.getRelativePath(GitBlitSuite.REPOSITORIES.getAbsolutePath(),
+ repository.getDirectory().getAbsolutePath());
+ }
+
@Test
public void testIndex() throws Exception {
+ LuceneExecutor lucene = newLuceneExecutor();
+
// reindex helloworld
Repository repository = GitBlitSuite.getHelloworldRepository();
- String name = StringUtils.getRelativePath(GitBlitSuite.REPOSITORIES.getAbsolutePath(),
- repository.getDirectory().getAbsolutePath());
- LuceneUtils.reindex(name, repository);
- SearchResult result = LuceneUtils.search("type:blob AND path:bit.bit", 1, repository).get(0);
- assertEquals("Mike Donaghy", result.author);
- result = LuceneUtils.search("type:blob AND path:clipper.prg", 1, repository).get(0);
- assertEquals("tinogomes", result.author);
+ String name = getName(repository);
+ lucene.reindex(name, repository);
repository.close();
+
+ SearchResult result = lucene.search("type:blob AND path:bit.bit", 1, name).get(0);
+ assertEquals("Mike Donaghy", result.author);
+ result = lucene.search("type:blob AND path:clipper.prg", 1, name).get(0);
+ assertEquals("tinogomes", result.author);
// reindex theoretical physics
repository = GitBlitSuite.getTheoreticalPhysicsRepository();
- name = StringUtils.getRelativePath(GitBlitSuite.REPOSITORIES.getAbsolutePath(),
- repository.getDirectory().getAbsolutePath());
- LuceneUtils.reindex(name, repository);
+ name = getName(repository);
+ lucene.reindex(name, repository);
repository.close();
// reindex JGit
repository = GitBlitSuite.getJGitRepository();
- name = StringUtils.getRelativePath(GitBlitSuite.REPOSITORIES.getAbsolutePath(),
- repository.getDirectory().getAbsolutePath());
- LuceneUtils.reindex(name, repository);
+ name = getName(repository);
+ lucene.reindex(name, repository);
repository.close();
- LuceneUtils.close();
+ lucene.close();
}
@Test
public void testQuery() throws Exception {
+ LuceneExecutor lucene = new LuceneExecutor(null, GitBlitSuite.REPOSITORIES);
+
// 2 occurrences on the master branch
- Repository repository = GitBlitSuite.getHelloworldRepository();
- List<SearchResult> results = LuceneUtils.search("ada", 10, repository);
+ Repository repository = GitBlitSuite.getHelloworldRepository();
+ String name = getName(repository);
+ repository.close();
+
+ List<SearchResult> results = lucene.search("ada", 10, name);
assertEquals(2, results.size());
for (SearchResult res : results) {
assertEquals("refs/heads/master", res.branch);
}
// author test
- results = LuceneUtils.search("author: tinogomes", 10, repository);
+ results = lucene.search("author: tinogomes AND type:commit", 10, name);
assertEquals(2, results.size());
-
- repository.close();
+
// blob test
- results = LuceneUtils.search("type: blob AND \"import std.stdio\"", 10, repository);
+ results = lucene.search("type: blob AND \"import std.stdio\"", 10, name);
assertEquals(1, results.size());
assertEquals("d.D", results.get(0).path);
// 1 occurrence on the gh-pages branch
repository = GitBlitSuite.getTheoreticalPhysicsRepository();
- results = LuceneUtils.search("\"add the .nojekyll file\"", 10, repository);
+ name = getName(repository);
+ repository.close();
+
+ results = lucene.search("\"add the .nojekyll file\"", 10, name);
assertEquals(1, results.size());
assertEquals("Ondrej Certik", results.get(0).author);
assertEquals("2648c0c98f2101180715b4d432fc58d0e21a51d7", results.get(0).commitId);
assertEquals("refs/heads/gh-pages", results.get(0).branch);
- results = LuceneUtils.search("type:blob AND \"src/intro.rst\"", 10, repository);
+ results = lucene.search("type:blob AND \"src/intro.rst\"", 10, name);
assertEquals(4, results.size());
// hash id tests
- results = LuceneUtils.search("commit:57c4f26f157ece24b02f4f10f5f68db1d2ce7ff5", 10, repository);
+ results = lucene.search("commit:57c4f26f157ece24b02f4f10f5f68db1d2ce7ff5", 10, name);
assertEquals(1, results.size());
- results = LuceneUtils.search("commit:57c4f26f157*", 10, repository);
- assertEquals(1, results.size());
-
- repository.close();
+ results = lucene.search("commit:57c4f26f157*", 10, name);
+ assertEquals(1, results.size());
// annotated tag test
repository = GitBlitSuite.getJGitRepository();
- results = LuceneUtils.search("I663208919f297836a9c16bf458e4a43ffaca4c12", 10, repository);
- assertEquals(1, results.size());
- assertEquals("[v1.3.0.201202151440-r]", results.get(0).labels.toString());
-
+ name = getName(repository);
repository.close();
- LuceneUtils.close();
+ results = lucene.search("I663208919f297836a9c16bf458e4a43ffaca4c12", 10, name);
+ assertEquals(1, results.size());
+ assertEquals("[v1.3.0.201202151440-r]", results.get(0).tags.toString());
+
+ lucene.close();
}
@Test
public void testMultiSearch() throws Exception {
- List<SearchResult> results = LuceneUtils.search("test", 10,
- GitBlitSuite.getHelloworldRepository(),
- GitBlitSuite.getJGitRepository());
- LuceneUtils.close();
+ LuceneExecutor lucene = newLuceneExecutor();
+ List<String> list = new ArrayList<String>();
+ Repository repository = GitBlitSuite.getHelloworldRepository();
+ list.add(getName(repository));
+ repository.close();
+
+ repository = GitBlitSuite.getJGitRepository();
+ list.add(getName(repository));
+ repository.close();
+
+ List<SearchResult> results = lucene.search("test", 10, list);
+ lucene.close();
assertEquals(10, results.size());
}
}
\ No newline at end of file |