| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.test.jmeter; |
| 21 |
|
|
| 22 |
|
import java.io.File; |
| 23 |
|
import java.io.FileNotFoundException; |
| 24 |
|
import java.io.IOException; |
| 25 |
|
import java.io.UnsupportedEncodingException; |
| 26 |
|
import java.net.URLEncoder; |
| 27 |
|
import java.util.ArrayList; |
| 28 |
|
import java.util.Collection; |
| 29 |
|
import java.util.List; |
| 30 |
|
import java.util.Locale; |
| 31 |
|
import java.util.regex.Pattern; |
| 32 |
|
|
| 33 |
|
import org.apache.commons.io.FileUtils; |
| 34 |
|
import org.apache.commons.io.IOUtils; |
| 35 |
|
import org.apache.jmeter.control.LoopController; |
| 36 |
|
import org.apache.jmeter.engine.StandardJMeterEngine; |
| 37 |
|
import org.apache.jmeter.protocol.http.sampler.HTTPSampler; |
| 38 |
|
import org.apache.jmeter.reporters.ResultCollector; |
| 39 |
|
import org.apache.jmeter.samplers.SampleSaveConfiguration; |
| 40 |
|
import org.apache.jmeter.testelement.TestPlan; |
| 41 |
|
import org.apache.jmeter.threads.ThreadGroup; |
| 42 |
|
import org.apache.jmeter.util.JMeterUtils; |
| 43 |
|
import org.apache.jorphan.collections.HashTree; |
| 44 |
|
import org.junit.BeforeClass; |
| 45 |
|
import org.junit.Test; |
| 46 |
|
import org.xwiki.model.internal.reference.DefaultStringEntityReferenceSerializer; |
| 47 |
|
import org.xwiki.model.reference.DocumentReference; |
| 48 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
| 49 |
|
import org.xwiki.model.reference.WikiReference; |
| 50 |
|
import org.xwiki.test.integration.XWikiExecutor; |
| 51 |
|
import org.xwiki.xar.XarEntry; |
| 52 |
|
import org.xwiki.xar.XarException; |
| 53 |
|
import org.xwiki.xar.XarPackage; |
| 54 |
|
|
| |
|
| 6.8% |
Uncovered Elements: 69 (74) |
Complexity: 11 |
Complexity Density: 0.18 |
|
| 55 |
|
public class HTTPPerformanceTest |
| 56 |
|
{ |
| 57 |
|
private static final DefaultStringEntityReferenceSerializer SERIALIZER = |
| 58 |
|
new DefaultStringEntityReferenceSerializer(); |
| 59 |
|
|
| |
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 60 |
0 |
protected static List<DocumentReference> readXarContents(String fileName, String patternFilter) throws Exception... |
| 61 |
|
{ |
| 62 |
0 |
Collection<XarEntry> entries = XarPackage.getEntries(new File(fileName)); |
| 63 |
|
|
| 64 |
0 |
List<DocumentReference> result = new ArrayList<DocumentReference>(entries.size()); |
| 65 |
|
|
| 66 |
0 |
WikiReference wikiReference = new WikiReference("xwiki"); |
| 67 |
|
|
| 68 |
0 |
for (XarEntry entry : entries) { |
| 69 |
0 |
result.add(new DocumentReference(entry, wikiReference)); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
0 |
return result; |
| 73 |
|
} |
| 74 |
|
|
| |
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 75 |
0 |
private static void addXarFiles(List<HTTPSampler> samplers) throws UnsupportedEncodingException, XarException,... |
| 76 |
|
IOException |
| 77 |
|
{ |
| 78 |
0 |
String path = System.getProperty("localRepository") + "/" + System.getProperty("pathToXWikiXar"); |
| 79 |
0 |
String patternFilter = System.getProperty("documentsToTest"); |
| 80 |
|
|
| 81 |
0 |
Pattern pattern = patternFilter == null ? null : Pattern.compile(patternFilter); |
| 82 |
|
|
| 83 |
0 |
for (XarEntry xarEntry : XarPackage.getEntries(new File(path))) { |
| 84 |
0 |
if (pattern == null || pattern.matcher(SERIALIZER.serialize(xarEntry)).matches()) { |
| 85 |
0 |
samplers.add(createSample(xarEntry, "get")); |
| 86 |
0 |
samplers.add(createSample(xarEntry, "view")); |
| 87 |
|
} |
| 88 |
|
} |
| 89 |
|
} |
| 90 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 91 |
0 |
private static HTTPSampler createSample(LocalDocumentReference documentReference, String action)... |
| 92 |
|
throws UnsupportedEncodingException |
| 93 |
|
{ |
| 94 |
0 |
return createSample(SERIALIZER.serialize(documentReference) + " (" + action + ")", |
| 95 |
|
"/xwiki/bin/" + action + "/" + URLEncoder.encode(documentReference.getParent().getName(), "UTF8") + "/" |
| 96 |
|
+ URLEncoder.encode(documentReference.getName(), "UTF8")); |
| 97 |
|
} |
| 98 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 99 |
1 |
@BeforeClass... |
| 100 |
|
public static void before() throws IOException |
| 101 |
|
{ |
| 102 |
1 |
FileUtils.writeByteArrayToFile(new File("target/jmeter/home/bin/httpclient.parameters"), |
| 103 |
|
IOUtils.toByteArray(HTTPPerformanceTest.class.getResource("/jmeterbin/httpclient.parameters"))); |
| 104 |
1 |
FileUtils.writeByteArrayToFile(new File("target/jmeter/home/bin/jmeter.properties"), |
| 105 |
|
IOUtils.toByteArray(HTTPPerformanceTest.class.getResource("/jmeterbin/jmeter.properties"))); |
| 106 |
1 |
FileUtils.writeByteArrayToFile(new File("target/jmeter/home/bin/saveservice.properties"), |
| 107 |
|
IOUtils.toByteArray(HTTPPerformanceTest.class.getResource("/jmeterbin/saveservice.properties"))); |
| 108 |
1 |
FileUtils.writeByteArrayToFile(new File("target/jmeter/home/bin/upgrade.properties"), |
| 109 |
|
IOUtils.toByteArray(HTTPPerformanceTest.class.getResource("/jmeterbin/upgrade.properties"))); |
| 110 |
|
} |
| 111 |
|
|
| |
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
| 112 |
0 |
private static HTTPSampler createSample(String name, String path)... |
| 113 |
|
{ |
| 114 |
0 |
HTTPSampler httpSampler = new HTTPSampler(); |
| 115 |
|
|
| 116 |
0 |
httpSampler.setDomain("localhost"); |
| 117 |
0 |
httpSampler.setPort(Integer.valueOf(XWikiExecutor.DEFAULT_PORT)); |
| 118 |
0 |
httpSampler.setMethod("GET"); |
| 119 |
|
|
| 120 |
0 |
httpSampler.setName(path); |
| 121 |
0 |
httpSampler.setPath(path); |
| 122 |
|
|
| 123 |
0 |
return httpSampler; |
| 124 |
|
} |
| 125 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 126 |
0 |
public void execute(List<HTTPSampler> samplers)... |
| 127 |
|
{ |
| 128 |
0 |
execute(samplers, null, null); |
| 129 |
|
} |
| 130 |
|
|
| |
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 1 |
Complexity Density: 0.03 |
|
| 131 |
0 |
public void execute(List<HTTPSampler> samplers, String user, String password)... |
| 132 |
|
{ |
| 133 |
|
|
| 134 |
0 |
JMeterUtils.loadJMeterProperties("target/jmeter/home/bin/saveservice.properties"); |
| 135 |
0 |
JMeterUtils.setLocale(Locale.ENGLISH); |
| 136 |
0 |
JMeterUtils.setJMeterHome("target/jmeter/home"); |
| 137 |
|
|
| 138 |
|
|
| 139 |
0 |
ResultCollector resultCollector = new ResultCollector(); |
| 140 |
0 |
resultCollector.setFilename("target/jmeter/report.jtl"); |
| 141 |
0 |
SampleSaveConfiguration saveConfiguration = new SampleSaveConfiguration(); |
| 142 |
0 |
saveConfiguration.setAsXml(true); |
| 143 |
0 |
saveConfiguration.setCode(true); |
| 144 |
0 |
saveConfiguration.setLatency(true); |
| 145 |
0 |
saveConfiguration.setTime(true); |
| 146 |
0 |
saveConfiguration.setTimestamp(true); |
| 147 |
0 |
resultCollector.setSaveConfig(saveConfiguration); |
| 148 |
|
|
| 149 |
|
|
| 150 |
0 |
ThreadGroup threadGroup = new ThreadGroup(); |
| 151 |
0 |
threadGroup.setName("xwiki"); |
| 152 |
0 |
threadGroup.setNumThreads(1); |
| 153 |
0 |
threadGroup.setRampUp(1); |
| 154 |
0 |
LoopController loopCtrl = new LoopController(); |
| 155 |
0 |
loopCtrl.setLoops(5); |
| 156 |
0 |
loopCtrl.setFirst(true); |
| 157 |
0 |
threadGroup.setSamplerController(loopCtrl); |
| 158 |
|
|
| 159 |
0 |
HashTree threadGroupTree = new HashTree(); |
| 160 |
0 |
threadGroupTree.add(samplers); |
| 161 |
|
|
| 162 |
|
|
| 163 |
0 |
TestPlan testPlan = new TestPlan("ping"); |
| 164 |
|
|
| 165 |
0 |
HashTree testPlanTree = new HashTree(); |
| 166 |
0 |
testPlanTree.add(threadGroup, threadGroupTree); |
| 167 |
0 |
testPlanTree.add(resultCollector); |
| 168 |
|
|
| 169 |
0 |
HashTree hashTree = new HashTree(); |
| 170 |
0 |
hashTree.add(testPlan, testPlanTree); |
| 171 |
|
|
| 172 |
|
|
| 173 |
0 |
StandardJMeterEngine jm = new StandardJMeterEngine("localhost"); |
| 174 |
|
|
| 175 |
0 |
jm.configure(hashTree); |
| 176 |
|
|
| 177 |
0 |
jm.run(); |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
|
| 181 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
3FAIL
|
|
| 182 |
0 |
@Test... |
| 183 |
|
public void guest() throws FileNotFoundException, Exception |
| 184 |
|
{ |
| 185 |
0 |
List<HTTPSampler> samplers = new ArrayList<HTTPSampler>(); |
| 186 |
|
|
| 187 |
0 |
samplers.add(createSample("root", "/xwiki/")); |
| 188 |
0 |
samplers.add(createSample("Main.WebHome (edit)", "/xwiki/bin/edit/Main/WebHome")); |
| 189 |
|
|
| 190 |
0 |
addXarFiles(samplers); |
| 191 |
|
|
| 192 |
0 |
execute(samplers); |
| 193 |
|
} |
| 194 |
|
} |