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 master updated: + checkUser jmeter test
Date Sat, 24 Oct 2020 19:50:23 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new ca8248a  + checkUser jmeter test
ca8248a is described below

commit ca8248a0d696b29c78b99c4f2ea6adbe673d06be
Author: Shawn McKinney <smckinney@symas.com>
AuthorDate: Sat Oct 24 14:50:17 2020 -0500

    + checkUser jmeter test
---
 README.md                                          | 13 ++++
 pom.xml                                            | 52 +++++++++++++
 .../directory/fortress/core/jmeter/CheckUser.java  | 88 ++++++++++++++++++++++
 .../directory/fortress/core/jmeter/UserBase.java   | 23 +++++-
 src/test/jmeter/ftAddUser.jmx                      |  4 +-
 src/test/jmeter/{ftAddUser.jmx => ftCheckUser.jmx} | 21 +++---
 6 files changed, 186 insertions(+), 15 deletions(-)

diff --git a/README.md b/README.md
index 91768a3..e8036a7 100644
--- a/README.md
+++ b/README.md
@@ -781,6 +781,9 @@ ________________________________________________________________________________
  G. Fortress Del User:
   [src/test/jmeter/ftDelUser.jmx](src/test/jmeter/ftDelUser.jmx)
 
+ H. Fortress Check User:
+  [src/test/jmeter/ftCheckUser.jmx](src/test/jmeter/ftCheckUser.jmx)
+
 3. Setting the jmeter parameters.
 
  These settings affect the length, duration, and the number of threads:
@@ -854,6 +857,16 @@ ________________________________________________________________________________
   mvn -Ploadtest-fortress-deluser jmeter:jmeter -Dqualifier=A1 -Dverify=true -Dsleep=30
   ```
 
+ H. Check Users:
+  ```
+  mvn -Ploadtest-fortress-checkuser jmeter:jmeter -Dqualifier=A1 -Dverify=true -Dsize=20
+  ```
+
+  This test performs createSession on users.  It uses runtime arguments to define behavior:
+   * size=20  <-- defines the number of users in the test set. 
+
+
+
   * Same properties as add except for 'ou', which is not used for delete ops
 
 ___________________________________________________________________________________
diff --git a/pom.xml b/pom.xml
index f973555..5a49c23 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1303,7 +1303,59 @@
               </dependency>
             </dependencies>
           </plugin>
+        </plugins>
+      </build>
+    </profile>
 
+    <!-- This profile starts Fortress core checkAccess loadTest -->
+    <!-- To execute: mvn -Ploadtest-fortress-checkuser jmeter:jmeter -->
+    <profile>
+      <id>loadtest-fortress-checkuser</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>com.lazerycode.jmeter</groupId>
+            <artifactId>jmeter-maven-plugin</artifactId>
+            <version>1.10.0</version>
+            <configuration>
+              <overrideRootLogLevel>DEBUG</overrideRootLogLevel>
+              <suppressJMeterOutput>false</suppressJMeterOutput>
+              <testFilesIncluded>
+                <jMeterTestFile>ftCheckUser.jmx</jMeterTestFile>
+              </testFilesIncluded>
+              <propertiesSystem>
+                <version>${project.version}</version>
+                <tenant>${tenant}</tenant>
+                <hostname>${hostname}</hostname>
+                <qualifier>${qualifier}</qualifier>
+                <verify>${verify}</verify>
+                <output>${output}</output>
+                <sleep>${sleep}</sleep>
+                <size>${size}</size>
+              </propertiesSystem>
+            </configuration>
+            <executions>
+              <execution>
+                <id>jmeter-tests</id>
+                <goals>
+                  <goal>jmeter</goal>
+                </goals>
+              </execution>
+            </executions>
+            <dependencies>
+              <dependency>
+                <groupId>org.apache.directory.fortress</groupId>
+                <artifactId>fortress-core</artifactId>
+                <version>${project.version}</version>
+              </dependency>
+              <dependency>
+                <groupId>org.apache.directory.fortress</groupId>
+                <artifactId>fortress-core</artifactId>
+                <type>test-jar</type>
+                <version>${project.version}</version>
+              </dependency>
+            </dependencies>
+          </plugin>
         </plugins>
       </build>
     </profile>
diff --git a/src/test/java/org/apache/directory/fortress/core/jmeter/CheckUser.java b/src/test/java/org/apache/directory/fortress/core/jmeter/CheckUser.java
new file mode 100644
index 0000000..1c9c369
--- /dev/null
+++ b/src/test/java/org/apache/directory/fortress/core/jmeter/CheckUser.java
@@ -0,0 +1,88 @@
+/*
+ *   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.directory.fortress.core.jmeter;
+
+import org.apache.directory.fortress.core.model.Session;
+import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.directory.fortress.core.model.User;
+
+import static org.junit.Assert.*;
+
+/**
+ * Description of the Class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CheckUser extends UserBase
+{
+    private int ctr = 0;
+
+    /**
+     * Description of the Method
+     *
+     * @param samplerContext Description of the Parameter
+     * @return Description of the Return Value
+     */
+    public SampleResult runTest( JavaSamplerContext samplerContext )
+    {
+        String userId  = hostname + '-' + qualifier + '-' + getRandomNumber();
+        SampleResult sampleResult = new SampleResult();
+        try
+        {
+            sampleResult.sampleStart();
+            assertNotNull( accessMgr );
+            User user = new User();
+            user.setUserId( userId );
+            user.setPassword( "secret" );
+            write( "threadid: " + getThreadId() + ", userId: " + userId );
+            LOG.warn( "CheckUser: " + userId );
+            Session session = accessMgr.createSession( user, false );
+            assertNotNull( session );
+            if ( verify )
+            {
+                assertTrue( verify( userId, Op.CHECK ) );
+            }
+            if( sleep > 0 )
+            {
+                try
+                {
+                    Thread.sleep( sleep );
+                }
+                catch (InterruptedException ie)
+                {
+                    Thread.currentThread().interrupt();
+                }
+            }
+            sampleResult.sampleEnd();
+            sampleResult.setBytes(1);
+            sampleResult.setResponseMessage("test completed TID: " + getThreadId() + " UID:
" + userId);
+            sampleResult.setSuccessful(true);
+        }
+        catch ( org.apache.directory.fortress.core.SecurityException se )
+        {
+            warn( "ThreadId: " + getThreadId() + ", error running test: " + se );
+            se.printStackTrace();
+            sampleResult.setSuccessful( false );
+        }
+
+        return sampleResult;
+    }
+}
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 9f1eaf7..8d96913 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
@@ -47,6 +47,7 @@ import static org.junit.Assert.assertNotNull;
  */
 public abstract class UserBase extends AbstractJavaSamplerClient
 {
+    protected AccessMgr accessMgr;
     protected AdminMgr adminMgr;
     protected ReviewMgr reviewMgr;
     protected static final Logger LOG = LoggerFactory.getLogger( UserBase.class );
@@ -59,12 +60,14 @@ public abstract class UserBase extends AbstractJavaSamplerClient
     protected boolean update = false;
     protected String ou = null;
     protected int sleep = 0;
+    protected int size = 0;
     private PrintWriter printWriter;
 
     protected enum Op
     {
         ADD,
-        DEL
+        DEL,
+        CHECK
     }
 
     protected boolean verify( String userId, Op op )
@@ -84,7 +87,7 @@ public abstract class UserBase extends AbstractJavaSamplerClient
         }
         catch ( org.apache.directory.fortress.core.SecurityException se )
         {
-            if( op == Op.ADD )
+            if( op == Op.ADD || op == Op.CHECK )
             {
                 warn( "Failed add check, threadId: " + getThreadId() + ", error reading user:
" + se );
                 se.printStackTrace();
@@ -106,6 +109,7 @@ public abstract class UserBase extends AbstractJavaSamplerClient
         System.out.println( message );
         try
         {
+            accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
             adminMgr = AdminMgrFactory.createInstance( TestUtils.getContext() );
             reviewMgr = ReviewMgrFactory.createInstance( TestUtils.getContext() );
         }
@@ -175,6 +179,15 @@ public abstract class UserBase extends AbstractJavaSamplerClient
         {
             sleep = Integer.valueOf(szSleep);
         }
+        String szSize = System.getProperty( "size" );
+        if (StringUtils.isEmpty( szSize ))
+        {
+            szSize = samplerContext.getParameter( "size" );
+        }
+        if (!StringUtils.isEmpty( szSize ))
+        {
+            size = Integer.valueOf(szSize);
+        }
         filename = "operations" + '-' + "thread" + getThreadId() + '-' + hostname + '-' +
qualifier + ".txt";
         open();
     }
@@ -253,4 +266,10 @@ public abstract class UserBase extends AbstractJavaSamplerClient
             printWriter.flush();
         }
     }
+
+    protected int getRandomNumber()
+    {
+        int number = (int) ((Math.random() * (size - 1)) + 1);
+        return number;
+    }
 }
diff --git a/src/test/jmeter/ftAddUser.jmx b/src/test/jmeter/ftAddUser.jmx
index 633de05..281aaec 100644
--- a/src/test/jmeter/ftAddUser.jmx
+++ b/src/test/jmeter/ftAddUser.jmx
@@ -45,9 +45,9 @@
         <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">10</stringProp>
+          <stringProp name="LoopController.loops">1000</stringProp>
         </elementProp>
-        <stringProp name="ThreadGroup.num_threads">2</stringProp>
+        <stringProp name="ThreadGroup.num_threads">10</stringProp>
         <stringProp name="ThreadGroup.ramp_time">10</stringProp>
         <boolProp name="ThreadGroup.scheduler">false</boolProp>
         <stringProp name="ThreadGroup.duration"></stringProp>
diff --git a/src/test/jmeter/ftAddUser.jmx b/src/test/jmeter/ftCheckUser.jmx
similarity index 90%
copy from src/test/jmeter/ftAddUser.jmx
copy to src/test/jmeter/ftCheckUser.jmx
index 633de05..ed43cdc 100644
--- a/src/test/jmeter/ftAddUser.jmx
+++ b/src/test/jmeter/ftCheckUser.jmx
@@ -32,7 +32,7 @@
       <CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="CSV Data Set
Config" enabled="false">
         <stringProp name="delimiter">,</stringProp>
         <stringProp name="fileEncoding"></stringProp>
-        <stringProp name="filename">AddUser.csv</stringProp>
+        <stringProp name="filename">CheckUser.csv</stringProp>
         <boolProp name="quotedData">false</boolProp>
         <boolProp name="recycle">true</boolProp>
         <stringProp name="shareMode">shareMode.all</stringProp>
@@ -40,21 +40,21 @@
         <stringProp name="variableNames"></stringProp>
       </CSVDataSet>
       <hashTree/>
-      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Fortress
CreateSession" enabled="true">
+      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Fortress
CheckUser" 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">10</stringProp>
+          <stringProp name="LoopController.loops">100000</stringProp>
         </elementProp>
-        <stringProp name="ThreadGroup.num_threads">2</stringProp>
+        <stringProp name="ThreadGroup.num_threads">10</stringProp>
         <stringProp name="ThreadGroup.ramp_time">10</stringProp>
         <boolProp name="ThreadGroup.scheduler">false</boolProp>
         <stringProp name="ThreadGroup.duration"></stringProp>
         <stringProp name="ThreadGroup.delay"></stringProp>
       </ThreadGroup>
       <hashTree>
-        <JavaSampler guiclass="JavaTestSamplerGui" testclass="JavaSampler" testname="Fortress
CheckAccess" enabled="true">
+        <JavaSampler guiclass="JavaTestSamplerGui" testclass="JavaSampler" testname="Fortress
CheckUser" enabled="true">
           <elementProp name="arguments" elementType="Arguments" guiclass="ArgumentsPanel"
testclass="Arguments" enabled="true">
             <collectionProp name="Arguments.arguments">
               <elementProp name="qualifier" elementType="Argument">
@@ -79,18 +79,17 @@
               </elementProp>
               <elementProp name="sleep" elementType="Argument">
                 <stringProp name="Argument.name">sleep</stringProp>
-                <stringProp name="Argument.value">5</stringProp>
+                <stringProp name="Argument.value">0</stringProp>
                 <stringProp name="Argument.metadata">=</stringProp>
               </elementProp>
-              <elementProp name="ou" elementType="Argument">
-                <stringProp name="Argument.name">ou</stringProp>
-                <!-- Use one from OrgUnitExample.xml -->
-                <stringProp name="Argument.value">uou1</stringProp>
+              <elementProp name="size" elementType="Argument">
+                <stringProp name="Argument.name">size</stringProp>
+                <stringProp name="Argument.value">20</stringProp>
                 <stringProp name="Argument.metadata">=</stringProp>
               </elementProp>
             </collectionProp>
           </elementProp>
-          <stringProp name="classname">org.apache.directory.fortress.core.jmeter.AddUser</stringProp>
+          <stringProp name="classname">org.apache.directory.fortress.core.jmeter.CheckUser</stringProp>
         </JavaSampler>
         <hashTree/>
         <ResultCollector guiclass="SummaryReport" testclass="ResultCollector" testname="Summary
Report" enabled="true">


Mime
View raw message