Skip to content

Commit

Permalink
Fix #179 Add in support for copying across .conf files
Browse files Browse the repository at this point in the history
  • Loading branch information
Ardesco committed Jan 21, 2017
1 parent 59ff49b commit 5151004
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/it/custom-conf-files/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=clean verify
65 changes: 65 additions & 0 deletions src/it/custom-conf-files/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.lazerycode.jmeter</groupId>
<artifactId>custom-conf-files-integration-test</artifactId>
<version>DEV-SNAPSHOT</version>

<description>Basic Jmeter test to check conf files overwrite ones provided by JMeter</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<repositories>
<repository>
<id>apache-snapshots</id>
<name>Apache Snapshots</name>
<url>https://repository.apache.org/content/groups/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<configuration>
<suppressJMeterOutput>false</suppressJMeterOutput>
<testFilesIncluded>
<testFilesIncluded>test.jmx</testFilesIncluded>
</testFilesIncluded>
</configuration>
<executions>
<execution>
<id>configure</id>
<goals>
<goal>configure</goal>
</goals>
</execution>
<execution>
<id>performance test</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>results</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
1 change: 1 addition & 0 deletions src/it/custom-conf-files/src/test/conf/invented.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
; made up file that should be copied
1 change: 1 addition & 0 deletions src/it/custom-conf-files/src/test/conf/krb5.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
; Test file that should overwrite original file
86 changes: 86 additions & 0 deletions src/it/custom-conf-files/src/test/jmeter/test.jmx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.9" jmeter="3.0">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">5</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<longProp name="ThreadGroup.start_time">1457547791000</longProp>
<longProp name="ThreadGroup.end_time">1457547791000</longProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
</ThreadGroup>
<hashTree>
<ResultCollector guiclass="TableVisualizer" testclass="ResultCollector" testname="View Results in Table" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>true</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<threadCounts>true</threadCounts>
<idleTime>true</idleTime>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP Request" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="HTTPSampler.domain">www.mozilla.com</stringProp>
<stringProp name="HTTPSampler.port">80</stringProp>
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
<stringProp name="HTTPSampler.response_timeout"></stringProp>
<stringProp name="HTTPSampler.protocol"></stringProp>
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
<stringProp name="HTTPSampler.path"></stringProp>
<stringProp name="HTTPSampler.method">GET</stringProp>
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
<boolProp name="HTTPSampler.monitor">false</boolProp>
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
</HTTPSamplerProxy>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>
16 changes: 15 additions & 1 deletion src/main/java/com/lazerycode/jmeter/mojo/AbstractJMeterMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.lazerycode.jmeter.configuration.JMeterProcessJVMSettings;
import com.lazerycode.jmeter.configuration.ProxyConfiguration;
import com.lazerycode.jmeter.configuration.RemoteConfiguration;
import com.lazerycode.jmeter.exceptions.IOException;
import com.lazerycode.jmeter.properties.ConfigurationFiles;
import com.lazerycode.jmeter.properties.PropertiesMapping;
import org.apache.commons.io.FileUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecution;
Expand Down Expand Up @@ -47,6 +49,12 @@ public abstract class AbstractJMeterMojo extends AbstractMojo {
@Parameter
protected List<String> testFilesExcluded = new ArrayList<>();

/**
* Path under which .conf files are stored.
*/
@Parameter(defaultValue = "${basedir}/src/test/conf")
protected File confFilesDirectory;

/**
* Path under which JMX files are stored.
*/
Expand Down Expand Up @@ -292,8 +300,14 @@ protected void loadMavenProxy() {
} catch (Exception e) {
getLog().error("Error while loading maven proxy", e);
}
}

static void CopyFilesInTestDirectory(File sourceDirectory, File destinationDirectory) throws IOException {
try {
FileUtils.copyDirectory(sourceDirectory, destinationDirectory);
} catch (java.io.IOException e) {
throw new IOException(e.getMessage(), e);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ private void populateJMeterDirectoryTree() throws DependencyResolutionException,
copyTransitiveRuntimeDependenciesToLibDirectory(returnedArtifact, downloadJMeterDependencies);
}
}

if (confFilesDirectory.exists()) {
CopyFilesInTestDirectory(confFilesDirectory, new File(jmeterDirectory, "bin"));
}
}

/**
Expand Down Expand Up @@ -497,10 +501,8 @@ private void extractConfigSettings(Artifact artifact) throws IOException {
break;
}
copyInputStreamToFile(configSettings.getInputStream(jarFileEntry), fileToCreate);
}
else if(!jarFileEntry.isDirectory() && jarFileEntry.getName().startsWith("bin")){
getLog().info(jarFileEntry.getName());
//todo report generation directory?
} else if (!jarFileEntry.isDirectory() && jarFileEntry.getName().startsWith("bin")) {
//TODO populate report generation directory
}
}
configSettings.close();
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/com/lazerycode/jmeter/mojo/RunJMeterMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,4 @@ public void doExecute() throws MojoExecutionException, MojoFailureException {
testConfig.setResultsFileLocations(jMeterTestManager.executeTests());
testConfig.writeResultFilesConfigTo(testConfigFile);
}


static void CopyFilesInTestDirectory(File sourceDirectory, File destinationDirectory) throws IOException {
try {
FileUtils.copyDirectory(sourceDirectory, destinationDirectory);
} catch (java.io.IOException e) {
throw new IOException(e.getMessage(), e);
}

}
}

0 comments on commit 5151004

Please sign in to comment.