Add basic testing support for the Cassandra Stress tool

Patch by Christopher Batey; reviewed by Joel Knighton for CASSANDRA-11638
This commit is contained in:
Christopher Batey 2016-04-24 12:52:30 +01:00 committed by Aleksey Yeschenko
parent 2aa665aa00
commit b73f581355
5 changed files with 108 additions and 16 deletions

View File

@ -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/"/>

View File

@ -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" />

View File

@ -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;
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}