Skip to content

Commit

Permalink
Merge pull request #18 from undera/master
Browse files Browse the repository at this point in the history
Repo update
  • Loading branch information
rbourga authored Sep 6, 2024
2 parents 4041dbe + ba07004 commit 218e98f
Show file tree
Hide file tree
Showing 7 changed files with 591 additions and 389 deletions.
2 changes: 1 addition & 1 deletion plugins/redis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>kg.apc</groupId>
<artifactId>jmeter-plugins-redis</artifactId>
<version>0.6</version>
<version>0.7</version>


<name>Redis</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@

package kg.apc.jmeter.config.redis;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.security.GeneralSecurityException;
import java.util.ResourceBundle;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocketFactory;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.apache.jmeter.config.ConfigTestElement;
import org.apache.jmeter.engine.event.LoopIterationEvent;
Expand All @@ -44,65 +32,69 @@
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.jmeter.util.JsseSSLManager;
import org.apache.jmeter.util.SSLManager;
import org.slf4j.LoggerFactory;
import org.apache.jorphan.util.JMeterStopThreadException;
import org.apache.jorphan.util.JOrphanUtils;
import org.slf4j.Logger;

import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.exceptions.JedisDataException;

import javax.net.ssl.*;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.security.GeneralSecurityException;
import java.util.ResourceBundle;

/**
* Redis DataSet using a Redis Set or List.
*
* @since 2.11
*/
public class RedisDataSet extends ConfigTestElement
implements TestBean, LoopIterationListener, NoConfigMerge, TestStateListener {


private interface PollingStrategy {
public String getDataFromConnection(Jedis conn, String key) throws JedisDataException;
String getDataFromConnection(Jedis conn, String key) throws JedisDataException;
}

/**
* Pops an element from a redis list from right (LIFO)
* Pops an element from a redis list from right (LIFO)
*/
private class PopFromListStrategy implements PollingStrategy {
@Override
public String getDataFromConnection(Jedis conn, String key) throws JedisDataException {
log.debug("Executing lpop against redis list");
String line = conn.lpop(key);
return line;
return conn.lpop(key);
}
}

private class QueueStrategy implements PollingStrategy {
@Override
public String getDataFromConnection(Jedis conn, String key) throws JedisDataException {
log.debug("Executing lmove against redis list");
String line = conn.lmove(key, key, ListDirection.RIGHT, ListDirection.LEFT);
return line;
return conn.lmove(key, key, ListDirection.RIGHT, ListDirection.LEFT);
}
}

private class PopFromSetStrategy implements PollingStrategy {
@Override
public String getDataFromConnection(Jedis conn, String key) throws JedisDataException {
log.debug("Executing spop against redis set");
String line = conn.spop(key);
return line;
return conn.spop(key);
}
}

private class CopyFromSetStrategy implements PollingStrategy {
@Override
public String getDataFromConnection(Jedis conn, String key) throws JedisDataException {
log.debug("Executing srandmember against redis set");
String line = conn.srandmember(key);
return line;
return conn.srandmember(key);
}
}

Expand Down Expand Up @@ -130,15 +122,21 @@ public String getDataFromConnection(Jedis conn, String key) throws JedisDataExce
}

public enum RedisDataType {
REDIS_DATA_TYPE_LIST((byte)0),
REDIS_DATA_TYPE_SET((byte)1);
REDIS_DATA_TYPE_LIST((byte) 0),
REDIS_DATA_TYPE_SET((byte) 1);

private final byte value;

private byte value;
RedisDataType(byte value) { this.value = value; }
public int getValue() { return value; }
RedisDataType(byte value) {
this.value = value;
}

public int getValue() {
return value;
}
}

private PollingStrategy selectPollingStrategy(){
private PollingStrategy selectPollingStrategy() {

switch (redisDataType) {
case REDIS_DATA_TYPE_SET:
Expand All @@ -154,7 +152,7 @@ private PollingStrategy selectPollingStrategy(){
if (!getRecycleDataOnUse()) {
return new PopFromListStrategy();
} else {
if (getPropertyAsBoolean("plugins.redis.legacy", false)){
if (getPropertyAsBoolean("plugins.redis.legacy", false)) {
return new PopAndPushBackListStrategy();
}
return new QueueStrategy();
Expand Down Expand Up @@ -255,8 +253,8 @@ public void testEnded() {
@Override
public void testEnded(String host) {
int idleConn = pool.getNumIdle();
for(int i=0;i<idleConn;i++){
pool.getResource();
for (int i = 0; i < idleConn; i++) {
pool.getResource();
}
pool.destroy();
}
Expand All @@ -268,7 +266,7 @@ public void testStarted() {

@Override
public Object clone() {
RedisDataSet clonedElement = (RedisDataSet)super.clone();
RedisDataSet clonedElement = (RedisDataSet) super.clone();
clonedElement.pool = this.pool;
return clonedElement;

Expand All @@ -291,12 +289,12 @@ public void setProperty(JMeterProperty property) {
try {
final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass());
final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor().getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE);
for(Enum<RedisDataType> e : RedisDataType.values()) {
for (Enum<RedisDataType> e : RedisDataType.values()) {
final String propName = e.toString();
if (objectValue.equals(rb.getObject(propName))) {
final int tmpType = e.ordinal();
if (log.isDebugEnabled()) {
log.debug("Converted " + pn + "=" + objectValue + " to data type=" + tmpType + " using Locale: " + rb.getLocale());
log.debug("Converted " + pn + "=" + objectValue + " to data type=" + tmpType + " using Locale: " + rb.getLocale());
}
super.setProperty(pn, tmpType);
return;
Expand Down Expand Up @@ -328,19 +326,19 @@ public void testStarted(String distributedHost) {
config.setSoftMinEvictableIdleTimeMillis(getSoftMinEvictableIdleTimeMillis());

int port = Protocol.DEFAULT_PORT;
if(!JOrphanUtils.isBlank(this.port)) {
if (!JOrphanUtils.isBlank(this.port)) {
port = Integer.parseInt(this.port);
}
int timeout = Protocol.DEFAULT_TIMEOUT;
if(!JOrphanUtils.isBlank(this.timeout)) {
if (!JOrphanUtils.isBlank(this.timeout)) {
timeout = Integer.parseInt(this.timeout);
}
int database = Protocol.DEFAULT_DATABASE;
if(!JOrphanUtils.isBlank(this.database)) {
if (!JOrphanUtils.isBlank(this.database)) {
database = Integer.parseInt(this.database);
}
String password = null;
if(!JOrphanUtils.isBlank(this.password)) {
if (!JOrphanUtils.isBlank(this.password)) {
password = this.password;
}
SSLSocketFactory sslSocketFactory = null;
Expand All @@ -349,11 +347,11 @@ public void testStarted(String distributedHost) {
if (this.ssl) {
SSLManager sslManager = SSLManager.getInstance();
try {
SSLContext sslContext = ((JsseSSLManager)sslManager).getContext();
SSLContext sslContext = ((JsseSSLManager) sslManager).getContext();
sslSocketFactory = sslContext.getSocketFactory();
sslParameters = sslContext.getDefaultSSLParameters();
hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
}catch(GeneralSecurityException ex) {
} catch (GeneralSecurityException ex) {
throw new IllegalStateException("Unable to get SSLContext from SSLManager", ex);
}
}
Expand Down Expand Up @@ -656,34 +654,18 @@ public void setSoftMinEvictableIdleTimeMillis(
this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
}

/**
*
* @return
*/
public boolean getRecycleDataOnUse() {
return recycleDataOnUse;
}

/**
*
* @param recycleDataOnUse
*/
public void setRecycleDataOnUse(boolean recycleDataOnUse) {
this.recycleDataOnUse = recycleDataOnUse;
}

/**
*
* @return
*/
public int getRedisDataType() {
return redisDataType.ordinal();
}

/**
*
* @param dataType
*/
public void setRedisDataType(int dataType) {
try {
this.redisDataType = RedisDataType.values()[dataType];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public VariableThroughputTimer() {
*/
public synchronized long delay() {
while (true) {
long curTimeMs = System.currentTimeMillis();
long curTimeMs = System.nanoTime() / 1_000_000;
long millisSinceLastSecond = curTimeMs % 1000;
long nowInMsRoundedAtSec = curTimeMs - millisSinceLastSecond;
checkNextSecond(nowInMsRoundedAtSec);
Expand Down
Loading

0 comments on commit 218e98f

Please sign in to comment.