Skip to content
Permalink
Browse files
+ checkUser jmeter test
  • Loading branch information
shawnmckinney committed Oct 24, 2020
1 parent 372a4ce commit ca8248a0d696b29c78b99c4f2ea6adbe673d06be
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 4 deletions.
@@ -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

___________________________________________________________________________________
52 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>
@@ -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;
}
}
@@ -47,6 +47,7 @@
*/
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 @@ protected boolean verify( String userId, Op op )
}
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 void setupTest( JavaSamplerContext samplerContext )
System.out.println( message );
try
{
accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
adminMgr = AdminMgrFactory.createInstance( TestUtils.getContext() );
reviewMgr = ReviewMgrFactory.createInstance( TestUtils.getContext() );
}
@@ -175,6 +179,15 @@ private void init( JavaSamplerContext samplerContext )
{
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 @@ protected void write( String message )
printWriter.flush();
}
}

protected int getRandomNumber()
{
int number = (int) ((Math.random() * (size - 1)) + 1);
return number;
}
}
@@ -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>
@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<jmeterTestPlan version="1.2" properties="2.6" jmeter="2.11 r1554548">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="RbacLoadTester" 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">../../../config</stringProp>
</TestPlan>
<hashTree>
<CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="CSV Data Set Config" enabled="false">
<stringProp name="delimiter">,</stringProp>
<stringProp name="fileEncoding"></stringProp>
<stringProp name="filename">CheckUser.csv</stringProp>
<boolProp name="quotedData">false</boolProp>
<boolProp name="recycle">true</boolProp>
<stringProp name="shareMode">shareMode.all</stringProp>
<boolProp name="stopThread">false</boolProp>
<stringProp name="variableNames"></stringProp>
</CSVDataSet>
<hashTree/>
<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">100000</stringProp>
</elementProp>
<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 CheckUser" enabled="true">
<elementProp name="arguments" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="qualifier" elementType="Argument">
<stringProp name="Argument.name">qualifier</stringProp>
<stringProp name="Argument.value">Z</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="verify" elementType="Argument">
<stringProp name="Argument.name">verify</stringProp>
<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>
<elementProp name="update" elementType="Argument">
<stringProp name="Argument.name">update</stringProp>
<stringProp name="Argument.value">true</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="sleep" elementType="Argument">
<stringProp name="Argument.name">sleep</stringProp>
<stringProp name="Argument.value">0</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<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.CheckUser</stringProp>
</JavaSampler>
<hashTree/>
<ResultCollector guiclass="SummaryReport" testclass="ResultCollector" testname="Summary Report" 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>true</xml>
<fieldNames>false</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>

0 comments on commit ca8248a

Please sign in to comment.