diff --git a/plugins/redis/pom.xml b/plugins/redis/pom.xml index 018cac694..265180136 100644 --- a/plugins/redis/pom.xml +++ b/plugins/redis/pom.xml @@ -12,7 +12,7 @@ kg.apc jmeter-plugins-redis - 0.6 + 0.7 Redis diff --git a/plugins/redis/src/main/java/kg/apc/jmeter/config/redis/RedisDataSet.java b/plugins/redis/src/main/java/kg/apc/jmeter/config/redis/RedisDataSet.java index 5010a9dfa..101a0cd55 100644 --- a/plugins/redis/src/main/java/kg/apc/jmeter/config/redis/RedisDataSet.java +++ b/plugins/redis/src/main/java/kg/apc/jmeter/config/redis/RedisDataSet.java @@ -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; @@ -44,20 +32,27 @@ 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 @@ -65,18 +60,17 @@ public class RedisDataSet extends ConfigTestElement 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); } } @@ -84,16 +78,15 @@ 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); } } @@ -101,8 +94,7 @@ 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); } } @@ -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: @@ -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(); @@ -255,8 +253,8 @@ public void testEnded() { @Override public void testEnded(String host) { int idleConn = pool.getNumIdle(); - for(int i=0;i e : RedisDataType.values()) { + for (Enum 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; @@ -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; @@ -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); } } @@ -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]; diff --git a/site/dat/repo/jpgc-plugins.json b/site/dat/repo/jpgc-plugins.json index f6bf209cb..87409de81 100644 --- a/site/dat/repo/jpgc-plugins.json +++ b/site/dat/repo/jpgc-plugins.json @@ -612,6 +612,15 @@ "jedis": "https://search.maven.org/remotecontent?filepath=redis/clients/jedis/3.6.3/jedis-3.6.3.jar", "commons-pool2": "https://search.maven.org/remotecontent?filepath=org/apache/commons/commons-pool2/2.9.0/commons-pool2-2.9.0.jar" } + }, + "0.7": { + "changes": "Fix JedisException when test ends", + "downloadUrl": "https://search.maven.org/remotecontent?filepath=kg/apc/jmeter-plugins-redis/0.7/jmeter-plugins-redis-0.7.jar", + "libs": { + "jmeter-plugins-cmn-jmeter": "https://search.maven.org/remotecontent?filepath=kg/apc/jmeter-plugins-cmn-jmeter/0.7/jmeter-plugins-cmn-jmeter-0.7.jar", + "jedis": "https://search.maven.org/remotecontent?filepath=redis/clients/jedis/3.6.3/jedis-3.6.3.jar", + "commons-pool2": "https://search.maven.org/remotecontent?filepath=org/apache/commons/commons-pool2/2.9.0/commons-pool2-2.9.0.jar" + } } } },