Repository: cassandra Updated Branches: refs/heads/trunk 2aa665aa0 -> b73f58135
Add basic testing support for the Cassandra Stress tool Patch by Christopher Batey; reviewed by Joel Knighton for CASSANDRA-11638 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/b73f5813 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/b73f5813 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/b73f5813 Branch: refs/heads/trunk Commit: b73f5813559e5356f2dd50e4c3c15e520d7db0cc Parents: 2aa665a Author: Christopher Batey <[email protected]> Authored: Sun Apr 24 12:52:30 2016 +0100 Committer: Aleksey Yeschenko <[email protected]> Committed: Mon Jul 4 14:48:52 2016 +0100 ---------------------------------------------------------------------- build.xml | 29 +++++++++++++- ide/idea-iml-file.xml | 1 + .../cassandra/stress/settings/SettingsNode.java | 18 ++------- .../stress/settings/OptionReplicationTest.java | 34 ++++++++++++++++ .../stress/settings/SettingsNodeTest.java | 42 ++++++++++++++++++++ 5 files changed, 108 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/b73f5813/build.xml ---------------------------------------------------------------------- diff --git a/build.xml b/build.xml index 9603855..1492d23 100644 --- a/build.xml +++ b/build.xml @@ -189,6 +189,7 @@ <mkdir dir="${build.classes.thrift}"/> <mkdir dir="${test.lib}"/> <mkdir dir="${test.classes}"/> + <mkdir dir="${stress.test.classes}"/> <mkdir dir="${build.src.gen-java}"/> <mkdir dir="${build.dir.lib}"/> <mkdir dir="${jacoco.export.dir}"/> @@ -830,12 +831,29 @@ <!-- Stress build file --> <property name="stress.build.src" value="${basedir}/tools/stress/src" /> + <property name="stress.test.src" value="${basedir}/tools/stress/test/unit" /> <property name="stress.build.classes" value="${build.classes}/stress" /> + <property name="stress.test.classes" value="${build.dir}/test/stress-classes" /> <property name="stress.manifest" value="${stress.build.classes}/MANIFEST.MF" /> <path id="cassandra.classes"> <pathelement location="${basedir}/build/classes/main" /> <pathelement location="${basedir}/build/classes/thrift" /> </path> + + <target name="stress-build-test" depends="stress-build" description="Compile stress tests"> + <javac debug="true" debuglevel="${debuglevel}" destdir="${stress.test.classes}" + includeantruntime="false" + source="${source.version}" + target="${target.version}" + encoding="utf-8"> + <classpath> + <path refid="cassandra.classpath"/> + <pathelement location="${stress.build.classes}" /> + </classpath> + <src path="${stress.test.src}"/> + </javac> + </target> + <target name="stress-build" depends="build" description="build stress tool"> <mkdir dir="${stress.build.classes}" /> <javac compiler="modern" debug="true" debuglevel="${debuglevel}" encoding="utf-8" destdir="${stress.build.classes}" includeantruntime="true" source="${source.version}" target="${target.version}"> @@ -854,6 +872,12 @@ </copy> </target> + <target name="stress-test" depends="stress-build-test, build-test" description="Runs stress tests"> + <testmacro inputdir="${stress.test.src}" + timeout="${test.timeout}"> + </testmacro> + </target> + <target name="_write-poms" depends="maven-declare-dependencies"> <artifact:writepom pomRefId="parent-pom" file="${build.dir}/${final.name}-parent.pom"/> <artifact:writepom pomRefId="thrift-pom" @@ -1248,8 +1272,10 @@ <optjvmargs/> <classpath> <pathelement path="${java.class.path}"/> + <pathelement location="${stress.build.classes}"/> <path refid="cassandra.classpath" /> <pathelement location="${test.classes}"/> + <pathelement location="${stress.test.classes}"/> <pathelement location="${test.conf}"/> <fileset dir="${test.lib}"> <include name="**/*.jar" /> @@ -1551,7 +1577,7 @@ </target> <target name="test-all" - depends="eclipse-warnings,test,long-test,test-compression,test-clientutil-jar" + depends="eclipse-warnings,test,long-test,test-compression,test-clientutil-jar,stress-test" description="Run all tests except for those under test-burn" /> <!-- Use JaCoCo ant extension without needing externally saved lib --> @@ -1824,6 +1850,7 @@ <classpathentry kind="src" output="build/test/classes" path="test/long"/> <classpathentry kind="src" output="build/test/classes" path="test/resources" /> <classpathentry kind="src" path="tools/stress/src"/> + <classpathentry kind="src" output="build/test/stress-classes" path="tools/stress/test/unit" /> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="output" path="build/classes/main"/> <classpathentry kind="lib" path="build/classes/thrift" sourcepath="interface/thrift/gen-java/"/> http://git-wip-us.apache.org/repos/asf/cassandra/blob/b73f5813/ide/idea-iml-file.xml ---------------------------------------------------------------------- diff --git a/ide/idea-iml-file.xml b/ide/idea-iml-file.xml index f14fe2e..3bb51b4 100644 --- a/ide/idea-iml-file.xml +++ b/ide/idea-iml-file.xml @@ -28,6 +28,7 @@ <sourceFolder url="file://$MODULE_DIR$/src/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/interface/thrift/gen-java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/tools/stress/src" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/tools/stress/test/unit" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/test/unit" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/test/long" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/test/microbench" isTestSource="true" /> http://git-wip-us.apache.org/repos/asf/cassandra/blob/b73f5813/tools/stress/src/org/apache/cassandra/stress/settings/SettingsNode.java ---------------------------------------------------------------------- diff --git a/tools/stress/src/org/apache/cassandra/stress/settings/SettingsNode.java b/tools/stress/src/org/apache/cassandra/stress/settings/SettingsNode.java index 89b7871..a081e55 100644 --- a/tools/stress/src/org/apache/cassandra/stress/settings/SettingsNode.java +++ b/tools/stress/src/org/apache/cassandra/stress/settings/SettingsNode.java @@ -42,9 +42,8 @@ public class SettingsNode implements Serializable try { String node; - List<String> tmpNodes = new ArrayList<String>(); - BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(options.file.value()))); - try + List<String> tmpNodes = new ArrayList<>(); + try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(options.file.value())))) { while ((node = in.readLine()) != null) { @@ -53,10 +52,6 @@ public class SettingsNode implements Serializable } nodes = Arrays.asList(tmpNodes.toArray(new String[tmpNodes.size()])); } - finally - { - in.close(); - } } catch(IOException ioe) { @@ -177,13 +172,6 @@ public class SettingsNode implements Serializable public static Runnable helpPrinter() { - return new Runnable() - { - @Override - public void run() - { - printHelp(); - } - }; + return SettingsNode::printHelp; } } http://git-wip-us.apache.org/repos/asf/cassandra/blob/b73f5813/tools/stress/test/unit/org/apache/cassandra/stress/settings/OptionReplicationTest.java ---------------------------------------------------------------------- diff --git a/tools/stress/test/unit/org/apache/cassandra/stress/settings/OptionReplicationTest.java b/tools/stress/test/unit/org/apache/cassandra/stress/settings/OptionReplicationTest.java new file mode 100644 index 0000000..803ee18 --- /dev/null +++ b/tools/stress/test/unit/org/apache/cassandra/stress/settings/OptionReplicationTest.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.stress.settings; + +import com.google.common.collect.ImmutableMap; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class OptionReplicationTest +{ + @Test + public void defaultsToReplicationFactorOfOne() throws Exception + { + OptionReplication defaults = new OptionReplication(); + assertEquals(ImmutableMap.of("replication_factor", "1"), defaults.getOptions()); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/b73f5813/tools/stress/test/unit/org/apache/cassandra/stress/settings/SettingsNodeTest.java ---------------------------------------------------------------------- diff --git a/tools/stress/test/unit/org/apache/cassandra/stress/settings/SettingsNodeTest.java b/tools/stress/test/unit/org/apache/cassandra/stress/settings/SettingsNodeTest.java new file mode 100644 index 0000000..ce56d27 --- /dev/null +++ b/tools/stress/test/unit/org/apache/cassandra/stress/settings/SettingsNodeTest.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.stress.settings; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class SettingsNodeTest +{ + @Test + public void testDefaults() throws Exception + { + SettingsNode settingsNode = new SettingsNode(new SettingsNode.Options()); + assertEquals(null, settingsNode.datacenter); + } + + @Test + public void testOveridingDataCenter() throws Exception + { + SettingsNode.Options options = new SettingsNode.Options(); + options.accept("datacenter=dc1"); + SettingsNode settingsNode = new SettingsNode(options); + assertEquals("dc1", settingsNode.datacenter); + } +}
