Skip to content

Commit

Permalink
Merge pull request #65 from swisspush/develop
Browse files Browse the repository at this point in the history
PR for new release
  • Loading branch information
mcweba authored Oct 8, 2018
2 parents 5329f90 + d0e3a7c commit 9dae698
Show file tree
Hide file tree
Showing 11 changed files with 365 additions and 161 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.swisspush</groupId>
<artifactId>redisques</artifactId>
<version>2.5.3-SNAPSHOT</version>
<version>2.5.4-SNAPSHOT</version>
<name>redisques</name>
<description>
A highly scalable redis-persistent queuing system for vertx
Expand Down
196 changes: 134 additions & 62 deletions src/main/java/org/swisspush/redisques/RedisQues.java

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void exec(int executionCounter) {
luaScripts.get(LuaScript.CHECK).loadLuaScript(new Check(keys, arguments, redisClient, handler), executionCounter);
}
} else {
log.error("Check request failed with message: " + message);
log.error("Check request failed.", event.cause());
}
}
});
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/swisspush/redisques/lua/LuaScriptState.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public void loadLuaScript(final RedisCommand redisCommand, int executionCounter)
} else {
log.info("load lua script for script type: " + luaScriptType);
redisClient.scriptLoad(script, stringAsyncResult -> {
if (stringAsyncResult.failed()) {
log.warn("Received failed message for loadLuaScript. Lets run into NullPointerException now.", stringAsyncResult.cause());
// IMO we should respond with 'HTTP 5xx'. But we don't, to keep backward compatibility.
}
String newSha = stringAsyncResult.result();
log.info("got sha from redis for lua script: " + luaScriptType + ": " + newSha);
if(!newSha.equals(sha)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import io.vertx.core.json.DecodeException;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;

import java.nio.charset.Charset;

Expand All @@ -16,6 +18,7 @@
*/
public class HttpServerRequestUtil {

private static final Logger log = LoggerFactory.getLogger(HttpServerRequestUtil.class);
private static final String EMPTY = "";
private static final String TRUE = "true";
private static final String UTF_8 = "UTF-8";
Expand Down Expand Up @@ -62,7 +65,9 @@ public static Result<JsonArray, String> extractNonEmptyJsonArrayFromBody(String
}
return Result.ok(jsonArray);
} catch (Exception ex){
return Result.err("failed to parse request payload");
final String msg = "failed to parse request payload";
log.error(msg, ex);
return Result.err(msg);
}
}

Expand All @@ -71,8 +76,11 @@ public static Result<JsonArray, String> extractNonEmptyJsonArrayFromBody(String
*
* @param decoded decoded
* @return String
* @throws Exception
* In case {@code decoded} is not valid json.
*/
public static String encodePayload(String decoded) throws Exception {
// This may throws io.vertx.core.json.DecodeException.
JsonObject object = new JsonObject(decoded);

String payloadString;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/swisspush/redisques/util/MessageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;

import java.util.Optional;
import java.util.regex.Pattern;
Expand All @@ -16,6 +18,8 @@
*/
public class MessageUtil {

private static final Logger log = LoggerFactory.getLogger(MessageUtil.class);

public static Result<Optional<Pattern>, String> extractFilterPattern(Message<JsonObject> event) {
JsonObject payload = event.body().getJsonObject(PAYLOAD);
if (payload == null || payload.getString(FILTER) == null) {
Expand All @@ -26,6 +30,7 @@ public static Result<Optional<Pattern>, String> extractFilterPattern(Message<Jso
Pattern pattern = Pattern.compile(filterString);
return Result.ok(Optional.of(pattern));
} catch (Exception ex) {
log.error("Interface doesn't allow to pass stack trace. Therefore simply log it now.", ex);
return Result.err("Error while compile regex pattern. Cause: " + ex.getMessage());
}
}
Expand Down
32 changes: 21 additions & 11 deletions src/main/java/org/swisspush/redisques/util/RedisquesAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;

import java.util.Optional;

/**
* Class RedisquesAPI listing the operations and response values which are supported in Redisques.
*
Expand Down Expand Up @@ -159,9 +157,13 @@ public static JsonObject buildGetQueuesOperation(){
return buildOperation(QueueOperation.getQueues);
}

public static JsonObject buildGetQueuesOperation(Optional<String> filterPattern){
if(filterPattern.isPresent()){
return buildOperation(QueueOperation.getQueues, new JsonObject().put(FILTER, filterPattern.get()));
/**
* @param filterPattern
* Filter pattern. Method handles {@code null} gracefully.
*/
public static JsonObject buildGetQueuesOperation(String filterPattern) {
if (filterPattern != null) {
return buildOperation(QueueOperation.getQueues, new JsonObject().put(FILTER, filterPattern));
} else {
return buildOperation(QueueOperation.getQueues);
}
Expand All @@ -171,9 +173,13 @@ public static JsonObject buildGetQueuesCountOperation(){
return buildOperation(QueueOperation.getQueuesCount);
}

public static JsonObject buildGetQueuesCountOperation(Optional<String> filterPattern){
if(filterPattern.isPresent()){
return buildOperation(QueueOperation.getQueuesCount, new JsonObject().put(FILTER, filterPattern.get()));
/**
* @param filterPattern
* Filter pattern. Method handles {@code null} gracefully.
*/
public static JsonObject buildGetQueuesCountOperation(String filterPattern) {
if (filterPattern != null) {
return buildOperation(QueueOperation.getQueuesCount, new JsonObject().put(FILTER, filterPattern));
} else {
return buildOperation(QueueOperation.getQueuesCount);
}
Expand Down Expand Up @@ -211,9 +217,13 @@ public static JsonObject buildGetAllLocksOperation(){
return buildOperation(QueueOperation.getAllLocks);
}

public static JsonObject buildGetAllLocksOperation(Optional<String> filterPattern){
if(filterPattern.isPresent()){
return buildOperation(QueueOperation.getAllLocks, new JsonObject().put(FILTER, filterPattern.get()));
/**
* @param filterPattern
* Filter pattern. Method handles {@code null} gracefully.
*/
public static JsonObject buildGetAllLocksOperation(String filterPattern) {
if (filterPattern != null) {
return buildOperation(QueueOperation.getAllLocks, new JsonObject().put(FILTER, filterPattern));
} else {
return buildGetAllLocksOperation();
}
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/org/swisspush/redisques/RedisQuesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ public void getQueuesFiltered(TestContext context) {

assertKeyCount(context, getQueuesRedisKeyPrefix(), 20);
Async async = context.async();
eventBusSend(buildGetQueuesOperation(Optional.of("3")), message -> {
eventBusSend(buildGetQueuesOperation("3"), message -> {
context.assertEquals(OK, message.result().body().getString(STATUS));
JsonArray queuesArray = message.result().body().getJsonObject(VALUE).getJsonArray("queues");
context.assertEquals(2, queuesArray.size());
context.assertTrue(queuesArray.contains("queue3"), "item queue1 expected to be in result");
context.assertTrue(queuesArray.contains("queue13"), "item queue11 expected to be in result");

eventBusSend(buildGetQueuesOperation(Optional.of("abc")), message2 -> {
eventBusSend(buildGetQueuesOperation("abc"), message2 -> {
context.assertEquals(OK, message2.result().body().getString(STATUS));
JsonArray queuesArray2 = message2.result().body().getJsonObject(VALUE).getJsonArray("queues");
context.assertTrue(queuesArray2.isEmpty());
Expand All @@ -285,7 +285,7 @@ public void getQueuesFilteredInvalidPattern(TestContext context) {

assertKeyCount(context, getQueuesRedisKeyPrefix(), 20);
Async async = context.async();
eventBusSend(buildGetQueuesOperation(Optional.of("abc(.*")), message -> {
eventBusSend(buildGetQueuesOperation("abc(.*"), message -> {
context.assertEquals(ERROR, message.result().body().getString(STATUS));
context.assertEquals(BAD_INPUT, message.result().body().getString(ERROR_TYPE));
context.assertTrue(message.result().body().getString(MESSAGE).contains("Error while compile regex pattern"));
Expand Down Expand Up @@ -330,10 +330,10 @@ public void getQueuesCountFiltered(TestContext context) {

assertKeyCount(context, getQueuesRedisKeyPrefix(), 50);
Async async = context.async();
eventBusSend(buildGetQueuesCountOperation(Optional.of("8")), message -> {
eventBusSend(buildGetQueuesCountOperation("8"), message -> {
context.assertEquals(OK, message.result().body().getString(STATUS));
context.assertEquals(5L, message.result().body().getLong(VALUE));
eventBusSend(buildGetQueuesCountOperation(Optional.of("abc")), message2 -> {
eventBusSend(buildGetQueuesCountOperation("abc"), message2 -> {
context.assertEquals(OK, message2.result().body().getString(STATUS));
context.assertEquals(0L, message2.result().body().getLong(VALUE));
async.complete();
Expand All @@ -356,7 +356,7 @@ public void getQueuesCountFilteredInvalidPattern(TestContext context) {

assertKeyCount(context, getQueuesRedisKeyPrefix(), 50);
Async async = context.async();
eventBusSend(buildGetQueuesCountOperation(Optional.of("abc(.*")), message -> {
eventBusSend(buildGetQueuesCountOperation("abc(.*"), message -> {
context.assertEquals(ERROR, message.result().body().getString(STATUS));
context.assertEquals(BAD_INPUT, message.result().body().getString(ERROR_TYPE));
context.assertTrue(message.result().body().getString(MESSAGE).contains("Error while compile regex pattern"));
Expand Down Expand Up @@ -721,7 +721,7 @@ public void getAllLocksFiltered(TestContext context) {
String item1 = locksArray1.getString(1);
context.assertTrue(item1.matches("abcLock.*"));
}
eventBusSend(buildGetAllLocksOperation(of("abc(.*)")), message4 -> {
eventBusSend(buildGetAllLocksOperation("abc(.*)"), message4 -> {
context.assertEquals(OK, message4.result().body().getString(STATUS));
JsonArray locksArray2 = message4.result().body().getJsonObject(VALUE).getJsonArray("locks");
context.assertNotNull(locksArray2, "locks array should not be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ public void testExtractFilterPattern(TestContext context) {
context.assertTrue(result.isOk());
context.assertFalse(result.getOk().isPresent());

when(message.body()).thenReturn(RedisquesAPI.buildGetAllLocksOperation(Optional.of(""))); // payload object with empty filter property
when(message.body()).thenReturn(RedisquesAPI.buildGetAllLocksOperation("")); // payload object with empty filter property
result = MessageUtil.extractFilterPattern(message);
context.assertTrue(result.isOk());
context.assertTrue(result.getOk().isPresent());

when(message.body()).thenReturn(RedisquesAPI.buildGetAllLocksOperation(Optional.of("xyz(.*)"))); // payload object with valid filter property
when(message.body()).thenReturn(RedisquesAPI.buildGetAllLocksOperation("xyz(.*)")); // payload object with valid filter property
result = MessageUtil.extractFilterPattern(message);
context.assertTrue(result.isOk());
context.assertTrue(result.getOk().isPresent());
context.assertEquals("xyz(.*)", result.getOk().get().pattern());

when(message.body()).thenReturn(RedisquesAPI.buildGetAllLocksOperation(Optional.of("xyz(.*"))); // payload object with invalid filter property
when(message.body()).thenReturn(RedisquesAPI.buildGetAllLocksOperation("xyz(.*")); // payload object with invalid filter property
result = MessageUtil.extractFilterPattern(message);
context.assertTrue(result.isErr());
context.assertTrue(result.getErr().contains("Error while compile regex pattern"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void testBuildGetQueuesOperation(TestContext context) throws Exception {
JsonObject operation = RedisquesAPI.buildGetQueuesOperation();
context.assertEquals(buildExpectedJsonObject("getQueues"), operation);

operation = RedisquesAPI.buildGetQueuesOperation(Optional.of("abc"));
operation = RedisquesAPI.buildGetQueuesOperation("abc");
JsonObject expected = buildExpectedJsonObject("getQueues", new JsonObject()
.put(FILTER, "abc"));
context.assertEquals(expected, operation);
Expand All @@ -201,7 +201,7 @@ public void testBuildGetQueuesCountOperation(TestContext context) throws Excepti
JsonObject operation = RedisquesAPI.buildGetQueuesCountOperation();
context.assertEquals(buildExpectedJsonObject("getQueuesCount"), operation);

operation = RedisquesAPI.buildGetQueuesCountOperation(Optional.of("abc"));
operation = RedisquesAPI.buildGetQueuesCountOperation("abc");
JsonObject expected = buildExpectedJsonObject("getQueuesCount", new JsonObject()
.put(FILTER, "abc"));
context.assertEquals(expected, operation);
Expand Down Expand Up @@ -271,7 +271,7 @@ public void testBuildGetAllLocksOperation(TestContext context) throws Exception
JsonObject operation = RedisquesAPI.buildGetAllLocksOperation();
context.assertEquals(buildExpectedJsonObject("getAllLocks"), operation);

operation = RedisquesAPI.buildGetAllLocksOperation(Optional.of("abc"));
operation = RedisquesAPI.buildGetAllLocksOperation("abc");
JsonObject expected = buildExpectedJsonObject("getAllLocks", new JsonObject()
.put(FILTER, "abc"));
context.assertEquals(expected, operation);
Expand Down

0 comments on commit 9dae698

Please sign in to comment.