-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
MemoryTest.java
119 lines (102 loc) · 4.33 KB
/
MemoryTest.java
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* SonarQube
* Copyright (C) 2009-2017 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program 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.
*
* This program 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.tests.performance.scanner;
import com.google.common.base.Strings;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarScanner;
import com.sonar.orchestrator.http.HttpMethod;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonarqube.tests.performance.AbstractPerfTest;
import org.sonarqube.tests.performance.MavenLogs;
import org.sonarqube.tests.performance.PerfRule;
public class MemoryTest extends AbstractPerfTest {
@Rule
public PerfRule perfRule = new PerfRule(4) {
@Override
protected void beforeEachRun() {
orchestrator.resetData();
}
};
@ClassRule
public static TemporaryFolder temp = new TemporaryFolder();
@ClassRule
public static Orchestrator orchestrator = ScannerPerformanceSuite.ORCHESTRATOR;
@Before
public void cleanDatabase() {
orchestrator.resetData();
}
int DEPTH = 4;
@Test
public void should_not_fail_with_limited_xmx_memory_and_no_coverage_per_test() {
orchestrator.executeBuild(
newScanner("-Xmx80m -server -XX:-HeapDumpOnOutOfMemoryError"));
}
// Property on root module is duplicated in each module so it may be big
@Test
public void analyzeProjectWithManyModulesAndBigProperties() throws IOException {
File baseDir = temp.newFolder();
prepareModule(baseDir, "moduleA", 1);
prepareModule(baseDir, "moduleB", 1);
prepareModule(baseDir, "moduleC", 1);
FileUtils.write(new File(baseDir, "sonar-project.properties"), "sonar.modules=moduleA,moduleB,moduleC\n", true);
FileUtils.write(new File(baseDir, "sonar-project.properties"), "sonar.myBigProp=" + Strings.repeat("A", 10000), true);
SonarScanner scanner = SonarScanner.create()
.setProperties(
"sonar.projectKey", "big-module-tree",
"sonar.projectName", "Big Module Tree",
"sonar.projectVersion", "1.0",
"sonar.sources", "",
"sonar.showProfiling", "true");
scanner.setEnvironmentVariable("SONAR_SCANNER_OPTS", "-Xmx512m -server")
.setProjectDir(baseDir);
BuildResult result = orchestrator.executeBuild(scanner);
perfRule.assertDurationAround(MavenLogs.extractTotalTime(result.getLogs()), 6740L);
// Second execution with a property on server side
orchestrator.getServer().newHttpCall("/api/settings/set")
.setMethod(HttpMethod.POST)
.setAdminCredentials()
.setParam("key", "sonar.anotherBigProp")
.setParam("value", Strings.repeat("B", 1000))
.setParam("component", "big-module-tree")
.execute();
result = orchestrator.executeBuild(scanner);
perfRule.assertDurationAround(MavenLogs.extractTotalTime(result.getLogs()), 6720L);
}
private void prepareModule(File parentDir, String moduleName, int depth) throws IOException {
File moduleDir = new File(parentDir, moduleName);
moduleDir.mkdir();
File projectProps = new File(moduleDir, "sonar-project.properties");
FileUtils.write(projectProps, "sonar.moduleKey=" + moduleName + "\n", true);
if (depth < DEPTH) {
FileUtils.write(projectProps, "sonar.modules=" + moduleName + "A," + moduleName + "B," + moduleName + "C\n", true);
prepareModule(moduleDir, moduleName + "A", depth + 1);
prepareModule(moduleDir, moduleName + "B", depth + 1);
prepareModule(moduleDir, moduleName + "C", depth + 1);
}
}
}