directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smckin...@apache.org
Subject [directory-fortress-core] branch jmeter-add-case updated: add option to write to output file
Date Mon, 21 Sep 2020 17:47:06 GMT
This is an automated email from the ASF dual-hosted git repository.

smckinney pushed a commit to branch jmeter-add-case
in repository https://gitbox.apache.org/repos/asf/directory-fortress-core.git


The following commit(s) were added to refs/heads/jmeter-add-case by this push:
     new 12d4ec3  add option to write to output file
12d4ec3 is described below

commit 12d4ec30e59c8bc79941947d30e3218a03606140
Author: Shawn McKinney <smckinney@symas.com>
AuthorDate: Mon Sep 21 12:46:59 2020 -0500

    add option to write to output file
---
 .../directory/fortress/core/jmeter/UserBase.java   | 91 +++++++++++++---------
 src/test/jmeter/ftAddUser.jmx                      |  5 ++
 src/test/jmeter/ftDelUser.jmx                      |  5 ++
 3 files changed, 65 insertions(+), 36 deletions(-)

diff --git a/src/test/java/org/apache/directory/fortress/core/jmeter/UserBase.java b/src/test/java/org/apache/directory/fortress/core/jmeter/UserBase.java
index e90242d..e447964 100644
--- a/src/test/java/org/apache/directory/fortress/core/jmeter/UserBase.java
+++ b/src/test/java/org/apache/directory/fortress/core/jmeter/UserBase.java
@@ -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 @@ public abstract class UserBase extends AbstractJavaSamplerClient
         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 @@ public abstract class UserBase extends AbstractJavaSamplerClient
         {
             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 @@ public abstract class UserBase extends AbstractJavaSamplerClient
     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();
+        }
     }
 }
diff --git a/src/test/jmeter/ftAddUser.jmx b/src/test/jmeter/ftAddUser.jmx
index 321690e..af45483 100644
--- a/src/test/jmeter/ftAddUser.jmx
+++ b/src/test/jmeter/ftAddUser.jmx
@@ -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>
diff --git a/src/test/jmeter/ftDelUser.jmx b/src/test/jmeter/ftDelUser.jmx
index e7c68e7..24aa09a 100644
--- a/src/test/jmeter/ftDelUser.jmx
+++ b/src/test/jmeter/ftDelUser.jmx
@@ -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>


Mime
View raw message