diff --git a/build.gradle b/build.gradle index 46d1f89..7d949e9 100755 --- a/build.gradle +++ b/build.gradle @@ -7,14 +7,17 @@ plugins { repositories { mavenCentral() + maven { + url "https://s01.oss.sonatype.org/content/repositories/snapshots" + } } ext{ - vertxVersion = '4.4.1' - jupiterVersion = '5.9.1' - jupiterLauncherVersion = '1.9.1' - slfApiVersion = '2.0.5' - logbackVersion = '1.4.5' + vertxVersion = '5.0.0-SNAPSHOT' + jupiterVersion = '5.10.0' + jupiterLauncherVersion = '1.10.0' + slfApiVersion = '2.0.9' + logbackVersion = '1.4.11' } dependencies { @@ -42,7 +45,7 @@ test { sourceCompatibility='1.8' targetCompatibility='1.8' -jar.archiveFileName = "vertx-web-accesslog-1.6.0.jar" +jar.archiveFileName = "vertx-web-accesslog-5.0.0-SNAPSHOT.jar" java { withSourcesJar() @@ -54,7 +57,7 @@ publishing { groupId 'com.mdac' artifactId 'vertx-web-accesslog' - version '1.6.0' + version '5.0.0-SNAPSHOT' from components.java diff --git a/src/main/java/com/romanpierson/vertx/web/accesslogger/configuration/element/impl/HeaderElement.java b/src/main/java/com/romanpierson/vertx/web/accesslogger/configuration/element/impl/HeaderElement.java index 3689561..638f724 100644 --- a/src/main/java/com/romanpierson/vertx/web/accesslogger/configuration/element/impl/HeaderElement.java +++ b/src/main/java/com/romanpierson/vertx/web/accesslogger/configuration/element/impl/HeaderElement.java @@ -39,7 +39,7 @@ public static HeaderElement of(final Mode mode, final String identifier) { HeaderElement element = new HeaderElement(); element.mode = mode; - element.identifier = identifier; + element.identifier = identifier.toLowerCase(); return element; } diff --git a/src/main/java/com/romanpierson/vertx/web/accesslogger/configuration/element/impl/HostElement.java b/src/main/java/com/romanpierson/vertx/web/accesslogger/configuration/element/impl/HostElement.java index c4b31ff..a92f545 100644 --- a/src/main/java/com/romanpierson/vertx/web/accesslogger/configuration/element/impl/HostElement.java +++ b/src/main/java/com/romanpierson/vertx/web/accesslogger/configuration/element/impl/HostElement.java @@ -77,5 +77,6 @@ public String getFormattedValue(final JsonObject values) { } } + } diff --git a/src/main/java/com/romanpierson/vertx/web/accesslogger/impl/AccessLoggerHandlerImpl.java b/src/main/java/com/romanpierson/vertx/web/accesslogger/impl/AccessLoggerHandlerImpl.java index c4b466c..853b346 100644 --- a/src/main/java/com/romanpierson/vertx/web/accesslogger/impl/AccessLoggerHandlerImpl.java +++ b/src/main/java/com/romanpierson/vertx/web/accesslogger/impl/AccessLoggerHandlerImpl.java @@ -27,6 +27,7 @@ import io.vertx.core.DeploymentOptions; import io.vertx.core.MultiMap; +import io.vertx.core.ThreadingModel; import io.vertx.core.Vertx; import io.vertx.core.eventbus.EventBus; import io.vertx.core.http.Cookie; @@ -79,10 +80,16 @@ public AccessLoggerHandlerImpl(final JsonObject handlerConfiguration) { logger.info("Start creating singleton verticle"); - Vertx.currentContext().owner().deployVerticle(AccessLoggerProducerVerticle.class.getName(), new DeploymentOptions().setWorker(true)); - - isProducerVerticleCreated = true; - + Vertx.currentContext().owner().deployVerticle(AccessLoggerProducerVerticle.class.getName(), new DeploymentOptions().setThreadingModel(ThreadingModel.WORKER)) + .onComplete(ar -> { + + if(ar.succeeded()) { + isProducerVerticleCreated = true; + } else { + throw new AccessLoggerException("Unable to deploy AccessLoggerProducerVerticle", ar.cause()); + } + + }); } } } @@ -95,41 +102,43 @@ public AccessLoggerHandlerImpl(final JsonObject handlerConfiguration) { final JsonObject configuration = (JsonObject) xConfiguration; - eventBus.request(AccessLoggerConstants.EVENTBUS_REGISTER_EVENT_NAME, configuration, ar -> { - - final String configurationIdentifier = configuration.getString(Registration.Request.IDENTIFIER); - - if(ar.succeeded()) { - JsonObject response = ar.result().body(); - if(Registration.Response.RESULT_OK.equals(response.getString(Registration.Response.RESULT, null))){ - - this.requiresCookies = response.getBoolean(Registration.Response.REQUIRES_COOKIES, false) ? true : this.requiresCookies; - this.requiresIncomingHeaders = response.getBoolean(Registration.Response.REQUIRES_INCOMING_HEADERS, false) ? true : this.requiresIncomingHeaders; - this.requiresOutgoingHeaders = response.getBoolean(Registration.Response.REQUIRES_OUTGOING_HEADERS, false) ? true : this.requiresOutgoingHeaders; - - this.registeredIdentifiers.add(configurationIdentifier); - - if(this.requiredConfigurationsCounter == this.registeredIdentifiers.size()) { - this.allConfigurationsSuccessfullyRegistered = true; + eventBus + .request(AccessLoggerConstants.EVENTBUS_REGISTER_EVENT_NAME, configuration) + .onComplete(ar -> { + + final String configurationIdentifier = configuration.getString(Registration.Request.IDENTIFIER); + + if(ar.succeeded()) { + JsonObject response = ar.result().body(); + if(Registration.Response.RESULT_OK.equals(response.getString(Registration.Response.RESULT, null))){ - logger.debug("Successfully registered all [" + this.requiredConfigurationsCounter + "] configurations with identifiers " + this.registeredIdentifiers); + this.requiresCookies = response.getBoolean(Registration.Response.REQUIRES_COOKIES, false) ? true : this.requiresCookies; + this.requiresIncomingHeaders = response.getBoolean(Registration.Response.REQUIRES_INCOMING_HEADERS, false) ? true : this.requiresIncomingHeaders; + this.requiresOutgoingHeaders = response.getBoolean(Registration.Response.REQUIRES_OUTGOING_HEADERS, false) ? true : this.requiresOutgoingHeaders; - if(this.requiresCookies || this.requiresIncomingHeaders || this.requiresOutgoingHeaders) { + this.registeredIdentifiers.add(configurationIdentifier); + + if(this.requiredConfigurationsCounter == this.registeredIdentifiers.size()) { + this.allConfigurationsSuccessfullyRegistered = true; - logger.debug("Specific data required for cookies [" + this.requiresCookies + "], incoming headers [" + this.requiresIncomingHeaders + "], outgoing headers [" + this.requiresOutgoingHeaders + "]"); + logger.debug("Successfully registered all [" + this.requiredConfigurationsCounter + "] configurations with identifiers " + this.registeredIdentifiers); - } else { - logger.debug("No specific data required"); + if(this.requiresCookies || this.requiresIncomingHeaders || this.requiresOutgoingHeaders) { + + logger.debug("Specific data required for cookies [" + this.requiresCookies + "], incoming headers [" + this.requiresIncomingHeaders + "], outgoing headers [" + this.requiresOutgoingHeaders + "]"); + + } else { + logger.debug("No specific data required"); + } } + + } else { + throw new AccessLoggerException("Unable to register access log configuration for identifier [" + configurationIdentifier + "]"); } } else { - throw new AccessLoggerException("Unable to register access log configuration for identifier [" + configurationIdentifier + "]"); + throw new AccessLoggerException("Unable to register access log configuration [" + configurationIdentifier + "]", ar.cause()); } - - } else { - throw new AccessLoggerException("Unable to register access log configuration [" + configurationIdentifier + "]", ar.cause()); - } }); }); @@ -156,7 +165,6 @@ private void log(final RoutingContext context, long startTSmillis){ final HttpServerRequest request = context.request(); final HttpServerResponse response = context.response(); - JsonObject jsonValues = new JsonObject() .put(RawEvent.Request.IDENTIFIERS, this.registeredIdentifiers) .put(Data.Type.START_TS_MILLIS.getFieldName(), startTSmillis) @@ -166,7 +174,7 @@ private void log(final RoutingContext context, long startTSmillis){ .put(Data.Type.URI.getFieldName(), request.path()) .put(Data.Type.VERSION.getFieldName(), request.version()) .put(Data.Type.REMOTE_HOST.getFieldName(), request.remoteAddress().host()) - .put(Data.Type.LOCAL_HOST.getFieldName(), request.host().contains(":") ? request.host().substring(0, request.host().indexOf(":")): request.host()) + .put(Data.Type.LOCAL_HOST.getFieldName(), request.authority() == null ? null : request.authority().host()) .put(Data.Type.LOCAL_PORT.getFieldName(), request.localAddress().port()); if(request.query() != null && !request.query().trim().isEmpty()){ @@ -194,7 +202,7 @@ private void log(final RoutingContext context, long startTSmillis){ private JsonObject extractHeaders(final MultiMap headersMap){ JsonObject headers = new JsonObject(); - headersMap.forEach(entry -> headers.put(entry.getKey(), entry.getValue())); + headersMap.forEach(entry -> headers.put(entry.getKey().toLowerCase(), entry.getValue())); return headers; diff --git a/src/main/java/com/romanpierson/vertx/web/accesslogger/util/FormatUtility.java b/src/main/java/com/romanpierson/vertx/web/accesslogger/util/FormatUtility.java index df55c45..43e9fbf 100644 --- a/src/main/java/com/romanpierson/vertx/web/accesslogger/util/FormatUtility.java +++ b/src/main/java/com/romanpierson/vertx/web/accesslogger/util/FormatUtility.java @@ -1,9 +1,10 @@ package com.romanpierson.vertx.web.accesslogger.util; + import io.vertx.core.json.JsonObject; public class FormatUtility { - + private FormatUtility() {} public static String getStringOrNull(final JsonObject values, final String fieldName) { @@ -18,4 +19,5 @@ public static String getIntegerOrNull(final JsonObject values, final String fiel } + } diff --git a/src/test/java/com/romanpierson/vertx/test/verticle/SimpleJsonResponseVerticle.java b/src/test/java/com/romanpierson/vertx/test/verticle/SimpleJsonResponseVerticle.java index 81f0061..23f2222 100644 --- a/src/test/java/com/romanpierson/vertx/test/verticle/SimpleJsonResponseVerticle.java +++ b/src/test/java/com/romanpierson/vertx/test/verticle/SimpleJsonResponseVerticle.java @@ -29,53 +29,55 @@ public void start(Promise startPromise) throws Exception { .setConfig(new JsonObject().put("path", configFile)); ConfigRetriever retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(store)); - - retriever.getConfig(result -> { - - if(result.succeeded()) { - router - .route() - .handler(BodyHandler.create()) - .handler(AccessLoggerHandler.create(result.result()) - ); + + retriever + .getConfig() + .onComplete(result -> { - router - .post("/posttest") - .handler(ctx -> { - - //System.out.println(ctx.body()); + if(result.succeeded()) { + router + .route() + .handler(BodyHandler.create()) + .handler(AccessLoggerHandler.create(result.result()) + ); + + router + .post("/posttest") + .handler(ctx -> { + + //System.out.println(ctx.body()); - final JsonObject resultJson = new JsonObject(); + final JsonObject resultJson = new JsonObject(); + + resultJson.put("uri", ctx.request().uri()); - resultJson.put("uri", ctx.request().uri()); - - ctx.response().putHeader("Content-Type", "application/json; charset=utf-8").end(resultJson.encodePrettily()); - }); - - router - .get("/empty") - .handler(ctx -> { - - ctx.response().putHeader("Content-Type", "application/json; charset=utf-8").end(); - }); - - router - .get() - .handler(ctx -> { - - final JsonObject resultJson = new JsonObject(); + ctx.response().putHeader("Content-Type", "application/json; charset=utf-8").end(resultJson.encodePrettily()); + }); + + router + .get("/empty") + .handler(ctx -> { - resultJson.put("uri", ctx.request().uri()); - - ctx.response().putHeader("Content-Type", "application/json; charset=utf-8").end(resultJson.encodePrettily()); - }); - - vertx.createHttpServer().requestHandler(router).listen(8080); + ctx.response().putHeader("Content-Type", "application/json; charset=utf-8").end(); + }); + + router + .get() + .handler(ctx -> { + + final JsonObject resultJson = new JsonObject(); + + resultJson.put("uri", ctx.request().uri()); + + ctx.response().putHeader("Content-Type", "application/json; charset=utf-8").end(resultJson.encodePrettily()); + }); + + vertx.createHttpServer().requestHandler(router).listen(8080); + + startPromise.complete(); + } - startPromise.complete(); - } - - }); + }); } diff --git a/src/test/java/com/romanpierson/vertx/web/accesslogger/AcessLogServerTest.java b/src/test/java/com/romanpierson/vertx/web/accesslogger/AcessLogServerTest.java index 8640598..9a5bb59 100644 --- a/src/test/java/com/romanpierson/vertx/web/accesslogger/AcessLogServerTest.java +++ b/src/test/java/com/romanpierson/vertx/web/accesslogger/AcessLogServerTest.java @@ -30,16 +30,21 @@ class AcessLogServerTest { void testInvalidConfig(Vertx vertx, VertxTestContext testContext) { vertx.exceptionHandler(throwable -> { + throwable.printStackTrace(); assertTrue(throwable instanceof IllegalArgumentException); assertEquals("must specify at least one valid configuration", throwable.getMessage()); testContext.completeNow(); }); - vertx.deployVerticle(new AccessLoggerProducerVerticle(),testContext.succeeding(id -> { + vertx + .deployVerticle(new AccessLoggerProducerVerticle()) + .onComplete(testContext.succeeding(deploymentId -> { + vertx + .deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-invalid.yaml")) + .onComplete(testContext.succeedingThenComplete()); + })); - vertx.deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-invalid.yaml")); - - })); + } diff --git a/src/test/java/com/romanpierson/vertx/web/accesslogger/ConsoleAppenderTest.java b/src/test/java/com/romanpierson/vertx/web/accesslogger/ConsoleAppenderTest.java index 5f4872c..010a8b6 100644 --- a/src/test/java/com/romanpierson/vertx/web/accesslogger/ConsoleAppenderTest.java +++ b/src/test/java/com/romanpierson/vertx/web/accesslogger/ConsoleAppenderTest.java @@ -33,7 +33,6 @@ class ConsoleAppenderTest { void testInvalidConsoleAppenderWithMissingResolvedPatttern(Vertx vertx, VertxTestContext testContext) { vertx.exceptionHandler(throwable -> { - throwable.printStackTrace(); assertTrue(throwable instanceof AccessLoggerException); assertEquals("Failed to create appender with [com.romanpierson.vertx.web.accesslogger.appender.console.impl.ConsoleAppender]", throwable.getMessage()); Throwable internalCause = throwable.getCause().getCause(); @@ -42,11 +41,15 @@ void testInvalidConsoleAppenderWithMissingResolvedPatttern(Vertx vertx, VertxTes testContext.completeNow(); }); - vertx.deployVerticle(new AccessLoggerProducerVerticle(),testContext.succeeding(id -> { - - vertx.deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-invalid-console-appender.yaml")); - - })); + vertx + .deployVerticle(new AccessLoggerProducerVerticle()) + .onComplete(testContext.succeeding(deploymentId -> { + vertx + .deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-invalid-console-appender.yaml")) + .onComplete(testContext.succeedingThenComplete()); + })); + + } @Test @@ -60,33 +63,38 @@ void testWithValidData(Vertx vertx, VertxTestContext testContext) { testContext.failNow(throwable); }); - vertx.deployVerticle(new AccessLoggerProducerVerticle(),testContext.succeeding(id -> { - vertx.deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-console-appender-valid.yaml"), testContext.succeeding(id2 -> { + vertx + .deployVerticle(new AccessLoggerProducerVerticle()) + .onComplete(testContext.succeeding(deploymentId -> { + vertx + .deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-console-appender-valid.yaml")) + .onComplete(testContext.succeeding(deploymentId2 -> { - System.setOut(new PrintStream(catchingStream)); - - HttpClient client = vertx.createHttpClient(); - - // Just to fix github actions issue - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - // we dont care - } - - client - .request(HttpMethod.GET, 8080, "localhost", "/test") - .compose(req -> req.send().compose(HttpClientResponse::body)) - .onComplete(testContext.succeeding(buffer -> testContext.verify(() -> { + System.setOut(new PrintStream(catchingStream)); - assertEquals("/test\n", catchingStream.toString()); // Has a newline at the end.... - - System.setOut(originalStream); - - testContext.completeNow(); + HttpClient client = vertx.createHttpClient(); + + // Just to fix github actions issue + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // we dont care + } + + client + .request(HttpMethod.GET, 8080, "localhost", "/test") + .compose(req -> req.send().compose(HttpClientResponse::body)) + .onComplete(testContext.succeeding(buffer -> testContext.verify(() -> { - }))); - })); + assertEquals("/test\n", catchingStream.toString()); // Has a newline at the end.... + + System.setOut(originalStream); + + testContext.completeNow(); + + }))); + })); })); + } } diff --git a/src/test/java/com/romanpierson/vertx/web/accesslogger/ElasticSearchAppenderTest.java b/src/test/java/com/romanpierson/vertx/web/accesslogger/ElasticSearchAppenderTest.java index 77128b0..51cc1b6 100644 --- a/src/test/java/com/romanpierson/vertx/web/accesslogger/ElasticSearchAppenderTest.java +++ b/src/test/java/com/romanpierson/vertx/web/accesslogger/ElasticSearchAppenderTest.java @@ -39,11 +39,13 @@ void testInvalidElasticSearchAppenderWithMissingInstanceIdentifier(Vertx vertx, testContext.completeNow(); }); - vertx.deployVerticle(new AccessLoggerProducerVerticle(),testContext.succeeding(id -> { - - vertx.deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-elasticsearch-appender-invalid-instance.yaml")); - - })); + vertx + .deployVerticle(new AccessLoggerProducerVerticle()) + .onComplete(testContext.succeeding(deploymentId -> { + vertx + .deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-invalid-console-appender.yaml")) + .onComplete(testContext.succeedingThenComplete()); + })); } @Test @@ -58,11 +60,13 @@ void testInvalidElasticSearchAppenderWithMissingFieldNames(Vertx vertx, VertxTes testContext.completeNow(); }); - vertx.deployVerticle(new AccessLoggerProducerVerticle(),testContext.succeeding(id -> { - - vertx.deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-elasticsearch-appender-invalid-fieldnames.yaml")); - - })); + vertx + .deployVerticle(new AccessLoggerProducerVerticle()) + .onComplete(testContext.succeeding(deploymentId -> { + vertx + .deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-elasticsearch-appender-invalid-fieldnames.yaml")) + .onComplete(testContext.succeedingThenComplete()); + })); } @Test @@ -80,25 +84,31 @@ void testValid(Vertx vertx, VertxTestContext testContext) { testContext.completeNow(); }); - vertx.deployVerticle(new AccessLoggerProducerVerticle(),testContext.succeeding(id -> { - vertx.deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-elasticsearch-appender-valid.yaml"), testContext.succeeding(id2 -> { - - // Just to fix github actions issue - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - // we dont care - } - - HttpClient client = vertx.createHttpClient(); - - client - .request(HttpMethod.GET, 8080, "localhost", "/test") - .compose(req -> req.send().compose(HttpClientResponse::body)) - .onComplete(testContext.succeeding(buffer -> testContext.verify(() -> { + vertx + .deployVerticle(new AccessLoggerProducerVerticle()) + .onComplete(testContext.succeeding(deploymentId -> { + vertx + .deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-elasticsearch-appender-valid.yaml")) + .onComplete(testContext.succeeding(deploymentId2 -> { - }))); - })); - })); + // Just to fix github actions issue + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // we dont care + } + + HttpClient client = vertx.createHttpClient(); + + client + .request(HttpMethod.GET, 8080, "localhost", "/test") + .compose(req -> req.send().compose(HttpClientResponse::body)) + .onComplete(testContext.succeeding(buffer -> testContext.verify(() -> { + + }))); + + })); + })); + } } diff --git a/src/test/java/com/romanpierson/vertx/web/accesslogger/EventBusAppenderTest.java b/src/test/java/com/romanpierson/vertx/web/accesslogger/EventBusAppenderTest.java index 5b11d33..bf45d3c 100644 --- a/src/test/java/com/romanpierson/vertx/web/accesslogger/EventBusAppenderTest.java +++ b/src/test/java/com/romanpierson/vertx/web/accesslogger/EventBusAppenderTest.java @@ -38,11 +38,14 @@ void testInvalidConfig(Vertx vertx, VertxTestContext testContext) { testContext.completeNow(); }); - vertx.deployVerticle(new AccessLoggerProducerVerticle(),testContext.succeeding(id -> { - - vertx.deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-eventbus-appender-invalid-config.yaml")); - - })); + vertx + .deployVerticle(new AccessLoggerProducerVerticle()) + .onComplete(testContext.succeeding(deploymentId -> { + vertx + .deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-eventbus-appender-invalid-config.yaml")) + .onComplete(testContext.succeedingThenComplete()); + })); + } @Test @@ -53,25 +56,31 @@ void testWithNotExistingAdress(Vertx vertx, VertxTestContext testContext) { testContext.failNow(throwable); }); - vertx.deployVerticle(new AccessLoggerProducerVerticle(),testContext.succeeding(id -> { - vertx.deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-eventbus-appender-inexisting-address.yaml"), testContext.succeeding(id2 -> { - - HttpClient client = vertx.createHttpClient(); - - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - client - .request(HttpMethod.GET, 8080, "localhost", "/test") - .compose(req -> req.send().compose(HttpClientResponse::body)) - .onComplete(testContext.succeeding(buffer -> testContext.verify(() -> { - testContext.completeNow(); - }))); - })); - })); + vertx + .deployVerticle(new AccessLoggerProducerVerticle()) + .onComplete(testContext.succeeding(deploymentId -> { + vertx + .deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-eventbus-appender-inexisting-address.yaml")) + .onComplete(testContext.succeeding(deploymentId2 -> { + + HttpClient client = vertx.createHttpClient(); + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + client + .request(HttpMethod.GET, 8080, "localhost", "/test") + .compose(req -> req.send().compose(HttpClientResponse::body)) + .onComplete(testContext.succeeding(buffer -> testContext.verify(() -> { + testContext.completeNow(); + }))); + + })); + })); + } @Test @@ -88,25 +97,32 @@ void testWithExistingAdress(Vertx vertx, VertxTestContext testContext) { testContext.completeNow(); }); - vertx.deployVerticle(new AccessLoggerProducerVerticle(),testContext.succeeding(id -> { - vertx.deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-eventbus-appender-existing-address.yaml"), testContext.succeeding(id2 -> { - - HttpClient client = vertx.createHttpClient(); - - // Just to fix github actions issue - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - // we dont care - } - - client - .request(HttpMethod.GET, 8080, "localhost", "/test") - .compose(req -> req.send().compose(HttpClientResponse::body)) - .onComplete(testContext.succeeding(buffer -> testContext.verify(() -> { + vertx + .deployVerticle(new AccessLoggerProducerVerticle()) + .onComplete(testContext.succeeding(deploymentId -> { + vertx + .deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-eventbus-appender-existing-address.yaml")) + .onComplete(testContext.succeeding(deploymentId2 -> { - }))); - })); - })); + HttpClient client = vertx.createHttpClient(); + + // Just to fix github actions issue + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // we dont care + } + + client + .request(HttpMethod.GET, 8080, "localhost", "/test") + .compose(req -> req.send().compose(HttpClientResponse::body)) + .onComplete(testContext.succeeding(buffer -> testContext.verify(() -> { + + }))); + + })); + })); + + } } diff --git a/src/test/java/com/romanpierson/vertx/web/accesslogger/LoggingAppenderTest.java b/src/test/java/com/romanpierson/vertx/web/accesslogger/LoggingAppenderTest.java index 0dc15c6..6adf63d 100644 --- a/src/test/java/com/romanpierson/vertx/web/accesslogger/LoggingAppenderTest.java +++ b/src/test/java/com/romanpierson/vertx/web/accesslogger/LoggingAppenderTest.java @@ -44,11 +44,13 @@ void testInvalidConfig(Vertx vertx, VertxTestContext testContext) { testContext.completeNow(); }); - vertx.deployVerticle(new AccessLoggerProducerVerticle(),testContext.succeeding(id -> { - - vertx.deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-logging-appender-invalid-loggername.yaml")); - - })); + vertx + .deployVerticle(new AccessLoggerProducerVerticle()) + .onComplete(testContext.succeeding(deploymentId -> { + vertx + .deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-logging-appender-invalid-loggername.yaml")) + .onComplete(testContext.succeedingThenComplete()); + })); } @Test @@ -68,11 +70,13 @@ void testInvalidLoggingAppenderWithMissingResolvedPatttern(Vertx vertx, VertxTes testContext.completeNow(); }); - vertx.deployVerticle(new AccessLoggerProducerVerticle(),testContext.succeeding(id -> { - - vertx.deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-logging-appender-invalid-logpattern.yaml")); - - })); + vertx + .deployVerticle(new AccessLoggerProducerVerticle()) + .onComplete(testContext.succeeding(deploymentId -> { + vertx + .deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-logging-appender-invalid-logpattern.yaml")) + .onComplete(testContext.succeedingThenComplete()); + })); } // TODO this test needs to be fixed - need to check how the message written by logback can be read and verified @@ -87,40 +91,46 @@ void testWithValidData(Vertx vertx, VertxTestContext testContext) { testContext.failNow(throwable); }); - vertx.deployVerticle(new AccessLoggerProducerVerticle(),testContext.succeeding(id -> { - vertx.deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-logging-appender-valid.yaml"), testContext.succeeding(id2 -> { - - // Just to fix github actions issue - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - // we dont care - } - - System.setOut(new PrintStream(catchingStream)); - - HttpClient client = vertx.createHttpClient(); - - client - .request(HttpMethod.GET, 8080, "localhost", "/test") - .compose(req -> req.send().compose(HttpClientResponse::body)) - .onComplete(testContext.succeeding(buffer -> testContext.verify(() -> { - - // Ensure it got logged by slf4j/logback - Thread.sleep(1000); - - //assertEquals("/test\n", catchingStream.toString()); - - System.setOut(originalStream); - - - //System.out.println(catchingStream); - //assertEquals("/test", catchingStream.toString()); - - testContext.completeNow(); - - }))); - })); - })); + vertx + .deployVerticle(new AccessLoggerProducerVerticle()) + .onComplete(testContext.succeeding(deploymentId -> { + vertx + .deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-logging-appender-valid.yaml")) + .onComplete(testContext.succeeding(deploymentId2 -> { + + // Just to fix github actions issue + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // we dont care + } + + System.setOut(new PrintStream(catchingStream)); + + HttpClient client = vertx.createHttpClient(); + + client + .request(HttpMethod.GET, 8080, "localhost", "/test") + .compose(req -> req.send().compose(HttpClientResponse::body)) + .onComplete(testContext.succeeding(buffer -> testContext.verify(() -> { + + // Ensure it got logged by slf4j/logback + Thread.sleep(1000); + + //assertEquals("/test\n", catchingStream.toString()); + + System.setOut(originalStream); + + + //System.out.println(catchingStream); + //assertEquals("/test", catchingStream.toString()); + + testContext.completeNow(); + + }))); + + })); + })); + } } diff --git a/src/test/java/com/romanpierson/vertx/web/accesslogger/configuration/pattern/PatternResolverTest.java b/src/test/java/com/romanpierson/vertx/web/accesslogger/configuration/pattern/PatternResolverTest.java index 8d5c2f4..3fa968d 100644 --- a/src/test/java/com/romanpierson/vertx/web/accesslogger/configuration/pattern/PatternResolverTest.java +++ b/src/test/java/com/romanpierson/vertx/web/accesslogger/configuration/pattern/PatternResolverTest.java @@ -22,7 +22,7 @@ public class PatternResolverTest { - //@Test + @Test public void resolvePattern_off_the_shelf_pattern() { PatternResolver patternResolver = new PatternResolver(); String logPattern = "server1 %{server1}static %{Accept-Encoding}i %t %D cs-uri %{foo}C"; @@ -36,7 +36,7 @@ public void resolvePattern_off_the_shelf_pattern() { assertResolvedPatterns(expected, actual); } - //@Test + @Test public void resolvePattern_single_pattern_element() { PatternResolver patternResolver = new PatternResolver(); String logPattern = "%m"; @@ -48,7 +48,7 @@ public void resolvePattern_single_pattern_element() { assertResolvedPatterns(expected, actual); } - //@Test + @Test public void resolvePattern_two_pattern_elements() { PatternResolver patternResolver = new PatternResolver(); String logPattern = "%D %m"; @@ -60,7 +60,7 @@ public void resolvePattern_two_pattern_elements() { assertResolvedPatterns(expected, actual); } - //@Test + @Test public void resolvePattern_two_pattern_elements_reversed_order() { PatternResolver patternResolver = new PatternResolver(); String logPattern = "%m %D"; @@ -72,7 +72,7 @@ public void resolvePattern_two_pattern_elements_reversed_order() { assertResolvedPatterns(expected, actual); } - //@Test + @Test public void resolvePattern_duplicate_pattern_elements() { PatternResolver patternResolver = new PatternResolver(); String logPattern = "%s %s %s"; @@ -84,7 +84,7 @@ public void resolvePattern_duplicate_pattern_elements() { assertResolvedPatterns(expected, actual); } - //@Test + @Test public void resolvePattern_unresolvable_parts() { PatternResolver patternResolver = new PatternResolver(); String logPattern = "xx %m yy"; diff --git a/src/test/java/com/romanpierson/vertx/web/accesslogger/element/ElementTest.java b/src/test/java/com/romanpierson/vertx/web/accesslogger/element/ElementTest.java index f2f1974..1e89f3c 100644 --- a/src/test/java/com/romanpierson/vertx/web/accesslogger/element/ElementTest.java +++ b/src/test/java/com/romanpierson/vertx/web/accesslogger/element/ElementTest.java @@ -4,6 +4,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.PrintStream; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -11,6 +13,8 @@ import com.romanpierson.vertx.web.accesslogger.verticle.AccessLoggerProducerVerticle; import io.vertx.core.Vertx; +import io.vertx.core.http.HttpClient; +import io.vertx.core.http.HttpClientResponse; import io.vertx.core.http.HttpMethod; import io.vertx.core.json.JsonArray; import io.vertx.ext.web.client.WebClient; @@ -45,26 +49,33 @@ void testWithEmptyResponse(Vertx vertx, VertxTestContext testContext) { testContext.completeNow(); }); - vertx.deployVerticle(new AccessLoggerProducerVerticle(),testContext.succeeding(id -> { - vertx.deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-elements-empty-result.yaml"), testContext.succeeding(id2 -> { - - WebClient client = WebClient.create(vertx); - - // Just to fix github actions issue - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - // we dont care - } - - client - .request(HttpMethod.GET, 8080, "localhost", "/empty") - .send() - .onComplete(testContext.succeeding(buffer -> testContext.verify(() -> { - - }))); - })); - })); + vertx + .deployVerticle(new AccessLoggerProducerVerticle()) + .onComplete(testContext.succeeding(deploymentId -> { + vertx + .deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-elements-empty-result.yaml")) + .onComplete(testContext.succeeding(deploymentId2 -> { + + WebClient client = WebClient.create(vertx); + + // Just to fix github actions issue + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // we dont care + } + + client + .request(HttpMethod.GET, 8080, "localhost", "/empty") + .send() + .onComplete(testContext.succeeding(buffer -> testContext.verify(() -> { + + }))); + + })); + })); + + } /** @@ -85,9 +96,7 @@ void testWithNonEmptyResponse(Vertx vertx, VertxTestContext testContext) { vertx.eventBus().consumer("target", message -> { - //System.out.println(message.body()); - - assertEquals(30, message.body().size()); + assertEquals(32, message.body().size()); assertEquals("33", message.body().getString(0)); assertEquals("33", message.body().getString(1)); @@ -113,38 +122,46 @@ void testWithNonEmptyResponse(Vertx vertx, VertxTestContext testContext) { assertEquals("xy", message.body().getString(21)); assertEquals("envVal1", message.body().getString(22)); assertEquals("header1val", message.body().getString(23)); - assertEquals("", message.body().getString(24)); - assertEquals("application/json; charset=utf-8", message.body().getString(25)); - assertEquals("", message.body().getString(26)); - assertEquals("cookie1Value", message.body().getString(27)); - assertEquals("cookie2Value", message.body().getString(28)); - assertEquals("", message.body().getString(29)); + assertEquals("header1val", message.body().getString(24)); + assertEquals("", message.body().getString(25)); + assertEquals("application/json; charset=utf-8", message.body().getString(26)); + assertEquals("application/json; charset=utf-8", message.body().getString(27)); + assertEquals("", message.body().getString(28)); + assertEquals("cookie1Value", message.body().getString(29)); + assertEquals("cookie2Value", message.body().getString(30)); + assertEquals("", message.body().getString(31)); testContext.completeNow(); }); - vertx.deployVerticle(new AccessLoggerProducerVerticle(),testContext.succeeding(id -> { - vertx.deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-elements-result.yaml"), testContext.succeeding(id2 -> { - - WebClient client = WebClient.create(vertx); - - // Just to fix github actions issue - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - // we dont care - } - - client - .request(HttpMethod.GET, 8080, "localhost", "/nonEmpty?foo=bar") - .putHeader("header1", "header1val") - .putHeader("Cookie", "cookie1=cookie1Value; cookie2=cookie2Value") - .send() - .onComplete(testContext.succeeding(buffer -> testContext.verify(() -> { + vertx + .deployVerticle(new AccessLoggerProducerVerticle()) + .onComplete(testContext.succeeding(deploymentId -> { + vertx + .deployVerticle(new SimpleJsonResponseVerticle("accesslog-config-elements-result.yaml")) + .onComplete(testContext.succeeding(deploymentId2 -> { + + WebClient client = WebClient.create(vertx); - }))); - })); - })); + // Just to fix github actions issue + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // we dont care + } + + client + .request(HttpMethod.GET, 8080, "localhost", "/nonEmpty?foo=bar") + .putHeader("header1", "header1val") + .putHeader("Cookie", "cookie1=cookie1Value; cookie2=cookie2Value") + .send() + .onComplete(testContext.succeeding(buffer -> testContext.verify(() -> { + + }))); + + })); + })); + } } diff --git a/src/test/resources/accesslog-config-elements-result.yaml b/src/test/resources/accesslog-config-elements-result.yaml index ecea71c..c3e2b84 100644 --- a/src/test/resources/accesslog-config-elements-result.yaml +++ b/src/test/resources/accesslog-config-elements-result.yaml @@ -1,7 +1,7 @@ isAutoDeployProducerVerticle: false configurations: - identifier: accesslog-formatted - logPattern: '%b %B %D %T sc-status %s %H %h %v %p cs-method %m %r cs-uri %U cs-uri-stem %q cs-uri-query %t %{msec}t %x %{xy}static %{envVar1}env %{header1}i %{header2}i %{Content-Type}o %{header3}o %{cookie1}C %{cookie2}C %{cookieFoo}C' + logPattern: '%b %B %D %T sc-status %s %H %h %v %p cs-method %m %r cs-uri %U cs-uri-stem %q cs-uri-query %t %{msec}t %x %{xy}static %{envVar1}env %{header1}i %{heADeR1}i %{header2}i %{Content-Type}o %{CoNTent-tyPe}o %{header3}o %{cookie1}C %{cookie2}C %{cookieFoo}C' appenders: - appenderClassName : com.romanpierson.vertx.web.accesslogger.appender.eventbus.impl.EventBusAppender config: