summaryrefslogtreecommitdiff
path: root/platform/vcs-log/impl/test/com/intellij/vcs/log
diff options
context:
space:
mode:
Diffstat (limited to 'platform/vcs-log/impl/test/com/intellij/vcs/log')
-rw-r--r--platform/vcs-log/impl/test/com/intellij/vcs/log/data/VcsLogJoinerTest.java141
-rw-r--r--platform/vcs-log/impl/test/com/intellij/vcs/log/data/VcsLogJoinerTest.kt468
-rw-r--r--platform/vcs-log/impl/test/com/intellij/vcs/log/impl/TestVcsLogProvider.java8
3 files changed, 473 insertions, 144 deletions
diff --git a/platform/vcs-log/impl/test/com/intellij/vcs/log/data/VcsLogJoinerTest.java b/platform/vcs-log/impl/test/com/intellij/vcs/log/data/VcsLogJoinerTest.java
deleted file mode 100644
index 63e54b910bfc..000000000000
--- a/platform/vcs-log/impl/test/com/intellij/vcs/log/data/VcsLogJoinerTest.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package com.intellij.vcs.log.data;
-
-import com.intellij.util.ArrayUtil;
-import com.intellij.util.Function;
-import com.intellij.util.containers.ContainerUtil;
-import com.intellij.vcs.log.Hash;
-import com.intellij.vcs.log.TimedCommitParser;
-import com.intellij.vcs.log.TimedVcsCommit;
-import com.intellij.vcs.log.impl.HashImpl;
-import org.junit.Test;
-
-import java.util.Collection;
-import java.util.List;
-
-import static java.util.Arrays.asList;
-import static org.junit.Assert.assertEquals;
-
-/**
- * @author Kirill Likhodedov
- */
-public class VcsLogJoinerTest {
-
- public void runTest(List<String> initial, List<String> updateBlock, List<String> oldRefs, List<String> newRefs, String expected) {
- List<TimedVcsCommit> savedLog = TimedCommitParser.log(ArrayUtil.toStringArray(initial));
- List<? extends TimedVcsCommit> firstBlock = TimedCommitParser.log(ArrayUtil.toStringArray(updateBlock));
- Collection<Hash> vcsOldRefs = ContainerUtil.map(oldRefs, new Function<String, Hash>() {
- @Override
- public Hash fun(String s) {
- return HashImpl.build(s);
- }
- });
- Collection<Hash> vcsNewRefs = ContainerUtil.map(newRefs, new Function<String, Hash>() {
- @Override
- public Hash fun(String s) {
- return HashImpl.build(s);
- }
- });
-
- List<? extends TimedVcsCommit> result = new VcsLogJoiner<Hash, TimedVcsCommit>().addCommits(savedLog, vcsOldRefs, firstBlock, vcsNewRefs).getFirst();
- assertEquals(expected, toStr(result));
- }
-
- @Test
- public void simpleTest() {
- runTest(
- asList("4|-a2|-a1", "3|-b1|-a", "2|-a1|-a", "1|-a|-"),
- asList("5|-f|-b1", "6|-e|-a2"),
- asList("a2", "b1"),
- asList("f", "e"),
- "e, f, a2, b1, a1, a"
- );
- }
-
- @Test
- public void oneNodeTest() {
- runTest(
- asList("3|-a1|-"),
- asList("3|-a1|-"),
- asList("a1"),
- asList("a1"),
- "a1"
- );
- }
-
- @Test
- public void oneNodeResetTest() {
- runTest(
- asList("3|-a1|-a2", "2|-a2|-"),
- asList("2|-a2|-"),
- asList("a2", "a1"),
- asList("a2"),
- "a2"
- );
- }
-
- @Test
- public void oneNodeReset2Test() {
- runTest(
- asList("3|-a1|-a2", "2|-a2|-"),
- asList("2|-a2|-"),
- asList("a1"),
- asList("a2"),
- "a2"
- );
- }
-
- @Test
- public void simpleRemoveCommitsTest() {
- runTest(
- asList("4|-a2|-a1", "3|-b1|-a", "2|-a1|-a", "1|-a|-"),
- asList("5|-f|-b1", "6|-e|-a1"),
- asList("a2"),
- asList("f", "e"),
- "e, f, b1, a1, a"
- );
- }
-
- @Test
- public void removeCommitsTest() {
- runTest(
- asList("5|-a5|-a4", "4|-a4|-a2 a3", "3|-a3|-a1", "2|-a2|-a1", "1|-a1|-"),
- asList("6|-a6|-a3"),
- asList("a5"),
- asList("a6"),
- "a6, a3, a1"
- );
- }
-
- @Test
- public void removeCommitsTest2() {
- runTest(
- asList("2|-a2|-a1", "1|-a1|-"),
- asList("5|-a5|-a4", "3|-a3|-a2", "4|-a4|-a3"),
- asList("a2"),
- asList("a5"),
- "a5, a4, a3, a2, a1"
- );
- }
-
- @Test
- public void removeCommitsTest3() {
- runTest(
- asList("3|-a3|-a2", "2|-a2|-a1", "1|-a1|-"),
- asList("2|-a2|-a1"),
- asList("a3"),
- asList("a2"),
- "a2, a1"
- );
- }
-
- private static String toStr(List<? extends TimedVcsCommit> commits) {
- StringBuilder s = new StringBuilder();
- for (TimedVcsCommit commit : commits) {
- if (s.length() != 0) {
- s.append(", ");
- }
- s.append(commit.getId().asString());
- }
- return s.toString();
- }
-}
diff --git a/platform/vcs-log/impl/test/com/intellij/vcs/log/data/VcsLogJoinerTest.kt b/platform/vcs-log/impl/test/com/intellij/vcs/log/data/VcsLogJoinerTest.kt
new file mode 100644
index 000000000000..ed4218473984
--- /dev/null
+++ b/platform/vcs-log/impl/test/com/intellij/vcs/log/data/VcsLogJoinerTest.kt
@@ -0,0 +1,468 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.vcs.log.data
+
+import org.junit.Test
+import java.util.ArrayList
+import com.intellij.vcs.log.TimedCommitParser
+import com.intellij.util.ArrayUtil
+import com.intellij.vcs.log.impl.HashImpl
+import com.intellij.vcs.log.TimedVcsCommit
+import com.intellij.vcs.log.Hash
+import org.junit.Assert.*
+
+
+class VcsLogJoinerTest {
+
+ class StringArrayBuilder() {
+ val result = ArrayList<String>()
+
+ fun String.plus() = result.add(this)
+
+ fun Collection<String>.plus() = result.addAll(this)
+ }
+
+ class TestRunner() {
+ private var fullLog: List<String>? = null
+ private var recentCommits: List<String>? = null
+ private var oldRefs: List<String>? = null
+ private var newRefs: List<String>? = null
+ private var expected: String? = null
+
+ private fun build(f: StringArrayBuilder.() -> Unit): List<String> {
+ val stringArrayBuilder = StringArrayBuilder()
+ stringArrayBuilder.f()
+ return stringArrayBuilder.result
+ }
+
+ fun fullLog(f: StringArrayBuilder.() -> Unit) {fullLog = build(f)}
+
+ fun recentCommits(f: StringArrayBuilder.() -> Unit) {recentCommits = build(f)}
+
+ fun oldRefs(f: StringArrayBuilder.() -> Unit) {oldRefs = build(f)}
+
+ fun newRefs(f: StringArrayBuilder.() -> Unit) {newRefs = build(f)}
+
+ fun expected(f: StringArrayBuilder.() -> Unit) {expected = build(f).join(separator = "\n")}
+
+ fun run() {
+ val vcsFullLog = TimedCommitParser.log(fullLog!!)
+ val vcsRecentCommits = TimedCommitParser.log(recentCommits!!)
+ val vcsOldRefs = oldRefs!!.map { HashImpl.build(it) }
+ val vcsNewRefs = newRefs!!.map { HashImpl.build(it) }
+
+ val result = VcsLogJoiner<Hash, TimedVcsCommit>().addCommits(vcsFullLog, vcsOldRefs, vcsRecentCommits, vcsNewRefs).getFirst()!!
+ val actual = result.map { it.getId().asString() }.join(separator = "\n")
+ assertEquals(expected, actual)
+ }
+ }
+
+ fun runTest(f: TestRunner.() -> Unit) {
+ val testRunner = TestRunner()
+ testRunner.f()
+ testRunner.run()
+ }
+
+ val BIG_TIME = 100000000
+
+ Test fun simple() {
+ runTest {
+ fullLog {
+ +"4|-a2|-a1"
+ +"3|-b1|-a"
+ +"2|-a1|-a"
+ +"1|-a|-"
+ }
+ recentCommits {
+ +"5|-f|-b1"
+ +"6|-e|-a2"
+ }
+ oldRefs {
+ +"a2"
+ +"b1"
+ }
+ newRefs {
+ +"f"
+ +"e"
+ }
+ expected {
+ +"e"
+ +"f"
+ +"a2"
+ +"b1"
+ +"a1"
+ +"a"
+ }
+ }
+ }
+
+ Test fun oneNode() {
+ runTest {
+ fullLog {
+ +"3|-a1|-"
+ }
+ recentCommits {
+ +"3|-a1|-"
+ }
+ oldRefs {
+ +"a1"
+ }
+ newRefs {
+ +"a1"
+ }
+ expected {
+ +"a1"
+ }
+ }
+ }
+
+ Test fun oneNodeReset() {
+ runTest {
+ fullLog {
+ +"3|-a1|-a2"
+ +"2|-a2|-"
+ }
+ recentCommits {
+ +"2|-a2|-"
+ }
+ oldRefs {
+ +"a2"
+ +"a1"
+ }
+ newRefs {
+ +"a2"
+ }
+ expected {
+ +"a2"
+ }
+ }
+ }
+
+ Test fun oneNodeReset2() {
+ runTest {
+ fullLog {
+ +"3|-a1|-a2"
+ +"2|-a2|-"
+ }
+ recentCommits {
+ +"2|-a2|-"
+ }
+ oldRefs {
+ +"a1"
+ }
+ newRefs {
+ +"a2"
+ }
+ expected {
+ +"a2"
+ }
+ }
+ }
+
+ Test fun simpleRemoveCommits() {
+ runTest {
+ fullLog {
+ +"4|-a2|-a1"
+ +"3|-b1|-a"
+ +"2|-a1|-a"
+ +"1|-a|-"
+ }
+ recentCommits {
+ +"5|-f|-b1"
+ +"6|-e|-a1"
+ }
+ oldRefs {
+ +"a2"
+ }
+ newRefs {
+ +"f"
+ +"e"
+ }
+ expected {
+ +"e"
+ +"f"
+ +"b1"
+ +"a1"
+ +"a"
+ }
+ }
+ }
+
+ Test fun removeCommits() {
+ runTest {
+ fullLog {
+ +"5|-a5|-a4"
+ +"4|-a4|-a2 a3"
+ +"3|-a3|-a1"
+ +"2|-a2|-a1"
+ +"1|-a1|-"
+ }
+ recentCommits {
+ +"6|-a6|-a3"
+ }
+ oldRefs {
+ +"a5"
+ }
+ newRefs {
+ +"a6"
+ }
+ expected {
+ +"a6"
+ +"a3"
+ +"a1"
+ }
+ }
+ }
+
+ Test fun removeCommits2() {
+ runTest {
+ fullLog {
+ +"2|-a2|-a1"
+ +"1|-a1|-"
+ }
+ recentCommits {
+ +"5|-a5|-a4"
+ +"3|-a3|-a2"
+ +"4|-a4|-a3"
+ }
+ oldRefs {
+ +"a2"
+ }
+ newRefs {
+ +"a5"
+ }
+ expected {
+ +"a5"
+ +"a4"
+ +"a3"
+ +"a2"
+ +"a1"
+ }
+ }
+ }
+
+ Test fun removeCommits3() {
+ runTest {
+ fullLog {
+ +"3|-a3|-a2"
+ +"2|-a2|-a1"
+ +"1|-a1|-"
+ }
+ recentCommits {
+ +"2|-a2|-a1"
+ }
+ oldRefs {
+ +"a3"
+ }
+ newRefs {
+ +"a2"
+ }
+ expected {
+ +"a2"
+ +"a1"
+ }
+ }
+ }
+
+ Test fun removeOldBranch() {
+ runTest {
+ fullLog {
+ +"100|-e1|-e10"
+ +(10..100000).map { "${BIG_TIME - it}|-e${it}|-e${it + 1}" }
+ +"5|-e100001|-a1"
+ +"4|-b2|-b1"
+ +"3|-b1|-a1"
+ +"1|-a1|-"
+ }
+ recentCommits {
+ +"100|-e1|-e10"
+ }
+ oldRefs {
+ +"e1"
+ +"b2"
+ }
+ newRefs {
+ "e1"
+ }
+ expected {
+ +"e1"
+ +(10..100000).map { "e$it" }
+ +"e100001"
+ +"a1"
+ }
+ }
+ }
+
+ Test fun addToOldBranch() {
+ runTest {
+ fullLog {
+ +"100|-e1|-e10"
+ +(10..100000).map { "${BIG_TIME - it}|-e${it}|-e${it + 1}" }
+ +"5|-e100001|-a1"
+ +"4|-b2|-b1"
+ +"3|-b1|-a1"
+ +"1|-a1|-"
+ }
+ recentCommits {
+ +"50|-b4|-b3"
+ +"49|-b3|-b2"
+ }
+ oldRefs {
+ +"e1"
+ +"b2"
+ }
+ newRefs {
+ +"e1"
+ +"b4"
+ }
+ expected {
+ +"e1"
+ +(10..100000).map { "e$it" }
+ +"b4"
+ +"b3"
+ +"e100001"
+ +"b2"
+ +"b1"
+ +"a1"
+ }
+ }
+ }
+
+ Test fun removeLongBranch() {
+ runTest {
+ fullLog {
+ +"100|-e1|-e10"
+ +(10..100000).map { "${BIG_TIME - it}|-e${it}|-e${it + 1}" }
+ +"5|-e100001|-a1"
+ +"4|-b2|-b1"
+ +"3|-b1|-a1"
+ +"1|-a1|-"
+ }
+ recentCommits {
+ +"50|-b4|-b3"
+ +"49|-b3|-b2"
+ }
+ oldRefs {
+ +"e1"
+ +"b2"
+ }
+ newRefs {
+ +"b4"
+ }
+ expected {
+ +"b4"
+ +"b3"
+ +"b2"
+ +"b1"
+ +"a1"
+ }
+ }
+ }
+
+ Test fun notEnoughDataExceptionTest() {
+ try {
+ runTest {
+ fullLog {
+ +"1|-a1|-"
+ }
+ recentCommits {
+ +"3|-a3|-a2"
+ }
+ oldRefs {
+ +"a1"
+ }
+ newRefs {
+ +"a3"
+ }
+ }
+ } catch (e: VcsLogRefreshNotEnoughDataException) {
+ return
+ }
+ fail()
+ }
+
+ Test fun illegalStateExceptionTest() {
+ try {
+ runTest {
+ fullLog {
+ +"1|-a1|-"
+ }
+ recentCommits {
+ +"1|-a1|-"
+ }
+ oldRefs {
+ +"a1"
+ +"a2"
+ }
+ newRefs {
+ +"a1"
+ }
+ }
+ } catch (e: IllegalStateException) {
+ return
+ }
+ fail()
+ }
+
+ Test fun removeParallelBranch() {
+ runTest {
+ fullLog {
+ +"4|-a4|-a1"
+ +"3|-a3|-a2"
+ +"2|-a2|-"
+ +"1|-a1|-"
+ }
+ recentCommits {
+
+ }
+ oldRefs {
+ +"a4"
+ +"a3"
+ }
+ newRefs {
+ +"a3"
+ }
+ expected {
+ +"a3"
+ +"a2"
+ }
+ }
+ }
+
+ Test fun removeAll() {
+ runTest {
+ fullLog {
+ +"4|-a4|-a1"
+ +"3|-a3|-a2"
+ +"2|-a2|-"
+ +"1|-a1|-"
+ }
+ recentCommits {
+
+ }
+ oldRefs {
+ +"a4"
+ +"a3"
+ }
+ newRefs {
+
+ }
+ expected {
+
+ }
+ }
+ }
+}
diff --git a/platform/vcs-log/impl/test/com/intellij/vcs/log/impl/TestVcsLogProvider.java b/platform/vcs-log/impl/test/com/intellij/vcs/log/impl/TestVcsLogProvider.java
index d3709b2d8f55..850478b048dc 100644
--- a/platform/vcs-log/impl/test/com/intellij/vcs/log/impl/TestVcsLogProvider.java
+++ b/platform/vcs-log/impl/test/com/intellij/vcs/log/impl/TestVcsLogProvider.java
@@ -93,9 +93,9 @@ public class TestVcsLogProvider implements VcsLogProvider {
return ContainerUtil.map(myCommits.subList(0, requirements.getCommitCount()), myCommitToMetadataConvertor);
}
- @NotNull
@Override
- public List<TimedVcsCommit> readAllHashes(@NotNull VirtualFile root, @NotNull Consumer<VcsUser> userRegistry) throws VcsException {
+ public void readAllHashes(@NotNull VirtualFile root, @NotNull Consumer<VcsUser> userRegistry,
+ @NotNull Consumer<TimedVcsCommit> commitConsumer) throws VcsException {
try {
myFullLogSemaphore.acquire();
}
@@ -103,7 +103,9 @@ public class TestVcsLogProvider implements VcsLogProvider {
throw new RuntimeException(e);
}
assertRoot(root);
- return myCommits;
+ for (TimedVcsCommit commit : myCommits) {
+ commitConsumer.consume(commit);
+ }
}
private void assertRoot(@NotNull VirtualFile root) {