diff --git a/gateleen-cache/src/main/java/org/swisspush/gateleen/cache/storage/RedisCacheStorage.java b/gateleen-cache/src/main/java/org/swisspush/gateleen/cache/storage/RedisCacheStorage.java index d2262fddd..147b565a4 100644 --- a/gateleen-cache/src/main/java/org/swisspush/gateleen/cache/storage/RedisCacheStorage.java +++ b/gateleen-cache/src/main/java/org/swisspush/gateleen/cache/storage/RedisCacheStorage.java @@ -8,10 +8,12 @@ import io.vertx.core.json.JsonArray; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.lock.Lock; import org.swisspush.gateleen.core.lua.LuaScriptState; import org.swisspush.gateleen.core.redis.RedisProvider; import org.swisspush.gateleen.core.util.Address; +import org.swisspush.gateleen.core.util.LockUtil; import java.time.Duration; import java.util.Collections; @@ -22,13 +24,13 @@ import java.util.stream.IntStream; import static org.swisspush.gateleen.core.util.LockUtil.acquireLock; -import static org.swisspush.gateleen.core.util.LockUtil.releaseLock; public class RedisCacheStorage implements CacheStorage { private Logger log = LoggerFactory.getLogger(RedisCacheStorage.class); private final Lock lock; + private final LockUtil lockUtil; private final RedisProvider redisProvider; private LuaScriptState clearCacheLuaScriptState; private LuaScriptState cacheRequestLuaScriptState; @@ -37,11 +39,18 @@ public class RedisCacheStorage implements CacheStorage { public static final String CACHE_PREFIX = "gateleen.cache:"; public static final String STORAGE_CLEANUP_TASK_LOCK = "cacheStorageCleanupTask"; - public RedisCacheStorage(Vertx vertx, Lock lock, RedisProvider redisProvider, long storageCleanupIntervalMs) { + public RedisCacheStorage( + Vertx vertx, + Lock lock, + RedisProvider redisProvider, + GateleenExceptionFactory exceptionFactory, + long storageCleanupIntervalMs + ) { this.lock = lock; + this.lockUtil = new LockUtil(exceptionFactory); this.redisProvider = redisProvider; - clearCacheLuaScriptState = new LuaScriptState(CacheLuaScripts.CLEAR_CACHE, redisProvider, false); - cacheRequestLuaScriptState = new LuaScriptState(CacheLuaScripts.CACHE_REQUEST, redisProvider, false); + clearCacheLuaScriptState = new LuaScriptState(CacheLuaScripts.CLEAR_CACHE, redisProvider, exceptionFactory, false); + cacheRequestLuaScriptState = new LuaScriptState(CacheLuaScripts.CACHE_REQUEST, redisProvider, exceptionFactory, false); vertx.setPeriodic(storageCleanupIntervalMs, event -> { String token = token(STORAGE_CLEANUP_TASK_LOCK); @@ -51,7 +60,7 @@ public RedisCacheStorage(Vertx vertx, Lock lock, RedisProvider redisProvider, lo cleanup().onComplete(cleanupResult -> { if (cleanupResult.failed()) { log.warn("storage cleanup has failed", cleanupResult.cause()); - releaseLock(lock, STORAGE_CLEANUP_TASK_LOCK, token, log); + lockUtil.releaseLock(lock, STORAGE_CLEANUP_TASK_LOCK, token, log); } else { log.debug("Successfully cleaned {} entries from storage", cleanupResult.result()); } diff --git a/gateleen-cache/src/test/java/org/swisspush/gateleen/cache/storage/RedisCacheStorageTest.java b/gateleen-cache/src/test/java/org/swisspush/gateleen/cache/storage/RedisCacheStorageTest.java index 04c160cf1..1849bc01d 100644 --- a/gateleen-cache/src/test/java/org/swisspush/gateleen/cache/storage/RedisCacheStorageTest.java +++ b/gateleen-cache/src/test/java/org/swisspush/gateleen/cache/storage/RedisCacheStorageTest.java @@ -20,6 +20,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.lock.Lock; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Jedis; @@ -37,6 +38,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.swisspush.gateleen.cache.storage.RedisCacheStorage.CACHED_REQUESTS; import static org.swisspush.gateleen.cache.storage.RedisCacheStorage.CACHE_PREFIX; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; /** * Tests for the {@link RedisCacheStorage} class @@ -50,6 +52,7 @@ public class RedisCacheStorageTest { public Timeout rule = Timeout.seconds(50); private Vertx vertx; + private final GateleenExceptionFactory exceptionFactory = newGateleenWastefulExceptionFactory(); private Lock lock; private Jedis jedis; private RedisCacheStorage redisCacheStorage; @@ -65,7 +68,7 @@ public void setUp() { RedisAPI redisAPI = RedisAPI.api(new RedisClient(vertx, new NetClientOptions(), new PoolOptions(), new RedisStandaloneConnectOptions(), TracingPolicy.IGNORE)); - redisCacheStorage = new RedisCacheStorage(vertx, lock, () -> Future.succeededFuture(redisAPI), 2000); + redisCacheStorage = new RedisCacheStorage(vertx, lock, () -> Future.succeededFuture(redisAPI), exceptionFactory, 2000); jedis = new Jedis(new HostAndPort("localhost", 6379)); try { jedis.flushAll(); diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/configuration/ConfigurationResourceManager.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/configuration/ConfigurationResourceManager.java index 5e2a97711..0583ff8b2 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/configuration/ConfigurationResourceManager.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/configuration/ConfigurationResourceManager.java @@ -11,6 +11,7 @@ import io.vertx.core.json.JsonObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.http.RequestLoggerFactory; import org.swisspush.gateleen.core.logging.LoggableResource; import org.swisspush.gateleen.core.logging.RequestLogger; @@ -35,6 +36,7 @@ public class ConfigurationResourceManager implements LoggableResource { private final Vertx vertx; private final ResourceStorage storage; + private final GateleenExceptionFactory exceptionFactory; private Map registeredResources; private Map> observers; private final ConfigurationResourceValidator configurationResourceValidator; @@ -44,9 +46,14 @@ public class ConfigurationResourceManager implements LoggableResource { private static final String MESSAGE_REQUEST_URI = "requestUri"; private static final String MESSAGE_RESOURCE_TYPE = "type"; - public ConfigurationResourceManager(Vertx vertx, final ResourceStorage storage) { + public ConfigurationResourceManager( + Vertx vertx, + ResourceStorage storage, + GateleenExceptionFactory exceptionFactory + ) { this.vertx = vertx; this.storage = storage; + this.exceptionFactory = exceptionFactory; this.configurationResourceValidator = new ConfigurationResourceValidator(vertx); @@ -192,11 +199,11 @@ private Future> getValidatedRegisteredResource(String resourceU if (event.result().isSuccess()) { promise.complete(Optional.of(buffer)); } else { - promise.fail(new Exception("Failure during validation of resource " + promise.fail(exceptionFactory.newException("Failure during validation of resource " + resourceUri + ". Message: " + event.result().getMessage())); } } else { - promise.fail(new Exception("ReleaseLockRedisCommand request failed", event.cause())); + promise.fail(exceptionFactory.newException("ReleaseLockRedisCommand request failed", event.cause())); } }); } else { @@ -217,9 +224,9 @@ private void notifyObserversAboutRemovedResource(String requestUri) { private void notifyObserverAboutResourceChange(String requestUri, ConfigurationResourceObserver observer) { getValidatedRegisteredResource(requestUri).onComplete(event -> { - if(event.failed()){ - log.warn("TODO error handling", new Exception(event.cause())); - } else if(event.result().isPresent()){ + if (event.failed()) { + log.warn("stacktrace", exceptionFactory.newException("TODO error handling", event.cause())); + } else if (event.result().isPresent()) { if(observer != null) { observer.resourceChanged(requestUri, event.result().get()); } else { diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenExceptionFactory.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenExceptionFactory.java new file mode 100644 index 000000000..af7db1e55 --- /dev/null +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenExceptionFactory.java @@ -0,0 +1,56 @@ +package org.swisspush.gateleen.core.exception; + +import io.vertx.core.eventbus.ReplyException; +import io.vertx.core.eventbus.ReplyFailure; + + +/** + * Applies dependency inversion for exception instantiation. + * + * This class did arise because we had different use cases in different + * applications. One of them has the need to perform fine-grained error + * reporting. Whereas in the other application this led to performance issues. + * So now through this abstraction, both applications can choose the behavior + * they need. + * + * There are two default options an app can use (if it does not want to provide + * a custom impl). + * One is {@link GateleenThriftyExceptionFactory}. It trades maintainability + * for speed. For example prefers lightweight exceptions without stacktrace + * recording. Plus it may apply other tricks to reduce resource costs. + * The other one is {@link GateleenWastefulExceptionFactory}. It trades speed + * for maintainability. So it tries to track as much error details as possible. + * For example recording stack traces, keeping 'cause' and 'suppressed' + * exceptions, plus maybe more. + * + * If none of those defaults matches, an app can provide its custom + * implementation via dependency injection. + */ +public interface GateleenExceptionFactory { + + /** Convenience overload for {@link #newException(String, Throwable)}. */ + public default Exception newException(String msg){ return newException(msg, null); } + + /** Convenience overload for {@link #newException(String, Throwable)}. */ + public default Exception newException(Throwable cause){ return newException(null, cause); } + + public Exception newException(String msg, Throwable cause); + + public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String message); + + + /** + * See {@link GateleenThriftyExceptionFactory}. + */ + public static GateleenExceptionFactory newGateleenThriftyExceptionFactory() { + return new GateleenThriftyExceptionFactory(); + } + + /** + * See {@link GateleenWastefulExceptionFactory}. + */ + public static GateleenExceptionFactory newGateleenWastefulExceptionFactory() { + return new GateleenWastefulExceptionFactory(); + } + +} diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenNoStackReplyException.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenNoStackReplyException.java new file mode 100644 index 000000000..91a384ff0 --- /dev/null +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenNoStackReplyException.java @@ -0,0 +1,30 @@ +package org.swisspush.gateleen.core.exception; + +import io.vertx.core.eventbus.ReplyFailure; + +/** + * There was once a fix in vertx for this (https://github.com/eclipse-vertx/vert.x/issues/4840) + * but for whatever reason in our case we still see stack-trace recordings. Passing + * this subclass to {@link io.vertx.core.eventbus.Message#reply(Object)} seems to + * do the trick. + */ +public class GateleenNoStackReplyException extends io.vertx.core.eventbus.ReplyException { + + public GateleenNoStackReplyException(ReplyFailure failureType, int failureCode, String message) { + super(failureType, failureCode, message); + } + + public GateleenNoStackReplyException(ReplyFailure failureType, String message) { + this(failureType, -1, message); + } + + public GateleenNoStackReplyException(ReplyFailure failureType) { + this(failureType, -1, null); + } + + @Override + public Throwable fillInStackTrace() { + return this; + } + +} diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenNoStacktraceException.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenNoStacktraceException.java new file mode 100644 index 000000000..36b32c45c --- /dev/null +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenNoStacktraceException.java @@ -0,0 +1,28 @@ +package org.swisspush.gateleen.core.exception; + +/** + * Basically same as in vertx, But adding the forgotten contructors. + */ +public class GateleenNoStacktraceException extends RuntimeException { + + public GateleenNoStacktraceException() { + } + + public GateleenNoStacktraceException(String message) { + super(message); + } + + public GateleenNoStacktraceException(String message, Throwable cause) { + super(message, cause); + } + + public GateleenNoStacktraceException(Throwable cause) { + super(cause); + } + + @Override + public Throwable fillInStackTrace() { + return this; + } + +} diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenThriftyExceptionFactory.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenThriftyExceptionFactory.java new file mode 100644 index 000000000..1a26ae481 --- /dev/null +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenThriftyExceptionFactory.java @@ -0,0 +1,24 @@ +package org.swisspush.gateleen.core.exception; + +import io.vertx.core.eventbus.ReplyException; +import io.vertx.core.eventbus.ReplyFailure; + +/** + * See {@link GateleenExceptionFactory} for details. + */ +class GateleenThriftyExceptionFactory implements GateleenExceptionFactory { + + GateleenThriftyExceptionFactory() { + } + + public Exception newException(String message, Throwable cause) { + if (cause instanceof Exception) return (Exception) cause; + return new GateleenNoStacktraceException(message, cause); + } + + @Override + public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String message) { + return new GateleenNoStackReplyException(failureType, failureCode, message); + } + +} diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenWastefulExceptionFactory.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenWastefulExceptionFactory.java new file mode 100644 index 000000000..1fc0889ca --- /dev/null +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/exception/GateleenWastefulExceptionFactory.java @@ -0,0 +1,23 @@ +package org.swisspush.gateleen.core.exception; + +import io.vertx.core.eventbus.ReplyException; +import io.vertx.core.eventbus.ReplyFailure; + +/** + * See {@link GateleenExceptionFactory} for details. + */ +class GateleenWastefulExceptionFactory implements GateleenExceptionFactory { + + GateleenWastefulExceptionFactory() { + } + + public Exception newException(String message, Throwable cause) { + return new Exception(message, cause); + } + + @Override + public ReplyException newReplyException(ReplyFailure failureType, int failureCode, String message) { + return new ReplyException(failureType, failureCode, message); + } + +} diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClient.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClient.java index 07848ea76..2d02b7efd 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClient.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClient.java @@ -5,6 +5,7 @@ import io.vertx.core.http.HttpClientRequest; import io.vertx.core.http.HttpMethod; import io.vertx.ext.web.RoutingContext; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; /** * Created by bovetl on 22.01.2015. @@ -13,10 +14,12 @@ public class LocalHttpClient extends AbstractHttpClient { private Handler wrappedRoutingContexttHandler; private Vertx vertx; + private final GateleenExceptionFactory exceptionFactory; - public LocalHttpClient(Vertx vertx) { + public LocalHttpClient(Vertx vertx, GateleenExceptionFactory exceptionFactory) { super(vertx); this.vertx = vertx; + this.exceptionFactory = exceptionFactory; } public void setRoutingContexttHandler(Handler wrappedRoutingContexttHandler) { @@ -25,6 +28,6 @@ public void setRoutingContexttHandler(Handler wrappedRoutingCont @Override protected HttpClientRequest doRequest(HttpMethod method, String uri) { - return new LocalHttpClientRequest(method, uri, vertx, wrappedRoutingContexttHandler, new LocalHttpServerResponse(vertx)); + return new LocalHttpClientRequest(method, uri, vertx, wrappedRoutingContexttHandler, exceptionFactory, new LocalHttpServerResponse(vertx)); } } diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClientRequest.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClientRequest.java index fb152839e..5cdc3b710 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClientRequest.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/http/LocalHttpClientRequest.java @@ -15,6 +15,7 @@ import io.vertx.ext.auth.User; import io.vertx.ext.web.*; import org.slf4j.Logger; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import javax.net.ssl.SSLSession; import javax.security.cert.X509Certificate; @@ -44,6 +45,7 @@ public class LocalHttpClientRequest extends BufferBridge implements FastFailHttp private HttpServerResponse serverResponse; private final HttpConnection connection; private Handler routingContextHandler; + private final GateleenExceptionFactory exceptionFactory; private boolean bound = false; private static final SocketAddress address = new SocketAddressImpl(0, "localhost"); @@ -538,11 +540,19 @@ public MultiMap queryParams(Charset charset) { } }; - public LocalHttpClientRequest(HttpMethod method, String uri, Vertx vertx, Handler routingContextHandler, HttpServerResponse response) { + public LocalHttpClientRequest( + HttpMethod method, + String uri, + Vertx vertx, + Handler routingContextHandler, + GateleenExceptionFactory exceptionFactory, + HttpServerResponse response + ) { super(vertx); this.method = method; this.uri = uri; this.routingContextHandler = routingContextHandler; + this.exceptionFactory = exceptionFactory; this.serverResponse = response; this.connection = new LocalHttpConnection(); } @@ -854,8 +864,7 @@ public boolean writeQueueFull() { @Override public HttpClientRequest drainHandler(Handler handler) { - log.warn("Happy debugging, as this impl will just ignore your drainHandler anyway", - new Exception("may this stacktrace lead you where this problem comes from")); + log.warn("stacktrace", exceptionFactory.newException("TODO impl drainHandler")); return this; } diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/lock/impl/RedisBasedLock.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/lock/impl/RedisBasedLock.java index 841973864..a89761f4e 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/lock/impl/RedisBasedLock.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/lock/impl/RedisBasedLock.java @@ -9,6 +9,7 @@ import io.vertx.redis.client.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.lock.Lock; import org.swisspush.gateleen.core.lock.lua.LockLuaScripts; import org.swisspush.gateleen.core.lock.lua.ReleaseLockRedisCommand; @@ -28,15 +29,18 @@ public class RedisBasedLock implements Lock { private static final Logger log = LoggerFactory.getLogger(RedisBasedLock.class); + private static final String[] EMPTY_STRING_ARRAY = new String[0]; public static final String STORAGE_PREFIX = "gateleen.core-lock:"; private final LuaScriptState releaseLockLuaScriptState; private final RedisProvider redisProvider; + private final GateleenExceptionFactory exceptionFactory; - public RedisBasedLock(RedisProvider redisProvider) { + public RedisBasedLock(RedisProvider redisProvider, GateleenExceptionFactory exceptionFactory) { this.redisProvider = redisProvider; - this.releaseLockLuaScriptState = new LuaScriptState(LockLuaScripts.LOCK_RELEASE, redisProvider, false); + this.exceptionFactory = exceptionFactory; + this.releaseLockLuaScriptState = new LuaScriptState(LockLuaScripts.LOCK_RELEASE, redisProvider, exceptionFactory, false); } private void redisSetWithOptions(String key, String value, boolean nx, long px, Handler> handler) { @@ -47,22 +51,28 @@ private void redisSetWithOptions(String key, String value, boolean nx, long px, } redisProvider.redis().onComplete( redisEv -> { if( redisEv.failed() ){ - handler.handle(new FailedAsyncResult<>(redisEv.cause())); + Throwable ex = exceptionFactory.newException("redisProvider.redis() failed", redisEv.cause()); + handler.handle(new FailedAsyncResult<>(ex)); return; } var redisAPI = redisEv.result(); - redisAPI.send(Command.SET, RedisUtils.toPayload(key, value, options).toArray(new String[0])) - .onComplete( ev -> { - if( ev.failed() && log.isInfoEnabled() ) log.info("stacktrace", new Exception("stacktrace", ev.cause())); - handler.handle(ev); - }); + String[] payload = RedisUtils.toPayload(key, value, options).toArray(EMPTY_STRING_ARRAY); + redisAPI.send(Command.SET, payload).onComplete(ev -> { + if (ev.failed()) { + Throwable ex = exceptionFactory.newException("redisAPI.send() failed", ev.cause()); + handler.handle(new FailedAsyncResult<>(ex)); + return; + } + handler.handle(ev); + }); }); } @Override public Future acquireLock(String lock, String token, long lockExpiryMs) { Promise promise = Promise.promise(); - redisSetWithOptions(buildLockKey(lock), token, true, lockExpiryMs, event -> { + String lockKey = buildLockKey(lock); + redisSetWithOptions(lockKey, token, true, lockExpiryMs, event -> { if (event.succeeded()) { if (event.result() != null) { promise.complete("OK".equalsIgnoreCase(event.result().toString())); @@ -70,8 +80,9 @@ public Future acquireLock(String lock, String token, long lockExpiryMs) promise.complete(false); } } else { - if( log.isInfoEnabled() ) log.info("stacktrace", new Exception("stacktrace", event.cause())); - promise.fail(event.cause().getMessage()); + Throwable ex = exceptionFactory.newException( + "redisSetWithOptions(lockKey=\"" + lockKey + "\") failed", event.cause()); + promise.fail(ex); } }); return promise.future(); @@ -83,7 +94,7 @@ public Future releaseLock(String lock, String token) { List keys = Collections.singletonList(buildLockKey(lock)); List arguments = Collections.singletonList(token); ReleaseLockRedisCommand cmd = new ReleaseLockRedisCommand(releaseLockLuaScriptState, - keys, arguments, redisProvider, log, promise); + keys, arguments, redisProvider, exceptionFactory, log, promise); cmd.exec(0); return promise.future(); } diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/lock/lua/ReleaseLockRedisCommand.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/lock/lua/ReleaseLockRedisCommand.java index 03f6e6281..c7c058dcf 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/lock/lua/ReleaseLockRedisCommand.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/lock/lua/ReleaseLockRedisCommand.java @@ -3,6 +3,7 @@ import io.vertx.core.Promise; import io.vertx.redis.client.RedisAPI; import org.slf4j.Logger; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.lua.LuaScriptState; import org.swisspush.gateleen.core.lua.RedisCommand; import org.swisspush.gateleen.core.redis.RedisProvider; @@ -20,14 +21,23 @@ public class ReleaseLockRedisCommand implements RedisCommand { private List arguments; private Promise promise; private RedisProvider redisProvider; + private final GateleenExceptionFactory exceptionFactory; private Logger log; - public ReleaseLockRedisCommand(LuaScriptState luaScriptState, List keys, List arguments, - RedisProvider redisProvider, Logger log, final Promise promise) { + public ReleaseLockRedisCommand( + LuaScriptState luaScriptState, + List keys, + List arguments, + RedisProvider redisProvider, + GateleenExceptionFactory exceptionFactory, + Logger log, + final Promise promise + ) { this.luaScriptState = luaScriptState; this.keys = keys; this.arguments = arguments; this.redisProvider = redisProvider; + this.exceptionFactory = exceptionFactory; this.log = log; this.promise = promise; } @@ -42,7 +52,7 @@ public void exec(int executionCounter) { redisProvider.redis().onComplete( redisEv -> { if( redisEv.failed() ){ - promise.fail(new Exception("redisProvider.redis()", redisEv.cause())); + promise.fail(exceptionFactory.newException("redisProvider.redis() failed", redisEv.cause())); return; } RedisAPI redisAPI = redisEv.result(); @@ -54,16 +64,17 @@ public void exec(int executionCounter) { Throwable ex = event.cause(); String message = ex.getMessage(); if (message != null && message.startsWith("NOSCRIPT")) { - log.warn("ReleaseLockRedisCommand script couldn't be found, reload it", new Exception("stacktrace",ex)); + log.warn("ReleaseLockRedisCommand script couldn't be found, reload it", + exceptionFactory.newException(ex)); log.warn("amount the script got loaded: {}", executionCounter); if (executionCounter > 10) { - promise.fail(new Exception("amount the script got loaded is higher than 10, we abort")); + promise.fail(exceptionFactory.newException("amount the script got loaded is higher than 10, we abort")); } else { luaScriptState.loadLuaScript(new ReleaseLockRedisCommand(luaScriptState, keys, - arguments, redisProvider, log, promise), executionCounter); + arguments, redisProvider, exceptionFactory, log, promise), executionCounter); } } else { - promise.fail(new Exception("ReleaseLockRedisCommand request failed", ex)); + promise.fail(exceptionFactory.newException("ReleaseLockRedisCommand request failed", ex)); } } }); diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/lua/LuaScriptState.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/lua/LuaScriptState.java index 5bb5e92f1..81f000928 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/lua/LuaScriptState.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/lua/LuaScriptState.java @@ -4,6 +4,7 @@ import org.apache.commons.codec.digest.DigestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.redis.RedisProvider; import java.io.BufferedReader; @@ -30,12 +31,19 @@ public class LuaScriptState { private String sha; private RedisProvider redisProvider; + private final GateleenExceptionFactory exceptionFactory; private Logger log = LoggerFactory.getLogger(LuaScriptState.class); - public LuaScriptState(LuaScript luaScriptType, RedisProvider redisProvider, boolean logoutput) { + public LuaScriptState( + LuaScript luaScriptType, + RedisProvider redisProvider, + GateleenExceptionFactory exceptionFactory, + boolean logoutput + ) { this.luaScriptType = luaScriptType; this.redisProvider = redisProvider; + this.exceptionFactory = exceptionFactory; this.logoutput = logoutput; this.composeLuaScript(luaScriptType); this.loadLuaScript(new RedisCommandDoNothing(), 0); @@ -87,17 +95,17 @@ private String readLuaScriptFromClasspath(LuaScript luaScriptType) { public void loadLuaScript(final RedisCommand redisCommand, int executionCounter) { final int executionCounterIncr = ++executionCounter; // check first if the lua script already exists in the store - redisProvider.redis().onComplete( redisEv -> { + redisProvider.redis().onComplete(redisEv -> { if (redisEv.failed()) { - log.error("Redis: Error checking whether lua script exists", - new Exception("stacktrace", redisEv.cause())); + log.error("stacktrace", exceptionFactory.newException( + "redisProvider.redis() failed", redisEv.cause())); return; } RedisAPI redisAPI = redisEv.result(); redisAPI.script(Arrays.asList("exists", sha), resultArray -> { if (resultArray.failed()) { - log.error("Error checking whether lua script exists", - new Exception("stacktrace", resultArray.cause())); + log.error("stacktrace", exceptionFactory.newException( + "redisAPI.script(['exists', sha]) failed", resultArray.cause())); return; } Long exists = resultArray.result().get(0).toLong(); diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java index f0913a6e7..17709e912 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/resource/CopyResourceHandler.java @@ -7,6 +7,7 @@ import io.vertx.core.json.JsonObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.http.HeaderFunction; import org.swisspush.gateleen.core.http.HeaderFunctions; import org.swisspush.gateleen.core.http.RequestLoggerFactory; @@ -25,11 +26,13 @@ public class CopyResourceHandler { private static final String SLASH = "/"; private static final int DEFAULT_TIMEOUT = 120000; - private final String copyPath; private final HttpClient selfClient; + private final GateleenExceptionFactory exceptionFactory; + private final String copyPath; - public CopyResourceHandler(HttpClient selfClient, String copyPath) { + public CopyResourceHandler(HttpClient selfClient, GateleenExceptionFactory exceptionFactory, String copyPath) { this.selfClient = selfClient; + this.exceptionFactory = exceptionFactory; this.copyPath = copyPath; } @@ -94,7 +97,8 @@ protected void performGETRequest(final HttpServerRequest request, final CopyTask selfClient.request(HttpMethod.GET, task.getSourceUri()).onComplete(event -> { if (event.failed()) { - log.warn("Failed request to {}", request.uri(), new Exception("stacktrace", event.cause())); + log.warn("stacktrace", exceptionFactory.newException( + "Failed request to " + request.uri(), event.cause())); return; } HttpClientRequest selfRequest = event.result(); @@ -105,12 +109,16 @@ protected void performGETRequest(final HttpServerRequest request, final CopyTask selfRequest.idleTimeout(DEFAULT_TIMEOUT); // add exception handler - selfRequest.exceptionHandler( ex -> log.warn("CopyResourceHandler: GET request failed: {}", request.uri(), new Exception("stacktrace", ex))); + selfRequest.exceptionHandler(ex -> { + log.warn("stacktrace", exceptionFactory.newException( + "CopyResourceHandler: GET request failed: " + request.uri(), ex)); + }); // fire selfRequest.send(asyncResult -> { - if( asyncResult.failed() ){ - log.warn("stacktrace", new Exception("stacktrace", asyncResult.cause())); + if (asyncResult.failed()) { + log.warn("stacktrace", exceptionFactory.newException( + "selfRequest.send() failed", asyncResult.cause())); return; } HttpClientResponse response = asyncResult.result(); @@ -138,7 +146,7 @@ protected void performPUTRequest(final HttpServerRequest request, final HttpClie selfClient.request(HttpMethod.PUT, task.getDestinationUri()).onComplete(event -> { if (event.failed()) { - log.warn("Failed request to {}", request.uri(), new Exception("stacktrace", event.cause())); + log.warn("Failed request to {}", request.uri(), exceptionFactory.newException(event.cause())); return; } HttpClientRequest selfRequest = event.result(); @@ -154,8 +162,9 @@ protected void performPUTRequest(final HttpServerRequest request, final HttpClie // fire selfRequest.send(asyncResult -> { - if( asyncResult.failed() ){ - log.warn("stacktrace", new Exception("stacktrace", asyncResult.cause())); + if (asyncResult.failed()) { + log.warn("stacktrace", exceptionFactory.newException( + "selfRequest.send() failed", asyncResult.cause())); return; } HttpClientResponse response = asyncResult.result(); diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/EventBusResourceStorage.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/EventBusResourceStorage.java index c4a699b8b..9b9c6aab6 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/EventBusResourceStorage.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/EventBusResourceStorage.java @@ -10,6 +10,7 @@ import io.vertx.core.json.JsonObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.http.HttpRequest; /** @@ -20,10 +21,12 @@ public class EventBusResourceStorage implements ResourceStorage { private static final Logger log = LoggerFactory.getLogger(EventBusResourceStorage.class); private final EventBus eventBus; private final String address; + private final GateleenExceptionFactory exceptionFactory; - public EventBusResourceStorage(EventBus eventBus, String address) { + public EventBusResourceStorage(EventBus eventBus, String address, GateleenExceptionFactory exceptionFactory) { this.eventBus = eventBus; this.address = address; + this.exceptionFactory = exceptionFactory; } @Override @@ -34,9 +37,9 @@ public void get(String uri, final Handler bodyHandler) { eventBus.request(address, request, (Handler>>) message -> { if (message.failed()) { - log.warn("Got failed msg from event bus while GET. Lets run into NPE now.", new Exception("stacktrace", message.cause())); - // Would be best to stop processing now. But we don't to keep backward - // compatibility (Will run into NPE anyway). + log.warn("stacktrace", exceptionFactory.newException( + "eventBus.request('" + address + "', request) failed", message.cause())); + return; } Buffer buffer = message.result().body(); int headerLength = buffer.getInt(0); @@ -58,10 +61,9 @@ public void put(String uri, MultiMap headers, Buffer buffer, final Handler>>) message -> { if (message.failed()) { - log.warn("Got failed msg from event bus while PUT. Lets run into NPE now.", - new Exception("stacktrace", message.cause())); - // Would be best to stop processing now. But we don't to keep backward - // compatibility (Will run into NPE anyway). + log.warn("stacktrace", exceptionFactory.newException( + "eventBus.request('" + address + "', request) failed", message.cause())); + return; } Buffer buffer1 = message.result().body(); int headerLength = buffer1.getInt(0); @@ -82,10 +84,9 @@ public void delete(String uri, final Handler doneHandler) { request.setInt(0, header.length()).appendBuffer(header); eventBus.request(address, request, (Handler>>) message -> { if (message.failed()) { - log.warn("Got failed msg from event bus while DELETE. Lets run into NPE now.", - new Exception("stacktrace", message.cause())); - // Would be best to stop processing now. But we don't to keep backward - // compatibility (Will run into NPE anyway). + log.warn("stacktrace", exceptionFactory.newException( + "eventBus.request('" + address + "', request) failed", message.cause())); + return; } Buffer buffer = message.result().body(); int headerLength = buffer.getInt(0); diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java index 3a5ba74af..511d73382 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/storage/HttpResourceStorage.java @@ -7,9 +7,12 @@ import io.vertx.core.http.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.util.HttpHeaderUtil; import org.swisspush.gateleen.core.util.StatusCode; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenThriftyExceptionFactory; + /** * Gives programmatic access to the resource storage. * @@ -17,19 +20,26 @@ */ public class HttpResourceStorage implements ResourceStorage { + private final GateleenExceptionFactory exceptionFactory; + private HttpClient client; private String host; private int port; - private HttpClient client; private Logger log = LoggerFactory.getLogger(HttpResourceStorage.class); private static final long TIMEOUT = 30000; public HttpResourceStorage(Vertx vertx) { - this(vertx, "localhost", 8989); + this(vertx, newGateleenThriftyExceptionFactory(), "localhost", 8989); } - public HttpResourceStorage(Vertx vertx, String host, int port) { + public HttpResourceStorage( + Vertx vertx, + GateleenExceptionFactory exceptionFactory, + String host, + int port + ) { + this.exceptionFactory = exceptionFactory; this.host = host; this.port = port; this.client = vertx.createHttpClient(new HttpClientOptions() @@ -46,20 +56,20 @@ public void get(final String path, final Handler bodyHandler) { log.debug("Reading {}", path); client.request(HttpMethod.GET, path).onComplete(asyncResult -> { if (asyncResult.failed()) { - log.warn("Failed request to {}", path, new Exception("stacktrace", asyncResult.cause())); + log.warn("Failed request to {}", path, exceptionFactory.newException(asyncResult.cause())); return; } HttpClientRequest request = asyncResult.result(); - request.exceptionHandler(e -> { - log.error("Storage request error", new Exception("stacktrace", e)); + request.exceptionHandler(ex -> { + log.error("Storage request error", exceptionFactory.newException(ex)); bodyHandler.handle(null); }); request.idleTimeout(TIMEOUT); request.send(event -> { HttpClientResponse response = event.result(); - response.exceptionHandler(exception -> { - log.error("Reading {} failed", path, new Exception("stacktrace", exception)); + response.exceptionHandler(ex -> { + log.error("Reading {} failed", path, exceptionFactory.newException(ex)); bodyHandler.handle(null); }); if (response.statusCode() == StatusCode.OK.getStatusCode()) { @@ -85,7 +95,7 @@ public int getPort() { public void put(final String uri, MultiMap headers, Buffer buffer, final Handler doneHandler) { client.request(HttpMethod.PUT, uri).onComplete(asyncResult -> { if (asyncResult.failed()) { - log.warn("Failed request to {}", uri, new Exception("stacktrace", asyncResult.cause())); + log.warn("Failed request to {}", uri, exceptionFactory.newException(asyncResult.cause())); return; } HttpClientRequest request = asyncResult.result(); @@ -104,13 +114,13 @@ public void put(final String uri, MultiMap headers, Buffer buffer, final Handler request.putHeader("Content-Length", "" + buffer.length()); request.write(buffer); request.send(asyncRespnose -> { - if( asyncRespnose.failed() ){ - log.error("TODO error handling", new Exception(request.getURI(), asyncRespnose.cause())); + if (asyncRespnose.failed()) { + log.error("TODO error handling", exceptionFactory.newException(request.getURI(), asyncRespnose.cause())); return; } HttpClientResponse response = asyncRespnose.result(); response.exceptionHandler( ex -> { - log.error("Exception on response to PUT {}", uri, new Exception("stacktrace", ex)); + log.error("Exception on response to PUT {}", uri, exceptionFactory.newException(ex)); doneHandler.handle(StatusCode.INTERNAL_SERVER_ERROR.getStatusCode()); }); response.endHandler(nothing -> doneHandler.handle(response.statusCode())); @@ -127,24 +137,26 @@ public void put(final String uri, final Buffer buffer, final Handler do public void delete(final String uri, final Handler doneHandler) { client.request(HttpMethod.DELETE, uri).onComplete(asyncResult -> { if (asyncResult.failed()) { - log.warn("Failed request to {}", uri, new Exception("stacktrace", asyncResult.cause())); + log.warn("Failed request to {}", uri, exceptionFactory.newException(asyncResult.cause())); return; } HttpClientRequest request = asyncResult.result(); request.exceptionHandler( ex -> { - log.warn("Deleting {} failed", uri, new Exception("stacktrace", ex)); + log.warn("Deleting {} failed", uri, exceptionFactory.newException(ex)); doneHandler.handle(StatusCode.INTERNAL_SERVER_ERROR.getStatusCode()); }); request.idleTimeout(TIMEOUT); request.send(asyncRespnose -> { if( asyncRespnose.failed() ){ - log.error("TODO error handling", new Exception(request.getURI(), asyncRespnose.cause())); + log.error("TODO error handling", exceptionFactory.newException( + request.getURI(), asyncRespnose.cause())); return; } HttpClientResponse response = asyncRespnose.result(); - response.exceptionHandler(exception -> { - log.error("Exception on response to DELETE from {}", uri, new Exception("stacktrace", exception)); + response.exceptionHandler(ex -> { + log.error("Exception on response to DELETE from {}", uri, + exceptionFactory.newException(ex)); doneHandler.handle(StatusCode.INTERNAL_SERVER_ERROR.getStatusCode()); }); response.endHandler(event -> doneHandler.handle(response.statusCode())); diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/util/LockUtil.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/util/LockUtil.java index 40b0093a8..705e03d2a 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/util/LockUtil.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/util/LockUtil.java @@ -3,6 +3,7 @@ import io.vertx.core.Future; import io.vertx.core.Promise; import org.slf4j.Logger; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.lock.Lock; /** @@ -12,7 +13,11 @@ */ public class LockUtil { - private LockUtil(){} + private final GateleenExceptionFactory exceptionFactory; + + public LockUtil(GateleenExceptionFactory exceptionFactory) { + this.exceptionFactory = exceptionFactory; + } /** * Acquire a lock. Resolves always to Boolean.TRUE when no lock implementation is provided @@ -58,7 +63,7 @@ public static Future acquireLock(Lock lockImpl, String lock, String tok * @param token the unique token * @param log the Logger */ - public static void releaseLock(Lock lockImpl, String lock, String token, Logger log){ + public void releaseLock(Lock lockImpl, String lock, String token, Logger log){ if(lockImpl == null){ log.info("No lock implementation defined, going to pretend like we released the lock"); return; @@ -70,7 +75,8 @@ public static void releaseLock(Lock lockImpl, String lock, String token, Logger log.debug("Released lock '{}' with token '{}'", lock, token); } } else { - log.error("Could not release lock '{}'.", lock, new Exception("stacktrace", releaseEvent.cause())); + log.error("Could not release lock '{}'.", lock, + exceptionFactory.newException(releaseEvent.cause())); } }); } diff --git a/gateleen-core/src/test/java/org/swisspush/gateleen/core/configuration/ConfigurationResourceManagerTest.java b/gateleen-core/src/test/java/org/swisspush/gateleen/core/configuration/ConfigurationResourceManagerTest.java index 57edbccab..4f28f807c 100644 --- a/gateleen-core/src/test/java/org/swisspush/gateleen/core/configuration/ConfigurationResourceManagerTest.java +++ b/gateleen-core/src/test/java/org/swisspush/gateleen/core/configuration/ConfigurationResourceManagerTest.java @@ -20,6 +20,7 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import static org.swisspush.gateleen.core.configuration.ConfigurationResourceManager.CONFIG_RESOURCE_CHANGED_ADDRESS; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; /** * Tests for the {@link ConfigurationResourceManager} class @@ -35,7 +36,7 @@ public class ConfigurationResourceManagerTest extends ConfigurationResourceTestB public void testGetRegisteredResourceNotYetRegistered(TestContext context) { Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); String resourceURI = "/gateleen/resources/person"; @@ -53,7 +54,7 @@ public void testGetRegisteredResourceNotYetRegistered(TestContext context) { public void testGetRegisteredResource(TestContext context) { Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); String resourceURI = "/gateleen/resources/person"; @@ -68,8 +69,7 @@ public void testGetRegisteredResource(TestContext context) { // resource should not be in storage context.assertFalse(storage.getMockData().containsKey(resourceURI)); - - boolean handled = configurationResourceManager.handleConfigurationResource(request); +boolean handled = configurationResourceManager.handleConfigurationResource(request); context.assertTrue(handled, "PUT Request to configuration resource should be handled"); // resource should be in storage @@ -87,7 +87,7 @@ public void testGetRegisteredResource(TestContext context) { public void testGetRegisteredResourceInitiallyLoadedFromStorage(TestContext context) { Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); String resourceURI = "/gateleen/resources/person"; @@ -118,7 +118,7 @@ public void testGetRegisteredResourceInitiallyLoadedFromStorage(TestContext cont public void testGetRegisteredResourceInitiallyLoadedFromStorageInvalid(TestContext context) { Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); String resourceURI = "/gateleen/resources/person"; @@ -148,7 +148,7 @@ public void testGetRegisteredResourceInitiallyLoadedFromStorageInvalid(TestConte public void testRegistrationAndValidUpdateWithSchema(TestContext context) { Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); String resourceURI = "/gateleen/resources/person"; @@ -178,7 +178,7 @@ public void testRegistrationAndValidUpdateWithSchema(TestContext context) { public void testRegistrationAndInvalidUpdateWithSchema(TestContext context) { Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); String resourceURI = "/gateleen/resources/person"; @@ -212,7 +212,7 @@ public void testNoNotificationAfterUnsuccessfulStoragePut(TestContext context) t int storagePutFailStatusCode = 400; storage.failPutWith(storagePutFailStatusCode); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); String resourceURI = "/gateleen/resources/person"; @@ -247,7 +247,7 @@ public void testNoNotificationAfterUnsuccessfulStoragePut(TestContext context) t public void testNotSupportedConfigurationResourceChangeType(TestContext context) { Async async = context.async(); MockResourceStorage storage = Mockito.spy(new MockResourceStorage()); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); String resourceURI = "/gateleen/resources/person"; @@ -274,7 +274,7 @@ public void testNotSupportedConfigurationResourceChangeType(TestContext context) public void testRequestWithoutUri(TestContext context) { Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); String resourceURI = "/gateleen/resources/person"; @@ -297,7 +297,7 @@ public void testRequestWithoutUri(TestContext context) { public void testGETRequestToRegisteredResourceUriShouldNotBeHandled(TestContext context) { Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); String resourceURI = "/gateleen/resources/person"; @@ -320,7 +320,7 @@ public void testGETRequestToRegisteredResourceUriShouldNotBeHandled(TestContext public void testNotificationAfterRegistration(TestContext context) { Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); String resourceURI = "/gateleen/resources/person"; storage.putMockData(resourceURI, CONTENT_MATCHING_PERSON_SCHEMA); @@ -348,7 +348,7 @@ public void testNotificationAfterRegistration(TestContext context) { public void testNotificationMultipleObserversAfterRegistration(TestContext context) { Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); String resourceURI = "/gateleen/resources/person"; storage.putMockData(resourceURI, CONTENT_MATCHING_PERSON_SCHEMA); @@ -379,7 +379,7 @@ public void testNotificationMultipleObserversAfterRegistration(TestContext conte public void testRemoveResource(TestContext context) { Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); String resourceURI = "/gateleen/resources/person"; @@ -420,7 +420,7 @@ public void testNoNotificationWhenRemovingNotExistingResource(TestContext contex Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); String resourceURI = "/gateleen/resources/person"; @@ -467,7 +467,7 @@ public void testNoNotificationWhenRemovingNotExistingResource(TestContext contex public void testRequestToNotRegisteredResourceUriShouldNotBeHandled(TestContext context) { Async async = context.async(); MockResourceStorage storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, newGateleenWastefulExceptionFactory()); configurationResourceManager.registerResource("/gateleen/resources/person/abc", PERSON_SCHEMA); configurationResourceManager.registerResource("/gateleen/resources/person/def", PERSON_SCHEMA); diff --git a/gateleen-core/src/test/java/org/swisspush/gateleen/core/lock/impl/RedisBasedLockTest.java b/gateleen-core/src/test/java/org/swisspush/gateleen/core/lock/impl/RedisBasedLockTest.java index d0f0e2a32..29f0b02ff 100644 --- a/gateleen-core/src/test/java/org/swisspush/gateleen/core/lock/impl/RedisBasedLockTest.java +++ b/gateleen-core/src/test/java/org/swisspush/gateleen/core/lock/impl/RedisBasedLockTest.java @@ -17,6 +17,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import redis.clients.jedis.Jedis; import redis.clients.jedis.exceptions.JedisConnectionException; @@ -24,6 +25,7 @@ import static org.awaitility.Awaitility.await; import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; /** * Tests for the {@link RedisBasedLock} class @@ -48,7 +50,7 @@ public static void setupLock(){ vertx = Vertx.vertx(); RedisAPI redisAPI = RedisAPI.api(new RedisClient(vertx, new NetClientOptions(), new PoolOptions(), new RedisStandaloneConnectOptions(), TracingPolicy.IGNORE)); - redisBasedLock = new RedisBasedLock(() -> Future.succeededFuture(redisAPI)); + redisBasedLock = new RedisBasedLock(() -> Future.succeededFuture(redisAPI), newGateleenWastefulExceptionFactory()); } @Before diff --git a/gateleen-core/src/test/java/org/swisspush/gateleen/core/resource/CopyResourceHandlerTest.java b/gateleen-core/src/test/java/org/swisspush/gateleen/core/resource/CopyResourceHandlerTest.java index c8530c1a5..7574a5c0d 100644 --- a/gateleen-core/src/test/java/org/swisspush/gateleen/core/resource/CopyResourceHandlerTest.java +++ b/gateleen-core/src/test/java/org/swisspush/gateleen/core/resource/CopyResourceHandlerTest.java @@ -12,6 +12,8 @@ import org.junit.runner.RunWith; import org.mockito.Mockito; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; + @RunWith(VertxUnitRunner.class) public class CopyResourceHandlerTest { private HttpServerRequest httpServerRequestMock; @@ -20,7 +22,7 @@ public class CopyResourceHandlerTest { @Before public void init() { httpServerRequestMock = Mockito.mock(HttpServerRequest.class); - copyResourceHandler = new CopyResourceHandler(Mockito.mock(HttpClient.class), null); + copyResourceHandler = new CopyResourceHandler(Mockito.mock(HttpClient.class), newGateleenWastefulExceptionFactory(), null); MultiMap headers = MultiMap.caseInsensitiveMultiMap().add("x-expire-after", "700"); Mockito.doReturn(headers).when(httpServerRequestMock).headers(); @@ -83,4 +85,4 @@ public void testApplyHeadersFailed() { Assert.assertNull(copyTask); } -} \ No newline at end of file +} diff --git a/gateleen-core/src/test/java/org/swisspush/gateleen/core/util/LockUtilTest.java b/gateleen-core/src/test/java/org/swisspush/gateleen/core/util/LockUtilTest.java index 68f2d5dc5..bb0598753 100644 --- a/gateleen-core/src/test/java/org/swisspush/gateleen/core/util/LockUtilTest.java +++ b/gateleen-core/src/test/java/org/swisspush/gateleen/core/util/LockUtilTest.java @@ -12,6 +12,7 @@ import org.swisspush.gateleen.core.lock.Lock; import static org.mockito.ArgumentMatchers.*; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; /** * Tests for the {@link LockUtil} class @@ -23,11 +24,13 @@ public class LockUtilTest { private Lock lock; private Logger log; + private LockUtil lockUtil; @Before public void setUp(){ lock = Mockito.mock(Lock.class); log = Mockito.mock(Logger.class); + lockUtil = new LockUtil(newGateleenWastefulExceptionFactory()); } @Test @@ -79,14 +82,14 @@ public void testAcquireLockError(TestContext context) { @Test public void testReleaseLockWithoutLockImplementationDefined(TestContext context) { - LockUtil.releaseLock(null, "someLock", "someToken", log); + lockUtil.releaseLock(null, "someLock", "someToken", log); Mockito.verify(log, Mockito.timeout(100).times(1)).info(eq("No lock implementation defined, going to pretend like we released the lock")); } @Test public void testReleaseLockSuccess(TestContext context) { Mockito.when(lock.releaseLock(anyString(), anyString())).thenReturn(Future.succeededFuture(Boolean.TRUE)); - LockUtil.releaseLock(lock, "someLock", "someToken", log); + lockUtil.releaseLock(lock, "someLock", "someToken", log); Mockito.verify(log, Mockito.times(1)).debug(eq("Trying to release lock '{}' with token '{}'"), eq("someLock"), eq("someToken")); Mockito.verify(log, Mockito.times(1)).debug(eq("Released lock '{}' with token '{}'"), eq("someLock"), eq("someToken")); } @@ -94,14 +97,14 @@ public void testReleaseLockSuccess(TestContext context) { @Test public void testReleaseLockFail(TestContext context) { Mockito.when(lock.releaseLock(anyString(), anyString())).thenReturn(Future.succeededFuture(Boolean.FALSE)); - LockUtil.releaseLock(lock, "someLock", "someToken", log); + lockUtil.releaseLock(lock, "someLock", "someToken", log); Mockito.verify(log, Mockito.times(1)).debug(eq("Trying to release lock '{}' with token '{}'"), eq("someLock"), eq("someToken")); } @Test public void testReleaseLockError(TestContext context) { Mockito.when(lock.releaseLock(anyString(), anyString())).thenReturn(Future.failedFuture("Booom")); - LockUtil.releaseLock(lock, "someLock", "someToken", log); + lockUtil.releaseLock(lock, "someLock", "someToken", log); Mockito.verify(log, Mockito.times(1)).debug(eq("Trying to release lock '{}' with token '{}'"), eq("someLock"), eq("someToken")); Mockito.verify(log, Mockito.times(1)).error(eq("Could not release lock '{}'."), eq("someLock"), isA(Throwable.class)); } diff --git a/gateleen-delegate/src/test/java/org/swisspush/gateleen/delegate/DelegateTest.java b/gateleen-delegate/src/test/java/org/swisspush/gateleen/delegate/DelegateTest.java index d870ed4b5..8d228d145 100644 --- a/gateleen-delegate/src/test/java/org/swisspush/gateleen/delegate/DelegateTest.java +++ b/gateleen-delegate/src/test/java/org/swisspush/gateleen/delegate/DelegateTest.java @@ -16,6 +16,7 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.http.ClientRequestCreator; import org.swisspush.gateleen.core.http.DummyHttpServerRequest; import org.swisspush.gateleen.core.http.LocalHttpClient; @@ -26,6 +27,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; import static org.swisspush.gateleen.core.util.ResourcesUtils.loadResource; /** @@ -43,6 +45,7 @@ public class DelegateTest { private final String VALID_TRANSFORM_PROPERTY_DELEGATE = loadResource("valid_transform_delegate", true); + private final GateleenExceptionFactory exceptionFactory = newGateleenWastefulExceptionFactory(); private String delegatesSchema = loadResource("gateleen_delegate_schema_delegates", true); private ClientRequestCreator clientRequestCreator; @@ -52,7 +55,7 @@ public class DelegateTest { public void setUp() { Vertx vertx = Mockito.mock(Vertx.class); Mockito.when(vertx.eventBus()).thenReturn(Mockito.mock(EventBus.class)); - final LocalHttpClient selfClient = new LocalHttpClient(vertx); + final LocalHttpClient selfClient = new LocalHttpClient(vertx, exceptionFactory); selfClient.setRoutingContexttHandler(event -> {}); clientRequestCreator = Mockito.spy(new ClientRequestCreator(selfClient)); delegateFactory = new DelegateFactory(clientRequestCreator, new HashMap<>(), delegatesSchema, null); diff --git a/gateleen-hook/src/main/java/org/swisspush/gateleen/hook/reducedpropagation/ReducedPropagationManager.java b/gateleen-hook/src/main/java/org/swisspush/gateleen/hook/reducedpropagation/ReducedPropagationManager.java index 7ee16d9aa..849123f84 100644 --- a/gateleen-hook/src/main/java/org/swisspush/gateleen/hook/reducedpropagation/ReducedPropagationManager.java +++ b/gateleen-hook/src/main/java/org/swisspush/gateleen/hook/reducedpropagation/ReducedPropagationManager.java @@ -8,10 +8,12 @@ import io.vertx.redis.client.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.http.HttpRequest; import org.swisspush.gateleen.core.lock.Lock; import org.swisspush.gateleen.core.util.Address; import org.swisspush.gateleen.core.util.HttpRequestHeader; +import org.swisspush.gateleen.core.util.LockUtil; import org.swisspush.gateleen.core.util.StringUtils; import org.swisspush.gateleen.queue.queuing.RequestQueue; @@ -21,7 +23,6 @@ import static org.swisspush.gateleen.core.util.HttpRequestHeader.CONTENT_LENGTH; import static org.swisspush.gateleen.core.util.LockUtil.acquireLock; -import static org.swisspush.gateleen.core.util.LockUtil.releaseLock; import static org.swisspush.redisques.util.RedisquesAPI.*; /** @@ -36,6 +37,7 @@ public class ReducedPropagationManager { private final ReducedPropagationStorage storage; private final RequestQueue requestQueue; private Lock lock; + private final LockUtil lockUtil; public static final String PROCESS_EXPIRED_QUEUES_LOCK = "reducedPropagationProcExpQueuesLock"; public static final String LOCK_REQUESTER = "ReducedPropagationManager"; public static final String PROCESSOR_ADDRESS = "gateleen.hook-expired-queues-processor"; @@ -50,11 +52,18 @@ public class ReducedPropagationManager { private Logger log = LoggerFactory.getLogger(ReducedPropagationManager.class); - public ReducedPropagationManager(Vertx vertx, ReducedPropagationStorage storage, RequestQueue requestQueue, Lock lock) { + public ReducedPropagationManager( + Vertx vertx, + ReducedPropagationStorage storage, + RequestQueue requestQueue, + Lock lock, + GateleenExceptionFactory exceptionFactory + ) { this.vertx = vertx; this.storage = storage; this.requestQueue = requestQueue; this.lock = lock; + this.lockUtil = new LockUtil(exceptionFactory); registerExpiredQueueProcessor(); } @@ -157,7 +166,7 @@ private void processExpiredQueues(String lockToken) { storage.removeExpiredQueues(System.currentTimeMillis()).onComplete(event -> { if (event.failed()) { log.error("Going to release lock because process expired queues failed. Cause: " + event.cause()); - releaseLock(this.lock, PROCESS_EXPIRED_QUEUES_LOCK, lockToken, log); + lockUtil.releaseLock(this.lock, PROCESS_EXPIRED_QUEUES_LOCK, lockToken, log); return; } Response response = event.result(); diff --git a/gateleen-hook/src/main/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorage.java b/gateleen-hook/src/main/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorage.java index cd1a34cc7..2e008ce36 100644 --- a/gateleen-hook/src/main/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorage.java +++ b/gateleen-hook/src/main/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorage.java @@ -8,6 +8,7 @@ import io.vertx.redis.client.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.lua.LuaScriptState; import org.swisspush.gateleen.core.redis.RedisProvider; import org.swisspush.gateleen.core.util.StringUtils; @@ -36,11 +37,11 @@ public class RedisReducedPropagationStorage implements ReducedPropagationStorage private LuaScriptState startQueueTimerLuaScriptState; private LuaScriptState removeExpiredQueuesRedisCommand; - public RedisReducedPropagationStorage(RedisProvider redisProvider) { + public RedisReducedPropagationStorage(RedisProvider redisProvider, GateleenExceptionFactory exceptionFactory) { this.redisProvider = redisProvider; - startQueueTimerLuaScriptState = new LuaScriptState(ReducedPropagationLuaScripts.START_QUEUE_TIMER, redisProvider, false); - removeExpiredQueuesRedisCommand = new LuaScriptState(ReducedPropagationLuaScripts.REMOVE_EXPIRED_QUEUES, redisProvider, false); + startQueueTimerLuaScriptState = new LuaScriptState(ReducedPropagationLuaScripts.START_QUEUE_TIMER, redisProvider, exceptionFactory, false); + removeExpiredQueuesRedisCommand = new LuaScriptState(ReducedPropagationLuaScripts.REMOVE_EXPIRED_QUEUES, redisProvider, exceptionFactory, false); } @Override diff --git a/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/ReducedPropagationManagerTest.java b/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/ReducedPropagationManagerTest.java index 57acaf179..099770d2c 100644 --- a/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/ReducedPropagationManagerTest.java +++ b/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/ReducedPropagationManagerTest.java @@ -17,6 +17,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.InOrder; import org.mockito.Mockito; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.http.HttpRequest; import org.swisspush.gateleen.core.lock.Lock; import org.swisspush.gateleen.queue.queuing.RequestQueue; @@ -25,6 +26,7 @@ import java.util.List; import static org.mockito.Mockito.*; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; import static org.swisspush.gateleen.core.util.HttpRequestHeader.CONTENT_LENGTH; import static org.swisspush.gateleen.core.util.HttpRequestHeader.getInteger; import static org.swisspush.gateleen.hook.reducedpropagation.ReducedPropagationManager.*; @@ -42,6 +44,7 @@ public class ReducedPropagationManagerTest { public Timeout rule = Timeout.seconds(50); private Vertx vertx; + private final GateleenExceptionFactory exceptionFactory = newGateleenWastefulExceptionFactory(); private ReducedPropagationStorage reducedPropagationStorage; private ReducedPropagationManager manager; private RequestQueue requestQueue; @@ -55,7 +58,7 @@ public void setUp() { requestQueue = Mockito.mock(RequestQueue.class); requestQueueInOrder = Mockito.inOrder(requestQueue); lock = Mockito.mock(Lock.class); - manager = new ReducedPropagationManager(vertx, reducedPropagationStorage, requestQueue, lock); + manager = new ReducedPropagationManager(vertx, reducedPropagationStorage, requestQueue, lock, exceptionFactory); } @Test diff --git a/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorageAddQueueMultipleQueuesTest.java b/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorageAddQueueMultipleQueuesTest.java index c744e2a8e..a0bc3e918 100644 --- a/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorageAddQueueMultipleQueuesTest.java +++ b/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorageAddQueueMultipleQueuesTest.java @@ -16,6 +16,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import redis.clients.jedis.Jedis; import redis.clients.jedis.Tuple; import redis.clients.jedis.exceptions.JedisConnectionException; @@ -25,6 +26,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; import static org.swisspush.gateleen.hook.reducedpropagation.impl.RedisReducedPropagationStorage.QUEUE_TIMERS; /** @@ -40,6 +42,7 @@ public class RedisReducedPropagationStorageAddQueueMultipleQueuesTest { private static Vertx vertx; + private static final GateleenExceptionFactory exceptionFactory = newGateleenWastefulExceptionFactory(); private Jedis jedis; private static RedisReducedPropagationStorage storage; @@ -51,7 +54,7 @@ public static void setupStorage() { vertx = Vertx.vertx(); RedisAPI redisAPI = RedisAPI.api(new RedisClient(vertx, new NetClientOptions(), new PoolOptions(), new RedisStandaloneConnectOptions(), TracingPolicy.IGNORE)); - storage = new RedisReducedPropagationStorage(() -> Future.succeededFuture(redisAPI)); + storage = new RedisReducedPropagationStorage(() -> Future.succeededFuture(redisAPI), exceptionFactory); } @Before diff --git a/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorageRemoveExpiredQueuesEmptyTest.java b/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorageRemoveExpiredQueuesEmptyTest.java index 2274cfee9..60c2a5574 100644 --- a/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorageRemoveExpiredQueuesEmptyTest.java +++ b/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorageRemoveExpiredQueuesEmptyTest.java @@ -17,11 +17,13 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import redis.clients.jedis.Jedis; import redis.clients.jedis.exceptions.JedisConnectionException; import java.util.Collections; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; import static org.swisspush.gateleen.hook.reducedpropagation.impl.RedisReducedPropagationStorage.QUEUE_TIMERS; /** @@ -38,6 +40,7 @@ public class RedisReducedPropagationStorageRemoveExpiredQueuesEmptyTest { private static Vertx vertx; + private static final GateleenExceptionFactory exceptionFactory = newGateleenWastefulExceptionFactory(); private Jedis jedis; private static RedisReducedPropagationStorage storage; @@ -49,7 +52,7 @@ public static void setupStorage() { vertx = Vertx.vertx(); RedisAPI redisAPI = RedisAPI.api(new RedisClient(vertx, new NetClientOptions(), new PoolOptions(), new RedisStandaloneConnectOptions(), TracingPolicy.IGNORE)); - storage = new RedisReducedPropagationStorage(() -> Future.succeededFuture(redisAPI)); + storage = new RedisReducedPropagationStorage(() -> Future.succeededFuture(redisAPI), exceptionFactory); } @Before diff --git a/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorageTest.java b/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorageTest.java index a4c42c5df..5adec3533 100644 --- a/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorageTest.java +++ b/gateleen-hook/src/test/java/org/swisspush/gateleen/hook/reducedpropagation/impl/RedisReducedPropagationStorageTest.java @@ -18,6 +18,7 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import redis.clients.jedis.Jedis; import redis.clients.jedis.Tuple; import redis.clients.jedis.exceptions.JedisConnectionException; @@ -28,6 +29,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; import static org.swisspush.gateleen.hook.reducedpropagation.impl.RedisReducedPropagationStorage.QUEUE_REQUESTS; import static org.swisspush.gateleen.hook.reducedpropagation.impl.RedisReducedPropagationStorage.QUEUE_TIMERS; @@ -40,6 +42,7 @@ public class RedisReducedPropagationStorageTest { private static Vertx vertx; + private static final GateleenExceptionFactory exceptionFactory = newGateleenWastefulExceptionFactory(); private Jedis jedis; private static RedisReducedPropagationStorage storage; @@ -51,7 +54,7 @@ public static void setupStorage() { vertx = Vertx.vertx(); RedisAPI redisAPI = RedisAPI.api(new RedisClient(vertx, new NetClientOptions(), new PoolOptions(), new RedisStandaloneConnectOptions(), TracingPolicy.IGNORE)); - storage = new RedisReducedPropagationStorage(() -> Future.succeededFuture(redisAPI)); + storage = new RedisReducedPropagationStorage(() -> Future.succeededFuture(redisAPI), exceptionFactory); } @Before diff --git a/gateleen-kafka/src/test/java/org/swisspush/gateleen/kafka/KafkaHandlerTest.java b/gateleen-kafka/src/test/java/org/swisspush/gateleen/kafka/KafkaHandlerTest.java index 054350367..8ed8cca73 100644 --- a/gateleen-kafka/src/test/java/org/swisspush/gateleen/kafka/KafkaHandlerTest.java +++ b/gateleen-kafka/src/test/java/org/swisspush/gateleen/kafka/KafkaHandlerTest.java @@ -17,6 +17,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.swisspush.gateleen.core.configuration.ConfigurationResourceManager; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.storage.MockResourceStorage; import org.swisspush.gateleen.core.util.ResourcesUtils; import org.swisspush.gateleen.core.util.StatusCode; @@ -34,6 +35,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; import static org.swisspush.gateleen.core.configuration.ConfigurationResourceManager.CONFIG_RESOURCE_CHANGED_ADDRESS; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; /** * Test class for the {@link KafkaHandler} @@ -50,6 +52,7 @@ public class KafkaHandlerTest { private ConfigurationResourceManager configurationResourceManager; private KafkaHandler handler; private MockResourceStorage storage; + private GateleenExceptionFactory exceptionFactory = newGateleenWastefulExceptionFactory(); private final String configResourceUri = "/kafka/topicsConfig"; private final String streamingPath = "/kafka/streaming/"; @@ -64,7 +67,7 @@ public void setUp() { kafkaMessageSender = Mockito.mock(KafkaMessageSender.class); messageValidator = Mockito.mock(KafkaMessageValidator.class); storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, exceptionFactory); handler = new KafkaHandler(configurationResourceManager, repository, kafkaMessageSender, configResourceUri, streamingPath); diff --git a/gateleen-playground/src/main/java/org/swisspush/gateleen/playground/Server.java b/gateleen-playground/src/main/java/org/swisspush/gateleen/playground/Server.java index 558ce5413..612a0b0a7 100755 --- a/gateleen-playground/src/main/java/org/swisspush/gateleen/playground/Server.java +++ b/gateleen-playground/src/main/java/org/swisspush/gateleen/playground/Server.java @@ -26,6 +26,7 @@ import org.swisspush.gateleen.core.configuration.ConfigurationResourceManager; import org.swisspush.gateleen.core.cors.CORSHandler; import org.swisspush.gateleen.core.event.EventBusHandler; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.http.ClientRequestCreator; import org.swisspush.gateleen.core.http.LocalHttpClient; import org.swisspush.gateleen.core.lock.Lock; @@ -86,6 +87,8 @@ import java.util.Arrays; import java.util.Map; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; + /** * Playground server to try Gateleen at home. * @@ -119,6 +122,7 @@ public class Server extends AbstractVerticle { private ResourceStorage storage; private CacheStorage cacheStorage; private CacheDataFetcher cacheDataFetcher; + private final GateleenExceptionFactory exceptionFactory = newGateleenWastefulExceptionFactory(); private Authorizer authorizer; private Router router; @@ -166,7 +170,7 @@ public static void main(String[] args) { @Override public void start() { - final LocalHttpClient selfClient = new LocalHttpClient(vertx); + final LocalHttpClient selfClient = new LocalHttpClient(vertx, exceptionFactory); final JsonObject info = new JsonObject(); final Map props = RunConfig.buildRedisProps("localhost", defaultRedisPort); @@ -204,26 +208,26 @@ public void start() { RedisProvider redisProvider = () -> Future.succeededFuture(redisApi); new CustomRedisMonitor(vertx, redisProvider, "main", "rest-storage", 10).start(); - storage = new EventBusResourceStorage(vertx.eventBus(), Address.storageAddress() + "-main"); + storage = new EventBusResourceStorage(vertx.eventBus(), Address.storageAddress() + "-main", exceptionFactory); corsHandler = new CORSHandler(); RuleProvider ruleProvider = new RuleProvider(vertx, RULES_ROOT, storage, props); deltaHandler = new DeltaHandler(redisProvider, selfClient, ruleProvider, true); expansionHandler = new ExpansionHandler(ruleProvider, selfClient, props, ROOT); - copyResourceHandler = new CopyResourceHandler(selfClient, SERVER_ROOT + "/v1/copy"); + copyResourceHandler = new CopyResourceHandler(selfClient, exceptionFactory, SERVER_ROOT + "/v1/copy"); monitoringHandler = new MonitoringHandler(vertx, storage, PREFIX, SERVER_ROOT + "/monitoring/rpr"); - Lock lock = new RedisBasedLock(redisProvider); + Lock lock = new RedisBasedLock(redisProvider, newGateleenWastefulExceptionFactory()); - cacheStorage = new RedisCacheStorage(vertx, lock, redisProvider, 20 * 1000); + cacheStorage = new RedisCacheStorage(vertx, lock, redisProvider, exceptionFactory, 20 * 1000); cacheDataFetcher = new DefaultCacheDataFetcher(new ClientRequestCreator(selfClient)); cacheHandler = new CacheHandler(cacheDataFetcher, cacheStorage, SERVER_ROOT + "/cache"); qosHandler = new QoSHandler(vertx, storage, SERVER_ROOT + "/admin/v1/qos", props, PREFIX); qosHandler.enableResourceLogging(true); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, exceptionFactory); configurationResourceManager.enableResourceLogging(true); eventBusHandler = new EventBusHandler(vertx, SERVER_ROOT + "/event/v1/", @@ -253,8 +257,8 @@ public void start() { roleProfileHandler.enableResourceLogging(true); QueueClient queueClient = new QueueClient(vertx, monitoringHandler); - reducedPropagationManager = new ReducedPropagationManager(vertx, new RedisReducedPropagationStorage(redisProvider), - queueClient, lock); + reducedPropagationManager = new ReducedPropagationManager(vertx, new RedisReducedPropagationStorage(redisProvider, exceptionFactory), + queueClient, lock, exceptionFactory); reducedPropagationManager.startExpiredQueueProcessing(5000); queueSplitter = new QueueSplitterImpl(configurationResourceManager, SERVER_ROOT + "/admin/v1/queueSplitters"); @@ -319,12 +323,12 @@ public void start() { queueCircuitBreakerConfigurationResourceManager = new QueueCircuitBreakerConfigurationResourceManager(vertx, storage, SERVER_ROOT + "/admin/v1/circuitbreaker"); queueCircuitBreakerConfigurationResourceManager.enableResourceLogging(true); - QueueCircuitBreakerStorage queueCircuitBreakerStorage = new RedisQueueCircuitBreakerStorage(redisProvider); + QueueCircuitBreakerStorage queueCircuitBreakerStorage = new RedisQueueCircuitBreakerStorage(redisProvider, exceptionFactory); QueueCircuitBreakerHttpRequestHandler requestHandler = new QueueCircuitBreakerHttpRequestHandler(vertx, queueCircuitBreakerStorage, SERVER_ROOT + "/queuecircuitbreaker/circuit"); QueueCircuitBreaker queueCircuitBreaker = new QueueCircuitBreakerImpl(vertx, lock, - Address.redisquesAddress(), queueCircuitBreakerStorage, ruleProvider, rulePatternToCircuitMapping, + Address.redisquesAddress(), queueCircuitBreakerStorage, ruleProvider, exceptionFactory, rulePatternToCircuitMapping, queueCircuitBreakerConfigurationResourceManager, requestHandler, circuitBreakerPort); new QueueProcessor(vertx, selfClient, monitoringHandler, queueCircuitBreaker); diff --git a/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/QueueProcessor.java b/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/QueueProcessor.java index 1ebb50c45..bd3f040dc 100755 --- a/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/QueueProcessor.java +++ b/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/QueueProcessor.java @@ -13,6 +13,7 @@ import io.vertx.core.json.JsonObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.http.HttpRequest; import org.swisspush.gateleen.core.http.RequestLoggerFactory; import org.swisspush.gateleen.core.util.Address; @@ -23,6 +24,7 @@ import org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueCircuitState; import org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueResponseType; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenThriftyExceptionFactory; import static org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueResponseType.FAILURE; import static org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueResponseType.SUCCESS; import static org.swisspush.redisques.util.RedisquesAPI.*; @@ -36,6 +38,7 @@ public class QueueProcessor { private HttpClient httpClient; private MonitoringHandler monitoringHandler; private QueueCircuitBreaker queueCircuitBreaker; + private final GateleenExceptionFactory exceptionFactory; private static final Handler DEV_NULL = buf -> {}; private MessageConsumer consumer; @@ -46,15 +49,22 @@ public QueueProcessor(final Vertx vertx, final HttpClient httpClient, final Moni } public QueueProcessor(final Vertx vertx, final HttpClient httpClient, final MonitoringHandler monitoringHandler, QueueCircuitBreaker queueCircuitBreaker) { - this(vertx, httpClient, monitoringHandler, queueCircuitBreaker, true); + this(vertx, httpClient, monitoringHandler, queueCircuitBreaker, newGateleenThriftyExceptionFactory(), true); } - public QueueProcessor(final Vertx vertx, final HttpClient httpClient, final MonitoringHandler monitoringHandler, - QueueCircuitBreaker queueCircuitBreaker, boolean immediatelyStartQueueProcessing) { + public QueueProcessor( + Vertx vertx, + HttpClient httpClient, + MonitoringHandler monitoringHandler, + QueueCircuitBreaker queueCircuitBreaker, + GateleenExceptionFactory exceptionFactory, + boolean immediatelyStartQueueProcessing + ) { this.vertx = vertx; this.httpClient = httpClient; this.monitoringHandler = monitoringHandler; this.queueCircuitBreaker = queueCircuitBreaker; + this.exceptionFactory = exceptionFactory; if (immediatelyStartQueueProcessing) { startQueueProcessing(); @@ -245,7 +255,8 @@ private void executeQueuedRequest(Message message, Logger logger, Ht Handler> httpAsyncHandler = asyncResult -> { if (asyncResult.failed()) { - logger.error("TODO error handling", new Exception("stacktrace", asyncResult.cause())); + logger.error("TODO error handling", exceptionFactory.newException( + "httpClientRequest.send() failed", asyncResult.cause())); return; } HttpClientResponse response = asyncResult.result(); diff --git a/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/QueueCircuitBreakerImpl.java b/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/QueueCircuitBreakerImpl.java index eb26a211c..fbd883d42 100644 --- a/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/QueueCircuitBreakerImpl.java +++ b/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/QueueCircuitBreakerImpl.java @@ -8,10 +8,12 @@ import io.vertx.redis.client.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.http.HttpRequest; import org.swisspush.gateleen.core.lock.Lock; import org.swisspush.gateleen.core.refresh.Refreshable; import org.swisspush.gateleen.core.util.Address; +import org.swisspush.gateleen.core.util.LockUtil; import org.swisspush.gateleen.queue.queuing.circuitbreaker.QueueCircuitBreaker; import org.swisspush.gateleen.queue.queuing.circuitbreaker.QueueCircuitBreakerStorage; import org.swisspush.gateleen.queue.queuing.circuitbreaker.configuration.QueueCircuitBreakerConfigurationResource; @@ -26,7 +28,6 @@ import java.util.concurrent.atomic.AtomicInteger; import static org.swisspush.gateleen.core.util.LockUtil.acquireLock; -import static org.swisspush.gateleen.core.util.LockUtil.releaseLock; import static org.swisspush.redisques.util.RedisquesAPI.*; @@ -43,6 +44,7 @@ public class QueueCircuitBreakerImpl implements QueueCircuitBreaker, RuleChanges private final QueueCircuitBreakerConfigurationResourceManager configResourceManager; private final Lock lock; + private final LockUtil lockUtil; public static final String OPEN_TO_HALF_OPEN_TASK_LOCK = "openToHalfOpenTask"; public static final String UNLOCK_QUEUES_TASK_LOCK = "unlockQueuesTask"; @@ -67,9 +69,21 @@ public class QueueCircuitBreakerImpl implements QueueCircuitBreaker, RuleChanges * @param queueCircuitBreakerHttpRequestHandler request handler * @param requestHandlerPort the port to listen to */ - public QueueCircuitBreakerImpl(Vertx vertx, Lock lock, String redisquesAddress, QueueCircuitBreakerStorage queueCircuitBreakerStorage, RuleProvider ruleProvider, QueueCircuitBreakerRulePatternToCircuitMapping ruleToCircuitMapping, QueueCircuitBreakerConfigurationResourceManager configResourceManager, Handler queueCircuitBreakerHttpRequestHandler, int requestHandlerPort) { + public QueueCircuitBreakerImpl( + Vertx vertx, + Lock lock, + String redisquesAddress, + QueueCircuitBreakerStorage queueCircuitBreakerStorage, + RuleProvider ruleProvider, + GateleenExceptionFactory exceptionFactory, + QueueCircuitBreakerRulePatternToCircuitMapping ruleToCircuitMapping, + QueueCircuitBreakerConfigurationResourceManager configResourceManager, + Handler queueCircuitBreakerHttpRequestHandler, + int requestHandlerPort + ) { this.vertx = vertx; this.lock = lock; + this.lockUtil = new LockUtil(exceptionFactory); this.redisquesAddress = redisquesAddress; this.queueCircuitBreakerStorage = queueCircuitBreakerStorage; ruleProvider.registerObserver(this); @@ -130,7 +144,7 @@ private void registerOpenToHalfOpenTask() { } } else { log.error(event1.cause().getMessage()); - releaseLock(this.lock, OPEN_TO_HALF_OPEN_TASK_LOCK, token, log); + lockUtil.releaseLock(this.lock, OPEN_TO_HALF_OPEN_TASK_LOCK, token, log); } }); } @@ -165,7 +179,7 @@ private void registerUnlockQueuesTask() { } } else { log.error("Unable to unlock queue '{}'", event1.cause().getMessage()); - releaseLock(this.lock, UNLOCK_QUEUES_TASK_LOCK, token, log); + lockUtil.releaseLock(this.lock, UNLOCK_QUEUES_TASK_LOCK, token, log); } }); } @@ -199,7 +213,7 @@ private void registerUnlockSampleQueuesTask() { } } else { log.error(event1.cause().getMessage()); - releaseLock(this.lock, UNLOCK_SAMPLE_QUEUES_TASK_LOCK, token, log); + lockUtil.releaseLock(this.lock, UNLOCK_SAMPLE_QUEUES_TASK_LOCK, token, log); } }); } diff --git a/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/RedisQueueCircuitBreakerStorage.java b/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/RedisQueueCircuitBreakerStorage.java index 49ac4900c..1746916f6 100644 --- a/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/RedisQueueCircuitBreakerStorage.java +++ b/gateleen-queue/src/main/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/RedisQueueCircuitBreakerStorage.java @@ -7,6 +7,7 @@ import io.vertx.redis.client.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.lua.LuaScriptState; import org.swisspush.gateleen.core.redis.RedisProvider; import org.swisspush.gateleen.core.util.StringUtils; @@ -47,15 +48,15 @@ public class RedisQueueCircuitBreakerStorage implements QueueCircuitBreakerStora private final LuaScriptState unlockSampleQueuesLuaScriptState; private final LuaScriptState getAllCircuitsLuaScriptState; - public RedisQueueCircuitBreakerStorage(RedisProvider redisProvider) { + public RedisQueueCircuitBreakerStorage(RedisProvider redisProvider, GateleenExceptionFactory exceptionFactory) { this.redisProvider = redisProvider; - openCircuitLuaScriptState = new LuaScriptState(QueueCircuitBreakerLuaScripts.UPDATE_CIRCUIT, redisProvider, false); - closeCircuitLuaScriptState = new LuaScriptState(QueueCircuitBreakerLuaScripts.CLOSE_CIRCUIT, redisProvider, false); - reOpenCircuitLuaScriptState = new LuaScriptState(QueueCircuitBreakerLuaScripts.REOPEN_CIRCUIT, redisProvider, false); - halfOpenCircuitLuaScriptState = new LuaScriptState(QueueCircuitBreakerLuaScripts.HALFOPEN_CIRCUITS, redisProvider, false); - unlockSampleQueuesLuaScriptState = new LuaScriptState(QueueCircuitBreakerLuaScripts.UNLOCK_SAMPLES, redisProvider, false); - getAllCircuitsLuaScriptState = new LuaScriptState(QueueCircuitBreakerLuaScripts.ALL_CIRCUITS, redisProvider, false); + openCircuitLuaScriptState = new LuaScriptState(QueueCircuitBreakerLuaScripts.UPDATE_CIRCUIT, redisProvider, exceptionFactory, false); + closeCircuitLuaScriptState = new LuaScriptState(QueueCircuitBreakerLuaScripts.CLOSE_CIRCUIT, redisProvider, exceptionFactory, false); + reOpenCircuitLuaScriptState = new LuaScriptState(QueueCircuitBreakerLuaScripts.REOPEN_CIRCUIT, redisProvider, exceptionFactory, false); + halfOpenCircuitLuaScriptState = new LuaScriptState(QueueCircuitBreakerLuaScripts.HALFOPEN_CIRCUITS, redisProvider, exceptionFactory, false); + unlockSampleQueuesLuaScriptState = new LuaScriptState(QueueCircuitBreakerLuaScripts.UNLOCK_SAMPLES, redisProvider, exceptionFactory, false); + getAllCircuitsLuaScriptState = new LuaScriptState(QueueCircuitBreakerLuaScripts.ALL_CIRCUITS, redisProvider, exceptionFactory, false); } @Override diff --git a/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/QueueProcessorTest.java b/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/QueueProcessorTest.java index 14889478c..c05d9d3e3 100644 --- a/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/QueueProcessorTest.java +++ b/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/QueueProcessorTest.java @@ -21,6 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.http.FastFaiHttpClientResponse; import org.swisspush.gateleen.core.http.HttpRequest; import org.swisspush.gateleen.core.http.LocalHttpClientRequest; @@ -34,6 +35,7 @@ import org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueResponseType; import static org.mockito.Mockito.*; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; /** * Tests for the {@link QueueProcessor} class @@ -45,6 +47,7 @@ public class QueueProcessorTest { private Vertx vertx; private HttpClient httpClient; private MonitoringHandler monitoringHandler; + private final GateleenExceptionFactory exceptionFactory = newGateleenWastefulExceptionFactory(); private String PAYLOAD = "{\"method\":\"PUT\",\"uri\":\"/playground/server/tests/exp/item_2\",\"headers\":[],\"payload\":\"eyJrZXkiOiAidmFsdWUifQ==\"}"; private final String QUEUE_RETRY_400 = ResourcesUtils.loadResource("testresource_queue_retry_400", true); @@ -68,10 +71,10 @@ public void testQueueProcessorStartStopQueueProcessing(TestContext context) { QueueProcessor queueProcessor = new QueueProcessor(vertx, httpClient, monitoringHandler); context.assertTrue(queueProcessor.isQueueProcessingStarted()); - queueProcessor = new QueueProcessor(vertx, httpClient, monitoringHandler, null, true); + queueProcessor = new QueueProcessor(vertx, httpClient, monitoringHandler, null, exceptionFactory, true); context.assertTrue(queueProcessor.isQueueProcessingStarted()); - queueProcessor = new QueueProcessor(vertx, httpClient, monitoringHandler, null, false); + queueProcessor = new QueueProcessor(vertx, httpClient, monitoringHandler, null, exceptionFactory, false); context.assertFalse(queueProcessor.isQueueProcessingStarted()); queueProcessor.startQueueProcessing(); @@ -214,7 +217,7 @@ private void setHttpClientRespondStatusCode(StatusCode statusCode) { String url = (String) invocation.getArguments()[1]; LocalHttpClientRequest request = new LocalHttpClientRequest(httpMethod, url, vertx, event -> { - }, new LocalHttpServerResponse(vertx)) { + }, exceptionFactory, new LocalHttpServerResponse(vertx)) { @Override public HttpClientRequest response(Handler> handler) { FastFaiHttpClientResponse response = new FastFaiHttpClientResponse() { diff --git a/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/QueueCircuitBreakerImplTest.java b/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/QueueCircuitBreakerImplTest.java index 21a31c522..d6dcb9916 100644 --- a/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/QueueCircuitBreakerImplTest.java +++ b/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/QueueCircuitBreakerImplTest.java @@ -37,6 +37,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; import static org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueResponseType.SUCCESS; /** @@ -88,9 +89,10 @@ public void setUp() { config.setUnlockSampleQueuesTaskInterval(1000); Mockito.when(configResourceManager.getConfigurationResource()).thenReturn(config); + var exceptionFactory = newGateleenWastefulExceptionFactory(); Handler queueCircuitBreakerHttpRequestHandler = Mockito.mock(Handler.class); queueCircuitBreaker = Mockito.spy(new QueueCircuitBreakerImpl(vertx, lock, Address.redisquesAddress(), queueCircuitBreakerStorage, ruleProvider, - ruleToCircuitMapping, configResourceManager, queueCircuitBreakerHttpRequestHandler, 9999)); + exceptionFactory, ruleToCircuitMapping, configResourceManager, queueCircuitBreakerHttpRequestHandler, 9999)); } @After diff --git a/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/RedisQueueCircuitBreakerStorageTest.java b/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/RedisQueueCircuitBreakerStorageTest.java index 6f12c2860..22145d719 100644 --- a/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/RedisQueueCircuitBreakerStorageTest.java +++ b/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/circuitbreaker/impl/RedisQueueCircuitBreakerStorageTest.java @@ -18,6 +18,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.queue.queuing.circuitbreaker.util.PatternAndCircuitHash; import org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueCircuitState; import org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueResponseType; @@ -28,6 +29,7 @@ import java.util.*; import java.util.regex.Pattern; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; import static org.swisspush.gateleen.queue.queuing.circuitbreaker.impl.RedisQueueCircuitBreakerStorage.*; import static org.swisspush.gateleen.queue.queuing.circuitbreaker.util.QueueCircuitState.*; @@ -50,7 +52,7 @@ public class RedisQueueCircuitBreakerStorageTest { public static void setupStorage(){ vertx = Vertx.vertx(); RedisAPI redisAPI = RedisAPI.api(new RedisClient(vertx, new NetClientOptions(), new PoolOptions(), new RedisStandaloneConnectOptions(), TracingPolicy.IGNORE)); - storage = new RedisQueueCircuitBreakerStorage(() -> Future.succeededFuture(redisAPI)); + storage = new RedisQueueCircuitBreakerStorage(() -> Future.succeededFuture(redisAPI), newGateleenWastefulExceptionFactory()); } @Before diff --git a/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/splitter/QueueSplitterImplTest.java b/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/splitter/QueueSplitterImplTest.java index 2fa996c49..0678fa2fa 100644 --- a/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/splitter/QueueSplitterImplTest.java +++ b/gateleen-queue/src/test/java/org/swisspush/gateleen/queue/queuing/splitter/QueueSplitterImplTest.java @@ -13,18 +13,21 @@ import org.junit.runner.RunWith; import org.swisspush.gateleen.core.configuration.ConfigurationResourceManager; import org.swisspush.gateleen.core.configuration.ConfigurationResourceObserver; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.storage.MockResourceStorage; import org.swisspush.gateleen.core.util.ResourcesUtils; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.swisspush.gateleen.core.configuration.ConfigurationResourceManager.CONFIG_RESOURCE_CHANGED_ADDRESS; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; @RunWith(VertxUnitRunner.class) public class QueueSplitterImplTest { private Vertx vertx; private MockResourceStorage storage; + private final GateleenExceptionFactory exceptionFactory = newGateleenWastefulExceptionFactory(); private final String configResourceUri = "/queueSplitters"; private ConfigurationResourceManager configurationResourceManager; private QueueSplitterImpl queueSplitter; @@ -37,7 +40,7 @@ public class QueueSplitterImplTest { public void setUp() { vertx = Vertx.vertx(); storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + configurationResourceManager = new ConfigurationResourceManager(vertx, storage, exceptionFactory); queueSplitter = new QueueSplitterImpl(configurationResourceManager, configResourceUri); } diff --git a/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java b/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java index ddc60968c..f54855529 100755 --- a/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java +++ b/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java @@ -535,7 +535,14 @@ private Handler> getAsyncHttpClientResponseHandl respondError(req, StatusCode.INTERNAL_SERVER_ERROR); }); - req.connection().closeHandler((aVoid) -> unpump.run()); + HttpConnection connection = req.connection(); + if (connection != null) { + connection.closeHandler((Void v) -> unpump.run()); + } else { + log.warn("TODO No way to call 'unpump.run()' in the right moment. As there seems" + + " to be no event we could register a handler for. Gateleen wishes you" + + " some happy timeouts ({})", req.uri()); + } }; } diff --git a/gateleen-runconfig/src/main/java/org/swisspush/gateleen/runconfig/RunConfig.java b/gateleen-runconfig/src/main/java/org/swisspush/gateleen/runconfig/RunConfig.java index 824add3af..2d9043015 100755 --- a/gateleen-runconfig/src/main/java/org/swisspush/gateleen/runconfig/RunConfig.java +++ b/gateleen-runconfig/src/main/java/org/swisspush/gateleen/runconfig/RunConfig.java @@ -38,7 +38,6 @@ import org.swisspush.gateleen.queue.queuing.QueueBrowser; import org.swisspush.gateleen.queue.queuing.QueuingHandler; import org.swisspush.gateleen.queue.queuing.circuitbreaker.configuration.QueueCircuitBreakerConfigurationResourceManager; -import org.swisspush.gateleen.queue.queuing.splitter.NoOpQueueSplitter; import org.swisspush.gateleen.queue.queuing.splitter.QueueSplitter; import org.swisspush.gateleen.routing.CustomHttpResponseHandler; import org.swisspush.gateleen.routing.Router; diff --git a/gateleen-scheduler/src/main/java/org/swisspush/gateleen/scheduler/Scheduler.java b/gateleen-scheduler/src/main/java/org/swisspush/gateleen/scheduler/Scheduler.java index 7cbf35ba6..65ab5a309 100755 --- a/gateleen-scheduler/src/main/java/org/swisspush/gateleen/scheduler/Scheduler.java +++ b/gateleen-scheduler/src/main/java/org/swisspush/gateleen/scheduler/Scheduler.java @@ -8,6 +8,7 @@ import org.quartz.CronExpression; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.http.HttpRequest; import org.swisspush.gateleen.core.redis.RedisProvider; import org.swisspush.gateleen.monitoring.MonitoringHandler; @@ -32,6 +33,7 @@ public class Scheduler { private final Vertx vertx; private final RedisProvider redisProvider; + private final GateleenExceptionFactory exceptionFactory; private final String redisquesAddress; private final String name; private CronExpression cronExpression; @@ -45,12 +47,23 @@ public class Scheduler { private Logger log; - public Scheduler(Vertx vertx, String redisquesAddress, RedisProvider redisProvider, String name, String cronExpression, - List requests, MonitoringHandler monitoringHandler, int maxRandomOffset, - boolean executeOnStartup, boolean executeOnReload) throws ParseException { + public Scheduler( + Vertx vertx, + String redisquesAddress, + RedisProvider redisProvider, + GateleenExceptionFactory exceptionFactory, + String name, + String cronExpression, + List requests, + MonitoringHandler monitoringHandler, + int maxRandomOffset, + boolean executeOnStartup, + boolean executeOnReload + ) throws ParseException { this.vertx = vertx; this.redisquesAddress = redisquesAddress; this.redisProvider = redisProvider; + this.exceptionFactory = exceptionFactory; this.name = name; this.cronExpression = new CronExpression(cronExpression); this.requests = requests; @@ -141,7 +154,10 @@ private void trigger() { JsonObject enqueOp = buildEnqueueOperation(queueName, request.toJsonObject().put(QueueClient.QUEUE_TIMESTAMP, System.currentTimeMillis()).encode()); vertx.eventBus().request(redisquesAddress, enqueOp, (Handler>>) event -> { if (event.failed()) { - if (log.isWarnEnabled()) log.warn("Could not enqueue request '{}' '{}'", queueName, request.getUri(), new Exception(event.cause())); + if (log.isWarnEnabled()) { + log.warn("Could not enqueue request '{}' '{}'", queueName, request.getUri(), + exceptionFactory.newException("eventBus.request('" + redisquesAddress + "', enqueOp) failed", event.cause())); + } return; } if (!OK.equals(event.result().body().getString(STATUS))) { diff --git a/gateleen-scheduler/src/main/java/org/swisspush/gateleen/scheduler/SchedulerFactory.java b/gateleen-scheduler/src/main/java/org/swisspush/gateleen/scheduler/SchedulerFactory.java index 5de530d2e..1a5c34f39 100755 --- a/gateleen-scheduler/src/main/java/org/swisspush/gateleen/scheduler/SchedulerFactory.java +++ b/gateleen-scheduler/src/main/java/org/swisspush/gateleen/scheduler/SchedulerFactory.java @@ -6,6 +6,7 @@ import io.vertx.core.json.JsonObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.http.HttpRequest; import org.swisspush.gateleen.core.redis.RedisProvider; import org.swisspush.gateleen.core.util.StringUtils; @@ -40,19 +41,28 @@ public class SchedulerFactory { private final JsonArray defaultRequestHeaders; private final Vertx vertx; private final RedisProvider redisProvider; + private final GateleenExceptionFactory exceptionFactory; private final MonitoringHandler monitoringHandler; private final String schedulersSchema; private final String redisquesAddress; private final Logger log = LoggerFactory.getLogger(SchedulerFactory.class); - public SchedulerFactory(Map properties, Map defaultRequestHeaders, Vertx vertx, - RedisProvider redisProvider, MonitoringHandler monitoringHandler, String schedulersSchema, - String redisquesAddress) { + public SchedulerFactory( + Map properties, + Map defaultRequestHeaders, + Vertx vertx, + RedisProvider redisProvider, + GateleenExceptionFactory exceptionFactory, + MonitoringHandler monitoringHandler, + String schedulersSchema, + String redisquesAddress + ) { this.properties = properties; this.defaultRequestHeaders = defaultRequestHeadersAsJsonArray(defaultRequestHeaders); this.vertx = vertx; this.redisProvider = redisProvider; + this.exceptionFactory = exceptionFactory; this.monitoringHandler = monitoringHandler; this.schedulersSchema = schedulersSchema; this.redisquesAddress = redisquesAddress; @@ -122,7 +132,7 @@ public List parseSchedulers(Buffer buffer) throws ValidationException } } try { - result.add(new Scheduler(vertx, redisquesAddress, redisProvider, entry.getKey(), + result.add(new Scheduler(vertx, redisquesAddress, redisProvider, exceptionFactory, entry.getKey(), (String) schedulerJson.get("cronExpression"), requests, monitoringHandler, maxRandomOffset, executeOnStartup, executeOnReload) ); } catch (ParseException e) { diff --git a/gateleen-scheduler/src/main/java/org/swisspush/gateleen/scheduler/SchedulerResourceManager.java b/gateleen-scheduler/src/main/java/org/swisspush/gateleen/scheduler/SchedulerResourceManager.java index 59b6d1eb6..da8bbbe18 100755 --- a/gateleen-scheduler/src/main/java/org/swisspush/gateleen/scheduler/SchedulerResourceManager.java +++ b/gateleen-scheduler/src/main/java/org/swisspush/gateleen/scheduler/SchedulerResourceManager.java @@ -8,6 +8,7 @@ import io.vertx.core.http.HttpServerRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.logging.LoggableResource; import org.swisspush.gateleen.core.logging.RequestLogger; import org.swisspush.gateleen.core.redis.RedisProvider; @@ -24,6 +25,8 @@ import java.util.List; import java.util.Map; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenThriftyExceptionFactory; + /** * @author https://github.com/lbovet [Laurent Bovet] */ @@ -53,12 +56,20 @@ public SchedulerResourceManager(Vertx vertx, RedisProvider redisProvider, final public SchedulerResourceManager(Vertx vertx, RedisProvider redisProvider, final ResourceStorage storage, MonitoringHandler monitoringHandler, String schedulersUri, Map props, String redisquesAddress) { - this(vertx, redisProvider, storage, monitoringHandler, schedulersUri, props, redisquesAddress, Collections.emptyMap()); + this(vertx, redisProvider, newGateleenThriftyExceptionFactory(), storage, monitoringHandler, schedulersUri, props, redisquesAddress, Collections.emptyMap()); } - public SchedulerResourceManager(Vertx vertx, RedisProvider redisProvider, final ResourceStorage storage, - MonitoringHandler monitoringHandler, String schedulersUri, Map props, - String redisquesAddress, Map defaultRequestHeaders) { + public SchedulerResourceManager( + Vertx vertx, + RedisProvider redisProvider, + GateleenExceptionFactory exceptionFactory, + ResourceStorage storage, + MonitoringHandler monitoringHandler, + String schedulersUri, + Map props, + String redisquesAddress, + Map defaultRequestHeaders + ) { this.vertx = vertx; this.storage = storage; this.schedulersUri = schedulersUri; @@ -66,7 +77,7 @@ public SchedulerResourceManager(Vertx vertx, RedisProvider redisProvider, final this.schedulersSchema = ResourcesUtils.loadResource("gateleen_scheduler_schema_schedulers", true); this.schedulerFactory = new SchedulerFactory(properties, defaultRequestHeaders, vertx, redisProvider, - monitoringHandler, schedulersSchema, redisquesAddress); + exceptionFactory, monitoringHandler, schedulersSchema, redisquesAddress); updateSchedulers(); diff --git a/gateleen-scheduler/src/test/java/org/swisspush/gateleen/scheduler/SchedulerFactoryTest.java b/gateleen-scheduler/src/test/java/org/swisspush/gateleen/scheduler/SchedulerFactoryTest.java index 037c7ed6d..13f7a3e6a 100755 --- a/gateleen-scheduler/src/test/java/org/swisspush/gateleen/scheduler/SchedulerFactoryTest.java +++ b/gateleen-scheduler/src/test/java/org/swisspush/gateleen/scheduler/SchedulerFactoryTest.java @@ -14,6 +14,7 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.Mockito; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.http.HttpRequest; import org.swisspush.gateleen.core.redis.RedisProvider; import org.swisspush.gateleen.core.util.Address; @@ -25,6 +26,7 @@ import java.util.List; import static org.mockito.Mockito.when; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; /** * Tests for the {@link SchedulerFactory} class @@ -39,6 +41,7 @@ public class SchedulerFactoryTest { private RedisAPI redisAPI; private RedisProvider redisProvider; + private GateleenExceptionFactory exceptionFactory = newGateleenWastefulExceptionFactory(); private SchedulerFactory schedulerFactory; @Rule @@ -62,8 +65,8 @@ public void setUp() { monitoringHandler = Mockito.mock(MonitoringHandler.class); - schedulerFactory = new SchedulerFactory(null, Collections.emptyMap(), vertx, redisProvider, monitoringHandler, - schedulersSchema, Address.redisquesAddress()); + schedulerFactory = new SchedulerFactory(null, Collections.emptyMap(), vertx, redisProvider, exceptionFactory, + monitoringHandler, schedulersSchema, Address.redisquesAddress()); } @Test @@ -105,7 +108,7 @@ public void testValidSchedulerConfig(TestContext context) throws ValidationExcep @Test public void testValidSchedulerConfigWithDefaultHeaders(TestContext context) throws ValidationException { schedulerFactory = new SchedulerFactory(null, Collections.singletonMap("x-foo", "zzz"), vertx, redisProvider, - monitoringHandler, schedulersSchema, Address.redisquesAddress()); + exceptionFactory, monitoringHandler, schedulersSchema, Address.redisquesAddress()); List schedulers = schedulerFactory.parseSchedulers(Buffer.buffer(VALID_SCHEDULER_RESOURCE)); context.assertNotNull(schedulers); context.assertEquals(4, schedulers.size()); diff --git a/gateleen-security/src/test/java/org/swisspush/gateleen/security/content/ContentTypeConstraintHandlerTest.java b/gateleen-security/src/test/java/org/swisspush/gateleen/security/content/ContentTypeConstraintHandlerTest.java index 3648b5b50..76f703538 100644 --- a/gateleen-security/src/test/java/org/swisspush/gateleen/security/content/ContentTypeConstraintHandlerTest.java +++ b/gateleen-security/src/test/java/org/swisspush/gateleen/security/content/ContentTypeConstraintHandlerTest.java @@ -27,6 +27,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; /** * Test class for the {@link ContentTypeConstraintHandler} @@ -49,7 +50,7 @@ public class ContentTypeConstraintHandlerTest extends ContentTypeConstraintTestB @Before public void setUp() { storage = new MockResourceStorage(); - configurationResourceManager = new ConfigurationResourceManager(Vertx.vertx(), storage); + configurationResourceManager = new ConfigurationResourceManager(Vertx.vertx(), storage, newGateleenWastefulExceptionFactory()); repository = Mockito.spy(new ContentTypeConstraintRepository()); handler = new ContentTypeConstraintHandler(configurationResourceManager, repository, configResourceUri); } diff --git a/gateleen-test/src/test/java/org/swisspush/gateleen/AbstractTest.java b/gateleen-test/src/test/java/org/swisspush/gateleen/AbstractTest.java index cf642f116..b02253c5d 100755 --- a/gateleen-test/src/test/java/org/swisspush/gateleen/AbstractTest.java +++ b/gateleen-test/src/test/java/org/swisspush/gateleen/AbstractTest.java @@ -30,6 +30,7 @@ import org.swisspush.gateleen.core.configuration.ConfigurationResourceManager; import org.swisspush.gateleen.core.cors.CORSHandler; import org.swisspush.gateleen.core.event.EventBusHandler; +import org.swisspush.gateleen.core.exception.GateleenExceptionFactory; import org.swisspush.gateleen.core.http.ClientRequestCreator; import org.swisspush.gateleen.core.http.LocalHttpClient; import org.swisspush.gateleen.core.lock.Lock; @@ -82,6 +83,8 @@ import java.util.Map; import java.util.Set; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; + /** * TestVerticle all Gateleen tests.
* @@ -117,6 +120,7 @@ public abstract class AbstractTest { protected static PropertyHandler propertyHandler; protected static Jedis jedis; private static HttpServer mainServer; + private static final GateleenExceptionFactory exceptionFactory = newGateleenWastefulExceptionFactory(); protected final static Map props = new HashMap<>(); protected static SchedulerResourceManager schedulerResourceManager; protected static HookHandler hookHandler; @@ -135,7 +139,7 @@ public static void setupBeforeClass(TestContext context) { jedis.flushAll(); final JsonObject info = new JsonObject(); - final LocalHttpClient selfClient = new LocalHttpClient(vertx); + final LocalHttpClient selfClient = new LocalHttpClient(vertx, exceptionFactory); props.putAll(RunConfig.buildRedisProps("localhost", REDIS_PORT)); String redisHost = (String) props.get("redis.host"); @@ -152,9 +156,9 @@ public static void setupBeforeClass(TestContext context) { RedisAPI redisAPI = RedisAPI.api(redisClient); RedisProvider redisProvider = () -> Future.succeededFuture(redisAPI); - ResourceStorage storage = new EventBusResourceStorage(vertx.eventBus(), Address.storageAddress() + "-main"); + ResourceStorage storage = new EventBusResourceStorage(vertx.eventBus(), Address.storageAddress() + "-main", exceptionFactory); MonitoringHandler monitoringHandler = new MonitoringHandler(vertx, storage, PREFIX); - ConfigurationResourceManager configurationResourceManager = new ConfigurationResourceManager(vertx, storage); + ConfigurationResourceManager configurationResourceManager = new ConfigurationResourceManager(vertx, storage, exceptionFactory); String eventBusConfigurationResource = SERVER_ROOT + "/admin/v1/hookconfig"; EventBusHandler eventBusHandler = new EventBusHandler(vertx, SERVER_ROOT + "/event/v1/", @@ -170,11 +174,11 @@ public static void setupBeforeClass(TestContext context) { RoleProfileHandler roleProfileHandler = new RoleProfileHandler(vertx, storage, SERVER_ROOT + "/roles/v1/([^/]+)/profile"); qosHandler = new QoSHandler(vertx, storage, SERVER_ROOT + "/admin/v1/qos", props, PREFIX); - Lock lock = new RedisBasedLock(redisProvider); + Lock lock = new RedisBasedLock(redisProvider, newGateleenWastefulExceptionFactory()); QueueClient queueClient = new QueueClient(vertx, monitoringHandler); ReducedPropagationManager reducedPropagationManager = new ReducedPropagationManager(vertx, - new RedisReducedPropagationStorage(redisProvider), queueClient, lock); + new RedisReducedPropagationStorage(redisProvider, exceptionFactory), queueClient, lock, exceptionFactory); reducedPropagationManager.startExpiredQueueProcessing(1000); hookHandler = new HookHandler(vertx, selfClient, storage, loggingResourceManager, logAppenderRepository, monitoringHandler, SERVER_ROOT + "/users/v1/%s/profile", ROOT + "/server/hooks/v1/", @@ -193,7 +197,7 @@ public static void setupBeforeClass(TestContext context) { cacheHandler = new CacheHandler( new DefaultCacheDataFetcher(new ClientRequestCreator(selfClient)), - new RedisCacheStorage(vertx, lock, redisProvider, 60000), + new RedisCacheStorage(vertx, lock, redisProvider, exceptionFactory, 60000), SERVER_ROOT + "/cache"); customHttpResponseHandler = new CustomHttpResponseHandler(RETURN_HTTP_STATUS_ROOT); @@ -205,13 +209,14 @@ public static void setupBeforeClass(TestContext context) { QueueCircuitBreakerConfigurationResourceManager queueCircuitBreakerConfigurationResourceManager = new QueueCircuitBreakerConfigurationResourceManager(vertx, storage, SERVER_ROOT + "/admin/v1/circuitbreaker"); - QueueCircuitBreakerStorage queueCircuitBreakerStorage = new RedisQueueCircuitBreakerStorage(redisProvider); + QueueCircuitBreakerStorage queueCircuitBreakerStorage = new RedisQueueCircuitBreakerStorage(redisProvider, exceptionFactory); QueueCircuitBreakerHttpRequestHandler requestHandler = new QueueCircuitBreakerHttpRequestHandler(vertx, queueCircuitBreakerStorage,SERVER_ROOT + "/queuecircuitbreaker/circuit"); QueueCircuitBreaker queueCircuitBreaker = new QueueCircuitBreakerImpl(vertx, lock, - Address.redisquesAddress(), queueCircuitBreakerStorage, ruleProvider, rulePatternToCircuitMapping, - queueCircuitBreakerConfigurationResourceManager, requestHandler, CIRCUIT_BREAKER_REST_API_PORT); + Address.redisquesAddress(), queueCircuitBreakerStorage, ruleProvider, exceptionFactory, + rulePatternToCircuitMapping, queueCircuitBreakerConfigurationResourceManager, requestHandler, + CIRCUIT_BREAKER_REST_API_PORT); new QueueProcessor(vertx, selfClient, monitoringHandler, queueCircuitBreaker); final QueueBrowser queueBrowser = new QueueBrowser(vertx, SERVER_ROOT + "/queuing", @@ -248,7 +253,7 @@ public static void setupBeforeClass(TestContext context) { .expansionHandler(new ExpansionHandler(vertx, storage, selfClient, props, ROOT, RULES_ROOT)) .hookHandler(hookHandler) .qosHandler(qosHandler) - .copyResourceHandler(new CopyResourceHandler(selfClient, SERVER_ROOT + "/v1/copy")) + .copyResourceHandler(new CopyResourceHandler(selfClient, exceptionFactory, SERVER_ROOT + "/v1/copy")) .eventBusHandler(eventBusHandler) .roleProfileHandler(roleProfileHandler) .userProfileHandler(userProfileHandler) diff --git a/gateleen-validation/src/test/java/org/swisspush/gateleen/validation/DefaultValidationSchemaProviderTest.java b/gateleen-validation/src/test/java/org/swisspush/gateleen/validation/DefaultValidationSchemaProviderTest.java index 8a22a201a..5fe61455e 100644 --- a/gateleen-validation/src/test/java/org/swisspush/gateleen/validation/DefaultValidationSchemaProviderTest.java +++ b/gateleen-validation/src/test/java/org/swisspush/gateleen/validation/DefaultValidationSchemaProviderTest.java @@ -21,6 +21,7 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.swisspush.gateleen.core.exception.GateleenExceptionFactory.newGateleenWastefulExceptionFactory; @RunWith(VertxUnitRunner.class) public class DefaultValidationSchemaProviderTest { @@ -32,7 +33,7 @@ public class DefaultValidationSchemaProviderTest { @Before public void setUp(){ vertx = Vertx.vertx(); - final LocalHttpClient selfClient = new LocalHttpClient(vertx); + final LocalHttpClient selfClient = new LocalHttpClient(vertx, newGateleenWastefulExceptionFactory()); selfClient.setRoutingContexttHandler(event -> {}); clientRequestCreator = Mockito.spy(new ClientRequestCreator(selfClient)); schemaProvider = new DefaultValidationSchemaProvider(vertx, clientRequestCreator, Duration.ofSeconds(5));