-
Notifications
You must be signed in to change notification settings - Fork 301
Expand file tree
/
Copy pathBigDiffTest.java
More file actions
97 lines (85 loc) · 3.43 KB
/
BigDiffTest.java
File metadata and controls
97 lines (85 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* This file is part of git-commit-id-maven-plugin
* Originally invented by Konrad 'ktoso' Malawski <konrad.malawski@java.pl>
*
* git-commit-id-maven-plugin is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* git-commit-id-maven-plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with git-commit-id-maven-plugin. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.project13.maven.git;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
import junitparams.JUnitParamsRunner;
import org.apache.maven.project.MavenProject;
import org.junit.Test;
import org.junit.runner.RunWith;
import pl.project13.core.git.GitDescribeConfig;
/**
* Run this to simulate hanging native-git-process for repo-state with lots of changes.
*
* <p>The test case will still finish successfully because all git-related errors are cught in.
*
* @author eternach
*/
@RunWith(JUnitParamsRunner.class)
public class BigDiffTest extends GitIntegrationTest {
@Test
// @Ignore("Run this to simulate hanging native-git-process for repo-state with lots of changes")
public void bigDiff() throws Exception {
// given
mavenSandbox
.withParentProject("my-pom-project", "pom")
.withChildProject("my-jar-module", "jar")
.withGitRepoInChild(AvailableGitTestRepo.MAVEN_GIT_COMMIT_ID_PLUGIN)
.create();
final MavenProject targetProject = mavenSandbox.getChildProject();
setProjectToExecuteMojoIn(targetProject);
final GitDescribeConfig gitDescribeConfig = createGitDescribeConfig(true, 7);
gitDescribeConfig.setAlways(true);
// set timeout to one hour
mojo.nativeGitTimeoutInMs = 60 * 60 * 1000;
mojo.useNativeGit = true;
mojo.gitDescribe = gitDescribeConfig;
for (int i = 0; i < 100000; i++) {
final Path path =
Paths.get(
mavenSandbox.getChildProject().getBasedir().toString(),
"very-long-file-name-with-id-" + Integer.toString(i) + ".txt");
final byte[] bytes = "for performance test\n".getBytes();
Files.createFile(path);
try (FileOutputStream fos = new FileOutputStream(path.toFile())) {
for (int ii = 0; ii < 100; ii++) {
fos.write(bytes);
}
}
}
// when
final long startTime = System.currentTimeMillis();
mojo.execute();
final long estimatedTime = System.currentTimeMillis() - startTime;
System.out.println("[***] time: " + (double) estimatedTime + " ms");
// then
assertGitPropertiesPresentInProject(targetProject.getProperties());
}
private GitDescribeConfig createGitDescribeConfig(
final boolean forceLongFormat, final int abbrev) {
final GitDescribeConfig gitDescribeConfig = new GitDescribeConfig();
gitDescribeConfig.setTags(true);
gitDescribeConfig.setForceLongFormat(forceLongFormat);
gitDescribeConfig.setAbbrev(abbrev);
return gitDescribeConfig;
}
}