diff --git a/README.md b/README.md
index 8ada631..cb66cf4 100644
--- a/README.md
+++ b/README.md
@@ -44,41 +44,41 @@ If an instance dies, its queues will be assigned to other instances.
The following configuration values are available:
-| Property | Default value | Description |
-|:----------------------------------------|:--------------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| address | redisques | The eventbus address the redisques module is listening to |
-| configuration-updated-address | redisques-configuration-updated | The eventbus address the redisques module publishes the configuration updates to |
-| redis-prefix | redisques: | Prefix for redis keys holding queues and consumers |
-| processor-address | redisques-processor | Address of message processors |
-| refresh-period | 10 | The frequency [s] of consumers refreshing their subscriptions to consume |
-| processorTimeout | 240000 | The timeout [ms] to wait for the queue processor to answer the event bus message |
-| processorDelayMax | 0 | The maximum delay [ms] to wait between queue items before notify the consumer |
-| redisHost | localhost | The host where redis is running on |
-| redisPort | 6379 | The port where redis is running on |
-| redisAuth | | The authentication key (password) to connect to redis |
-| maxPoolSize | 200 | The maximum size of the redis connection pool |
-| maxPoolWaitingSize | -1 | The maximum waiting requests for a connection from the pool |
-| maxPipelineWaitingSize | 2048 | The maximum allowed queued waiting handlers |
-| checkInterval | 60 | The interval [s] to check timestamps of not-active / empty queues by executing **check** queue operation. _checkInterval_ value must be greater 0, otherwise the default is used. |
-| queueSpeedIntervalSec | 60 | The interval [s] to check queue speed |
-| memoryUsageLimitPercent | 100 | Percentage of the available system memory to be used by vertx-redisques. Only values between 0 and 100 are allowed. When the used memory ratio is higher than this limit, enqueues are rejected |
-| memoryUsageCheckIntervalSec | 60 | The interval [s] to check the current memory usage. _memoryUsageCheckIntervalSec_ value must be greater 0, otherwise the default is used. |
-| redisReconnectAttempts | 0 | The amount of attempts to reconnect when redis connection is lost. Use **0** to not reconnect at all or **-1** to reconnect indefinitely. |
-| redisReconnectDelaySec | 30 | The interval [s] to attempt to reconnect when redis connection is lost. |
-| redisPoolRecycleTimeoutMs | 180000 | The timeout [ms] when the connection pool is recycled. Use **-1** when having reconnect feature enabled. |
-| httpRequestHandlerEnabled | false | Enable / disable the HTTP API |
-| httpRequestHandlerAuthenticationEnabled | false | Enable / disable authentication for the HTTP API |
-| httpRequestHandlerUsername | | The username for the HTTP API authentication |
-| httpRequestHandlerPassword | | The password for the HTTP API authentication |
-| enableQueueNameDecoding | true | Enable / disable the encoding of queue names when using the HTTP API |
-| httpRequestHandlerPrefix | /queuing | The url prefix for all HTTP API endpoints |
-| httpRequestHandlerPort | 7070 | The port of the HTTP API |
-| httpRequestHandlerUserHeader | x-rp-usr | The name of the header property where the user information is provided. Used for the HTTP API |
-| queueConfigurations | | Configure retry intervals and enqueue delaying for queue patterns |
+| Property | Default value | Description |
+|:----------------------------------------|:--------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| address | redisques | The eventbus address the redisques module is listening to |
+| configuration-updated-address | redisques-configuration-updated | The eventbus address the redisques module publishes the configuration updates to |
+| redis-prefix | redisques: | Prefix for redis keys holding queues and consumers |
+| processor-address | redisques-processor | Address of message processors |
+| refresh-period | 10 | The frequency [s] of consumers refreshing their subscriptions to consume |
+| processorTimeout | 240000 | The timeout [ms] to wait for the queue processor to answer the event bus message |
+| processorDelayMax | 0 | The maximum delay [ms] to wait between queue items before notify the consumer |
+| redisHost | localhost | The host where redis is running on |
+| redisPort | 6379 | The port where redis is running on |
+| redisAuth | | The authentication key (password) to connect to redis |
+| maxPoolSize | 200 | The maximum size of the redis connection pool |
+| maxPoolWaitingSize | -1 | The maximum waiting requests for a connection from the pool |
+| maxPipelineWaitingSize | 2048 | The maximum allowed queued waiting handlers |
+| checkInterval | 60 | The interval [s] to check timestamps of not-active / empty queues by executing **check** queue operation. _checkInterval_ value must be greater 0, otherwise the default is used. |
+| queueSpeedIntervalSec | 60 | The interval [s] to check queue speed |
+| memoryUsageLimitPercent | 100 | Percentage of the available system memory to be used by vertx-redisques. Only values between 0 and 100 are allowed. When the used memory ratio is higher than this limit, enqueues are rejected |
+| memoryUsageCheckIntervalSec | 60 | The interval [s] to check the current memory usage. _memoryUsageCheckIntervalSec_ value must be greater 0, otherwise the default is used. |
+| redisReconnectAttempts | 0 | The amount of attempts to reconnect when redis connection is lost. Use **0** to not reconnect at all or **-1** to reconnect indefinitely. |
+| redisReconnectDelaySec | 30 | The interval [s] to attempt to reconnect when redis connection is lost. |
+| redisPoolRecycleTimeoutMs | 180000 | The timeout [ms] when the connection pool is recycled. Use **-1** when having reconnect feature enabled. |
+| httpRequestHandlerEnabled | false | Enable / disable the HTTP API |
+| httpRequestHandlerAuthenticationEnabled | false | Enable / disable authentication for the HTTP API |
+| httpRequestHandlerUsername | | The username for the HTTP API authentication |
+| httpRequestHandlerPassword | | The password for the HTTP API authentication |
+| enableQueueNameDecoding | true | Enable / disable the encoding of queue names when using the HTTP API |
+| httpRequestHandlerPrefix | /queuing | The url prefix for all HTTP API endpoints |
+| httpRequestHandlerPort | 7070 | The port of the HTTP API |
+| httpRequestHandlerUserHeader | x-rp-usr | The name of the header property where the user information is provided. Used for the HTTP API |
+| queueConfigurations | | Configure retry intervals and enqueue delaying for queue patterns |
| dequeueStatisticReportIntervalSec | -1 | The interval [s] to publish the dequeue statistics into shared map. Use **-1** to not publish at all. In a hazelcast-cluster environment need config Semaphore first, see: [Semaphore Config](#Semaphore Config) |
-| publish-metrics-address | | The EventBus address to send collected redis metrics to |
-| metric-storage-name | queue | The name of the storage used in the published metrics |
-| metric-refresh-period | 10 | The frequency [s] of collecting metrics from redis database |
+| publish-metrics-address | | The EventBus address to send collected redis metrics to |
+| metric-storage-name | queue | The name of the storage used in the published metrics |
+| metric-refresh-period | 10 | The frequency [s] of collecting metrics from redis database |
### Configuration util
diff --git a/pom.xml b/pom.xml
index a8a6f72..24df9fc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
4.0.0
org.swisspush
redisques
- 3.1.13-SNAPSHOT
+ 4.1.1-SNAPSHOT
redisques
A highly scalable redis-persistent queuing system for vertx
diff --git a/src/main/java/org/swisspush/redisques/RedisQues.java b/src/main/java/org/swisspush/redisques/RedisQues.java
index 784e744..afb61e9 100644
--- a/src/main/java/org/swisspush/redisques/RedisQues.java
+++ b/src/main/java/org/swisspush/redisques/RedisQues.java
@@ -675,10 +675,10 @@ int updateQueueFailureCountAndGetRetryInterval(final String queueName, boolean s
private void registerQueueCheck() {
vertx.setPeriodic(configurationProvider.configuration().getCheckIntervalTimerMs(), periodicEvent -> {
- redisProvider.redis().compose((RedisAPI redisAPI) -> {
+ redisProvider.redis().compose((RedisAPI redisAPI) -> {
int checkInterval = configurationProvider.configuration().getCheckInterval();
return redisAPI.send(Command.SET, queueCheckLastexecKey, String.valueOf(currentTimeMillis()), "NX", "EX", String.valueOf(checkInterval));
- }).compose((Response todoExplainWhyThisIsIgnored) -> {
+ }).compose((Response todoExplainWhyThisIsIgnored) -> {
log.info("periodic queue check is triggered now");
return checkQueues();
}).onFailure((Throwable ex) -> {
@@ -815,7 +815,7 @@ private Future consume(final String queueName) {
log.trace("RedisQues consume get: {}", consumerKey);
redisProvider.redis().onSuccess(redisAPI -> redisAPI.get(consumerKey, event1 -> {
if (event1.failed()) {
- log.error("Unable to get consumer for queue " + queueName, event1.cause());
+ log.error("Unable to get consumer for queue {}", queueName, event1.cause());
return;
}
String consumer = Objects.toString(event1.result(), "");
@@ -857,7 +857,7 @@ private Future consume(final String queueName) {
});
}
}))
- .onFailure(throwable -> log.error("Redis: Unable to get consumer for queue " + queueName, throwable));
+ .onFailure(throwable -> log.error("Redis: Unable to get consumer for queue {}", queueName, throwable));
});
return promise.future();
}
@@ -1151,17 +1151,17 @@ private Future checkQueues() {
AtomicInteger counter;
Iterator iter;
};
- return Future.succeededFuture().compose((Void v) -> {
+ return Future.succeededFuture().compose((Void v) -> {
log.debug("Checking queues timestamps");
// List all queues that look inactive (i.e. that have not been updated since 3 periods).
ctx.limit = currentTimeMillis() - 3L * configurationProvider.configuration().getRefreshPeriod() * 1000;
return redisProvider.redis();
- }).compose((RedisAPI redisAPI) -> {
+ }).compose((RedisAPI redisAPI) -> {
ctx.redisAPI = redisAPI;
var p = Promise.promise();
redisAPI.zrangebyscore(Arrays.asList(queuesKey, "-inf", String.valueOf(ctx.limit)), p);
return p.future();
- }).compose((Response queues) -> {
+ }).compose((Response queues) -> {
assert ctx.counter == null;
assert ctx.iter == null;
ctx.counter = new AtomicInteger(queues.size());
diff --git a/src/main/java/org/swisspush/redisques/RedisQuesRunner.java b/src/main/java/org/swisspush/redisques/RedisQuesRunner.java
index 3ec9b00..ca78c38 100644
--- a/src/main/java/org/swisspush/redisques/RedisQuesRunner.java
+++ b/src/main/java/org/swisspush/redisques/RedisQuesRunner.java
@@ -10,7 +10,7 @@
* Deploys vertx-redisques to vert.x.
* Used in the standalone scenario.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class RedisQuesRunner {
@@ -20,7 +20,7 @@ public static void main(String[] args) {
.httpRequestHandlerEnabled(true)
.redisReconnectAttempts(-1)
.redisPoolRecycleTimeoutMs(-1)
- .redisReadyCheckIntervalMs(10000)
+ .redisReadyCheckIntervalMs(5000)
.build().asJsonObject();
Vertx.vertx().deployVerticle(new RedisQues(), new DeploymentOptions().setConfig(configuration),
diff --git a/src/main/java/org/swisspush/redisques/action/AbstractQueueAction.java b/src/main/java/org/swisspush/redisques/action/AbstractQueueAction.java
index dae9b8a..483957a 100644
--- a/src/main/java/org/swisspush/redisques/action/AbstractQueueAction.java
+++ b/src/main/java/org/swisspush/redisques/action/AbstractQueueAction.java
@@ -9,6 +9,7 @@
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
import org.swisspush.redisques.util.RedisProvider;
@@ -33,11 +34,12 @@ public abstract class AbstractQueueAction implements QueueAction {
protected final String consumersPrefix;
protected final String locksKey;
protected final List queueConfigurations;
+ protected final RedisQuesExceptionFactory exceptionFactory;
protected final QueueStatisticsCollector queueStatisticsCollector;
public AbstractQueueAction(Vertx vertx, RedisProvider redisProvider, String address, String queuesKey,
String queuesPrefix, String consumersPrefix, String locksKey, List queueConfigurations,
- QueueStatisticsCollector queueStatisticsCollector, Logger log) {
+ RedisQuesExceptionFactory exceptionFactory, QueueStatisticsCollector queueStatisticsCollector, Logger log) {
this.vertx = vertx;
this.redisProvider = redisProvider;
this.address = address;
@@ -46,6 +48,7 @@ public AbstractQueueAction(Vertx vertx, RedisProvider redisProvider, String addr
this.consumersPrefix = consumersPrefix;
this.locksKey = locksKey;
this.queueConfigurations = queueConfigurations;
+ this.exceptionFactory = exceptionFactory;
this.queueStatisticsCollector = queueStatisticsCollector;
this.log = log;
}
@@ -57,6 +60,11 @@ protected Handler replyErrorMessageHandler(Message event)
};
}
+ protected void handleFail(Message event, String message, Throwable throwable) {
+ log.warn(message, exceptionFactory.newException(throwable));
+ event.fail(0, throwable.getMessage());
+ }
+
protected long getMaxAgeTimestamp() {
return System.currentTimeMillis() - MAX_AGE_MILLISECONDS;
}
diff --git a/src/main/java/org/swisspush/redisques/action/AddQueueItemAction.java b/src/main/java/org/swisspush/redisques/action/AddQueueItemAction.java
index 5919f6e..4c1ab7a 100644
--- a/src/main/java/org/swisspush/redisques/action/AddQueueItemAction.java
+++ b/src/main/java/org/swisspush/redisques/action/AddQueueItemAction.java
@@ -4,6 +4,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.AddQueueItemHandler;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
@@ -19,10 +20,10 @@ public class AddQueueItemAction extends AbstractQueueAction {
public AddQueueItemAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey, String queuesPrefix,
String consumersPrefix, String locksKey, List queueConfigurations,
- QueueStatisticsCollector queueStatisticsCollector, Logger log
+ RedisQuesExceptionFactory exceptionFactory, QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
@@ -30,8 +31,8 @@ public void execute(Message event) {
String key1 = queuesPrefix + event.body().getJsonObject(PAYLOAD).getString(QUEUENAME);
String valueAddItem = event.body().getJsonObject(PAYLOAD).getString(BUFFER);
var p = redisProvider.redis();
- p.onSuccess(redisAPI -> redisAPI.rpush(Arrays.asList(key1, valueAddItem), new AddQueueItemHandler(event)));
- p.onFailure(ex -> replyErrorMessageHandler(event).handle(ex));
+ p.onSuccess(redisAPI -> redisAPI.rpush(Arrays.asList(key1, valueAddItem), new AddQueueItemHandler(event, exceptionFactory)));
+ p.onFailure(ex -> handleFail(event,"Operation AddQueueItemAction failed", ex));
}
}
diff --git a/src/main/java/org/swisspush/redisques/action/BulkDeleteLocksAction.java b/src/main/java/org/swisspush/redisques/action/BulkDeleteLocksAction.java
index 278a1c8..3a65828 100644
--- a/src/main/java/org/swisspush/redisques/action/BulkDeleteLocksAction.java
+++ b/src/main/java/org/swisspush/redisques/action/BulkDeleteLocksAction.java
@@ -8,6 +8,7 @@
import io.vertx.redis.client.impl.types.MultiType;
import io.vertx.redis.client.impl.types.SimpleStringType;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
import org.swisspush.redisques.util.RedisProvider;
@@ -20,9 +21,9 @@ public class BulkDeleteLocksAction extends AbstractQueueAction {
public BulkDeleteLocksAction(Vertx vertx, RedisProvider redisProvider, String address, String queuesKey, String queuesPrefix,
String consumersPrefix, String locksKey, List queueConfigurations,
- QueueStatisticsCollector queueStatisticsCollector, Logger log) {
+ RedisQuesExceptionFactory exceptionFactory, QueueStatisticsCollector queueStatisticsCollector, Logger log) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey, queueConfigurations,
- queueStatisticsCollector, log);
+ exceptionFactory, queueStatisticsCollector, log);
}
@Override
diff --git a/src/main/java/org/swisspush/redisques/action/BulkDeleteQueuesAction.java b/src/main/java/org/swisspush/redisques/action/BulkDeleteQueuesAction.java
index 6c13733..7d67067 100644
--- a/src/main/java/org/swisspush/redisques/action/BulkDeleteQueuesAction.java
+++ b/src/main/java/org/swisspush/redisques/action/BulkDeleteQueuesAction.java
@@ -5,6 +5,7 @@
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
import org.swisspush.redisques.util.RedisProvider;
@@ -18,10 +19,10 @@ public class BulkDeleteQueuesAction extends AbstractQueueAction {
public BulkDeleteQueuesAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey, String queuesPrefix,
String consumersPrefix, String locksKey, List queueConfigurations,
- QueueStatisticsCollector queueStatisticsCollector, Logger log
+ RedisQuesExceptionFactory exceptionFactory, QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
@@ -49,11 +50,10 @@ public void execute(Message event) {
if (delManyReply.succeeded()) {
event.reply(createOkReply().put(VALUE, delManyReply.result().toLong()));
} else {
- log.error("Failed to bulkDeleteQueues", new Exception(delManyReply.cause()));
- event.reply(createErrorReply());
+ handleFail(event, "Failed to bulkDeleteQueues", delManyReply.cause());
}
}));
- p.onFailure(ex -> replyErrorMessageHandler(event).handle(ex));
+ p.onFailure(ex -> handleFail(event, "Operation BulkDeleteQueuesAction failed", ex));
}
}
diff --git a/src/main/java/org/swisspush/redisques/action/BulkPutLocksAction.java b/src/main/java/org/swisspush/redisques/action/BulkPutLocksAction.java
index 6e6ca83..2fbb5fb 100644
--- a/src/main/java/org/swisspush/redisques/action/BulkPutLocksAction.java
+++ b/src/main/java/org/swisspush/redisques/action/BulkPutLocksAction.java
@@ -5,6 +5,7 @@
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.PutLockHandler;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
@@ -19,10 +20,10 @@ public class BulkPutLocksAction extends AbstractQueueAction {
public BulkPutLocksAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey, String queuesPrefix,
String consumersPrefix, String locksKey, List queueConfigurations,
- QueueStatisticsCollector queueStatisticsCollector, Logger log
+ RedisQuesExceptionFactory exceptionFactory, QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
@@ -45,9 +46,7 @@ public void execute(Message event) {
}
var p = redisProvider.redis();
- p.onSuccess(redisAPI -> {
- redisAPI.hmset(buildLocksItems(locksKey, locks, lockInfo), new PutLockHandler(event));
- });
+ p.onSuccess(redisAPI -> redisAPI.hmset(buildLocksItems(locksKey, locks, lockInfo), new PutLockHandler(event, exceptionFactory)));
p.onFailure(ex -> replyErrorMessageHandler(event).handle(ex));
}
diff --git a/src/main/java/org/swisspush/redisques/action/DeleteAllLocksAction.java b/src/main/java/org/swisspush/redisques/action/DeleteAllLocksAction.java
index dc816a8..f49dec4 100644
--- a/src/main/java/org/swisspush/redisques/action/DeleteAllLocksAction.java
+++ b/src/main/java/org/swisspush/redisques/action/DeleteAllLocksAction.java
@@ -5,6 +5,7 @@
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
import org.swisspush.redisques.util.RedisProvider;
@@ -18,10 +19,10 @@ public class DeleteAllLocksAction extends AbstractQueueAction {
public DeleteAllLocksAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey, String queuesPrefix,
String consumersPrefix, String locksKey, List queueConfigurations,
- QueueStatisticsCollector queueStatisticsCollector, Logger log
+ RedisQuesExceptionFactory exceptionFactory, QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
diff --git a/src/main/java/org/swisspush/redisques/action/DeleteAllQueueItemsAction.java b/src/main/java/org/swisspush/redisques/action/DeleteAllQueueItemsAction.java
index 169dd76..e225f8c 100644
--- a/src/main/java/org/swisspush/redisques/action/DeleteAllQueueItemsAction.java
+++ b/src/main/java/org/swisspush/redisques/action/DeleteAllQueueItemsAction.java
@@ -6,6 +6,7 @@
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
import org.swisspush.redisques.util.RedisProvider;
@@ -21,10 +22,10 @@ public class DeleteAllQueueItemsAction extends AbstractQueueAction {
public DeleteAllQueueItemsAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey, String queuesPrefix,
String consumersPrefix, String locksKey, List queueConfigurations,
- QueueStatisticsCollector queueStatisticsCollector, Logger log
+ RedisQuesExceptionFactory exceptionFactory, QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
@@ -36,11 +37,8 @@ public void execute(Message event) {
p.onSuccess(redisAPI -> {
redisAPI.del(Collections.singletonList(buildQueueKey(queue)), deleteReply -> {
if (deleteReply.failed()) {
- log.warn("Failed to deleteAllQueueItems. But we'll continue anyway",
- new Exception(deleteReply.cause()));
- // May we should 'fail()' here. But:
- // 1st: We don't, to keep backward compatibility
- // 2nd: We don't, to may unlock below.
+ handleFail(event, "Operation DeleteAllQueueItems failed", deleteReply.cause());
+ return;
}
queueStatisticsCollector.resetQueueFailureStatistics(queue, (Throwable ex, Void v) -> {
if (ex != null) log.warn("TODO_2958iouhj error handling", ex);
@@ -48,28 +46,24 @@ public void execute(Message event) {
if (unlock) {
redisAPI.hdel(Arrays.asList(locksKey, queue), unlockReply -> {
if (unlockReply.failed()) {
- log.warn("Failed to unlock queue '{}'. Will continue anyway",
- queue, unlockReply.cause());
- // IMO we should 'fail()' here. But we don't, to keep backward compatibility.
+ handleFail(event, "Failed to unlock queue " + queue, unlockReply.cause());
+ } else {
+ handleDeleteQueueReply(event, deleteReply);
}
- handleDeleteQueueReply(event, deleteReply);
});
} else {
handleDeleteQueueReply(event, deleteReply);
}
});
});
- p.onFailure(ex -> {
- log.error("Redis: Failed to delete all queue items", new Exception(ex));
- event.reply(createErrorReply());
- });
+ p.onFailure(ex -> handleFail(event, "Operation DeleteAllQueueItems failed", ex));
}
private void handleDeleteQueueReply(Message event, AsyncResult reply) {
if (reply.succeeded()) {
event.reply(createOkReply().put(VALUE, reply.result().toLong()));
} else {
- log.error("Failed to replyResultGreaterThanZero", new Exception(reply.cause()));
+ log.error("Failed to replyResultGreaterThanZero", exceptionFactory.newException(reply.cause()));
event.reply(createErrorReply());
}
}
diff --git a/src/main/java/org/swisspush/redisques/action/DeleteLockAction.java b/src/main/java/org/swisspush/redisques/action/DeleteLockAction.java
index 530c8a7..5e7dad7 100644
--- a/src/main/java/org/swisspush/redisques/action/DeleteLockAction.java
+++ b/src/main/java/org/swisspush/redisques/action/DeleteLockAction.java
@@ -4,6 +4,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.DeleteLockHandler;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
@@ -21,10 +22,10 @@ public class DeleteLockAction extends AbstractQueueAction {
public DeleteLockAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey, String queuesPrefix,
String consumersPrefix, String locksKey, List queueConfigurations,
- QueueStatisticsCollector queueStatisticsCollector, Logger log
+ RedisQuesExceptionFactory exceptionFactory, QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
@@ -33,14 +34,18 @@ public void execute(Message event) {
var p = redisProvider.redis();
p.onSuccess(redisAPI -> {
redisAPI.exists(Collections.singletonList(queuesPrefix + queueName), event1 -> {
- if( event1.failed() ) log.warn("Concealed error", new Exception(event1.cause()));
+ if (event1.failed()) {
+ log.warn("Concealed error", exceptionFactory.newException(event1.cause()));
+ }
+
if (event1.succeeded() && event1.result() != null && event1.result().toInteger() == 1) {
notifyConsumer(queueName);
}
- redisAPI.hdel(Arrays.asList(locksKey, queueName), new DeleteLockHandler(event));
+
+ redisAPI.hdel(Arrays.asList(locksKey, queueName), new DeleteLockHandler(event, exceptionFactory));
});
});
- p.onFailure(ex -> replyErrorMessageHandler(event).handle(ex));
+ p.onFailure(ex -> handleFail(event, "Operation DeleteLockAction failed", ex));
}
}
diff --git a/src/main/java/org/swisspush/redisques/action/DeleteQueueItemAction.java b/src/main/java/org/swisspush/redisques/action/DeleteQueueItemAction.java
index 2e0ce4e..1fc2c71 100644
--- a/src/main/java/org/swisspush/redisques/action/DeleteQueueItemAction.java
+++ b/src/main/java/org/swisspush/redisques/action/DeleteQueueItemAction.java
@@ -4,6 +4,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
import org.swisspush.redisques.util.RedisProvider;
@@ -17,10 +18,10 @@ public class DeleteQueueItemAction extends AbstractQueueAction {
public DeleteQueueItemAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey, String queuesPrefix,
String consumersPrefix, String locksKey, List queueConfigurations,
- QueueStatisticsCollector queueStatisticsCollector, Logger log
+ RedisQuesExceptionFactory exceptionFactory, QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
@@ -28,24 +29,32 @@ public void execute(Message event) {
String keyLset = queuesPrefix + event.body().getJsonObject(PAYLOAD).getString(QUEUENAME);
int indexLset = event.body().getJsonObject(PAYLOAD).getInteger(INDEX);
redisProvider.redis().onSuccess(redisAPI -> redisAPI.lset(keyLset, String.valueOf(indexLset), "TO_DELETE",
- event1 -> {
- if (event1.succeeded()) {
- String keyLrem = queuesPrefix + event.body().getJsonObject(PAYLOAD).getString(QUEUENAME);
- redisAPI.lrem(keyLrem, "0", "TO_DELETE", replyLrem -> {
- if (replyLrem.failed()) {
- log.warn("Redis 'lrem' command failed. But will continue anyway.",
- new Exception(replyLrem.cause()));
- // IMO we should 'fail()' here. But we don't, to keep backward compatibility.
+ event1 -> {
+ if (event1.succeeded()) {
+ String keyLrem = queuesPrefix + event.body().getJsonObject(PAYLOAD).getString(QUEUENAME);
+ redisAPI.lrem(keyLrem, "0", "TO_DELETE", replyLrem -> {
+ if (replyLrem.failed()) {
+ handleFail(event, "Failed to 'lrem' while deleteQueueItem", replyLrem.cause());
+ } else {
+ event.reply(createOkReply());
+ }
+ });
+ } else {
+ if(checkRedisErrorCodes(event1.cause().getMessage())) {
+ log.error("Failed to 'lset' while deleteQueueItem.", exceptionFactory.newException(event1.cause()));
+ event.reply(createErrorReply());
+ } else{
+ handleFail(event, "Failed to 'lset' while deleteQueueItem", event1.cause());
+ }
}
- event.reply(createOkReply());
- });
- } else {
- log.error("Failed to 'lset' while deleteQueueItem.", new Exception(event1.cause()));
- event.reply(createErrorReply());
- }
- })).onFailure(ex -> {
- log.error("Redis: Failed to deleteQueueItem.", new Exception(ex));
- event.reply(createErrorReply());
- });
+ }))
+ .onFailure(ex -> handleFail(event,"Operation DeleteQueueItemAction failed", ex));
+ }
+
+ private boolean checkRedisErrorCodes(String message) {
+ if(message == null) {
+ return false;
+ }
+ return message.contains("no such key") || message.contains("index out of range");
}
}
diff --git a/src/main/java/org/swisspush/redisques/action/EnqueueAction.java b/src/main/java/org/swisspush/redisques/action/EnqueueAction.java
index b2f1c77..0fd3397 100644
--- a/src/main/java/org/swisspush/redisques/action/EnqueueAction.java
+++ b/src/main/java/org/swisspush/redisques/action/EnqueueAction.java
@@ -4,6 +4,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.util.MemoryUsageProvider;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
@@ -22,11 +23,11 @@ public class EnqueueAction extends AbstractQueueAction {
public EnqueueAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey, String queuesPrefix,
String consumersPrefix, String locksKey, List queueConfigurations,
- QueueStatisticsCollector queueStatisticsCollector, Logger log, MemoryUsageProvider memoryUsageProvider,
- int memoryUsageLimitPercent
+ RedisQuesExceptionFactory exceptionFactory, QueueStatisticsCollector queueStatisticsCollector, Logger log,
+ MemoryUsageProvider memoryUsageProvider, int memoryUsageLimitPercent
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
this.memoryUsageProvider = memoryUsageProvider;
this.memoryUsageLimitPercent = memoryUsageLimitPercent;
}
diff --git a/src/main/java/org/swisspush/redisques/action/GetAllLocksAction.java b/src/main/java/org/swisspush/redisques/action/GetAllLocksAction.java
index 5aae3aa..ad96609 100644
--- a/src/main/java/org/swisspush/redisques/action/GetAllLocksAction.java
+++ b/src/main/java/org/swisspush/redisques/action/GetAllLocksAction.java
@@ -4,6 +4,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.GetAllLocksHandler;
import org.swisspush.redisques.util.*;
@@ -18,20 +19,20 @@ public class GetAllLocksAction extends AbstractQueueAction {
public GetAllLocksAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey,
String queuesPrefix, String consumersPrefix, String locksKey,
- List queueConfigurations, QueueStatisticsCollector queueStatisticsCollector,
- Logger log
+ List queueConfigurations, RedisQuesExceptionFactory exceptionFactory,
+ QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
public void execute(Message event) {
Result, String> result = MessageUtil.extractFilterPattern(event);
if (result.isOk()) {
- var p = redisProvider.redis();
- p.onSuccess(redisAPI -> redisAPI.hkeys(locksKey, new GetAllLocksHandler(event, result.getOk())));
- p.onFailure(ex -> replyErrorMessageHandler(event).handle(ex));
+ redisProvider.redis()
+ .onSuccess(redisAPI -> redisAPI.hkeys(locksKey, new GetAllLocksHandler(exceptionFactory, event, result.getOk())))
+ .onFailure(throwable -> handleFail(event, "Operation GetAllLocks failed", throwable));
} else {
event.reply(createErrorReply().put(ERROR_TYPE, BAD_INPUT).put(MESSAGE, result.getErr()));
}
diff --git a/src/main/java/org/swisspush/redisques/action/GetLockAction.java b/src/main/java/org/swisspush/redisques/action/GetLockAction.java
index b7f86c6..15d8228 100644
--- a/src/main/java/org/swisspush/redisques/action/GetLockAction.java
+++ b/src/main/java/org/swisspush/redisques/action/GetLockAction.java
@@ -5,6 +5,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.GetLockHandler;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
@@ -20,27 +21,26 @@ public class GetLockAction extends AbstractQueueAction {
public GetLockAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey,
String queuesPrefix, String consumersPrefix, String locksKey,
- List queueConfigurations, QueueStatisticsCollector queueStatisticsCollector,
- Logger log
+ List queueConfigurations, RedisQuesExceptionFactory exceptionFactory,
+ QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
public void execute(Message event) {
final JsonObject body = event.body();
if (body == null) {
- replyErrorMessageHandler(event).handle(new NullPointerException("" +
- "Got msg with no body from event bus. address=" +
+ replyErrorMessageHandler(event).handle(new NullPointerException("Got msg with no body from event bus. address=" +
event.address() + " replyAddress=" + event.replyAddress()));
return;
}
var p = redisProvider.redis();
p.onSuccess(redisAPI -> {
- redisAPI.hget(locksKey, body.getJsonObject(PAYLOAD).getString(QUEUENAME), new GetLockHandler(event));
+ redisAPI.hget(locksKey, body.getJsonObject(PAYLOAD).getString(QUEUENAME), new GetLockHandler(event, exceptionFactory));
});
- p.onFailure(ex -> replyErrorMessageHandler(event).handle(ex));
+ p.onFailure(ex -> handleFail(event,"Operation GetLockAction failed", ex));
}
}
diff --git a/src/main/java/org/swisspush/redisques/action/GetQueueItemAction.java b/src/main/java/org/swisspush/redisques/action/GetQueueItemAction.java
index 78a7b1b..51bbf0f 100644
--- a/src/main/java/org/swisspush/redisques/action/GetQueueItemAction.java
+++ b/src/main/java/org/swisspush/redisques/action/GetQueueItemAction.java
@@ -4,6 +4,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.GetQueueItemHandler;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
@@ -19,11 +20,11 @@ public class GetQueueItemAction extends AbstractQueueAction {
public GetQueueItemAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey,
String queuesPrefix, String consumersPrefix, String locksKey,
- List queueConfigurations, QueueStatisticsCollector queueStatisticsCollector,
- Logger log
+ List queueConfigurations, RedisQuesExceptionFactory exceptionFactory,
+ QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
@@ -31,10 +32,8 @@ public void execute(Message event) {
String key = queuesPrefix + event.body().getJsonObject(PAYLOAD).getString(QUEUENAME);
int index = event.body().getJsonObject(PAYLOAD).getInteger(INDEX);
var p = redisProvider.redis();
- p.onSuccess(redisAPI -> {
- redisAPI.lindex(key, String.valueOf(index), new GetQueueItemHandler(event));
- });
- p.onFailure(ex -> replyErrorMessageHandler(event).handle(ex));
+ p.onSuccess(redisAPI -> redisAPI.lindex(key, String.valueOf(index), new GetQueueItemHandler(event, exceptionFactory)));
+ p.onFailure(ex -> handleFail(event,"Operation GetQueueItemAction failed", ex));
}
}
diff --git a/src/main/java/org/swisspush/redisques/action/GetQueueItemsAction.java b/src/main/java/org/swisspush/redisques/action/GetQueueItemsAction.java
index 6f44fb5..028fc61 100644
--- a/src/main/java/org/swisspush/redisques/action/GetQueueItemsAction.java
+++ b/src/main/java/org/swisspush/redisques/action/GetQueueItemsAction.java
@@ -4,6 +4,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.GetQueueItemsHandler;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
@@ -19,9 +20,9 @@ public class GetQueueItemsAction extends AbstractQueueAction {
public GetQueueItemsAction(Vertx vertx, RedisProvider redisProvider, String address, String queuesKey, String queuesPrefix,
String consumersPrefix, String locksKey, List queueConfigurations,
- QueueStatisticsCollector queueStatisticsCollector, Logger log) {
+ RedisQuesExceptionFactory exceptionFactory, QueueStatisticsCollector queueStatisticsCollector, Logger log) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey, queueConfigurations,
- queueStatisticsCollector, log);
+ exceptionFactory, queueStatisticsCollector, log);
}
@Override
@@ -29,25 +30,19 @@ public void execute(Message event) {
String queueName = event.body().getJsonObject(PAYLOAD).getString(QUEUENAME);
String keyListRange = queuesPrefix + queueName;
int maxQueueItemCountIndex = getMaxQueueItemCountIndex(event.body().getJsonObject(PAYLOAD).getString(LIMIT));
- var p = redisProvider.redis();
- p.onSuccess(redisAPI -> redisAPI.llen(keyListRange, countReply -> {
- Long queueItemCount = countReply.result().toLong();
- if (countReply.succeeded() && queueItemCount != null) {
+
+ redisProvider.redis().onSuccess(redisAPI -> redisAPI.llen(keyListRange).onSuccess(countReply -> {
+ Long queueItemCount = countReply.toLong();
+ if(queueItemCount != null) {
redisAPI.lrange(keyListRange, "0", String.valueOf(maxQueueItemCountIndex),
new GetQueueItemsHandler(event, queueItemCount));
} else {
- if( countReply.failed() ) {
- log.warn("Operation getQueueItems failed. But I'll not notify my caller :)",
- countReply.cause());
- // IMO we should 'event.fail(countReply.cause())' here. But we don't, to keep
- // backward compatibility.
- }
+ String msg = "Operation getQueueItems failed to extract queueItemCount";
+ log.warn(msg);
+ event.fail(0, msg);
}
- }));
- p.onFailure(ex -> {
- log.warn("Operation getQueueItems failed. But I'll not notify my caller :)", ex);
- // IMO we should 'event.fail(countReply.cause())' here. But we don't, to keep backward compatibility.
- });
+ }).onFailure(throwable -> handleFail(event, "Operation getQueueItems failed", throwable)))
+ .onFailure(throwable -> handleFail(event, "Operation getQueueItems failed", throwable));
}
private int getMaxQueueItemCountIndex(String limit) {
@@ -58,7 +53,7 @@ private int getMaxQueueItemCountIndex(String limit) {
if (maxIndex >= 0) {
defaultMaxIndex = maxIndex;
}
- log.info("use limit parameter " + maxIndex);
+ log.info("use limit parameter {}", maxIndex);
} catch (NumberFormatException ex) {
log.warn("Invalid limit parameter '{}' configured for max queue item count. Using default {}",
limit, DEFAULT_MAX_QUEUEITEM_COUNT);
diff --git a/src/main/java/org/swisspush/redisques/action/GetQueueItemsCountAction.java b/src/main/java/org/swisspush/redisques/action/GetQueueItemsCountAction.java
index 04d8ca5..9f9328c 100644
--- a/src/main/java/org/swisspush/redisques/action/GetQueueItemsCountAction.java
+++ b/src/main/java/org/swisspush/redisques/action/GetQueueItemsCountAction.java
@@ -4,6 +4,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.GetQueueItemsCountHandler;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
@@ -22,11 +23,11 @@ public class GetQueueItemsCountAction extends AbstractQueueAction {
public GetQueueItemsCountAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey,
String queuesPrefix, String consumersPrefix, String locksKey,
- List queueConfigurations, QueueStatisticsCollector queueStatisticsCollector,
- Logger log
+ List queueConfigurations, RedisQuesExceptionFactory exceptionFactory,
+ QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
diff --git a/src/main/java/org/swisspush/redisques/action/GetQueuesAction.java b/src/main/java/org/swisspush/redisques/action/GetQueuesAction.java
index 2fa4d51..a7a7259 100644
--- a/src/main/java/org/swisspush/redisques/action/GetQueuesAction.java
+++ b/src/main/java/org/swisspush/redisques/action/GetQueuesAction.java
@@ -4,6 +4,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.GetQueuesHandler;
import org.swisspush.redisques.util.*;
@@ -19,11 +20,11 @@ public class GetQueuesAction extends AbstractQueueAction {
public GetQueuesAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey,
String queuesPrefix, String consumersPrefix, String locksKey,
- List queueConfigurations, QueueStatisticsCollector queueStatisticsCollector,
- Logger log
+ List queueConfigurations, RedisQuesExceptionFactory exceptionFactory,
+ QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
diff --git a/src/main/java/org/swisspush/redisques/action/GetQueuesCountAction.java b/src/main/java/org/swisspush/redisques/action/GetQueuesCountAction.java
index 4fbb105..7f23acf 100644
--- a/src/main/java/org/swisspush/redisques/action/GetQueuesCountAction.java
+++ b/src/main/java/org/swisspush/redisques/action/GetQueuesCountAction.java
@@ -4,6 +4,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.GetQueuesCountHandler;
import org.swisspush.redisques.util.*;
@@ -18,11 +19,11 @@ public class GetQueuesCountAction extends GetQueuesAction {
public GetQueuesCountAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey,
String queuesPrefix, String consumersPrefix, String locksKey,
- List queueConfigurations, QueueStatisticsCollector queueStatisticsCollector,
- Logger log
+ List queueConfigurations, RedisQuesExceptionFactory exceptionFactory,
+ QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
diff --git a/src/main/java/org/swisspush/redisques/action/GetQueuesItemsCountAction.java b/src/main/java/org/swisspush/redisques/action/GetQueuesItemsCountAction.java
index d3e7b03..33216bd 100644
--- a/src/main/java/org/swisspush/redisques/action/GetQueuesItemsCountAction.java
+++ b/src/main/java/org/swisspush/redisques/action/GetQueuesItemsCountAction.java
@@ -38,7 +38,7 @@ public GetQueuesItemsCountAction(
Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey, queueConfigurations,
- queueStatisticsCollector, log);
+ exceptionFactory, queueStatisticsCollector, log);
this.exceptionFactory = exceptionFactory;
this.redisRequestQuota = redisRequestQuota;
}
diff --git a/src/main/java/org/swisspush/redisques/action/GetQueuesSpeedAction.java b/src/main/java/org/swisspush/redisques/action/GetQueuesSpeedAction.java
index 4cbe70e..2386a03 100644
--- a/src/main/java/org/swisspush/redisques/action/GetQueuesSpeedAction.java
+++ b/src/main/java/org/swisspush/redisques/action/GetQueuesSpeedAction.java
@@ -4,6 +4,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.GetQueuesSpeedHandler;
import org.swisspush.redisques.util.*;
@@ -21,11 +22,11 @@ public class GetQueuesSpeedAction extends AbstractQueueAction {
public GetQueuesSpeedAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey,
String queuesPrefix, String consumersPrefix, String locksKey,
- List queueConfigurations, QueueStatisticsCollector queueStatisticsCollector,
- Logger log
+ List queueConfigurations, RedisQuesExceptionFactory exceptionFactory,
+ QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
diff --git a/src/main/java/org/swisspush/redisques/action/GetQueuesStatisticsAction.java b/src/main/java/org/swisspush/redisques/action/GetQueuesStatisticsAction.java
index 99ada01..83da35b 100644
--- a/src/main/java/org/swisspush/redisques/action/GetQueuesStatisticsAction.java
+++ b/src/main/java/org/swisspush/redisques/action/GetQueuesStatisticsAction.java
@@ -4,6 +4,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.GetQueuesStatisticsHandler;
import org.swisspush.redisques.util.*;
@@ -21,11 +22,11 @@ public class GetQueuesStatisticsAction extends AbstractQueueAction {
public GetQueuesStatisticsAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey,
String queuesPrefix, String consumersPrefix, String locksKey,
- List queueConfigurations, QueueStatisticsCollector queueStatisticsCollector,
- Logger log
+ List queueConfigurations, RedisQuesExceptionFactory exceptionFactory,
+ QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
diff --git a/src/main/java/org/swisspush/redisques/action/LockedEnqueueAction.java b/src/main/java/org/swisspush/redisques/action/LockedEnqueueAction.java
index f7fc06a..bc7412f 100644
--- a/src/main/java/org/swisspush/redisques/action/LockedEnqueueAction.java
+++ b/src/main/java/org/swisspush/redisques/action/LockedEnqueueAction.java
@@ -4,6 +4,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.util.MemoryUsageProvider;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
@@ -19,10 +20,12 @@ public class LockedEnqueueAction extends EnqueueAction {
public LockedEnqueueAction(Vertx vertx, RedisProvider redisProvider,
String address, String queuesKey, String queuesPrefix,
String consumersPrefix, String locksKey, List queueConfigurations,
+ RedisQuesExceptionFactory exceptionFactory,
QueueStatisticsCollector queueStatisticsCollector, Logger log,
MemoryUsageProvider memoryUsageProvider, int memoryUsageLimitPercent) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix,
- locksKey, queueConfigurations, queueStatisticsCollector, log, memoryUsageProvider, memoryUsageLimitPercent);
+ locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log, memoryUsageProvider,
+ memoryUsageLimitPercent);
}
@Override
diff --git a/src/main/java/org/swisspush/redisques/action/PutLockAction.java b/src/main/java/org/swisspush/redisques/action/PutLockAction.java
index 8731190..e42b999 100644
--- a/src/main/java/org/swisspush/redisques/action/PutLockAction.java
+++ b/src/main/java/org/swisspush/redisques/action/PutLockAction.java
@@ -5,6 +5,7 @@
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.PutLockHandler;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
@@ -20,10 +21,11 @@ public PutLockAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey,
String queuesPrefix, String consumersPrefix, String locksKey,
List queueConfigurations,
+ RedisQuesExceptionFactory exceptionFactory,
QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
- queueConfigurations, queueStatisticsCollector, log);
+ queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
@@ -36,10 +38,9 @@ public void execute(Message event) {
return;
}
var p = redisProvider.redis();
- p.onSuccess(redisAPI -> {
- redisAPI.hmset(buildLocksItems(locksKey, lockNames, lockInfo), new PutLockHandler(event));
- });
- p.onFailure(ex -> replyErrorMessageHandler(event).handle(ex));
+ p.onSuccess(redisAPI -> redisAPI.hmset(buildLocksItems(locksKey, lockNames, lockInfo),
+ new PutLockHandler(event, exceptionFactory)));
+ p.onFailure(ex -> handleFail(event,"Operation PutLockAction failed", ex));
} else {
event.reply(createErrorReply().put(MESSAGE, "Property '" + REQUESTED_BY + "' missing"));
}
diff --git a/src/main/java/org/swisspush/redisques/action/ReplaceQueueItemAction.java b/src/main/java/org/swisspush/redisques/action/ReplaceQueueItemAction.java
index ebf81a0..b7860d3 100644
--- a/src/main/java/org/swisspush/redisques/action/ReplaceQueueItemAction.java
+++ b/src/main/java/org/swisspush/redisques/action/ReplaceQueueItemAction.java
@@ -4,6 +4,7 @@
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.ReplaceQueueItemHandler;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
@@ -19,10 +20,11 @@ public ReplaceQueueItemAction(
Vertx vertx, RedisProvider redisProvider, String address, String queuesKey,
String queuesPrefix, String consumersPrefix, String locksKey,
List queueConfigurations,
+ RedisQuesExceptionFactory exceptionFactory,
QueueStatisticsCollector queueStatisticsCollector, Logger log
) {
super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix,
- locksKey, queueConfigurations, queueStatisticsCollector, log);
+ locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
}
@Override
@@ -32,8 +34,8 @@ public void execute(Message event) {
String bufferReplaceItem = event.body().getJsonObject(PAYLOAD).getString(BUFFER);
var p = redisProvider.redis();
p.onSuccess(redisAPI -> redisAPI.lset(keyReplaceItem, String.valueOf(indexReplaceItem),
- bufferReplaceItem, new ReplaceQueueItemHandler(event)));
- p.onFailure(ex -> replyErrorMessageHandler(event).handle(ex));
+ bufferReplaceItem, new ReplaceQueueItemHandler(event, exceptionFactory)));
+ p.onFailure(ex -> handleFail(event, "Operation ReplaceQueueItemAction failed", ex));
}
}
diff --git a/src/main/java/org/swisspush/redisques/handler/AddQueueItemHandler.java b/src/main/java/org/swisspush/redisques/handler/AddQueueItemHandler.java
index 7473558..5179aa3 100644
--- a/src/main/java/org/swisspush/redisques/handler/AddQueueItemHandler.java
+++ b/src/main/java/org/swisspush/redisques/handler/AddQueueItemHandler.java
@@ -6,24 +6,26 @@
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import static org.slf4j.LoggerFactory.getLogger;
-import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
/**
* Class AddQueueItemHandler.
*
- * @author baldim, https://github.com/mcweba [Marc-Andre Weber]
+ * @author baldim, Marc-André Weber
*/
public class AddQueueItemHandler implements Handler> {
private static final Logger log = getLogger(AddQueueItemHandler.class);
private final Message event;
+ private final RedisQuesExceptionFactory exceptionFactory;
- public AddQueueItemHandler(Message event) {
+ public AddQueueItemHandler(Message event, RedisQuesExceptionFactory exceptionFactory) {
this.event = event;
+ this.exceptionFactory = exceptionFactory;
}
@Override
@@ -31,8 +33,8 @@ public void handle(AsyncResult reply) {
if(reply.succeeded()){
event.reply(new JsonObject().put(STATUS, OK));
} else {
- log.warn("Concealed error", new Exception(reply.cause()));
- event.reply(new JsonObject().put(STATUS, ERROR));
+ log.warn("Concealed error", exceptionFactory.newException(reply.cause()));
+ event.fail(0, reply.cause().getMessage());
}
}
}
diff --git a/src/main/java/org/swisspush/redisques/handler/DeleteLockHandler.java b/src/main/java/org/swisspush/redisques/handler/DeleteLockHandler.java
index 7dbf9f7..f193c4e 100644
--- a/src/main/java/org/swisspush/redisques/handler/DeleteLockHandler.java
+++ b/src/main/java/org/swisspush/redisques/handler/DeleteLockHandler.java
@@ -6,9 +6,9 @@
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import static org.slf4j.LoggerFactory.getLogger;
-import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
@@ -21,9 +21,11 @@ public class DeleteLockHandler implements Handler> {
private static final Logger log = getLogger(DeleteLockHandler.class);
private final Message event;
+ private final RedisQuesExceptionFactory exceptionFactory;
- public DeleteLockHandler(Message event) {
+ public DeleteLockHandler(Message event, RedisQuesExceptionFactory exceptionFactory) {
this.event = event;
+ this.exceptionFactory = exceptionFactory;
}
@Override
@@ -31,8 +33,8 @@ public void handle(AsyncResult reply) {
if (reply.succeeded()) {
event.reply(new JsonObject().put(STATUS, OK));
} else {
- log.warn("Concealed error", new Exception(reply.cause()));
- event.reply(new JsonObject().put(STATUS, ERROR));
+ log.warn("Concealed error", exceptionFactory.newException(reply.cause()));
+ event.fail(0, reply.cause().getMessage());
}
}
}
diff --git a/src/main/java/org/swisspush/redisques/handler/GetAllLocksHandler.java b/src/main/java/org/swisspush/redisques/handler/GetAllLocksHandler.java
index 7c49c9c..952eaba 100644
--- a/src/main/java/org/swisspush/redisques/handler/GetAllLocksHandler.java
+++ b/src/main/java/org/swisspush/redisques/handler/GetAllLocksHandler.java
@@ -7,6 +7,7 @@
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.util.HandlerUtil;
import java.util.List;
@@ -29,8 +30,11 @@ public class GetAllLocksHandler implements Handler> {
private static final Logger log = getLogger(GetAllLocksHandler.class);
private final Message event;
private final Optional filterPattern;
+ private final RedisQuesExceptionFactory exceptionFactory;
- public GetAllLocksHandler(Message event, Optional filterPattern) {
+ public GetAllLocksHandler(RedisQuesExceptionFactory exceptionFactory, Message event,
+ Optional filterPattern) {
+ this.exceptionFactory = exceptionFactory;
this.event = event;
this.filterPattern = filterPattern;
}
@@ -44,7 +48,7 @@ public void handle(AsyncResult reply) {
result.put("locks", new JsonArray(filteredLocks));
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, result));
} else {
- if( reply.failed() ) log.warn("Concealed error", new Exception(reply.cause()));
+ if( reply.failed() ) log.warn("Concealed error", exceptionFactory.newException(reply.cause()));
event.reply(new JsonObject().put(STATUS, ERROR));
}
}
diff --git a/src/main/java/org/swisspush/redisques/handler/GetLockHandler.java b/src/main/java/org/swisspush/redisques/handler/GetLockHandler.java
index d40b673..7d4a9b9 100644
--- a/src/main/java/org/swisspush/redisques/handler/GetLockHandler.java
+++ b/src/main/java/org/swisspush/redisques/handler/GetLockHandler.java
@@ -6,9 +6,9 @@
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import static org.slf4j.LoggerFactory.getLogger;
-import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.NO_SUCH_LOCK;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
@@ -23,9 +23,11 @@ public class GetLockHandler implements Handler> {
private static final Logger log = getLogger(GetLockHandler.class);
private final Message event;
+ private final RedisQuesExceptionFactory exceptionFactory;
- public GetLockHandler(Message event) {
+ public GetLockHandler(Message event, RedisQuesExceptionFactory exceptionFactory) {
this.event = event;
+ this.exceptionFactory = exceptionFactory;
}
@Override
@@ -37,8 +39,8 @@ public void handle(AsyncResult reply) {
event.reply(new JsonObject().put(STATUS, NO_SUCH_LOCK));
}
} else {
- log.warn("Concealed error", new Exception(reply.cause()));
- event.reply(new JsonObject().put(STATUS, ERROR));
+ log.warn("Concealed error", exceptionFactory.newException(reply.cause()));
+ event.fail(0, reply.cause().getMessage());
}
}
diff --git a/src/main/java/org/swisspush/redisques/handler/GetQueueItemHandler.java b/src/main/java/org/swisspush/redisques/handler/GetQueueItemHandler.java
index 57c7915..8c13a1c 100644
--- a/src/main/java/org/swisspush/redisques/handler/GetQueueItemHandler.java
+++ b/src/main/java/org/swisspush/redisques/handler/GetQueueItemHandler.java
@@ -6,6 +6,7 @@
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
@@ -16,23 +17,27 @@
/**
* Class GetQueueItemHandler.
*
- * @author baldim, https://github.com/mcweba [Marc-Andre Weber]
+ * @author baldim, Marc-André Weber
*/
public class GetQueueItemHandler implements Handler> {
private static final Logger log = getLogger(GetQueueItemHandler.class);
private final Message event;
+ private final RedisQuesExceptionFactory exceptionFactory;
- public GetQueueItemHandler(Message event) {
+ public GetQueueItemHandler(Message event, RedisQuesExceptionFactory exceptionFactory) {
this.event = event;
+ this.exceptionFactory = exceptionFactory;
}
@Override
public void handle(AsyncResult reply) {
- if (reply.succeeded() && reply.result() != null) {
+ if(reply.failed()) {
+ log.warn("Concealed error", exceptionFactory.newException(reply.cause()));
+ event.fail(0, reply.cause().getMessage());
+ } else if (reply.result() != null) {
event.reply(new JsonObject().put(STATUS, OK).put(VALUE, reply.result().toString()));
} else {
- if( reply.failed() ) log.warn("Concealed error", new Exception(reply.cause()));
event.reply(new JsonObject().put(STATUS, ERROR));
}
}
diff --git a/src/main/java/org/swisspush/redisques/handler/GetQueueItemsCountHandler.java b/src/main/java/org/swisspush/redisques/handler/GetQueueItemsCountHandler.java
index a63fa62..e32e1c7 100644
--- a/src/main/java/org/swisspush/redisques/handler/GetQueueItemsCountHandler.java
+++ b/src/main/java/org/swisspush/redisques/handler/GetQueueItemsCountHandler.java
@@ -16,7 +16,7 @@
/**
* Class GetQueueItemsCountHandler.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class GetQueueItemsCountHandler implements Handler> {
diff --git a/src/main/java/org/swisspush/redisques/handler/GetQueueItemsHandler.java b/src/main/java/org/swisspush/redisques/handler/GetQueueItemsHandler.java
index 770adbd..a13e497 100644
--- a/src/main/java/org/swisspush/redisques/handler/GetQueueItemsHandler.java
+++ b/src/main/java/org/swisspush/redisques/handler/GetQueueItemsHandler.java
@@ -18,7 +18,7 @@
/**
* Class GetQueueItemsHandler.
*
- * @author baldim, https://github.com/mcweba [Marc-Andre Weber]
+ * @author baldim, Marc-André Weber
*/
public class GetQueueItemsHandler implements Handler> {
diff --git a/src/main/java/org/swisspush/redisques/handler/GetQueuesCountHandler.java b/src/main/java/org/swisspush/redisques/handler/GetQueuesCountHandler.java
index 2b241f4..c013200 100644
--- a/src/main/java/org/swisspush/redisques/handler/GetQueuesCountHandler.java
+++ b/src/main/java/org/swisspush/redisques/handler/GetQueuesCountHandler.java
@@ -16,7 +16,7 @@
/**
* Class GetQueuesCountHandler.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class GetQueuesCountHandler implements Handler> {
diff --git a/src/main/java/org/swisspush/redisques/handler/GetQueuesHandler.java b/src/main/java/org/swisspush/redisques/handler/GetQueuesHandler.java
index 3a794a8..06b8d26 100644
--- a/src/main/java/org/swisspush/redisques/handler/GetQueuesHandler.java
+++ b/src/main/java/org/swisspush/redisques/handler/GetQueuesHandler.java
@@ -21,7 +21,7 @@
import static org.swisspush.redisques.util.RedisquesAPI.VALUE;
/**
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class GetQueuesHandler implements Handler> {
diff --git a/src/main/java/org/swisspush/redisques/handler/GetQueuesItemsCountHandler.java b/src/main/java/org/swisspush/redisques/handler/GetQueuesItemsCountHandler.java
index 7cf2d09..5e5a0ff 100644
--- a/src/main/java/org/swisspush/redisques/handler/GetQueuesItemsCountHandler.java
+++ b/src/main/java/org/swisspush/redisques/handler/GetQueuesItemsCountHandler.java
@@ -92,7 +92,7 @@ public void handle(AsyncResult handleQueues) {
return;
}
- redisProvider.redis().compose((RedisAPI redis_) -> {
+ redisProvider.redis().compose((RedisAPI redis_) -> {
ctx.redis = redis_;
ctx.queueLengths = new int[ctx.queues.size()];
ctx.iter = ctx.queues.iterator();
@@ -105,9 +105,7 @@ public void handle(AsyncResult handleQueues) {
ctx.redis.send(Command.LLEN, queuesPrefix + queue).onSuccess((Response rsp) -> {
ctx.queueLengths[iNum] = rsp.toInteger();
onLLenDone.accept(null, null);
- }).onFailure((Throwable ex) -> {
- onLLenDone.accept(ex, null);
- });
+ }).onFailure((Throwable ex) -> onLLenDone.accept(ex, null));
}
return ctx.iter.hasNext();
}
@@ -121,9 +119,9 @@ public void handle(AsyncResult handleQueues) {
}
});
return p.future();
- }).compose((Void v) -> {
+ }).compose((Void v) -> {
/*going to waste another threads time to produce those garbage objects*/
- return vertx.executeBlocking((Promise workerPromise) -> {
+ return vertx.executeBlocking((Promise workerPromise) -> {
assert !Thread.currentThread().getName().toUpperCase().contains("EVENTLOOP");
long beginEpchMs = currentTimeMillis();
diff --git a/src/main/java/org/swisspush/redisques/handler/PutLockHandler.java b/src/main/java/org/swisspush/redisques/handler/PutLockHandler.java
index 0f73342..beccdcd 100644
--- a/src/main/java/org/swisspush/redisques/handler/PutLockHandler.java
+++ b/src/main/java/org/swisspush/redisques/handler/PutLockHandler.java
@@ -6,9 +6,9 @@
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import static org.slf4j.LoggerFactory.getLogger;
-import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
import static org.swisspush.redisques.util.RedisquesAPI.OK;
import static org.swisspush.redisques.util.RedisquesAPI.STATUS;
@@ -21,9 +21,11 @@ public class PutLockHandler implements Handler> {
private static final Logger log = getLogger(PutLockHandler.class);
private final Message event;
+ private final RedisQuesExceptionFactory exceptionFactory;
- public PutLockHandler(Message event) {
+ public PutLockHandler(Message event, RedisQuesExceptionFactory exceptionFactory) {
this.event = event;
+ this.exceptionFactory = exceptionFactory;
}
@Override
@@ -31,8 +33,8 @@ public void handle(AsyncResult reply) {
if(reply.succeeded()){
event.reply(new JsonObject().put(STATUS, OK));
} else {
- log.warn("Concealed error", new Exception(reply.cause()));
- event.reply(new JsonObject().put(STATUS, ERROR));
+ log.warn("Concealed error", exceptionFactory.newException(reply.cause()));
+ event.fail(0, reply.cause().getMessage());
}
}
diff --git a/src/main/java/org/swisspush/redisques/handler/RedisquesConfigurationAuthentication.java b/src/main/java/org/swisspush/redisques/handler/RedisquesConfigurationAuthentication.java
index d8f553e..ae66b92 100644
--- a/src/main/java/org/swisspush/redisques/handler/RedisquesConfigurationAuthentication.java
+++ b/src/main/java/org/swisspush/redisques/handler/RedisquesConfigurationAuthentication.java
@@ -16,7 +16,7 @@
/**
* Custom implementation of a {@link AuthenticationProvider} using credentials from {@link RedisquesConfiguration}
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class RedisquesConfigurationAuthentication implements AuthenticationProvider {
diff --git a/src/main/java/org/swisspush/redisques/handler/RedisquesHttpRequestHandler.java b/src/main/java/org/swisspush/redisques/handler/RedisquesHttpRequestHandler.java
index 02acbb8..a5af7a1 100644
--- a/src/main/java/org/swisspush/redisques/handler/RedisquesHttpRequestHandler.java
+++ b/src/main/java/org/swisspush/redisques/handler/RedisquesHttpRequestHandler.java
@@ -22,7 +22,6 @@
import org.swisspush.redisques.QueueStatsService;
import org.swisspush.redisques.QueueStatsService.GetQueueStatsMentor;
import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
-import org.swisspush.redisques.util.DequeueStatistic;
import org.swisspush.redisques.util.DequeueStatisticCollector;
import org.swisspush.redisques.util.QueueStatisticsCollector;
import org.swisspush.redisques.util.RedisquesAPI;
@@ -30,6 +29,7 @@
import org.swisspush.redisques.util.Result;
import org.swisspush.redisques.util.StatusCode;
+import javax.annotation.Nullable;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -45,7 +45,7 @@
/**
* Handler class for HTTP requests providing access to Redisques over HTTP.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class RedisquesHttpRequestHandler implements Handler {
@@ -65,7 +65,9 @@ public class RedisquesHttpRequestHandler implements Handler {
private static final String EMPTY_QUEUES_PARAM = "emptyQueues";
private static final String DELETED = "deleted";
- /** @deprecated about obsolete date formats */
+ /**
+ * @deprecated about obsolete date formats
+ */
@Deprecated
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
@@ -79,9 +81,9 @@ public class RedisquesHttpRequestHandler implements Handler {
private final GetQueueStatsMentor queueStatsMentor = new MyQueueStatsMentor();
public static void init(
- Vertx vertx, RedisquesConfiguration modConfig, QueueStatisticsCollector queueStatisticsCollector,
- DequeueStatisticCollector dequeueStatisticCollector, RedisQuesExceptionFactory exceptionFactory,
- Semaphore queueStatsRequestQuota
+ Vertx vertx, RedisquesConfiguration modConfig, QueueStatisticsCollector queueStatisticsCollector,
+ DequeueStatisticCollector dequeueStatisticCollector, RedisQuesExceptionFactory exceptionFactory,
+ Semaphore queueStatsRequestQuota
) {
log.info("Enabling http request handler: {}", modConfig.getHttpRequestHandlerEnabled());
if (modConfig.getHttpRequestHandlerEnabled()) {
@@ -118,12 +120,12 @@ private Result checkHttpAuthenticationConfiguration(RedisquesCo
}
private RedisquesHttpRequestHandler(
- Vertx vertx,
- RedisquesConfiguration modConfig,
- QueueStatisticsCollector queueStatisticsCollector,
- DequeueStatisticCollector dequeueStatisticCollector,
- RedisQuesExceptionFactory exceptionFactory,
- Semaphore queueStatsRequestQuota
+ Vertx vertx,
+ RedisquesConfiguration modConfig,
+ QueueStatisticsCollector queueStatisticsCollector,
+ DequeueStatisticCollector dequeueStatisticCollector,
+ RedisQuesExceptionFactory exceptionFactory,
+ Semaphore queueStatsRequestQuota
) {
this.vertx = vertx;
this.router = Router.router(vertx);
@@ -316,8 +318,9 @@ private void getAllLocks(RoutingContext ctx) {
String filter = ctx.request().params().get(FILTER);
eventBus.request(redisquesAddress, buildGetAllLocksOperation(filter), (Handler>>) reply -> {
if (reply.failed()) {
- log.warn("Received failed message for getAllLocksOperation. Lets run into NullPointerException now", reply.cause());
- // IMO we should respond with 'HTTP 5xx'. But we don't, to keep backward compatibility.
+ log.warn("Received failed message for getAllLocksOperation", exceptionFactory.newException(reply.cause()));
+ respondWith(StatusCode.INTERNAL_SERVER_ERROR, reply.cause().getMessage(), ctx.request());
+ return;
}
final JsonObject body = reply.result().body();
if (OK.equals(body.getString(STATUS))) {
@@ -342,11 +345,12 @@ private void addLock(RoutingContext ctx) {
queue -> eventBus.request(redisquesAddress, buildPutLockOperation(queue, extractUser(ctx.request())),
(Handler>>) reply -> {
if (reply.failed()) {
- log.warn("Received failed message for addLockOperation. Lets run into NullPointerException now", reply.cause());
- // IMO we should respond with 'HTTP 5xx' here. But we don't, to keep backward compatibility.
- // Nevertheless. Lets run into NullPointerException by calling method below.
+ String error = "Received failed message for addLockOperation";
+ log.warn(error, exceptionFactory.newException(reply.cause()));
+ respondWith(StatusCode.INTERNAL_SERVER_ERROR, error, ctx.request());
+ } else {
+ checkReply(reply.result(), ctx.request(), StatusCode.BAD_REQUEST);
}
- checkReply(reply.result(), ctx.request(), StatusCode.BAD_REQUEST);
}
));
}
@@ -356,10 +360,10 @@ private void getSingleLock(RoutingContext ctx) {
queue -> eventBus.request(redisquesAddress, buildGetLockOperation(queue), (Handler>>) reply -> {
final HttpServerResponse response = ctx.response();
if (reply.failed()) {
- log.warn("Received failed message for getSingleLockOperation. Lets run into NullPointerException now", reply.cause());
- // IMO we should respond with 'HTTP 5xx' here. But we don't, to keep backward compatibility.
- }
- if (OK.equals(reply.result().body().getString(STATUS))) {
+ String error = "Received failed message for getSingleLockOperation";
+ log.warn(error, exceptionFactory.newException(reply.cause()));
+ respondWith(StatusCode.INTERNAL_SERVER_ERROR, error, ctx.request());
+ } else if (OK.equals(reply.result().body().getString(STATUS))) {
response.putHeader(CONTENT_TYPE, APPLICATION_JSON);
response.end(reply.result().body().getString(VALUE));
} else {
@@ -390,11 +394,12 @@ private void deleteSingleLock(RoutingContext ctx) {
queue -> eventBus.request(redisquesAddress, buildDeleteLockOperation(queue),
(Handler>>) reply -> {
if (reply.failed()) {
- log.warn("Received failed message for deleteSingleLockOperation. Lets run into NullPointerException now", reply.cause());
- // IMO we should respond with 'HTTP 5xx'. But we don't, to keep backward compatibility.
- // Nevertheless. Lets run into NullPointerException by calling below method.
+ String error = "Received failed message for deleteSingleLockOperation";
+ log.warn(error, exceptionFactory.newException(reply.cause()));
+ respondWith(StatusCode.INTERNAL_SERVER_ERROR, error, ctx.request());
+ } else {
+ checkReply(reply.result(), ctx.request(), StatusCode.INTERNAL_SERVER_ERROR);
}
- checkReply(reply.result(), ctx.request(), StatusCode.INTERNAL_SERVER_ERROR);
}));
}
@@ -556,6 +561,7 @@ public void onQueueStatistics(List queues, RoutingConte
Iterator queueSrc;
JsonObject queueJson = new JsonObject();
boolean isFirst = true;
+
void run(RoutingContext ctx_) {
ctx = ctx_;
queueSrc = queues.iterator();
@@ -565,6 +571,7 @@ void run(RoutingContext ctx_) {
rsp.write("{\"queues\": [");
resumeJsonWriting();
}
+
void resumeJsonWriting() {
while (true) {
if (rsp.writeQueueFull()) {
@@ -606,7 +613,7 @@ void resumeJsonWriting() {
public void onError(Throwable ex, RoutingContext ctx) {
if (!ctx.response().headWritten()) {
log.debug("TODO error handling {}", ctx.request().uri(), exceptionFactory.newException(
- "Failed to serve queue stats", ex));
+ "Failed to serve queue stats", ex));
StatusCode rspCode = tryExtractStatusCode(ex, StatusCode.INTERNAL_SERVER_ERROR);
respondWith(rspCode, ex.getMessage(), ctx.request());
} else {
@@ -701,7 +708,7 @@ private void listQueueItems(RoutingContext ctx) {
}
eventBus.request(redisquesAddress, buildGetQueueItemsOperation(queue, limitParam), (Handler>>) reply -> {
if (reply.failed()) {
- log.error("Received failed message for listQueueItemsOperation", reply.cause());
+ log.error("Received failed message for listQueueItemsOperation", exceptionFactory.newException(reply.cause()));
respondWith(StatusCode.INTERNAL_SERVER_ERROR, ctx.request());
return;
}
@@ -732,11 +739,12 @@ private void addQueueItem(RoutingContext ctx) {
eventBus.request(redisquesAddress, buildAddQueueItemOperation(queue, strBuffer),
(Handler>>) reply -> {
if (reply.failed()) {
- log.warn("Received failed message for addQueueItemOperation. Lets run into NullPointerException now", reply.cause());
- // IMO we should respond with 'HTTP 5xx'. But we don't, to keep backward compatibility.
- // Nevertheless. Lets run into NullPointerException by calling method below.
+ String error = "Received failed message for addQueueItemOperation";
+ log.warn(error, exceptionFactory.newException(reply.cause()));
+ respondWith(StatusCode.INTERNAL_SERVER_ERROR, error, ctx.request());
+ } else {
+ checkReply(reply.result(), ctx.request(), StatusCode.BAD_REQUEST);
}
- checkReply(reply.result(), ctx.request(), StatusCode.BAD_REQUEST);
});
} catch (Exception ex) {
respondWith(StatusCode.BAD_REQUEST, ex.getMessage(), ctx.request());
@@ -751,8 +759,10 @@ private void getSingleQueueItem(RoutingContext ctx) {
final int index = Integer.parseInt(lastPart(requestPath));
eventBus.request(redisquesAddress, buildGetQueueItemOperation(queue, index), (Handler>>) reply -> {
if (reply.failed()) {
- log.warn("Received failed message for getSingleQueueItemOperation. Lets run into NullPointerException now", reply.cause());
- // IMO we should respond with 'HTTP 5xx'. But we don't, to keep backward compatibility.
+ String error = "Received failed message for getSingleQueueItemOperation";
+ log.warn(error, exceptionFactory.newException(reply.cause()));
+ respondWith(StatusCode.INTERNAL_SERVER_ERROR, error, ctx.request());
+ return;
}
final JsonObject replyBody = reply.result().body();
final HttpServerResponse response = ctx.response();
@@ -779,11 +789,12 @@ private void replaceSingleQueueItem(RoutingContext ctx) {
eventBus.request(redisquesAddress, buildReplaceQueueItemOperation(queue, index, strBuffer),
(Handler>>) reply -> {
if (reply.failed()) {
- log.warn("Received failed message for replaceSingleQueueItemOperation. Lets run into NullPointerException now", reply.cause());
- // IMO we should respond with 'HTTP 5xx'. But we don't, to keep backward compatibility.
- // Nevertheless. Lets run into NullPointerException by calling method below.
+ String error = "Received failed message for replaceSingleQueueItemOperation";
+ log.warn(error, exceptionFactory.newException(reply.cause()));
+ respondWith(StatusCode.INTERNAL_SERVER_ERROR, error, ctx.request());
+ } else {
+ checkReply(reply.result(), request, StatusCode.NOT_FOUND);
}
- checkReply(reply.result(), request, StatusCode.NOT_FOUND);
});
} catch (Exception ex) {
log.warn("Undocumented exception caught while replaceSingleQueueItem. But assume its the clients bad ;)", ex);
@@ -797,15 +808,17 @@ private void deleteQueueItem(RoutingContext ctx) {
final HttpServerRequest request = ctx.request();
decodedQueueNameOrRespondWithBadRequest(ctx, part(request.path(), 2)).ifPresent(queue -> {
final int index = Integer.parseInt(lastPart(request.path()));
+
checkLocked(queue, request, event ->
eventBus.request(redisquesAddress, buildDeleteQueueItemOperation(queue, index),
(Handler>>) reply -> {
if (reply.failed()) {
- log.warn("Received failed message for deleteQueueItemOperation. Lets run into NullPointerException now", reply.cause());
- // IMO we should respond with 'HTTP 5xx'. But we don't, to keep backward compatibility.
- // Nevertheless. Lets run into NullPointerException by calling method below.
+ String error = "Received failed message for deleteQueueItemOperation";
+ log.warn(error, exceptionFactory.newException(reply.cause()));
+ respondWith(StatusCode.INTERNAL_SERVER_ERROR, error, ctx.request());
+ } else {
+ checkReply(reply.result(), request, StatusCode.NOT_FOUND);
}
- checkReply(reply.result(), request, StatusCode.NOT_FOUND);
}
));
});
@@ -817,7 +830,7 @@ private void deleteAllQueueItems(RoutingContext ctx) {
final String queue = lastPart(request.path());
eventBus.request(redisquesAddress, buildDeleteAllQueueItemsOperation(queue, unlock), (Handler>>) reply -> {
if (reply.failed()) {
- log.warn("Received failed message for deleteAllQueueItemsOperation", reply.cause());
+ log.warn("Received failed message for deleteAllQueueItemsOperation", exceptionFactory.newException(reply.cause()));
respondWith(StatusCode.INTERNAL_SERVER_ERROR, "Error deleting all queue items of queue " + queue, request);
return;
}
@@ -843,9 +856,10 @@ private void bulkDeleteQueues(RoutingContext ctx) {
}
eventBus.request(redisquesAddress, buildBulkDeleteQueuesOperation(result.getOk()), (Handler>>) reply -> {
if (reply.failed()) {
- log.warn("Failed to bulkDeleteQueues. Lets run into NullPointerException now", reply.cause());
- // IMO we should respond with 'HTTP 5xx'. But we don't, to keep backward compatibility.
- // Nevertheless. Lets run into NullPointerException in else case below now.
+ String error = "Failed to bulkDeleteQueues";
+ log.warn(error, exceptionFactory.newException(reply.cause()));
+ respondWith(StatusCode.INTERNAL_SERVER_ERROR, error, ctx.request());
+ return;
}
if (reply.succeeded() && OK.equals(reply.result().body().getString(STATUS))) {
JsonObject resultObj = new JsonObject();
@@ -875,13 +889,17 @@ private void bulkDeleteQueues(RoutingContext ctx) {
}
}
- private void respondWith(StatusCode statusCode, String responseMessage, HttpServerRequest request) {
+ private void respondWith(StatusCode statusCode, @Nullable String responseMessage, HttpServerRequest request) {
final HttpServerResponse response = request.response();
log.info("Responding with status code {} and message '{}' to request '{}'", statusCode, responseMessage, request.uri());
response.setStatusCode(statusCode.getStatusCode());
response.setStatusMessage(statusCode.getStatusMessage());
response.putHeader(CONTENT_TYPE, TEXT_PLAIN);
- response.end(responseMessage);
+ if (responseMessage != null) {
+ response.end(responseMessage);
+ } else {
+ response.end();
+ }
}
private void respondWith(StatusCode statusCode, HttpServerRequest request) {
@@ -915,8 +933,15 @@ private void checkLocked(String queue, final HttpServerRequest request, final Ha
request.pause();
eventBus.request(redisquesAddress, buildGetLockOperation(queue), (Handler>>) reply -> {
request.resume();
+ if (reply.failed()) {
+ String error = "Received failed message for checkLocked operation";
+ log.warn(error, exceptionFactory.newException(reply.cause()));
+ respondWith(StatusCode.INTERNAL_SERVER_ERROR, error, request);
+ return;
+ }
if (NO_SUCH_LOCK.equals(reply.result().body().getString(STATUS))) {
final HttpServerResponse response = request.response();
+ response.putHeader(CONTENT_TYPE, TEXT_PLAIN);
response.setStatusCode(StatusCode.CONFLICT.getStatusCode());
response.setStatusMessage("Queue must be locked to perform this operation");
response.end("Queue must be locked to perform this operation");
@@ -937,6 +962,7 @@ private void checkReply(Message reply, HttpServerRequest request, St
} else {
response.setStatusCode(statusCode.getStatusCode());
response.setStatusMessage(statusCode.getStatusMessage());
+ response.putHeader(CONTENT_TYPE, TEXT_PLAIN);
response.end(statusCode.getStatusMessage());
}
}
diff --git a/src/main/java/org/swisspush/redisques/handler/ReplaceQueueItemHandler.java b/src/main/java/org/swisspush/redisques/handler/ReplaceQueueItemHandler.java
index f789db4..81950cc 100644
--- a/src/main/java/org/swisspush/redisques/handler/ReplaceQueueItemHandler.java
+++ b/src/main/java/org/swisspush/redisques/handler/ReplaceQueueItemHandler.java
@@ -6,6 +6,7 @@
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.Response;
import org.slf4j.Logger;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import static org.slf4j.LoggerFactory.getLogger;
import static org.swisspush.redisques.util.RedisquesAPI.ERROR;
@@ -15,25 +16,35 @@
/**
* Class ReplaceQueueItemHandler.
*
- * @author baldim, https://github.com/mcweba [Marc-Andre Weber]
+ * @author baldim, Marc-André Weber
*/
public class ReplaceQueueItemHandler implements Handler> {
private static final Logger log = getLogger(ReplaceQueueItemHandler.class);
private final Message event;
+ private final RedisQuesExceptionFactory exceptionFactory;
- public ReplaceQueueItemHandler(Message event) {
+ public ReplaceQueueItemHandler(Message event, RedisQuesExceptionFactory exceptionFactory) {
this.event = event;
+ this.exceptionFactory = exceptionFactory;
}
@Override
public void handle(AsyncResult reply) {
if(reply.succeeded()){
event.reply(new JsonObject().put(STATUS, OK));
- } else {
- log.warn("Concealed error", new Exception(reply.cause()));
+ } else if(checkRedisErrorCodes(reply.cause().getMessage())) {
event.reply(new JsonObject().put(STATUS, ERROR));
+ } else {
+ log.warn("Concealed error", exceptionFactory.newException(reply.cause()));
+ event.fail(0, reply.cause().getMessage());
}
}
+ private boolean checkRedisErrorCodes(String message) {
+ if(message == null) {
+ return false;
+ }
+ return message.contains("index out of range");
+ }
}
diff --git a/src/main/java/org/swisspush/redisques/performance/UpperBoundParallel.java b/src/main/java/org/swisspush/redisques/performance/UpperBoundParallel.java
index f3ec76a..d0a8aa1 100644
--- a/src/main/java/org/swisspush/redisques/performance/UpperBoundParallel.java
+++ b/src/main/java/org/swisspush/redisques/performance/UpperBoundParallel.java
@@ -158,7 +158,6 @@ private void resume(Request req) {
"No more resources to handle yet another request now.", null);
req.mentor.onError(ex, req.ctx);
assert req.numTokensAvailForOurself == 0 : "assert(numTokensAvailForOurself != " + req.numTokensAvailForOurself + ")";
- return;
} else {
log.error("If you see this log, some unreachable code got reached. numInProgress={}, hasStarted={}",
req.numInProgress, req.hasStarted);
diff --git a/src/main/java/org/swisspush/redisques/util/DefaultRedisProvider.java b/src/main/java/org/swisspush/redisques/util/DefaultRedisProvider.java
index 2d4e334..bb6a8b8 100644
--- a/src/main/java/org/swisspush/redisques/util/DefaultRedisProvider.java
+++ b/src/main/java/org/swisspush/redisques/util/DefaultRedisProvider.java
@@ -19,7 +19,7 @@
/**
* Default implementation for a Provider for {@link RedisAPI}
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class DefaultRedisProvider implements RedisProvider {
diff --git a/src/main/java/org/swisspush/redisques/util/DefaultRedisReadyProvider.java b/src/main/java/org/swisspush/redisques/util/DefaultRedisReadyProvider.java
index a4092e8..9f56de8 100644
--- a/src/main/java/org/swisspush/redisques/util/DefaultRedisReadyProvider.java
+++ b/src/main/java/org/swisspush/redisques/util/DefaultRedisReadyProvider.java
@@ -13,7 +13,7 @@
/**
* Default implementation of the {@link RedisReadyProvider} based on the INFO
command in Redis
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class DefaultRedisReadyProvider implements RedisReadyProvider {
@@ -29,9 +29,7 @@ public class DefaultRedisReadyProvider implements RedisReadyProvider {
* @param updateIntervalMs interval in ms how often to update the "ready-state"
*/
public DefaultRedisReadyProvider(Vertx vertx, int updateIntervalMs) {
- vertx.setPeriodic(updateIntervalMs, l -> {
- updateRedisReady.set(true);
- });
+ vertx.setPeriodic(updateIntervalMs, l -> updateRedisReady.set(true));
}
@Override
diff --git a/src/main/java/org/swisspush/redisques/util/HttpServerRequestUtil.java b/src/main/java/org/swisspush/redisques/util/HttpServerRequestUtil.java
index 1fab314..76803bb 100644
--- a/src/main/java/org/swisspush/redisques/util/HttpServerRequestUtil.java
+++ b/src/main/java/org/swisspush/redisques/util/HttpServerRequestUtil.java
@@ -15,7 +15,7 @@
/**
* Util class to work with {@link HttpServerRequest}s
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class HttpServerRequestUtil {
diff --git a/src/main/java/org/swisspush/redisques/util/MessageUtil.java b/src/main/java/org/swisspush/redisques/util/MessageUtil.java
index 9546780..bd02928 100644
--- a/src/main/java/org/swisspush/redisques/util/MessageUtil.java
+++ b/src/main/java/org/swisspush/redisques/util/MessageUtil.java
@@ -14,7 +14,7 @@
/**
* Util class to work with {@link Message}s
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class MessageUtil {
diff --git a/src/main/java/org/swisspush/redisques/util/QueueActionFactory.java b/src/main/java/org/swisspush/redisques/util/QueueActionFactory.java
index a275de9..930c851 100644
--- a/src/main/java/org/swisspush/redisques/util/QueueActionFactory.java
+++ b/src/main/java/org/swisspush/redisques/util/QueueActionFactory.java
@@ -62,73 +62,73 @@ public QueueAction buildQueueAction(RedisquesAPI.QueueOperation queueOperation){
switch (queueOperation){
case addQueueItem:
return new AddQueueItemAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case deleteQueueItem:
return new DeleteQueueItemAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case deleteAllQueueItems:
return new DeleteAllQueueItemsAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case bulkDeleteQueues:
return new BulkDeleteQueuesAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case replaceQueueItem:
return new ReplaceQueueItemAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case getQueueItem:
return new GetQueueItemAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case getQueueItems:
return new GetQueueItemsAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case getQueues:
return new GetQueuesAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case getQueuesCount:
return new GetQueuesCountAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case getQueueItemsCount:
return new GetQueueItemsCountAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case getQueuesItemsCount:
return new GetQueuesItemsCountAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
consumersPrefix, locksKey, queueConfigurations, exceptionFactory,
getQueuesItemsCountRedisRequestQuota, queueStatisticsCollector, log);
case enqueue:
return new EnqueueAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log, memoryUsageProvider,
- memoryUsageLimitPercent);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log,
+ memoryUsageProvider, memoryUsageLimitPercent);
case lockedEnqueue:
return new LockedEnqueueAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log, memoryUsageProvider,
- memoryUsageLimitPercent);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log,
+ memoryUsageProvider, memoryUsageLimitPercent);
case getLock:
return new GetLockAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case putLock:
return new PutLockAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case bulkPutLocks:
return new BulkPutLocksAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case getAllLocks:
return new GetAllLocksAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case deleteLock:
return new DeleteLockAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case bulkDeleteLocks:
return new BulkDeleteLocksAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case deleteAllLocks:
return new DeleteAllLocksAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case getQueuesSpeed:
return new GetQueuesSpeedAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case getQueuesStatistics:
return new GetQueuesStatisticsAction(vertx, redisProvider, address, queuesKey, queuesPrefix,
- consumersPrefix, locksKey, queueConfigurations, queueStatisticsCollector, log);
+ consumersPrefix, locksKey, queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
case setConfiguration:
return new SetConfigurationAction(configurationProvider, log);
case getConfiguration:
diff --git a/src/main/java/org/swisspush/redisques/util/QueueStatisticsCollector.java b/src/main/java/org/swisspush/redisques/util/QueueStatisticsCollector.java
index 43be606..1bef19f 100644
--- a/src/main/java/org/swisspush/redisques/util/QueueStatisticsCollector.java
+++ b/src/main/java/org/swisspush/redisques/util/QueueStatisticsCollector.java
@@ -513,7 +513,7 @@ Future step2(RequestCtx ctx) {
/* [TODO](https://github.com/swisspost/vertx-redisques/issues/198) */
vertx.executeBlocking(() -> {
return ctx.redisAPI.send(LLEN, queuePrefix + queueName);
- }).compose((Future rspWrappedInsideAFuture) -> {
+ }).compose((Future rspWrappedInsideAFuture) -> {
return rspWrappedInsideAFuture;
}).compose((Response rsp) -> {
NumberType num = (NumberType) rsp;
@@ -544,19 +544,17 @@ Future step2(RequestCtx ctx) {
log.debug(fmt2, numQueues, durRedisRequestsMs);
}
if (ctx.queueLengthList.size() != ctx.queueNames.size()) {
- return failedFuture(exceptionFactory.newException(""
- + "Unexpected queue length result with unequal size "
+ return failedFuture(exceptionFactory.newException("Unexpected queue length result with unequal size "
+ ctx.queueNames.size() + " : " + ctx.queueLengthList.size()));
}
return succeededFuture();
- }).compose((Void v) -> {
+ }).compose((Void v) -> {
if (ctx.queueLengthList == null) {
assert false : "TODO I guess this unreachable code could be removed";
return failedFuture(exceptionFactory.newException("Unexpected queue length result: null"));
}
if (ctx.queueLengthList.size() != ctx.queueNames.size()) {
- return failedFuture(exceptionFactory.newException(""
- + "Unexpected queue length result with unequal size "
+ return failedFuture(exceptionFactory.newException("Unexpected queue length result with unequal size "
+ ctx.queueNames.size() + " : " + ctx.queueLengthList.size()));
}
return succeededFuture();
diff --git a/src/main/java/org/swisspush/redisques/util/RedisProvider.java b/src/main/java/org/swisspush/redisques/util/RedisProvider.java
index a18a045..72a1591 100644
--- a/src/main/java/org/swisspush/redisques/util/RedisProvider.java
+++ b/src/main/java/org/swisspush/redisques/util/RedisProvider.java
@@ -6,7 +6,7 @@
/**
* Provider for {@link RedisAPI}
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public interface RedisProvider {
Future redis();
diff --git a/src/main/java/org/swisspush/redisques/util/RedisQuesTimer.java b/src/main/java/org/swisspush/redisques/util/RedisQuesTimer.java
index f372b35..44696cc 100644
--- a/src/main/java/org/swisspush/redisques/util/RedisQuesTimer.java
+++ b/src/main/java/org/swisspush/redisques/util/RedisQuesTimer.java
@@ -11,7 +11,7 @@
/**
* Utility class for the vertx timer functionalities.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class RedisQuesTimer {
private final Vertx vertx;
@@ -36,7 +36,7 @@ public Future executeDelayedMax(long delayMs) {
if (delayMs > 0) {
int delay = random.nextInt((int) (delayMs + 1)) + 1;
- log.debug("starting timer with a delay of " + delay + "ms");
+ log.debug("starting timer with a delay of {}ms", delay);
vertx.setTimer(delay, delayed -> promise.complete());
} else {
vertx.runOnContext(aVoid -> promise.complete());
diff --git a/src/main/java/org/swisspush/redisques/util/RedisReadyProvider.java b/src/main/java/org/swisspush/redisques/util/RedisReadyProvider.java
index 6f7f9f0..d49d5f8 100644
--- a/src/main/java/org/swisspush/redisques/util/RedisReadyProvider.java
+++ b/src/main/java/org/swisspush/redisques/util/RedisReadyProvider.java
@@ -7,7 +7,7 @@
* Provides the "ready state" of the Redis database. The connection to Redis may be already established, but Redis is not
* yet ready to be used
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public interface RedisReadyProvider {
diff --git a/src/main/java/org/swisspush/redisques/util/RedisquesAPI.java b/src/main/java/org/swisspush/redisques/util/RedisquesAPI.java
index 0fe3e25..6fcebf0 100644
--- a/src/main/java/org/swisspush/redisques/util/RedisquesAPI.java
+++ b/src/main/java/org/swisspush/redisques/util/RedisquesAPI.java
@@ -8,7 +8,7 @@
/**
* Class RedisquesAPI listing the operations and response values which are supported in Redisques.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class RedisquesAPI {
public static final String OK = "ok";
diff --git a/src/main/java/org/swisspush/redisques/util/RedisquesConfiguration.java b/src/main/java/org/swisspush/redisques/util/RedisquesConfiguration.java
index 0d5cda8..e44cfc1 100644
--- a/src/main/java/org/swisspush/redisques/util/RedisquesConfiguration.java
+++ b/src/main/java/org/swisspush/redisques/util/RedisquesConfiguration.java
@@ -10,13 +10,12 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
-import java.util.concurrent.Semaphore;
import java.util.stream.Collectors;
/**
* Utility class to configure the Redisques module.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class RedisquesConfiguration {
private final String address;
diff --git a/src/main/java/org/swisspush/redisques/util/ResourcesUtils.java b/src/main/java/org/swisspush/redisques/util/ResourcesUtils.java
index 8675afb..ebebf4f 100644
--- a/src/main/java/org/swisspush/redisques/util/ResourcesUtils.java
+++ b/src/main/java/org/swisspush/redisques/util/ResourcesUtils.java
@@ -12,7 +12,7 @@
* Utility class providing handy methods to deal with Resources.
*
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class ResourcesUtils {
diff --git a/src/main/java/org/swisspush/redisques/util/StatusCode.java b/src/main/java/org/swisspush/redisques/util/StatusCode.java
index 6e974f9..dbae777 100644
--- a/src/main/java/org/swisspush/redisques/util/StatusCode.java
+++ b/src/main/java/org/swisspush/redisques/util/StatusCode.java
@@ -3,7 +3,7 @@
/**
* Enum for HTTP status codes
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public enum StatusCode {
OK(200, "OK"),
diff --git a/src/test/java/org/swisspush/redisques/MaxWaitingHandlersTest.java b/src/test/java/org/swisspush/redisques/MaxWaitingHandlersTest.java
index 1ecf04b..cdcd390 100644
--- a/src/test/java/org/swisspush/redisques/MaxWaitingHandlersTest.java
+++ b/src/test/java/org/swisspush/redisques/MaxWaitingHandlersTest.java
@@ -24,7 +24,7 @@
/**
* Tests for the {@link RedisOptions#setMaxWaitingHandlers(int)} method
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class MaxWaitingHandlersTest {
diff --git a/src/test/java/org/swisspush/redisques/RedisQuesProcessorDelayedExecutionTest.java b/src/test/java/org/swisspush/redisques/RedisQuesProcessorDelayedExecutionTest.java
index f86dcc9..dd68d33 100644
--- a/src/test/java/org/swisspush/redisques/RedisQuesProcessorDelayedExecutionTest.java
+++ b/src/test/java/org/swisspush/redisques/RedisQuesProcessorDelayedExecutionTest.java
@@ -22,7 +22,7 @@
import static org.swisspush.redisques.util.RedisquesAPI.*;
/**
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class RedisQuesProcessorDelayedExecutionTest extends AbstractTestCase {
@@ -69,7 +69,7 @@ protected void deployRedisques(TestContext context) {
RedisQues redisQues = new RedisQues();
vertx.deployVerticle(redisQues, new DeploymentOptions().setConfig(config), context.asyncAssertSuccess(event -> {
deploymentId = event;
- log.info("vert.x Deploy - " + redisQues.getClass().getSimpleName() + " was successful.");
+ log.info("vert.x Deploy - {} was successful.", redisQues.getClass().getSimpleName());
jedis = new Jedis("localhost", 6379, 5000);
}));
}
diff --git a/src/test/java/org/swisspush/redisques/RedisQuesProcessorRedeployTest.java b/src/test/java/org/swisspush/redisques/RedisQuesProcessorRedeployTest.java
index 3456922..b6dad86 100644
--- a/src/test/java/org/swisspush/redisques/RedisQuesProcessorRedeployTest.java
+++ b/src/test/java/org/swisspush/redisques/RedisQuesProcessorRedeployTest.java
@@ -47,7 +47,7 @@ protected static void deployRedisques(TestContext context, int refreshPeriod) {
RedisQues redisQues = new RedisQues();
vertx.deployVerticle(redisQues, new DeploymentOptions().setConfig(config), context.asyncAssertSuccess(event -> {
deploymentId = event;
- log.info("vert.x Deploy - " + redisQues.getClass().getSimpleName() + " was successful.");
+ log.info("vert.x Deploy - {} was successful.", redisQues.getClass().getSimpleName());
jedis = new Jedis("localhost", 6379, 5000);
}));
}
diff --git a/src/test/java/org/swisspush/redisques/RedisQuesProcessorTest.java b/src/test/java/org/swisspush/redisques/RedisQuesProcessorTest.java
index ff78f88..9552995 100644
--- a/src/test/java/org/swisspush/redisques/RedisQuesProcessorTest.java
+++ b/src/test/java/org/swisspush/redisques/RedisQuesProcessorTest.java
@@ -78,7 +78,7 @@ protected void deployRedisques(TestContext context) {
RedisQues redisQues = new RedisQues();
vertx.deployVerticle(redisQues, new DeploymentOptions().setConfig(config), context.asyncAssertSuccess(event -> {
deploymentId = event;
- log.info("vert.x Deploy - " + redisQues.getClass().getSimpleName() + " was successful.");
+ log.info("vert.x Deploy - {} was successful.", redisQues.getClass().getSimpleName());
jedis = new Jedis("localhost", 6379, 5000);
}));
}
@@ -93,7 +93,7 @@ public void test10Queues(TestContext context) {
final String payload = message.body().getString("payload");
if ("STOP".equals(payload)) {
- log.info("STOP message " + payload);
+ log.info("STOP message {}", payload);
message.reply(new JsonObject().put(STATUS, OK));
vertx.eventBus().send("digest-" + queue, DatatypeConverter.printBase64Binary(signatures.get(queue).digest()));
} else {
@@ -107,11 +107,11 @@ public void test10Queues(TestContext context) {
}
}
signature.update(payload.getBytes());
- log.info("added queue [" + queue + "] signature [" + digestStr(signature) + "]");
+ log.info("added queue [{}] signature [{}]", queue, digestStr(signature));
}
vertx.setTimer(new Random().nextLong() % 1 + 1, event -> {
- log.info("Processed message " + payload);
+ log.info("Processed message {}", payload);
message.reply(new JsonObject().put(STATUS, OK));
});
});
@@ -120,7 +120,7 @@ public void test10Queues(TestContext context) {
flushAll();
assertKeyCount(context, 0);
for (int i = 0; i < NUM_QUEUES; i++) {
- log.info("create new sender for queue: queue_" + i);
+ log.info("create new sender for queue: queue_{}", i);
new Sender(context, async, "queue_" + i).send(null);
}
}
@@ -153,9 +153,9 @@ class Sender {
}
vertx.eventBus().consumer("digest-" + queue, (Handler>) event -> {
- log.info("Received signature for " + queue + ": " + event.body());
+ log.info("Received signature for {}: {}", queue, event.body());
if (!event.body().equals(DatatypeConverter.printBase64Binary(signature.digest()))) {
- log.error("signatures are not identical: " + event.body() + " != " + DatatypeConverter.printBase64Binary(signature.digest()));
+ log.error("signatures are not identical: {} != {}", event.body(), DatatypeConverter.printBase64Binary(signature.digest()));
}
context.assertEquals(event.body(), DatatypeConverter.printBase64Binary(signature.digest()), "Signatures differ");
if (finished.incrementAndGet() == NUM_QUEUES) {
@@ -173,12 +173,12 @@ void send(final String m) {
message = m;
}
signature.update(message.getBytes());
- log.info("send message [" + digestStr(signature) + "] for queue [" + queue + "] ");
+ log.info("send message [{}] for queue [{}] ", digestStr(signature), queue);
vertx.eventBus().request(getRedisquesAddress(), buildEnqueueOperation(queue, message), (Handler>>) event -> {
if (event.result().body().getString(STATUS).equals(OK)) {
send(null);
} else {
- log.error("ERROR sending " + message + " to " + queue);
+ log.error("ERROR sending {} to {}", message, queue);
send(message);
}
});
diff --git a/src/test/java/org/swisspush/redisques/RedisQuesTest.java b/src/test/java/org/swisspush/redisques/RedisQuesTest.java
index 9baf839..daff483 100644
--- a/src/test/java/org/swisspush/redisques/RedisQuesTest.java
+++ b/src/test/java/org/swisspush/redisques/RedisQuesTest.java
@@ -24,7 +24,7 @@
/**
* Class RedisQueueBrowserTest.
*
- * @author baldim, webermarca
+ * @author baldim, Marc-André Weber
*/
public class RedisQuesTest extends AbstractTestCase {
@@ -61,7 +61,7 @@ public void deployRedisques(TestContext context) {
.build();
vertx.deployVerticle(redisQues, new DeploymentOptions().setConfig(config), context.asyncAssertSuccess(event -> {
deploymentId = event;
- log.info("vert.x Deploy - " + redisQues.getClass().getSimpleName() + " was successful.");
+ log.info("vert.x Deploy - {} was successful.", redisQues.getClass().getSimpleName());
jedis = new Jedis("localhost", 6379, 5000);
}));
}
diff --git a/src/test/java/org/swisspush/redisques/action/AbstractQueueActionTest.java b/src/test/java/org/swisspush/redisques/action/AbstractQueueActionTest.java
index 66b59fe..af514ef 100644
--- a/src/test/java/org/swisspush/redisques/action/AbstractQueueActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/AbstractQueueActionTest.java
@@ -1,12 +1,18 @@
package org.swisspush.redisques.action;
+import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
+import io.vertx.core.Handler;
import io.vertx.core.Vertx;
+import io.vertx.core.buffer.Buffer;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.redis.client.RedisAPI;
+import io.vertx.redis.client.Response;
import org.junit.Before;
import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.util.MemoryUsageProvider;
import org.swisspush.redisques.util.RedisProvider;
@@ -18,6 +24,7 @@ public abstract class AbstractQueueActionTest {
protected RedisAPI redisAPI;
protected RedisProvider redisProvider;
+ protected RedisQuesExceptionFactory exceptionFactory;
protected Vertx vertx;
@@ -26,10 +33,14 @@ public abstract class AbstractQueueActionTest {
protected Message message;
protected AbstractQueueAction action;
+ protected static final JsonObject STATUS_OK = new JsonObject(Buffer.buffer("{\"status\":\"ok\"}"));
+ protected static final JsonObject STATUS_ERROR = new JsonObject(Buffer.buffer("{\"status\":\"error\"}"));
+
@Before
public void setup() {
redisAPI = Mockito.mock(RedisAPI.class);
redisProvider = Mockito.mock(RedisProvider.class);
+ exceptionFactory = Mockito.mock(RedisQuesExceptionFactory.class);
when(redisProvider.redis()).thenReturn(Future.succeededFuture(redisAPI));
memoryUsageProvider = Mockito.mock(MemoryUsageProvider.class);
@@ -39,4 +50,7 @@ public void setup() {
message = Mockito.mock(Message.class);
}
+ protected Handler> createResponseHandler(InvocationOnMock invocation, int handlerIndex) {
+ return (Handler>) invocation.getArguments()[handlerIndex];
+ }
}
diff --git a/src/test/java/org/swisspush/redisques/action/AddQueueItemActionTest.java b/src/test/java/org/swisspush/redisques/action/AddQueueItemActionTest.java
index 144a42a..4593ecf 100644
--- a/src/test/java/org/swisspush/redisques/action/AddQueueItemActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/AddQueueItemActionTest.java
@@ -1,8 +1,6 @@
package org.swisspush.redisques.action;
import io.vertx.core.Future;
-import io.vertx.core.buffer.Buffer;
-import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import org.junit.Before;
@@ -20,7 +18,7 @@
/**
* Tests for {@link AddQueueItemAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class AddQueueItemActionTest extends AbstractQueueActionTest {
@@ -31,7 +29,7 @@ public void setup() {
super.setup();
action = new AddQueueItemAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
@@ -41,7 +39,40 @@ public void testAddQueueItemWhenRedisIsNotReady(TestContext context){
action.execute(message);
- verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\"}"))));
+ verify(message, times(1)).fail(eq(0), eq("not ready"));
verifyNoInteractions(redisAPI);
}
+
+ @Test
+ public void testAddQueueItem(TestContext context){
+ when(message.body()).thenReturn(buildAddQueueItemOperation("queue2", "fooBar"));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.succeededFuture());
+ return null;
+ }).when(redisAPI).rpush(anyList(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).rpush(anyList(), any());
+ verify(message, times(1)).reply(eq(STATUS_OK));
+
+ }
+
+ @Test
+ public void testAddQueueItemRPUSHFail(TestContext context){
+ when(message.body()).thenReturn(buildAddQueueItemOperation("queue2", "fooBar"));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.failedFuture("booom"));
+ return null;
+ }).when(redisAPI).rpush(anyList(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).rpush(anyList(), any());
+ verify(message, times(1)).fail(eq(0), eq("booom"));
+ }
}
diff --git a/src/test/java/org/swisspush/redisques/action/BulkDeleteLocksActionTest.java b/src/test/java/org/swisspush/redisques/action/BulkDeleteLocksActionTest.java
index ccc6d93..a9d9878 100644
--- a/src/test/java/org/swisspush/redisques/action/BulkDeleteLocksActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/BulkDeleteLocksActionTest.java
@@ -21,7 +21,7 @@
/**
* Tests for {@link BulkDeleteLocksAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class BulkDeleteLocksActionTest extends AbstractQueueActionTest {
@@ -32,7 +32,7 @@ public void setup() {
super.setup();
action = new BulkDeleteLocksAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
diff --git a/src/test/java/org/swisspush/redisques/action/BulkDeleteQueuesActionTest.java b/src/test/java/org/swisspush/redisques/action/BulkDeleteQueuesActionTest.java
index 91f8f3b..557f605 100644
--- a/src/test/java/org/swisspush/redisques/action/BulkDeleteQueuesActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/BulkDeleteQueuesActionTest.java
@@ -6,22 +6,25 @@
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
+import io.vertx.redis.client.impl.types.SimpleStringType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.swisspush.redisques.util.QueueStatisticsCollector;
+import org.swisspush.redisques.util.RedisquesAPI;
import java.util.ArrayList;
import static org.mockito.Mockito.*;
import static org.swisspush.redisques.util.RedisquesAPI.buildBulkDeleteQueuesOperation;
+import static org.swisspush.redisques.util.RedisquesAPI.buildOperation;
/**
* Tests for {@link BulkDeleteQueuesAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class BulkDeleteQueuesActionTest extends AbstractQueueActionTest {
@@ -32,7 +35,7 @@ public void setup() {
super.setup();
action = new BulkDeleteQueuesAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
@@ -42,7 +45,69 @@ public void testBulkDeleteQueuesWhenRedisIsNotReady(TestContext context){
action.execute(message);
- verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\"}"))));
+ verify(message, times(1)).fail(eq(0), eq("not ready"));
verifyNoInteractions(redisAPI);
}
+
+ @Test
+ public void testBulkDeleteQueues(TestContext context){
+ when(message.body()).thenReturn(buildBulkDeleteQueuesOperation(new JsonArray().add("q1").add("q3")));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.succeededFuture(SimpleStringType.create("2")));
+ return null;
+ }).when(redisAPI).del(anyList(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).del(anyList(), any());
+ verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"ok\",\"value\":2}"))));
+ }
+
+ @Test
+ public void testBulkDeleteQueuesDELFail(TestContext context){
+ when(message.body()).thenReturn(buildBulkDeleteQueuesOperation(new JsonArray().add("q1").add("q3")));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.failedFuture("booom"));
+ return null;
+ }).when(redisAPI).del(anyList(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).del(anyList(), any());
+ verify(message, times(1)).fail(eq(0), eq("booom"));
+ }
+
+ @Test
+ public void testBulkDeleteQueuesNoQueuesProvided(TestContext context){
+ when(message.body()).thenReturn(buildOperation(RedisquesAPI.QueueOperation.bulkDeleteQueues, new JsonObject().put("SomeProperty", "foobar")));
+
+ action.execute(message);
+
+ verifyNoInteractions(redisAPI);
+ verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\",\"message\":\"No queues to delete provided\"}"))));
+ }
+
+ @Test
+ public void testBulkDeleteQueuesEmptyQueuesProvided(TestContext context){
+ when(message.body()).thenReturn(buildBulkDeleteQueuesOperation(new JsonArray()));
+
+ action.execute(message);
+
+ verifyNoInteractions(redisAPI);
+ verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"ok\",\"value\":0}"))));
+ }
+
+ @Test
+ public void testBulkDeleteQueuesInvalidQueuesEntries(TestContext context){
+ when(message.body()).thenReturn(buildBulkDeleteQueuesOperation(new JsonArray().add(new JsonObject()).add(new JsonArray())));
+
+ action.execute(message);
+
+ verifyNoInteractions(redisAPI);
+ verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\",\"errorType\":\"bad input\",\"message\":\"Queues must be string values\"}"))));
+ }
}
diff --git a/src/test/java/org/swisspush/redisques/action/BulkPutLocksActionTest.java b/src/test/java/org/swisspush/redisques/action/BulkPutLocksActionTest.java
index c4d6485..1516e16 100644
--- a/src/test/java/org/swisspush/redisques/action/BulkPutLocksActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/BulkPutLocksActionTest.java
@@ -21,7 +21,7 @@
/**
* Tests for {@link BulkPutLocksAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class BulkPutLocksActionTest extends AbstractQueueActionTest {
@@ -32,7 +32,7 @@ public void setup() {
super.setup();
action = new BulkPutLocksAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
diff --git a/src/test/java/org/swisspush/redisques/action/DeleteAllLocksActionTest.java b/src/test/java/org/swisspush/redisques/action/DeleteAllLocksActionTest.java
index 68224a5..dcf2acc 100644
--- a/src/test/java/org/swisspush/redisques/action/DeleteAllLocksActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/DeleteAllLocksActionTest.java
@@ -20,7 +20,7 @@
/**
* Tests for {@link DeleteAllLocksAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class DeleteAllLocksActionTest extends AbstractQueueActionTest {
@@ -31,7 +31,7 @@ public void setup() {
super.setup();
action = new DeleteAllLocksAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
diff --git a/src/test/java/org/swisspush/redisques/action/DeleteAllQueueItemsActionTest.java b/src/test/java/org/swisspush/redisques/action/DeleteAllQueueItemsActionTest.java
index 9023565..297400c 100644
--- a/src/test/java/org/swisspush/redisques/action/DeleteAllQueueItemsActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/DeleteAllQueueItemsActionTest.java
@@ -5,6 +5,7 @@
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
+import io.vertx.redis.client.impl.types.SimpleStringType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -20,7 +21,7 @@
/**
* Tests for {@link DeleteAllQueueItemsAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class DeleteAllQueueItemsActionTest extends AbstractQueueActionTest {
@@ -31,7 +32,47 @@ public void setup() {
super.setup();
action = new DeleteAllQueueItemsAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ }
+
+ @Test
+ public void testDeleteAllQueueItemsNoUnlock(TestContext context){
+ when(message.body()).thenReturn(buildDeleteAllQueueItemsOperation("q1"));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.succeededFuture(SimpleStringType.create("1")));
+ return null;
+ }).when(redisAPI).del(anyList(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).del(anyList(), any());
+ verify(redisAPI, never()).hdel(anyList());
+ verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"ok\",\"value\":1}"))));
+ }
+
+ @Test
+ public void testDeleteAllQueueItemsWithUnlock(TestContext context){
+ when(message.body()).thenReturn(buildDeleteAllQueueItemsOperation("q1", true));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.succeededFuture(SimpleStringType.create("1")));
+ return null;
+ }).when(redisAPI).del(anyList(), any());
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.succeededFuture(SimpleStringType.create("1")));
+ return null;
+ }).when(redisAPI).hdel(anyList(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).del(anyList(), any());
+ verify(redisAPI, times(1)).hdel(anyList(), any());
+ verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"ok\",\"value\":1}"))));
}
@Test
@@ -41,7 +82,46 @@ public void testDeleteAllQueueItemsWhenRedisIsNotReady(TestContext context){
action.execute(message);
- verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\"}"))));
+ verify(message, times(1)).fail(eq(0), eq("not ready"));
verifyNoInteractions(redisAPI);
}
+
+ @Test
+ public void testRedisApiDELFail(TestContext context){
+ when(message.body()).thenReturn(buildDeleteAllQueueItemsOperation("q1"));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.failedFuture("boooom"));
+ return null;
+ }).when(redisAPI).del(anyList(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).del(anyList(), any());
+ verify(message, times(1)).fail(eq(0), eq("boooom"));
+ }
+
+ @Test
+ public void testRedisApiUnlockFail(TestContext context){
+ when(message.body()).thenReturn(buildDeleteAllQueueItemsOperation("q1", true));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.succeededFuture(SimpleStringType.create("1")));
+ return null;
+ }).when(redisAPI).del(anyList(), any());
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.failedFuture("boooom"));
+ return null;
+ }).when(redisAPI).hdel(anyList(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).del(anyList(), any());
+ verify(redisAPI, times(1)).hdel(anyList(), any());
+ verify(message, times(1)).fail(eq(0), eq("boooom"));
+ }
}
diff --git a/src/test/java/org/swisspush/redisques/action/DeleteLockActionTest.java b/src/test/java/org/swisspush/redisques/action/DeleteLockActionTest.java
index 48e2dff..16d3bc0 100644
--- a/src/test/java/org/swisspush/redisques/action/DeleteLockActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/DeleteLockActionTest.java
@@ -1,10 +1,9 @@
package org.swisspush.redisques.action;
import io.vertx.core.Future;
-import io.vertx.core.buffer.Buffer;
-import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
+import io.vertx.redis.client.impl.types.SimpleStringType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -20,7 +19,7 @@
/**
* Tests for {@link DeleteLockAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class DeleteLockActionTest extends AbstractQueueActionTest {
@@ -31,7 +30,7 @@ public void setup() {
super.setup();
action = new DeleteLockAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
@@ -41,7 +40,76 @@ public void testDeleteLockWhenRedisIsNotReady(TestContext context){
action.execute(message);
- verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\"}"))));
+ verify(message, times(1)).fail(eq(0), eq("not ready"));
verifyNoInteractions(redisAPI);
}
+
+ @Test
+ public void testDeleteLock(TestContext context){
+ when(message.body()).thenReturn(buildDeleteLockOperation("testLock1"));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.succeededFuture(SimpleStringType.create("0")));
+ return null;
+ }).when(redisAPI).exists(anyList(), any());
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.succeededFuture());
+ return null;
+ }).when(redisAPI).hdel(anyList(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).exists(anyList(), any());
+ verify(redisAPI, times(1)).hdel(anyList(), any());
+ verify(message, times(1)).reply(eq(STATUS_OK));
+ }
+
+ @Test
+ public void testDeleteLockExistsFail(TestContext context){
+ when(message.body()).thenReturn(buildDeleteLockOperation("testLock1"));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.failedFuture("booom"));
+ return null;
+ }).when(redisAPI).exists(anyList(), any());
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.succeededFuture());
+ return null;
+ }).when(redisAPI).hdel(anyList(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).exists(anyList(), any());
+ verify(redisAPI, times(1)).hdel(anyList(), any());
+ verify(message, times(1)).reply(eq(STATUS_OK));
+ }
+
+ @Test
+ public void testDeleteLockHDELFail(TestContext context){
+ when(message.body()).thenReturn(buildDeleteLockOperation("testLock1"));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.succeededFuture(SimpleStringType.create("0")));
+ return null;
+ }).when(redisAPI).exists(anyList(), any());
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.failedFuture("booom"));
+ return null;
+ }).when(redisAPI).hdel(anyList(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).exists(anyList(), any());
+ verify(redisAPI, times(1)).hdel(anyList(), any());
+ verify(message, times(1)).fail(eq(0), eq("booom"));
+ }
}
diff --git a/src/test/java/org/swisspush/redisques/action/DeleteQueueItemActionTest.java b/src/test/java/org/swisspush/redisques/action/DeleteQueueItemActionTest.java
index 35928d6..f2c5512 100644
--- a/src/test/java/org/swisspush/redisques/action/DeleteQueueItemActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/DeleteQueueItemActionTest.java
@@ -1,8 +1,6 @@
package org.swisspush.redisques.action;
import io.vertx.core.Future;
-import io.vertx.core.buffer.Buffer;
-import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import org.junit.Before;
@@ -20,7 +18,7 @@
/**
* Tests for {@link DeleteQueueItemAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class DeleteQueueItemActionTest extends AbstractQueueActionTest {
@@ -31,7 +29,7 @@ public void setup() {
super.setup();
action = new DeleteQueueItemAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
@@ -41,7 +39,88 @@ public void testDeleteQueueItemWhenRedisIsNotReady(TestContext context){
action.execute(message);
- verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\"}"))));
+ verify(message, times(1)).fail(eq(0), eq("not ready"));
verifyNoInteractions(redisAPI);
}
+
+ @Test
+ public void testFailedLSET(TestContext context){
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,3);
+ handler.handle(Future.failedFuture("boooom"));
+ return null;
+ }).when(redisAPI).lset(anyString(), anyString(), anyString(), any());
+
+ when(message.body()).thenReturn(buildDeleteQueueItemOperation("queue1", 0));
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).lset(anyString(), eq("0"), eq("TO_DELETE"), any());
+ verify(redisAPI, never()).lrem(anyString(), anyString(), anyString());
+ verify(message, times(1)).fail(eq(0), eq("boooom"));
+ }
+
+ @Test
+ public void testFailedLSETNoSuchKey(TestContext context){
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,3);
+ handler.handle(Future.failedFuture("ERR no such key"));
+ return null;
+ }).when(redisAPI).lset(anyString(), anyString(), anyString(), any());
+
+ when(message.body()).thenReturn(buildDeleteQueueItemOperation("queue1", 0));
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).lset(anyString(), eq("0"), eq("TO_DELETE"), any());
+ verify(redisAPI, never()).lrem(anyString(), anyString(), anyString());
+ verify(message, times(1)).reply(eq(STATUS_ERROR));
+ }
+
+ @Test
+ public void testFailedLREM(TestContext context){
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,3);
+ handler.handle(Future.succeededFuture());
+ return null;
+ }).when(redisAPI).lset(anyString(), anyString(), anyString(), any());
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,3);
+ handler.handle(Future.failedFuture("boooom"));
+ return null;
+ }).when(redisAPI).lrem(anyString(), anyString(), anyString(), any());
+
+ when(message.body()).thenReturn(buildDeleteQueueItemOperation("queue1", 0));
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).lset(anyString(), eq("0"), eq("TO_DELETE"), any());
+ verify(redisAPI, times(1)).lrem(anyString(), eq("0"), eq("TO_DELETE"), any());
+ verify(message, times(1)).fail(eq(0), eq("boooom"));
+ }
+
+ @Test
+ public void testDeleteQueueItem(TestContext context){
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,3);
+ handler.handle(Future.succeededFuture());
+ return null;
+ }).when(redisAPI).lset(anyString(), anyString(), anyString(), any());
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,3);
+ handler.handle(Future.succeededFuture());
+ return null;
+ }).when(redisAPI).lrem(anyString(), anyString(), anyString(), any());
+
+ when(message.body()).thenReturn(buildDeleteQueueItemOperation("queue1", 0));
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).lset(anyString(), eq("0"), eq("TO_DELETE"), any());
+ verify(redisAPI, times(1)).lrem(anyString(), eq("0"), eq("TO_DELETE"), any());
+ verify(message, times(1)).reply(eq(STATUS_OK));
+ }
}
diff --git a/src/test/java/org/swisspush/redisques/action/EnqueueActionTest.java b/src/test/java/org/swisspush/redisques/action/EnqueueActionTest.java
index 3aa75fb..cda5c0f 100644
--- a/src/test/java/org/swisspush/redisques/action/EnqueueActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/EnqueueActionTest.java
@@ -23,7 +23,7 @@
/**
* Tests for {@link EnqueueAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class EnqueueActionTest extends AbstractQueueActionTest {
@@ -34,7 +34,8 @@ public void setup() {
super.setup();
action = new EnqueueAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class), memoryUsageProvider, 80);
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class),
+ Mockito.mock(Logger.class), memoryUsageProvider, 80);
}
@Test
diff --git a/src/test/java/org/swisspush/redisques/action/GetAllLocksActionTest.java b/src/test/java/org/swisspush/redisques/action/GetAllLocksActionTest.java
index 1b63c09..60bfd94 100644
--- a/src/test/java/org/swisspush/redisques/action/GetAllLocksActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/GetAllLocksActionTest.java
@@ -2,9 +2,13 @@
import io.vertx.core.Future;
import io.vertx.core.buffer.Buffer;
+import io.vertx.core.impl.future.FailedFuture;
+import io.vertx.core.impl.future.SucceededFuture;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
+import io.vertx.redis.client.impl.types.MultiType;
+import io.vertx.redis.client.impl.types.SimpleStringType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -20,7 +24,7 @@
/**
* Tests for {@link GetAllLocksAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class GetAllLocksActionTest extends AbstractQueueActionTest {
@@ -31,7 +35,7 @@ public void setup() {
super.setup();
action = new GetAllLocksAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
@@ -41,7 +45,54 @@ public void testGetAllLocksWhenRedisIsNotReady(TestContext context){
action.execute(message);
- verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\"}"))));
+ verify(message, times(1)).fail(eq(0), eq("not ready"));
verifyNoInteractions(redisAPI);
}
+
+ @Test
+ public void testGetAllLocksInvalidFilter(TestContext context){
+ when(message.body()).thenReturn(buildGetAllLocksOperation("xyz(.*"));
+
+ action.execute(message);
+
+ verify(message, times(1)).reply(eq(new JsonObject(
+ Buffer.buffer("{\"status\":\"error\",\"errorType\":\"bad input\",\"message\":\"Error while compile" +
+ " regex pattern. Cause: Unclosed group near index 6\\nxyz(.*\"}"))));
+ verifyNoInteractions(redisAPI);
+ }
+
+ @Test
+ public void testGetAllLocksHKEYSFail(TestContext context){
+ when(message.body()).thenReturn(buildGetAllLocksOperation());
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation, 1);
+ handler.handle(new FailedFuture("booom"));
+ return null;
+ }).when(redisAPI).hkeys(anyString(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).hkeys(anyString(), any());
+ verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\"}"))));
+ }
+
+ @Test
+ public void testGetAllLocks(TestContext context){
+ when(message.body()).thenReturn(buildGetAllLocksOperation());
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation, 1);
+ MultiType response = MultiType.create(2, false);
+ response.add(SimpleStringType.create("foo"));
+ response.add(SimpleStringType.create("bar"));
+ handler.handle(new SucceededFuture<>(response));
+ return null;
+ }).when(redisAPI).hkeys(anyString(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).hkeys(anyString(), any());
+ verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"ok\",\"value\":{\"locks\":[\"foo\",\"bar\"]}}"))));
+ }
}
diff --git a/src/test/java/org/swisspush/redisques/action/GetLockActionTest.java b/src/test/java/org/swisspush/redisques/action/GetLockActionTest.java
index b85e527..7bf0547 100644
--- a/src/test/java/org/swisspush/redisques/action/GetLockActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/GetLockActionTest.java
@@ -5,6 +5,7 @@
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
+import io.vertx.redis.client.impl.types.SimpleStringType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -20,7 +21,7 @@
/**
* Tests for {@link GetLockAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class GetLockActionTest extends AbstractQueueActionTest {
@@ -31,7 +32,7 @@ public void setup() {
super.setup();
action = new GetLockAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
@@ -41,7 +42,56 @@ public void testGetLockWhenRedisIsNotReady(TestContext context){
action.execute(message);
- verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\"}"))));
+ verify(message, times(1)).fail(eq(0), eq("not ready"));
verifyNoInteractions(redisAPI);
}
+
+ @Test
+ public void testGetLock(TestContext context){
+ when(message.body()).thenReturn(buildGetLockOperation("q1"));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,2);
+ handler.handle(Future.succeededFuture(SimpleStringType.create(new JsonObject().put("requestedBy", "UNKNOWN").put("timestamp", 1719931433522L).encode())));
+ return null;
+ }).when(redisAPI).hget(anyString(), anyString(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).hget(anyString(), anyString(), any());
+ verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"ok\"," +
+ "\"value\":\"{\\\"requestedBy\\\":\\\"UNKNOWN\\\",\\\"timestamp\\\":1719931433522}\"}"))));
+ }
+
+ @Test
+ public void testGetLockNoSuchLock(TestContext context){
+ when(message.body()).thenReturn(buildGetLockOperation("q1"));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,2);
+ handler.handle(Future.succeededFuture());
+ return null;
+ }).when(redisAPI).hget(anyString(), anyString(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).hget(anyString(), anyString(), any());
+ verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"No such lock\"}"))));
+ }
+
+ @Test
+ public void testGetLockHGETFail(TestContext context){
+ when(message.body()).thenReturn(buildGetLockOperation("q1"));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,2);
+ handler.handle(Future.failedFuture("booom"));
+ return null;
+ }).when(redisAPI).hget(anyString(), anyString(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).hget(anyString(), anyString(), any());
+ verify(message, times(1)).fail(eq(0), eq("booom"));
+ }
}
diff --git a/src/test/java/org/swisspush/redisques/action/GetQueueItemActionTest.java b/src/test/java/org/swisspush/redisques/action/GetQueueItemActionTest.java
index d5c3c80..b20d9de 100644
--- a/src/test/java/org/swisspush/redisques/action/GetQueueItemActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/GetQueueItemActionTest.java
@@ -5,6 +5,7 @@
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
+import io.vertx.redis.client.impl.types.SimpleStringType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -20,7 +21,7 @@
/**
* Tests for {@link GetQueueItemAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class GetQueueItemActionTest extends AbstractQueueActionTest {
@@ -31,7 +32,7 @@ public void setup() {
super.setup();
action = new GetQueueItemAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
@@ -41,7 +42,56 @@ public void testGetQueueItemWhenRedisIsNotReady(TestContext context){
action.execute(message);
- verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\"}"))));
+ verify(message, times(1)).fail(eq(0), eq("not ready"));
verifyNoInteractions(redisAPI);
}
+
+ @Test
+ public void testGetQueueItem(TestContext context){
+ when(message.body()).thenReturn(buildGetQueueItemOperation("q1", 0));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,2);
+ handler.handle(Future.succeededFuture(SimpleStringType.create(new JsonObject().put("foo", "bar").encode())));
+ return null;
+ }).when(redisAPI).lindex(anyString(), anyString(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).lindex(anyString(), anyString(), any());
+ verify(message, times(1)).reply(eq(new JsonObject(
+ Buffer.buffer("{\"status\":\"ok\",\"value\":\"{\\\"foo\\\":\\\"bar\\\"}\"}"))));
+ }
+
+ @Test
+ public void testGetQueueItemNotExistingIndex(TestContext context){
+ when(message.body()).thenReturn(buildGetQueueItemOperation("q1", 0));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,2);
+ handler.handle(Future.succeededFuture());
+ return null;
+ }).when(redisAPI).lindex(anyString(), anyString(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).lindex(anyString(), anyString(), any());
+ verify(message, times(1)).reply(eq(STATUS_ERROR));
+ }
+
+ @Test
+ public void testGetQueueItemLINDEXFail(TestContext context){
+ when(message.body()).thenReturn(buildGetQueueItemOperation("q1", 0));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,2);
+ handler.handle(Future.failedFuture("booom"));
+ return null;
+ }).when(redisAPI).lindex(anyString(), anyString(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).lindex(anyString(), anyString(), any());
+ verify(message, times(1)).fail(eq(0), eq("booom"));
+ }
}
diff --git a/src/test/java/org/swisspush/redisques/action/GetQueueItemsActionTest.java b/src/test/java/org/swisspush/redisques/action/GetQueueItemsActionTest.java
index 50166af..c22a59e 100644
--- a/src/test/java/org/swisspush/redisques/action/GetQueueItemsActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/GetQueueItemsActionTest.java
@@ -1,12 +1,10 @@
package org.swisspush.redisques.action;
import io.vertx.core.Future;
-import io.vertx.core.buffer.Buffer;
-import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
+import io.vertx.redis.client.impl.types.SimpleStringType;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
@@ -21,7 +19,7 @@
/**
* Tests for {@link GetQueueItemsAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class GetQueueItemsActionTest extends AbstractQueueActionTest {
@@ -32,21 +30,39 @@ public void setup() {
super.setup();
action = new GetQueueItemsAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
- /*
- * This test should work when issue #192 https://github.com/swisspost/vertx-redisques/issues/192 is resolved
- */
@Test
- @Ignore
public void testGetQueueItemsWhenRedisIsNotReady(TestContext context){
when(redisProvider.redis()).thenReturn(Future.failedFuture("not ready"));
when(message.body()).thenReturn(buildGetQueueItemsOperation("q1", null));
action.execute(message);
- verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\"}"))));
+ verify(message, times(1)).fail(eq(0), eq("not ready"));
verifyNoInteractions(redisAPI);
}
+
+ @Test
+ public void testLLENFail(TestContext context){
+ when(message.body()).thenReturn(buildGetQueueItemsOperation("q1", null));
+ when(redisAPI.llen(anyString())).thenReturn(Future.failedFuture("boooom"));
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).llen(anyString());
+ verify(message, times(1)).fail(eq(0), eq("boooom"));
+ }
+
+ @Test
+ public void testLLENInvalidResponseValue(TestContext context){
+ when(message.body()).thenReturn(buildGetQueueItemsOperation("q1", null));
+ when(redisAPI.llen(anyString())).thenReturn(Future.succeededFuture(SimpleStringType.create(null)));
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).llen(anyString());
+ verify(message, times(1)).fail(eq(0), eq("Operation getQueueItems failed to extract queueItemCount"));
+ }
}
diff --git a/src/test/java/org/swisspush/redisques/action/GetQueueItemsCountActionTest.java b/src/test/java/org/swisspush/redisques/action/GetQueueItemsCountActionTest.java
index 2a4726c..86fefc6 100644
--- a/src/test/java/org/swisspush/redisques/action/GetQueueItemsCountActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/GetQueueItemsCountActionTest.java
@@ -20,7 +20,7 @@
/**
* Tests for {@link GetQueueItemsCountAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class GetQueueItemsCountActionTest extends AbstractQueueActionTest {
@@ -31,7 +31,7 @@ public void setup() {
super.setup();
action = new GetQueueItemsCountAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
diff --git a/src/test/java/org/swisspush/redisques/action/GetQueuesActionTest.java b/src/test/java/org/swisspush/redisques/action/GetQueuesActionTest.java
index d8a16ba..70a7e02 100644
--- a/src/test/java/org/swisspush/redisques/action/GetQueuesActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/GetQueuesActionTest.java
@@ -20,7 +20,7 @@
/**
* Tests for {@link GetQueuesAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class GetQueuesActionTest extends AbstractQueueActionTest {
@@ -31,7 +31,7 @@ public void setup() {
super.setup();
action = new GetQueuesAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
diff --git a/src/test/java/org/swisspush/redisques/action/GetQueuesCountActionTest.java b/src/test/java/org/swisspush/redisques/action/GetQueuesCountActionTest.java
index ec575fd..d53523d 100644
--- a/src/test/java/org/swisspush/redisques/action/GetQueuesCountActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/GetQueuesCountActionTest.java
@@ -20,7 +20,7 @@
/**
* Tests for {@link GetQueuesCountAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class GetQueuesCountActionTest extends AbstractQueueActionTest {
@@ -31,7 +31,7 @@ public void setup() {
super.setup();
action = new GetQueuesCountAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
diff --git a/src/test/java/org/swisspush/redisques/action/GetQueuesItemsCountActionTest.java b/src/test/java/org/swisspush/redisques/action/GetQueuesItemsCountActionTest.java
index 126844c..cfcc455 100644
--- a/src/test/java/org/swisspush/redisques/action/GetQueuesItemsCountActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/GetQueuesItemsCountActionTest.java
@@ -22,7 +22,7 @@
/**
* Tests for {@link GetQueuesItemsCountAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class GetQueuesItemsCountActionTest extends AbstractQueueActionTest {
diff --git a/src/test/java/org/swisspush/redisques/action/GetQueuesSpeedActionTest.java b/src/test/java/org/swisspush/redisques/action/GetQueuesSpeedActionTest.java
index 8fea725..3364b5a 100644
--- a/src/test/java/org/swisspush/redisques/action/GetQueuesSpeedActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/GetQueuesSpeedActionTest.java
@@ -20,7 +20,7 @@
/**
* Tests for {@link GetQueuesSpeedAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class GetQueuesSpeedActionTest extends AbstractQueueActionTest {
@@ -31,7 +31,7 @@ public void setup() {
super.setup();
action = new GetQueuesSpeedAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
diff --git a/src/test/java/org/swisspush/redisques/action/GetQueuesStatisticsActionTest.java b/src/test/java/org/swisspush/redisques/action/GetQueuesStatisticsActionTest.java
index 75aca91..ec9af99 100644
--- a/src/test/java/org/swisspush/redisques/action/GetQueuesStatisticsActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/GetQueuesStatisticsActionTest.java
@@ -20,7 +20,7 @@
/**
* Tests for {@link GetQueuesStatisticsAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class GetQueuesStatisticsActionTest extends AbstractQueueActionTest {
@@ -31,7 +31,7 @@ public void setup() {
super.setup();
action = new GetQueuesStatisticsAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
diff --git a/src/test/java/org/swisspush/redisques/action/LockedEnqueueActionTest.java b/src/test/java/org/swisspush/redisques/action/LockedEnqueueActionTest.java
index 828a71e..471581b 100644
--- a/src/test/java/org/swisspush/redisques/action/LockedEnqueueActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/LockedEnqueueActionTest.java
@@ -20,7 +20,7 @@
/**
* Tests for {@link LockedEnqueueAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class LockedEnqueueActionTest extends AbstractQueueActionTest {
@@ -31,7 +31,8 @@ public void setup() {
super.setup();
action = new LockedEnqueueAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class), memoryUsageProvider, 80);
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class),
+ Mockito.mock(Logger.class), memoryUsageProvider, 80);
}
@Test
diff --git a/src/test/java/org/swisspush/redisques/action/PutLockActionTest.java b/src/test/java/org/swisspush/redisques/action/PutLockActionTest.java
index a7738ac..ea01e01 100644
--- a/src/test/java/org/swisspush/redisques/action/PutLockActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/PutLockActionTest.java
@@ -11,16 +11,17 @@
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.swisspush.redisques.util.QueueStatisticsCollector;
+import org.swisspush.redisques.util.RedisquesAPI;
import java.util.ArrayList;
import static org.mockito.Mockito.*;
-import static org.swisspush.redisques.util.RedisquesAPI.buildPutLockOperation;
+import static org.swisspush.redisques.util.RedisquesAPI.*;
/**
* Tests for {@link PutLockAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class PutLockActionTest extends AbstractQueueActionTest {
@@ -31,7 +32,7 @@ public void setup() {
super.setup();
action = new PutLockAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
@@ -41,7 +42,59 @@ public void testPutLockWhenRedisIsNotReady(TestContext context){
action.execute(message);
- verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\"}"))));
+ verify(message, times(1)).fail(eq(0), eq("not ready"));
verifyNoInteractions(redisAPI);
}
+
+ @Test
+ public void testPutLockWithoutRequestedByProperty(TestContext context){
+ when(message.body()).thenReturn(buildOperation(RedisquesAPI.QueueOperation.putLock, new JsonObject().put(QUEUENAME, "q1")));
+
+ action.execute(message);
+
+ verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\",\"message\":\"Property 'requestedBy' missing\"}"))));
+ verifyNoInteractions(redisAPI);
+ }
+
+ @Test
+ public void testPutLockWithInvalidQueuenameProperty(TestContext context){
+ when(message.body()).thenReturn(buildOperation(RedisquesAPI.QueueOperation.putLock, new JsonObject().put(REQUESTED_BY, "geronimo")));
+
+ action.execute(message);
+
+ verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\",\"errorType\":\"bad input\",\"message\":\"Lock must be a string value\"}"))));
+ verifyNoInteractions(redisAPI);
+ }
+
+ @Test
+ public void testPutLock(TestContext context){
+ when(message.body()).thenReturn(buildPutLockOperation("q1", "geronimo"));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.succeededFuture());
+ return null;
+ }).when(redisAPI).hmset(anyList(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).hmset(anyList(), any());
+ verify(message, times(1)).reply(eq(STATUS_OK));
+ }
+
+ @Test
+ public void testPutLockHMSETFail(TestContext context){
+ when(message.body()).thenReturn(buildPutLockOperation("q1", "geronimo"));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,1);
+ handler.handle(Future.failedFuture("booom"));
+ return null;
+ }).when(redisAPI).hmset(anyList(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).hmset(anyList(), any());
+ verify(message, times(1)).fail(eq(0), eq("booom"));
+ }
}
diff --git a/src/test/java/org/swisspush/redisques/action/ReplaceQueueItemActionTest.java b/src/test/java/org/swisspush/redisques/action/ReplaceQueueItemActionTest.java
index ea5cb48..f3cc925 100644
--- a/src/test/java/org/swisspush/redisques/action/ReplaceQueueItemActionTest.java
+++ b/src/test/java/org/swisspush/redisques/action/ReplaceQueueItemActionTest.java
@@ -20,7 +20,7 @@
/**
* Tests for {@link ReplaceQueueItemAction} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class ReplaceQueueItemActionTest extends AbstractQueueActionTest {
@@ -31,7 +31,7 @@ public void setup() {
super.setup();
action = new ReplaceQueueItemAction(vertx, redisProvider,
"addr", "q-", "prefix-", "c-", "l-",
- new ArrayList<>(), Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
+ new ArrayList<>(), exceptionFactory, Mockito.mock(QueueStatisticsCollector.class), Mockito.mock(Logger.class));
}
@Test
@@ -41,7 +41,39 @@ public void testReplaceQueueItemWhenRedisIsNotReady(TestContext context){
action.execute(message);
- verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"error\"}"))));
+ verify(message, times(1)).fail(eq(0), eq("not ready"));
verifyNoInteractions(redisAPI);
}
+
+ @Test
+ public void testReplaceQueueItem(TestContext context){
+ when(message.body()).thenReturn(buildReplaceQueueItemOperation("q1", 0,"geronimo"));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,3);
+ handler.handle(Future.succeededFuture());
+ return null;
+ }).when(redisAPI).lset(anyString(), anyString(), anyString(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).lset(anyString(), anyString(), anyString(), any());
+ verify(message, times(1)).reply(eq(new JsonObject(Buffer.buffer("{\"status\":\"ok\"}"))));
+ }
+
+ @Test
+ public void testReplaceQueueItemWithLSETFail(TestContext context){
+ when(message.body()).thenReturn(buildReplaceQueueItemOperation("q1", 0,"geronimo"));
+
+ doAnswer(invocation -> {
+ var handler = createResponseHandler(invocation,3);
+ handler.handle(Future.failedFuture("booom"));
+ return null;
+ }).when(redisAPI).lset(anyString(), anyString(), anyString(), any());
+
+ action.execute(message);
+
+ verify(redisAPI, times(1)).lset(anyString(), anyString(), anyString(), any());
+ verify(message, times(1)).fail(eq(0), eq("booom"));
+ }
}
diff --git a/src/test/java/org/swisspush/redisques/handler/DisableQueueNameEncodingTest.java b/src/test/java/org/swisspush/redisques/handler/DisableQueueNameEncodingTest.java
index 0ce444c..35254e4 100644
--- a/src/test/java/org/swisspush/redisques/handler/DisableQueueNameEncodingTest.java
+++ b/src/test/java/org/swisspush/redisques/handler/DisableQueueNameEncodingTest.java
@@ -65,7 +65,7 @@ public void deployRedisques(TestContext context) {
testVertx.deployVerticle(redisQues, new DeploymentOptions().setConfig(config), context.asyncAssertSuccess(event -> {
deploymentId = event;
- log.info("vert.x Deploy - " + redisQues.getClass().getSimpleName() + " was successful.");
+ log.info("vert.x Deploy - {} was successful.", redisQues.getClass().getSimpleName());
jedis = new Jedis("localhost", 6379, 5000);
try {
Thread.sleep(1000);
diff --git a/src/test/java/org/swisspush/redisques/handler/RedisquesAuthenticationHttpRequestHandlerTest.java b/src/test/java/org/swisspush/redisques/handler/RedisquesAuthenticationHttpRequestHandlerTest.java
index 51cc6d5..b9c4a0f 100644
--- a/src/test/java/org/swisspush/redisques/handler/RedisquesAuthenticationHttpRequestHandlerTest.java
+++ b/src/test/java/org/swisspush/redisques/handler/RedisquesAuthenticationHttpRequestHandlerTest.java
@@ -28,7 +28,7 @@
/**
* Tests for the {@link RedisquesHttpRequestHandler} class respecting authentication
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class RedisquesAuthenticationHttpRequestHandlerTest extends AbstractTestCase {
private static String deploymentId = "";
diff --git a/src/test/java/org/swisspush/redisques/handler/RedisquesHttpRequestHandlerTest.java b/src/test/java/org/swisspush/redisques/handler/RedisquesHttpRequestHandlerTest.java
index 565e7f4..8e42455 100644
--- a/src/test/java/org/swisspush/redisques/handler/RedisquesHttpRequestHandlerTest.java
+++ b/src/test/java/org/swisspush/redisques/handler/RedisquesHttpRequestHandlerTest.java
@@ -58,7 +58,7 @@
/**
* Tests for the {@link RedisquesHttpRequestHandler} class
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
public class RedisquesHttpRequestHandlerTest extends AbstractTestCase {
private static String deploymentId = "";
@@ -184,7 +184,7 @@ public void deployRedisques(TestContext context) {
testVertx.deployVerticle(redisQues, new DeploymentOptions().setConfig(config), context.asyncAssertSuccess(event -> {
deploymentId = event;
- log.info("vert.x Deploy - " + redisQues.getClass().getSimpleName() + " was successful.");
+ log.info("vert.x Deploy - {} was successful.", redisQues.getClass().getSimpleName());
jedis = new Jedis("localhost", 6379, 5000);
delay(1000);
async.complete();
@@ -709,6 +709,11 @@ public void addQueueItemInvalidBody(TestContext context) {
assertKeyCount(context, getQueuesRedisKeyPrefix(), 0);
context.assertEquals(0L, jedis.llen(getQueuesRedisKeyPrefix() + queueName));
+ // this body creates a NullpointerException because there is no header property
+ given().body(configurationValid).when().post("/queuing/queues/" + queueName + "/").then().assertThat().statusCode(400);
+ assertKeyCount(context, getQueuesRedisKeyPrefix(), 0);
+ context.assertEquals(0L, jedis.llen(getQueuesRedisKeyPrefix() + queueName));
+
async.complete();
}
diff --git a/src/test/java/org/swisspush/redisques/util/DefaultMemoryUsageProviderTest.java b/src/test/java/org/swisspush/redisques/util/DefaultMemoryUsageProviderTest.java
index 04e0878..d06021d 100644
--- a/src/test/java/org/swisspush/redisques/util/DefaultMemoryUsageProviderTest.java
+++ b/src/test/java/org/swisspush/redisques/util/DefaultMemoryUsageProviderTest.java
@@ -25,7 +25,7 @@
/**
* Tests for {@link DefaultMemoryUsageProvider} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class DefaultMemoryUsageProviderTest {
diff --git a/src/test/java/org/swisspush/redisques/util/DefaultRedisReadyProviderTest.java b/src/test/java/org/swisspush/redisques/util/DefaultRedisReadyProviderTest.java
index 4d58f0e..a8446c1 100644
--- a/src/test/java/org/swisspush/redisques/util/DefaultRedisReadyProviderTest.java
+++ b/src/test/java/org/swisspush/redisques/util/DefaultRedisReadyProviderTest.java
@@ -19,7 +19,7 @@
/**
* Tests for the {@link DefaultRedisReadyProvider} class
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class DefaultRedisReadyProviderTest {
diff --git a/src/test/java/org/swisspush/redisques/util/DefaultRedisquesConfigurationProviderTest.java b/src/test/java/org/swisspush/redisques/util/DefaultRedisquesConfigurationProviderTest.java
index 9a403dc..f52678f 100644
--- a/src/test/java/org/swisspush/redisques/util/DefaultRedisquesConfigurationProviderTest.java
+++ b/src/test/java/org/swisspush/redisques/util/DefaultRedisquesConfigurationProviderTest.java
@@ -16,7 +16,7 @@
/**
* Tests for {@link DefaultRedisquesConfigurationProvider} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class DefaultRedisquesConfigurationProviderTest {
diff --git a/src/test/java/org/swisspush/redisques/util/HttpServerRequestUtilTest.java b/src/test/java/org/swisspush/redisques/util/HttpServerRequestUtilTest.java
index 4551df8..07dd5cd 100644
--- a/src/test/java/org/swisspush/redisques/util/HttpServerRequestUtilTest.java
+++ b/src/test/java/org/swisspush/redisques/util/HttpServerRequestUtilTest.java
@@ -18,7 +18,7 @@
/**
* Tests for {@link HttpServerRequestUtil} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class HttpServerRequestUtilTest {
diff --git a/src/test/java/org/swisspush/redisques/util/MessageUtilTest.java b/src/test/java/org/swisspush/redisques/util/MessageUtilTest.java
index f7c9d3b..27f4f79 100644
--- a/src/test/java/org/swisspush/redisques/util/MessageUtilTest.java
+++ b/src/test/java/org/swisspush/redisques/util/MessageUtilTest.java
@@ -17,7 +17,7 @@
/**
* Tests for {@link MessageUtil} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class MessageUtilTest {
diff --git a/src/test/java/org/swisspush/redisques/util/RedisQuesTimerTest.java b/src/test/java/org/swisspush/redisques/util/RedisQuesTimerTest.java
index a69dda8..a5d6fe4 100644
--- a/src/test/java/org/swisspush/redisques/util/RedisQuesTimerTest.java
+++ b/src/test/java/org/swisspush/redisques/util/RedisQuesTimerTest.java
@@ -10,7 +10,7 @@
/**
* Tests for {@link RedisQuesTimer} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class RedisQuesTimerTest {
diff --git a/src/test/java/org/swisspush/redisques/util/RedisquesAPITest.java b/src/test/java/org/swisspush/redisques/util/RedisquesAPITest.java
index a6e0767..1a53495 100644
--- a/src/test/java/org/swisspush/redisques/util/RedisquesAPITest.java
+++ b/src/test/java/org/swisspush/redisques/util/RedisquesAPITest.java
@@ -12,7 +12,7 @@
/**
* Tests for {@link RedisquesAPI} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class RedisquesAPITest {
diff --git a/src/test/java/org/swisspush/redisques/util/RedisquesConfigurationTest.java b/src/test/java/org/swisspush/redisques/util/RedisquesConfigurationTest.java
index 066ae23..e9790f2 100644
--- a/src/test/java/org/swisspush/redisques/util/RedisquesConfigurationTest.java
+++ b/src/test/java/org/swisspush/redisques/util/RedisquesConfigurationTest.java
@@ -16,7 +16,7 @@
/**
* Tests for {@link RedisquesConfiguration} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class RedisquesConfigurationTest {
diff --git a/src/test/java/org/swisspush/redisques/util/StatuscodeTest.java b/src/test/java/org/swisspush/redisques/util/StatuscodeTest.java
index e1e4b0b..6dba836 100644
--- a/src/test/java/org/swisspush/redisques/util/StatuscodeTest.java
+++ b/src/test/java/org/swisspush/redisques/util/StatuscodeTest.java
@@ -8,7 +8,7 @@
/**
* Tests for {@link StatusCode} class.
*
- * @author https://github.com/mcweba [Marc-Andre Weber]
+ * @author Marc-André Weber
*/
@RunWith(VertxUnitRunner.class)
public class StatuscodeTest {