Author: [email protected]
Date: Tue Mar 29 16:18:34 2011
New Revision: 917
Log:
[AMDATU-332] Added support for older Amdatu versions
Modified:
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/analysis/ZSamples.java
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/runtest/AmdatuLauncher.java
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/runtest/JMeterRunner.java
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/runtest/TestContext.java
Modified:
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/analysis/ZSamples.java
==============================================================================
---
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/analysis/ZSamples.java
(original)
+++
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/analysis/ZSamples.java
Tue Mar 29 16:18:34 2011
@@ -168,10 +168,10 @@
private int getSampleSize(double samples) {
if (m_context.sampleSize == -1) {
sampleMeanSize = (int) Math.min(150, Math.round(samples/1000));
- return sampleMeanSize;
} else {
- return m_context.sampleSize;
+ sampleMeanSize = m_context.sampleSize;
}
+ return sampleMeanSize;
}
private void preProcess(List<XYSample> x, List<XYSample> y) throws
MathException {
Modified:
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/runtest/AmdatuLauncher.java
==============================================================================
---
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/runtest/AmdatuLauncher.java
(original)
+++
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/runtest/AmdatuLauncher.java
Tue Mar 29 16:18:34 2011
@@ -36,7 +36,7 @@
// For now hardcoded, could be read from deploy/org.apache.felix.http.cfg
private static final String[] CHECK_URLS = new String[] {
"http://localhost:${PORT}/dashboard/jsp/dashboard.jsp",
- "http://localhost:${PORT}/rest/authorization/status"
+ "http://localhost:${PORT}${REST}"
};
private ApplicationContext m_context;
@@ -82,10 +82,17 @@
// Now wait until the dashboard returns a 200 for a maximum of 3
minutes
System.out.println("Starting Amdatu, this may take some time...");
+ Thread.sleep(5000); // Wait for 5 seconds before we even start
checking if startup completed
long before = System.currentTimeMillis();
boolean ok = false;
for (String checkUrl : CHECK_URLS) {
String url = checkUrl.replace("${PORT}", new
Integer(m_context.port).toString());
+ boolean after010 =
m_context.currentContext.isAfterVersion("0.1.0") >= 0;
+ if (after010) {
+ url = url.replace("${REST}", "/rest/authorization/status");
+ } else {
+ url = url.replace("${REST}",
"/rest/services/authorization/authorization/status");
+ }
System.out.println("Waiting for " + url + " to return a 200");
ok |= waitForURL(new URL(url), 200, 180000);
}
@@ -113,7 +120,7 @@
m_amdatuProcess.waitFor();
}
-
+
if (m_context.clean) {
// Clean up work directory after shutdown
FileUtils.deleteDirectory(new File(m_tmpDir, "work"));
@@ -151,16 +158,18 @@
private void setPortNumber() throws IOException {
if (m_context.port != -1) {
File felixHttpConfig = new File(m_tmpDir,
"deploy/org.apache.felix.http.cfg");
- List<String> lines = FileUtils.readLines(felixHttpConfig);
- List<String> newLines = new ArrayList<String>();
- for (String line : lines) {
- if (line.indexOf("org.osgi.service.http.port=") != -1) {
- newLines.add("org.osgi.service.http.port=" +
m_context.port);
- } else {
- newLines.add(line);
+ if (felixHttpConfig.exists()) {
+ List<String> lines = FileUtils.readLines(felixHttpConfig);
+ List<String> newLines = new ArrayList<String>();
+ for (String line : lines) {
+ if (line.indexOf("org.osgi.service.http.port=") != -1) {
+ newLines.add("org.osgi.service.http.port=" +
m_context.port);
+ } else {
+ newLines.add(line);
+ }
}
+ FileUtils.writeLines(felixHttpConfig, newLines);
}
- FileUtils.writeLines(felixHttpConfig, newLines);
}
}
Modified:
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/runtest/JMeterRunner.java
==============================================================================
---
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/runtest/JMeterRunner.java
(original)
+++
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/runtest/JMeterRunner.java
Tue Mar 29 16:18:34 2011
@@ -62,8 +62,8 @@
for (File jmeterPlan : plans.listFiles()) {
if (jmeterPlan.isFile() && jmeterPlan.getName().endsWith(".jmx")) {
// Update the port number for the http samples in the JMeter
plans
- setPlanPortNumbers(jmeterPlan);
-
+ preparePlan(jmeterPlan);
+
// Run the JMeter plan!
String sampleName = jmeterPlan.getName().replace(".jmx", "") +
m_context.getSamplesPostFix()+ "." + m_context.currentContextName;
m_sampleFile = new File(resultDir, sampleName);
@@ -76,7 +76,7 @@
} else {
command.add("jmeter.sh");
}
-
+
command.add("-n"); // Non-GUI mode
command.add("-t");
command.add(jmeterPlan.getAbsolutePath());
@@ -88,7 +88,7 @@
}
command.add("-j");
command.add(jmeterLogFile.getAbsolutePath());
-
+
String cmd = "";
for (String c : command) {
cmd += c + " ";
@@ -200,13 +200,38 @@
fis.close();
}
}
-
- private void setPlanPortNumbers(File plan) throws IOException {
+
+ private final static String SAMPLER_PORT_PROP =
"name=\"HTTPSampler.port\"";
+ private final static String SAMPLER_PATH_PROP =
"name=\"HTTPSampler.path\"";
+
+ private void preparePlan(File plan) throws IOException {
+ boolean after010 = m_context.currentContext.isAfterVersion("0.1.0") >=
0;
+
List<String> lines = FileUtils.readLines(plan);
List<String> newLines = new ArrayList<String>();
for (String line : lines) {
- if (line.indexOf("name=\"HTTPSampler.port\"") != -1) {
- newLines.add("<stringProp name=\"HTTPSampler.port\">" +
m_context.port + "</stringProp>");
+ if (line.indexOf(SAMPLER_PORT_PROP) != -1) {
+ newLines.add("<stringProp " + SAMPLER_PORT_PROP + ">" +
m_context.port + "</stringProp>");
+ } else if (line.indexOf(SAMPLER_PATH_PROP) != -1) {
+ int start = line.indexOf(SAMPLER_PATH_PROP) +
SAMPLER_PATH_PROP.length() + 1;
+ int end = line.indexOf("</stringProp>");
+ String path = line.substring(start, end);
+ if (!path.isEmpty()) {
+ if (!after010) {
+ // Before 0.1.0, rest urls were
/rest/services/[alias]/[alias]
+ if (path.startsWith("/rest/") &&
!path.startsWith("/rest/services")) {
+ String alias =
path.substring(path.indexOf("/rest/") + "/rest/".length());
+ path = "/rest/services/" + alias + "/" + alias;
+ }
+ } else {
+ // In 0.1.0 and later, rest urls are /rest/[alias]
+ if (path.startsWith("/rest/services")) {
+ String alias =
path.substring(path.indexOf("/rest/services/") + "/rest/services/".length());
+ path = "/rest/" + alias;
+ }
+ }
+ }
+ newLines.add("<stringProp " + SAMPLER_PATH_PROP + ">" + path +
"</stringProp>");
} else {
newLines.add(line);
}
Modified:
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/runtest/TestContext.java
==============================================================================
---
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/runtest/TestContext.java
(original)
+++
trunk/etc/performancetest/src/main/java/org/amdatu/test/performance/runtest/TestContext.java
Tue Mar 29 16:18:34 2011
@@ -37,4 +37,49 @@
version = version.substring(version.indexOf("amdatu-release-") +
"amdatu-release-".length());
return version;
}
+
+ // Compares given version to this version.
+ // Returns:
+ // 0 if they are equal
+ // -1 if the specified version is before the version of this context
+ // +1 if the specified version is after the version of this context
+ public int isAfterVersion(String version) {
+ if (label.equals(version)) {
+ // Same versions
+ return 0;
+ }
+ String[] v1 = label.split("\\.");
+ String[] v2 = version.split("\\.");
+ if (v1[2].endsWith("-SNAPSHOT")) {
+ v1[2] = v1[2].substring(0, v1[2].indexOf("-SNAPSHOT"));
+ }
+ if (v2[2].endsWith("-SNAPSHOT")) {
+ v2[2] = v2[2].substring(0, v2[2].indexOf("-SNAPSHOT"));
+ }
+ int major1 = Integer.parseInt(v1[0]);
+ int major2 = Integer.parseInt(v2[0]);
+ if (major1 < major2) {
+ return -1;
+ } else if (major1 > major2) {
+ return +1;
+ } else {
+ int minor1 = Integer.parseInt(v1[1]);
+ int minor2 = Integer.parseInt(v2[1]);
+ if (minor1 < minor2) {
+ return -1;
+ } else if (minor1 > minor2) {
+ return +1;
+ } else {
+ int micro1 = Integer.parseInt(v1[2]);
+ int micro2 = Integer.parseInt(v2[2]);
+ if (micro1 < micro2) {
+ return -1;
+ } else if (micro1 > micro2) {
+ return +1;
+ } else {
+ return 0;
+ }
+ }
+ }
+ }
}
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits