From 12405f543196ee002a1642387c52c18266bb6b24 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 7 Dec 2007 16:40:51 +0000 Subject: [PATCH] refactored package layout added list-variable and range-variable support git-svn-id: http://developer.marklogic.com/svn/performance-meters/trunk@746 e04f4502-82db-0310-b1af-f799f365da79 --- src/build.xml | 2 +- .../marklogic/performance/Configuration.java | 33 ++++--- .../marklogic/performance/ListVariable.java | 51 +++++++++++ .../performance/PerformanceMeters.java | 10 +- .../marklogic/performance/RangeVariable.java | 80 ++++++++++++++++ .../com/marklogic/performance/Result.java | 2 +- .../marklogic/performance/SummaryResults.java | 2 + .../UnknownResultFieldException.java | 6 +- .../marklogic/performance/XMLFileTest.java | 91 ++++++++++++++----- .../performance/junit/TestSampler.java | 6 +- .../{ => reporter}/AbstractReporter.java | 6 +- .../{ => reporter}/CSVReporter.java | 10 +- .../performance/{ => reporter}/Reporter.java | 8 +- .../{ => reporter}/ReporterException.java | 4 +- .../{ => reporter}/XMLReporter.java | 10 +- .../{ => sampler}/Base64Encoder.java | 2 +- .../{ => sampler}/HTTPSampler.java | 16 +++- .../performance/{ => sampler}/Sampler.java | 14 ++- .../{ => sampler}/SamplerException.java | 4 +- .../performance/{ => sampler}/URISampler.java | 15 ++- .../performance/{ => sampler}/XCCSampler.java | 12 ++- .../{ => sampler}/XDBCSampler.java | 14 ++- 22 files changed, 312 insertions(+), 86 deletions(-) create mode 100644 src/java/com/marklogic/performance/ListVariable.java create mode 100644 src/java/com/marklogic/performance/RangeVariable.java rename src/java/com/marklogic/performance/{ => reporter}/AbstractReporter.java (86%) rename src/java/com/marklogic/performance/{ => reporter}/CSVReporter.java (92%) rename src/java/com/marklogic/performance/{ => reporter}/Reporter.java (87%) rename src/java/com/marklogic/performance/{ => reporter}/ReporterException.java (91%) rename src/java/com/marklogic/performance/{ => reporter}/XMLReporter.java (94%) rename src/java/com/marklogic/performance/{ => sampler}/Base64Encoder.java (98%) rename src/java/com/marklogic/performance/{ => sampler}/HTTPSampler.java (89%) rename src/java/com/marklogic/performance/{ => sampler}/Sampler.java (94%) rename src/java/com/marklogic/performance/{ => sampler}/SamplerException.java (91%) rename src/java/com/marklogic/performance/{ => sampler}/URISampler.java (88%) rename src/java/com/marklogic/performance/{ => sampler}/XCCSampler.java (92%) rename src/java/com/marklogic/performance/{ => sampler}/XDBCSampler.java (90%) diff --git a/src/build.xml b/src/build.xml index d5a73e3..c6f8183 100644 --- a/src/build.xml +++ b/src/build.xml @@ -24,7 +24,7 @@ - + diff --git a/src/java/com/marklogic/performance/Configuration.java b/src/java/com/marklogic/performance/Configuration.java index 74ae91e..3769c22 100644 --- a/src/java/com/marklogic/performance/Configuration.java +++ b/src/java/com/marklogic/performance/Configuration.java @@ -25,6 +25,9 @@ import com.marklogic.xdmp.XDMPConnection; +import com.marklogic.performance.reporter.Reporter; +import com.marklogic.performance.reporter.XMLReporter; + public class Configuration { /** @@ -40,7 +43,8 @@ public class Configuration { /** * */ - public static final String REPORTER_DEFAULT = "XMLReporter"; + public static final String REPORTER_DEFAULT = XMLReporter.class + .getCanonicalName(); /** * @@ -156,7 +160,8 @@ public class Configuration { public Configuration(String[] paths, boolean loadSystemProperties) throws IOException { - // set up the initial object using a set of paths, plus system properties + // set up the initial object using a set of paths, plus system + // properties // if the user wants to supply more properties, // the load() method is public. props = new Properties(); @@ -171,8 +176,7 @@ public Configuration(String[] paths, boolean loadSystemProperties) load(System.getProperties()); } } - - + // for unit testing public Configuration(Properties _props) { props = new Properties(); @@ -290,9 +294,8 @@ public void load(Properties _props) { // System.err.println("reporterClassName = " + reporterClassName); if (reporterClassName.indexOf('.') < 1) { - // prepend this class's package name - reporterClassName = Configuration.class.getPackage() - .getName() + // prepend the reporter package name + reporterClassName = Reporter.class.getPackage().getName() + "." + reporterClassName; } @@ -341,11 +344,11 @@ public String configString() { + recordResults + " -DtestType=" + testType; } - String getHost() { + public String getHost() { if (host == null) { return null; } - + if (host.length < 2) { return host[0]; } @@ -353,11 +356,11 @@ String getHost() { return host[hostIndex++ % host.length]; } - String getUser() { + public String getUser() { return user; } - String getPassword() { + public String getPassword() { return password; } @@ -373,19 +376,19 @@ int getNumThreads() { return numThreads; } - int getPort() { + public int getPort() { return port; } - boolean isReportTime() { + public boolean isReportTime() { return reportTime; } - long getRandomSeed() { + public long getRandomSeed() { return randomSeed; } - boolean getRecordResults() { + public boolean getRecordResults() { return recordResults; } diff --git a/src/java/com/marklogic/performance/ListVariable.java b/src/java/com/marklogic/performance/ListVariable.java new file mode 100644 index 0000000..f929bae --- /dev/null +++ b/src/java/com/marklogic/performance/ListVariable.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2007 Mark Logic Corporation. All rights reserved. + */ +package com.marklogic.performance; + +import com.marklogic.xcc.types.XName; +import com.marklogic.xcc.types.XdmValue; +import com.marklogic.xcc.types.XdmVariable; + +/** + * @author Michael Blakeley, michael.blakeley@marklogic.com + * + */ +public class ListVariable implements XdmVariable { + + private XName xname; + private XdmValue[] xvalues; + + /** + * @param name + * @param namespace + * @param type + * @param values + */ + public ListVariable(String name, String namespace, String type, + String[] values) { + xname = new XName(namespace, name); + xvalues = new XdmValue[values.length]; + // copy the input values + for (int i = 0; i < values.length; i++) { + xvalues[i] = XMLFileTest.newValue(type, values[i]); + } + } + + /* (non-Javadoc) + * @see com.marklogic.xcc.types.XdmVariable#getName() + */ + public XName getName() { + return xname; + } + + /* (non-Javadoc) + * @see com.marklogic.xcc.types.XdmVariable#getValue() + */ + public XdmValue getValue() { + // return a random value from the sequence + // TODO also allow sequential values? + return xvalues[(int)(Math.random() * xvalues.length)]; + } + +} diff --git a/src/java/com/marklogic/performance/PerformanceMeters.java b/src/java/com/marklogic/performance/PerformanceMeters.java index 7b375f3..4ab8144 100644 --- a/src/java/com/marklogic/performance/PerformanceMeters.java +++ b/src/java/com/marklogic/performance/PerformanceMeters.java @@ -27,6 +27,14 @@ import java.util.Date; import java.util.List; +import com.marklogic.performance.reporter.ReporterException; +import com.marklogic.performance.reporter.Reporter; +import com.marklogic.performance.sampler.HTTPSampler; +import com.marklogic.performance.sampler.Sampler; +import com.marklogic.performance.sampler.URISampler; +import com.marklogic.performance.sampler.XCCSampler; +import com.marklogic.performance.sampler.XDBCSampler; + /** * @author Ron Avnur, ron.avnur@marklogic.com * @author Michael Blakeley, michael.blakeley@marklogic.com @@ -64,7 +72,6 @@ public static void main(String args[]) throws Exception { // use reflection to create the reporter, for output Class reporterClass = Class .forName(config.getReporterClassName()).asSubclass(Reporter.class); - // System.err.println("reporter class: " + reporterClass.getName()); Constructor reporterConstructor = reporterClass .getConstructor(new Class[0]); reporter = reporterConstructor.newInstance(new Object[0]); @@ -123,6 +130,7 @@ void run() throws Exception { ti = new OffsetTestIterator(tests, i * offsetPerThread); } + // TODO use reflection instead? if (config.isHTTP()) { sampler = new HTTPSampler(ti, config); } else if (config.isURI()) { diff --git a/src/java/com/marklogic/performance/RangeVariable.java b/src/java/com/marklogic/performance/RangeVariable.java new file mode 100644 index 0000000..059f88b --- /dev/null +++ b/src/java/com/marklogic/performance/RangeVariable.java @@ -0,0 +1,80 @@ +/** + * Copyright (c) 2007 Mark Logic Corporation. All rights reserved. + */ +package com.marklogic.performance; + +import com.marklogic.xcc.ValueFactory; +import com.marklogic.xcc.exceptions.UnimplementedFeatureException; +import com.marklogic.xcc.types.ValueType; +import com.marklogic.xcc.types.XName; +import com.marklogic.xcc.types.XSDouble; +import com.marklogic.xcc.types.XSInteger; +import com.marklogic.xcc.types.XdmValue; +import com.marklogic.xcc.types.XdmVariable; + +/** + * @author Michael Blakeley, michael.blakeley@marklogic.com + * + */ +public class RangeVariable implements XdmVariable { + + private XName xname; + + private XdmValue xMin; + + private XdmValue xMax; + + private String type; + + /** + * @param name + * @param namespace + * @param type + * @param minValue + * @param maxValue + */ + public RangeVariable(String name, String namespace, String type, + String minValue, String maxValue) { + // TODO Auto-generated constructor stub + xname = new XName(namespace, name); + // prepare min, max values + xMin = XMLFileTest.newValue(type, minValue); + xMax = XMLFileTest.newValue(type, maxValue); + this.type = type; + } + + /* + * (non-Javadoc) + * + * @see com.marklogic.xcc.types.XdmVariable#getName() + */ + public XName getName() { + return xname; + } + + /* + * (non-Javadoc) + * + * @see com.marklogic.xcc.types.XdmVariable#getValue() + */ + public XdmValue getValue() { + if (xMin instanceof XSInteger) { + long min = ((XSInteger) xMin).asPrimitiveLong(); + long range = ((XSInteger) xMax).asPrimitiveLong() - min; + return ValueFactory.newXSInteger(min + + (long) (Math.random() * range)); + } + + if (xMin instanceof XSDouble) { + double min = ((XSDouble) xMin).asPrimitiveDouble(); + double range = ((XSDouble) xMax).asPrimitiveDouble() - min; + return ValueFactory.newValue(ValueType.XS_DOUBLE, min + + (Math.random() * range)); + } + + // TODO implement types as needed + + throw new UnimplementedFeatureException( + "cannot use ranges of type " + type); + } +} diff --git a/src/java/com/marklogic/performance/Result.java b/src/java/com/marklogic/performance/Result.java index 16fbe0f..8da5d17 100644 --- a/src/java/com/marklogic/performance/Result.java +++ b/src/java/com/marklogic/performance/Result.java @@ -165,7 +165,7 @@ public void setQueryResult(String res, boolean e) { bytesReceived += res.length(); } - void print() { + public void print() { System.out.println(queryResult); } diff --git a/src/java/com/marklogic/performance/SummaryResults.java b/src/java/com/marklogic/performance/SummaryResults.java index 6b1ecfd..ad92010 100644 --- a/src/java/com/marklogic/performance/SummaryResults.java +++ b/src/java/com/marklogic/performance/SummaryResults.java @@ -25,6 +25,8 @@ import java.util.List; import java.util.Vector; +import com.marklogic.performance.sampler.Sampler; + /** * @author Michael Blakeley, michael.blakeley@marklogic.com * diff --git a/src/java/com/marklogic/performance/UnknownResultFieldException.java b/src/java/com/marklogic/performance/UnknownResultFieldException.java index 90a8cb0..0310502 100644 --- a/src/java/com/marklogic/performance/UnknownResultFieldException.java +++ b/src/java/com/marklogic/performance/UnknownResultFieldException.java @@ -1,5 +1,5 @@ /* - * Copyright (c)2005-2006 Mark Logic Corporation + * Copyright (c)2005-2007 Mark Logic Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,11 +18,13 @@ */ package com.marklogic.performance; +import java.io.IOException; + /** * @author Michael Blakeley, michael.blakeley@marklogic.com * */ -public class UnknownResultFieldException extends ReporterException { +public class UnknownResultFieldException extends IOException { /** * @param message diff --git a/src/java/com/marklogic/performance/XMLFileTest.java b/src/java/com/marklogic/performance/XMLFileTest.java index 879ee6e..9d3d249 100644 --- a/src/java/com/marklogic/performance/XMLFileTest.java +++ b/src/java/com/marklogic/performance/XMLFileTest.java @@ -30,8 +30,12 @@ import com.marklogic.xcc.exceptions.UnimplementedFeatureException; import com.marklogic.xcc.types.ValueType; import com.marklogic.xcc.types.XName; +import com.marklogic.xcc.types.XdmValue; import com.marklogic.xcc.types.XdmVariable; +/* + * @author Ron Avnur @author Michael Blakeley + */ class XMLFileTest extends AbstractTest { /** @@ -71,6 +75,12 @@ class XMLFileTest extends AbstractTest { private static final String VARIABLE_VALUE_LOCAL_NAME = "value"; + private static final String VARIABLE_VALUELIST_LOCAL_NAME = "value-csv"; + + private static final String VARIABLE_MINVALUE_LOCAL_NAME = "min-value"; + + private static final String VARIABLE_MAXVALUE_LOCAL_NAME = "max-value"; + private String commentExpectedResult; private String query; @@ -124,8 +134,10 @@ private void configureVariables(Node variablesNode) } NodeList children = variablesNode.getChildNodes(); int length = children.getLength(); - variables = new XdmVariable[length]; + variables = new ListVariable[length]; Node n, name, namespaceNode, typeNode, value = null; + // TODO support variable ranges and lists of values + Node valuesCSV, minValue, maxValue = null; String namespace, type; NamedNodeMap attr; for (int i = 0; i < length; i++) { @@ -152,24 +164,55 @@ private void configureVariables(Node variablesNode) + VARIABLE_NAME_LOCAL_NAME); } if (null == value) { + + // TODO look for value lists and ranges + valuesCSV = attr + .getNamedItem(VARIABLE_VALUELIST_LOCAL_NAME); + if (null != valuesCSV) { + variables[i] = new ListVariable(name.getNodeValue(), + namespace, type, valuesCSV.getNodeValue() + .split(",")); + continue; + } + + minValue = attr + .getNamedItem(VARIABLE_MINVALUE_LOCAL_NAME); + maxValue = attr + .getNamedItem(VARIABLE_MAXVALUE_LOCAL_NAME); + if (null != minValue && null != maxValue) { + variables[i] = new RangeVariable(name.getNodeValue(), + namespace, type, minValue.getNodeValue(), + maxValue.getNodeValue()); + continue; + } + // values may not be needed if (type.endsWith("?") || type.endsWith("*")) { variables[i] = newVariable(name.getNodeValue(), - namespace, type, null); + namespace, type); + continue; } throw new NullPointerException( "missing required variable attribute: " + VARIABLE_VALUE_LOCAL_NAME + " (or child items)"); - } else if (null != value) { - variables[i] = newVariable(name.getNodeValue(), - namespace, type, value.getNodeValue()); } - // System.err.println("variable " + variables[i].getName() - // + " = " + variables[i].getValue().asString()); + variables[i] = newVariable(name.getNodeValue(), namespace, + type, value.getNodeValue()); } } + /** + * @param name + * @param namespace + * @param type + * @return + */ + private static XdmVariable newVariable(String name, String namespace, + String type) { + return newVariable(name, namespace, type, null); + } + /** * @param name * @param namespace @@ -177,48 +220,47 @@ private void configureVariables(Node variablesNode) * @param value * @return */ - private XdmVariable newVariable(String name, String namespace, + private static XdmVariable newVariable(String name, String namespace, String type, String value) { XName xname = (null == namespace) ? new XName(name) : new XName( namespace, name); // System.err.println("variable " + xname + " = " + value + " (" // + type + ")"); + XdmValue xvalue = newValue(type, value); + return ValueFactory.newVariable(xname, xvalue); + } + + static XdmValue newValue(String type, String value) { // if type is empty, we assume a string if (null == type) { - return newVariable(name, namespace, "xs:string", value); + return newValue("xs:string", value); } if (type.equals("xs:string")) { - return ValueFactory.newVariable(xname, ValueFactory - .newXSString(value)); + return ValueFactory.newXSString(value); } if (type.equals("xs:boolean")) { - return ValueFactory.newVariable(xname, ValueFactory - .newXSBoolean(Boolean.parseBoolean(value))); + return ValueFactory.newXSBoolean(Boolean.parseBoolean(value)); } if (type.equals("xs:integer")) { - return ValueFactory.newVariable(xname, ValueFactory - .newXSInteger(Integer.parseInt(value))); + return ValueFactory.newXSInteger(Integer.parseInt(value)); } if (type.equals("xs:double")) { - return ValueFactory.newVariable(xname, ValueFactory.newValue( - ValueType.XS_DOUBLE, Double.parseDouble(value))); + return ValueFactory.newValue(ValueType.XS_DOUBLE, Double + .parseDouble(value)); } if (type.equals("xs:date")) { - return ValueFactory.newVariable(xname, ValueFactory - .newXSDate(value, null, null)); + return ValueFactory.newXSDate(value, null, null); } if (type.equals("xs:dateTime")) { - return ValueFactory.newVariable(xname, ValueFactory - .newXSDateTime(value, null, null)); + return ValueFactory.newXSDateTime(value, null, null); } if (type.equals("xs:time")) { - return ValueFactory.newVariable(xname, ValueFactory - .newXSTime(value, null, null)); + return ValueFactory.newXSTime(value, null, null); } // TODO implement more types as needed throw new UnimplementedFeatureException( - "variable/@type not implemented: " + name); + "variable type not implemented: " + type); } /* @@ -259,4 +301,5 @@ public boolean hasVariables() { public XdmVariable[] getVariables() { return variables; } + } \ No newline at end of file diff --git a/src/java/com/marklogic/performance/junit/TestSampler.java b/src/java/com/marklogic/performance/junit/TestSampler.java index 6594354..a4cace0 100644 --- a/src/java/com/marklogic/performance/junit/TestSampler.java +++ b/src/java/com/marklogic/performance/junit/TestSampler.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2006 Mark Logic Corporation. All rights reserved. + * Copyright (c) 2006-2007 Mark Logic Corporation. All rights reserved. */ package com.marklogic.performance.junit; @@ -7,7 +7,7 @@ import com.marklogic.performance.Configuration; import com.marklogic.performance.Result; -import com.marklogic.performance.Sampler; +import com.marklogic.performance.sampler.Sampler; import com.marklogic.performance.TestInterface; import com.marklogic.performance.TestIterator; @@ -30,7 +30,7 @@ public class TestSampler extends Sampler { * * @see com.marklogic.performance.Sampler#sample(com.marklogic.performance.TestInterface) */ - protected Result sample(TestInterface test) throws IOException { + public Result sample(TestInterface test) throws IOException { throw new IOException("unimplemented"); } diff --git a/src/java/com/marklogic/performance/AbstractReporter.java b/src/java/com/marklogic/performance/reporter/AbstractReporter.java similarity index 86% rename from src/java/com/marklogic/performance/AbstractReporter.java rename to src/java/com/marklogic/performance/reporter/AbstractReporter.java index 2535971..b20c8f5 100644 --- a/src/java/com/marklogic/performance/AbstractReporter.java +++ b/src/java/com/marklogic/performance/reporter/AbstractReporter.java @@ -1,5 +1,5 @@ /* - * Copyright (c)2005-2006 Mark Logic Corporation + * Copyright (c)2005-2007 Mark Logic Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,9 @@ * The use of the Apache License does not indicate that this project is * affiliated with the Apache Software Foundation. */ -package com.marklogic.performance; +package com.marklogic.performance.reporter; + +import com.marklogic.performance.SummaryResults; /** * @author Michael Blakeley, michael.blakeley@marklogic.com diff --git a/src/java/com/marklogic/performance/CSVReporter.java b/src/java/com/marklogic/performance/reporter/CSVReporter.java similarity index 92% rename from src/java/com/marklogic/performance/CSVReporter.java rename to src/java/com/marklogic/performance/reporter/CSVReporter.java index 67f3ccf..65201e2 100644 --- a/src/java/com/marklogic/performance/CSVReporter.java +++ b/src/java/com/marklogic/performance/reporter/CSVReporter.java @@ -1,5 +1,5 @@ /* - * Copyright (c)2005-2006 Mark Logic Corporation + * Copyright (c)2005-2007 Mark Logic Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ * The use of the Apache License does not indicate that this project is * affiliated with the Apache Software Foundation. */ -package com.marklogic.performance; +package com.marklogic.performance.reporter; import java.io.IOException; import java.io.Writer; @@ -24,11 +24,15 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.marklogic.performance.Result; +import com.marklogic.performance.ResultInterface; +import com.marklogic.performance.sampler.Sampler; + /** * @author Michael Blakeley, michael.blakeley@marklogic.com * */ -class CSVReporter extends AbstractReporter { +public class CSVReporter extends AbstractReporter { Pattern multilineWhitespace = Pattern.compile(".*\\s+.*", Pattern.DOTALL); private Matcher matcher; diff --git a/src/java/com/marklogic/performance/Reporter.java b/src/java/com/marklogic/performance/reporter/Reporter.java similarity index 87% rename from src/java/com/marklogic/performance/Reporter.java rename to src/java/com/marklogic/performance/reporter/Reporter.java index e0489a1..ebff860 100644 --- a/src/java/com/marklogic/performance/Reporter.java +++ b/src/java/com/marklogic/performance/reporter/Reporter.java @@ -1,5 +1,5 @@ /* - * Copyright (c)2005-2006 Mark Logic Corporation + * Copyright (c)2005-2007 Mark Logic Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,17 +16,19 @@ * The use of the Apache License does not indicate that this project is * affiliated with the Apache Software Foundation. */ -package com.marklogic.performance; +package com.marklogic.performance.reporter; import java.io.IOException; import java.io.Writer; +import com.marklogic.performance.SummaryResults; + /** * @author Ron Avnur, ron.avnur@marklogic.com * @author Michael Blakeley, michael.blakeley@marklogic.com * */ -interface Reporter { +public interface Reporter { void report(Writer out, boolean reportTime) throws IOException; diff --git a/src/java/com/marklogic/performance/ReporterException.java b/src/java/com/marklogic/performance/reporter/ReporterException.java similarity index 91% rename from src/java/com/marklogic/performance/ReporterException.java rename to src/java/com/marklogic/performance/reporter/ReporterException.java index 797b634..25f3fd5 100644 --- a/src/java/com/marklogic/performance/ReporterException.java +++ b/src/java/com/marklogic/performance/reporter/ReporterException.java @@ -1,5 +1,5 @@ /* - * Copyright (c)2005-2006 Mark Logic Corporation + * Copyright (c)2005-2007 Mark Logic Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ * The use of the Apache License does not indicate that this project is * affiliated with the Apache Software Foundation. */ -package com.marklogic.performance; +package com.marklogic.performance.reporter; import java.io.IOException; diff --git a/src/java/com/marklogic/performance/XMLReporter.java b/src/java/com/marklogic/performance/reporter/XMLReporter.java similarity index 94% rename from src/java/com/marklogic/performance/XMLReporter.java rename to src/java/com/marklogic/performance/reporter/XMLReporter.java index 76069db..14c6cbf 100644 --- a/src/java/com/marklogic/performance/XMLReporter.java +++ b/src/java/com/marklogic/performance/reporter/XMLReporter.java @@ -1,5 +1,5 @@ /* - * Copyright (c)2005-2006 Mark Logic Corporation + * Copyright (c)2005-2007 Mark Logic Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,18 +16,22 @@ * The use of the Apache License does not indicate that this project is * affiliated with the Apache Software Foundation. */ -package com.marklogic.performance; +package com.marklogic.performance.reporter; import java.io.IOException; import java.io.Writer; import java.util.List; +import com.marklogic.performance.Result; +import com.marklogic.performance.ResultInterface; +import com.marklogic.performance.sampler.Sampler; + /** * @author Ron Avnur, ron.avnur@marklogic.com * @author Michael Blakeley, michael.blakeley@marklogic.com * */ -class XMLReporter extends AbstractReporter { +public class XMLReporter extends AbstractReporter { public XMLReporter() { super(); diff --git a/src/java/com/marklogic/performance/Base64Encoder.java b/src/java/com/marklogic/performance/sampler/Base64Encoder.java similarity index 98% rename from src/java/com/marklogic/performance/Base64Encoder.java rename to src/java/com/marklogic/performance/sampler/Base64Encoder.java index 88ea235..02175dd 100644 --- a/src/java/com/marklogic/performance/Base64Encoder.java +++ b/src/java/com/marklogic/performance/sampler/Base64Encoder.java @@ -15,7 +15,7 @@ * */ -package com.marklogic.performance; +package com.marklogic.performance.sampler; /** * This class provides an implementation of Base64 encoding without relying on diff --git a/src/java/com/marklogic/performance/HTTPSampler.java b/src/java/com/marklogic/performance/sampler/HTTPSampler.java similarity index 89% rename from src/java/com/marklogic/performance/HTTPSampler.java rename to src/java/com/marklogic/performance/sampler/HTTPSampler.java index 4f48a9e..4f2ca9f 100644 --- a/src/java/com/marklogic/performance/HTTPSampler.java +++ b/src/java/com/marklogic/performance/sampler/HTTPSampler.java @@ -1,5 +1,5 @@ /* - * Copyright (c)2005-2006 Mark Logic Corporation + * Copyright (c)2005-2007 Mark Logic Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ * The use of the Apache License does not indicate that this project is * affiliated with the Apache Software Foundation. */ -package com.marklogic.performance; +package com.marklogic.performance.sampler; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; @@ -27,13 +27,19 @@ import java.net.URLConnection; import java.net.URLEncoder; -class HTTPSampler extends Sampler { +import com.marklogic.performance.Configuration; +import com.marklogic.performance.Result; +import com.marklogic.performance.ResultInterface; +import com.marklogic.performance.TestInterface; +import com.marklogic.performance.TestIterator; + +public class HTTPSampler extends Sampler { public final static String AUTO_REDIRECTS = "HTTPSampler.auto_redirects"; private static final String ENCODING = "UTF-8"; - HTTPSampler(TestIterator ti, Configuration cfg) { + public HTTPSampler(TestIterator ti, Configuration cfg) { super(ti, cfg); } @@ -91,7 +97,7 @@ private byte[] readResponse(HttpURLConnection conn) return w.toByteArray(); } - protected Result sample(TestInterface test) throws IOException { + public Result sample(TestInterface test) throws IOException { Result res = new Result(test.getName(), test .getCommentExpectedResult()); byte[] responseData = null; diff --git a/src/java/com/marklogic/performance/Sampler.java b/src/java/com/marklogic/performance/sampler/Sampler.java similarity index 94% rename from src/java/com/marklogic/performance/Sampler.java rename to src/java/com/marklogic/performance/sampler/Sampler.java index d2bac02..7dd7d58 100644 --- a/src/java/com/marklogic/performance/Sampler.java +++ b/src/java/com/marklogic/performance/sampler/Sampler.java @@ -1,5 +1,5 @@ /* - * Copyright (c)2005-2006 Mark Logic Corporation + * Copyright (c)2005-2007 Mark Logic Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ * The use of the Apache License does not indicate that this project is * affiliated with the Apache Software Foundation. */ -package com.marklogic.performance; +package com.marklogic.performance.sampler; import java.io.IOException; import java.util.ArrayList; @@ -24,6 +24,12 @@ import java.util.List; import java.util.Random; +import com.marklogic.performance.Configuration; +import com.marklogic.performance.Result; +import com.marklogic.performance.ResultInterface; +import com.marklogic.performance.TestInterface; +import com.marklogic.performance.TestIterator; + // TODO implement fixed number of test loops (iterations) public abstract class Sampler extends Thread { @@ -58,14 +64,14 @@ public abstract class Sampler extends Thread { byte[] readBuffer = new byte[readsize]; - protected Sampler(TestIterator ti, Configuration cfg) { + public Sampler(TestIterator ti, Configuration cfg) { testIterator = ti; config = cfg; // ensure that results are never null results = new ArrayList(); } - protected abstract Result sample(TestInterface test) + public abstract Result sample(TestInterface test) throws IOException; public int getResultsCount() { diff --git a/src/java/com/marklogic/performance/SamplerException.java b/src/java/com/marklogic/performance/sampler/SamplerException.java similarity index 91% rename from src/java/com/marklogic/performance/SamplerException.java rename to src/java/com/marklogic/performance/sampler/SamplerException.java index 18e744e..76893e0 100644 --- a/src/java/com/marklogic/performance/SamplerException.java +++ b/src/java/com/marklogic/performance/sampler/SamplerException.java @@ -1,5 +1,5 @@ /* - * Copyright (c)2005-2006 Mark Logic Corporation + * Copyright (c)2005-2007 Mark Logic Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ * The use of the Apache License does not indicate that this project is * affiliated with the Apache Software Foundation. */ -package com.marklogic.performance; +package com.marklogic.performance.sampler; import java.io.IOException; diff --git a/src/java/com/marklogic/performance/URISampler.java b/src/java/com/marklogic/performance/sampler/URISampler.java similarity index 88% rename from src/java/com/marklogic/performance/URISampler.java rename to src/java/com/marklogic/performance/sampler/URISampler.java index 7be8aa6..20fde9f 100644 --- a/src/java/com/marklogic/performance/URISampler.java +++ b/src/java/com/marklogic/performance/sampler/URISampler.java @@ -1,5 +1,5 @@ /* - * Copyright (c)2005-2006 Mark Logic Corporation + * Copyright (c)2005-2007 Mark Logic Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ * The use of the Apache License does not indicate that this project is * affiliated with the Apache Software Foundation. */ -package com.marklogic.performance; +package com.marklogic.performance.sampler; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; @@ -24,13 +24,18 @@ import java.net.HttpURLConnection; import java.net.URL; +import com.marklogic.performance.Configuration; +import com.marklogic.performance.Result; +import com.marklogic.performance.TestInterface; +import com.marklogic.performance.TestIterator; + /* * this class expects the query to contain a simple URI, which it attempts to * GET from the server */ -class URISampler extends Sampler { +public class URISampler extends Sampler { - URISampler(TestIterator ti, Configuration cfg) { + public URISampler(TestIterator ti, Configuration cfg) { super(ti, cfg); } @@ -79,7 +84,7 @@ private byte[] readResponse(HttpURLConnection conn) } } - protected Result sample(TestInterface test) throws IOException { + public Result sample(TestInterface test) throws IOException { Result res = new Result(test.getName(), test .getCommentExpectedResult()); byte[] responseData = null; diff --git a/src/java/com/marklogic/performance/XCCSampler.java b/src/java/com/marklogic/performance/sampler/XCCSampler.java similarity index 92% rename from src/java/com/marklogic/performance/XCCSampler.java rename to src/java/com/marklogic/performance/sampler/XCCSampler.java index 67ca79e..0b5fcd9 100644 --- a/src/java/com/marklogic/performance/XCCSampler.java +++ b/src/java/com/marklogic/performance/sampler/XCCSampler.java @@ -16,11 +16,15 @@ * The use of the Apache License does not indicate that this project is * affiliated with the Apache Software Foundation. */ -package com.marklogic.performance; +package com.marklogic.performance.sampler; import java.io.IOException; import java.io.Reader; +import com.marklogic.performance.Configuration; +import com.marklogic.performance.Result; +import com.marklogic.performance.TestInterface; +import com.marklogic.performance.TestIterator; import com.marklogic.xcc.ContentSource; import com.marklogic.xcc.ContentSourceFactory; import com.marklogic.xcc.Request; @@ -31,7 +35,7 @@ import com.marklogic.xcc.exceptions.XccException; import com.marklogic.xcc.types.XdmVariable; -class XCCSampler extends Sampler { +public class XCCSampler extends Sampler { // use char instead of superclass byte char[] readBuffer = new char[readsize]; @@ -40,11 +44,11 @@ class XCCSampler extends Sampler { * @param ti * @param cfg */ - XCCSampler(TestIterator ti, Configuration cfg) { + public XCCSampler(TestIterator ti, Configuration cfg) { super(ti, cfg); } - protected Result sample(TestInterface test) throws IOException { + public Result sample(TestInterface test) throws IOException { // time to make sure we have a connection: // do this per sample, in case Java's thread management isn't fair // new connection every time, to distribute load more evenly diff --git a/src/java/com/marklogic/performance/XDBCSampler.java b/src/java/com/marklogic/performance/sampler/XDBCSampler.java similarity index 90% rename from src/java/com/marklogic/performance/XDBCSampler.java rename to src/java/com/marklogic/performance/sampler/XDBCSampler.java index 571222b..89108a3 100644 --- a/src/java/com/marklogic/performance/XDBCSampler.java +++ b/src/java/com/marklogic/performance/sampler/XDBCSampler.java @@ -1,5 +1,5 @@ /* - * Copyright (c)2005-2006 Mark Logic Corporation + * Copyright (c)2005-2007 Mark Logic Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,17 +16,21 @@ * The use of the Apache License does not indicate that this project is * affiliated with the Apache Software Foundation. */ -package com.marklogic.performance; +package com.marklogic.performance.sampler; import java.io.IOException; import java.io.Reader; +import com.marklogic.performance.Configuration; +import com.marklogic.performance.Result; +import com.marklogic.performance.TestInterface; +import com.marklogic.performance.TestIterator; import com.marklogic.xdbc.XDBCException; import com.marklogic.xdbc.XDBCResultSequence; import com.marklogic.xdbc.XDBCStatement; import com.marklogic.xdmp.XDMPConnection; -class XDBCSampler extends Sampler { +public class XDBCSampler extends Sampler { // use char instead of superclass byte char[] readBuffer = new char[readsize]; @@ -35,11 +39,11 @@ class XDBCSampler extends Sampler { * @param ti * @param cfg */ - XDBCSampler(TestIterator ti, Configuration cfg) { + public XDBCSampler(TestIterator ti, Configuration cfg) { super(ti, cfg); } - protected Result sample(TestInterface test) throws IOException { + public Result sample(TestInterface test) throws IOException { // time to make sure we have a connection: // do this per sample, in case Java's thread management isn't fair