Skip to content
Permalink
Browse files
add option to write to output file
  • Loading branch information
shawnmckinney committed Sep 21, 2020
1 parent 24a0137 commit 12d4ec30e59c8bc79941947d30e3218a03606140
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 36 deletions.
@@ -53,7 +53,8 @@ public abstract class UserBase extends AbstractJavaSamplerClient
protected String hostname;
protected String qualifier;
private String filename;
protected boolean verify;
protected boolean verify = false;
protected boolean output = false;
private PrintWriter printWriter;

protected enum Op
@@ -88,6 +89,30 @@ protected boolean verify( String userId, Op op )
return found;
}

/**
* Description of the Method
*
* @param samplerContext Description of the Parameter
*/
public void setupTest( JavaSamplerContext samplerContext )
{
init( samplerContext );
String message = "FT SETUP User TID: " + getThreadId() + ", hostname: " + hostname + ", qualifier: " + qualifier + ", verify:" + verify;
info( message );
System.out.println( message );
try
{
adminMgr = AdminMgrFactory.createInstance( TestUtils.getContext() );
reviewMgr = ReviewMgrFactory.createInstance( TestUtils.getContext() );
}
catch ( SecurityException se )
{
warn( "ThreadId: " + getThreadId() + ", error setting up test: " + se );
se.printStackTrace();
}
open();
}

private void init( JavaSamplerContext samplerContext )
{
hostname = System.getProperty( "hostname" );
@@ -110,35 +135,20 @@ private void init( JavaSamplerContext samplerContext )
{
verify = szVerify.equalsIgnoreCase( "true" );
}
filename = "operations" + '-' + "thread" + getThreadId() + '-' + hostname + '-' + qualifier + ".txt";
open();
}

/**
* Description of the Method
*
* @param samplerContext Description of the Parameter
*/
public void setupTest( JavaSamplerContext samplerContext )
{
init( samplerContext );
String message = "FT SETUP User TID: " + getThreadId() + ", hostname: " + hostname + ", qualifier: " + qualifier + ", verify:" + verify;
log( message );
System.out.println( message );
try
String szLog = System.getProperty( "log" );
if (StringUtils.isEmpty( szLog ))
{
adminMgr = AdminMgrFactory.createInstance( TestUtils.getContext() );
reviewMgr = ReviewMgrFactory.createInstance( TestUtils.getContext() );
output = samplerContext.getParameter( "output" ).equalsIgnoreCase( "true" );
}
catch ( SecurityException se )
else
{
warn( "ThreadId: " + getThreadId() + ", error setting up test: " + se );
se.printStackTrace();
output = szLog.equalsIgnoreCase( "true" );
}
filename = "operations" + '-' + "thread" + getThreadId() + '-' + hostname + '-' + qualifier + ".txt";
open();
}

protected void log( String message )
protected void info(String message )
{
LOG.info( message );
System.out.println( message );
@@ -173,34 +183,43 @@ String getThreadId()
public void teardownTest( JavaSamplerContext samplerContext )
{
String message = "FT SETUP User TID: " + getThreadId();
log( message );
info( message );
close();
System.exit(0);
}

private void open()
{
try
if( output )
{
FileWriter fileWriter = new FileWriter(filename);
printWriter = new PrintWriter(fileWriter);
}
catch ( IOException ie )
{
warn( ie.getMessage() );
try
{
FileWriter fileWriter = new FileWriter(filename);
printWriter = new PrintWriter(fileWriter);
}
catch ( IOException ie )
{
warn( ie.getMessage() );
}
}
}

private void close()
{
printWriter.close();
if( output )
{
printWriter.close();
}
}

protected void write( String message )
{
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
printWriter.printf("%s : %s\n", now, message);
printWriter.flush();
if( output )
{
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
printWriter.printf("%s : %s\n", now, message);
printWriter.flush();
}
}
}
@@ -72,6 +72,11 @@
<stringProp name="Argument.value">true</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="output" elementType="Argument">
<stringProp name="Argument.name">output</stringProp>
<stringProp name="Argument.value">false</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</elementProp>
<stringProp name="classname">org.apache.directory.fortress.core.jmeter.AddUser</stringProp>
@@ -72,6 +72,11 @@
<stringProp name="Argument.value">true</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="output" elementType="Argument">
<stringProp name="Argument.name">output</stringProp>
<stringProp name="Argument.value">false</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</elementProp>
<stringProp name="classname">org.apache.directory.fortress.core.jmeter.DelUser</stringProp>

0 comments on commit 12d4ec3

Please sign in to comment.