diff --git a/README.md b/README.md index f94f6a4..aa766b0 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,15 @@ x-xss-protection: 1; mode=block ] ``` +# Performance + +``` +Benchmark Mode Cnt Score Error Units +NormalizedFeignLoggerBenchmarkTest.testFeignWithoutLogger thrpt 25 16281.625 ± 279.774 ops/s +NormalizedFeignLoggerBenchmarkTest.testNormalizedFeignLogger thrpt 25 6081.675 ± 229.912 ops/s +NormalizedFeignLoggerBenchmarkTest.testSlf4jFeignLogger thrpt 25 16593.059 ± 151.327 ops/s +``` + # How to use In order to use Normalized Logger into the application they must the following. diff --git a/logger-testing/pom.xml b/logger-testing/pom.xml new file mode 100644 index 0000000..552a38b --- /dev/null +++ b/logger-testing/pom.xml @@ -0,0 +1,91 @@ + + + + me.bvn13.openfeign.logger + feign-normalized-logger + 0.1.5-SNAPSHOT + + 4.0.0 + + me.bvn13.openfeign.logger.test + logger-testing + + + 17 + 17 + UTF-8 + + + + + me.bvn13.openfeign.logger + feign-normalized-logger + 0.1.4 + test + + + org.slf4j + slf4j-api + ${slf4j.version} + test + + + org.slf4j + slf4j-jdk14 + ${slf4j.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + + org.eclipse.jetty + jetty-server + ${jetty-server.version} + test + + + org.eclipse.jetty + jetty-servlet + ${jetty-server.version} + test + + + org.openjdk.jmh + jmh-core + ${jmh.version} + test + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + test + + + io.github.openfeign + feign-core + ${feign.version} + test + + + io.github.openfeign + feign-gson + ${feign.version} + test + + + io.github.openfeign + feign-slf4j + ${feign.version} + test + + + + \ No newline at end of file diff --git a/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLoggerBenchmarkTest.java b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLoggerBenchmarkTest.java new file mode 100644 index 0000000..783dafd --- /dev/null +++ b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLoggerBenchmarkTest.java @@ -0,0 +1,107 @@ +package me.bvn13.openfeign.logger.normalized; + +import feign.Feign; +import feign.Logger; +import feign.gson.GsonDecoder; +import feign.slf4j.Slf4jLogger; +import org.junit.jupiter.api.Assertions; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; +import org.openjdk.jmh.annotations.Warmup; + +import static me.bvn13.openfeign.logger.normalized.TestJettyServer.PORT; + +public class NormalizedFeignLoggerBenchmarkTest { + @State(Scope.Benchmark) + public static class BenchmarkStateWithoutLogging { + TestJettyServer jettyServer; + TestFeignClient feignClient; + + @Setup + public void init() { + jettyServer = new TestJettyServer(); + jettyServer.start(); + feignClient = Feign.builder() + .decoder(new GsonDecoder()) + .target(TestFeignClient.class, "http://localhost:" + PORT); + } + + @TearDown + public void tearDown() { + jettyServer.stop(); + } + } + + @State(Scope.Benchmark) + public static class BenchmarkStateWithSlf4jLogging { + TestJettyServer jettyServer; + TestFeignClient feignClient; + + @Setup + public void init() { + jettyServer = new TestJettyServer(); + jettyServer.start(); + feignClient = Feign.builder() + .logger(new Slf4jLogger()) + .logLevel(Logger.Level.FULL) + .decoder(new GsonDecoder()) + .target(TestFeignClient.class, "http://localhost:" + PORT); + } + + @TearDown + public void tearDown() { + jettyServer.stop(); + } + } + + @State(Scope.Benchmark) + public static class BenchmarkStateWithNormalizedLogging { + TestJettyServer jettyServer; + TestFeignClient feignClient; + + @Setup + public void init() { + jettyServer = new TestJettyServer(); + jettyServer.start(); + feignClient = Feign.builder() + .logger(new NormalizedFeignLogger()) + .logLevel(Logger.Level.FULL) + .decoder(new GsonDecoder()) + .target(TestFeignClient.class, "http://localhost:" + PORT); + } + + @TearDown + public void tearDown() { + jettyServer.stop(); + } + } + + @Benchmark + @Warmup(iterations = 3) + public void testFeignLogger(BenchmarkStateWithoutLogging benchmarkState) { + final ResponseDto status = benchmarkState.feignClient.getStatus(); + Assertions.assertEquals("ok", status.getStatus()); + } + + @Benchmark + @Warmup(iterations = 3) + public void testSlf4jFeignLogger(BenchmarkStateWithSlf4jLogging benchmarkState) { + final ResponseDto status = benchmarkState.feignClient.getStatus(); + Assertions.assertEquals("ok", status.getStatus()); + } + + @Benchmark + @Warmup(iterations = 3) + public void testNormalizedFeignLogger(BenchmarkStateWithNormalizedLogging benchmarkState) { + final ResponseDto status = benchmarkState.feignClient.getStatus(); + Assertions.assertEquals("ok", status.getStatus()); + } + + public static void main(String[] args) throws Exception { + org.openjdk.jmh.Main.main(args); + } + +} diff --git a/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/ResponseDto.java b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/ResponseDto.java new file mode 100644 index 0000000..0306821 --- /dev/null +++ b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/ResponseDto.java @@ -0,0 +1,15 @@ +package me.bvn13.openfeign.logger.normalized; + +public class ResponseDto { + + private String status; + + public String getStatus() { + return status; + } + + public ResponseDto setStatus(String status) { + this.status = status; + return this; + } +} diff --git a/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestBlockingServlet.java b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestBlockingServlet.java new file mode 100644 index 0000000..bf111f3 --- /dev/null +++ b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestBlockingServlet.java @@ -0,0 +1,19 @@ +package me.bvn13.openfeign.logger.normalized; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; + +public class TestBlockingServlet extends HttpServlet { + + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + response.setContentType("application/json"); + response.setStatus(HttpServletResponse.SC_OK); + response.getWriter().println("{ \"status\": \"ok\"}"); + } + +} diff --git a/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestFeignClient.java b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestFeignClient.java new file mode 100644 index 0000000..7e4088d --- /dev/null +++ b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestFeignClient.java @@ -0,0 +1,11 @@ +package me.bvn13.openfeign.logger.normalized; + + +import feign.RequestLine; + +public interface TestFeignClient { + + @RequestLine("GET /status") + ResponseDto getStatus(); + +} diff --git a/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestJettyServer.java b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestJettyServer.java new file mode 100644 index 0000000..985bc82 --- /dev/null +++ b/logger-testing/src/test/java/me/bvn13/openfeign/logger/normalized/TestJettyServer.java @@ -0,0 +1,51 @@ +package me.bvn13.openfeign.logger.normalized; + +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.servlet.ServletHandler; + +public class TestJettyServer { + + public static final int PORT = 8090; + private Server server; + + public TestJettyServer() { + server = new Server(); + ServerConnector connector = new ServerConnector(server); + connector.setPort(PORT); + server.setConnectors(new Connector[] {connector}); + } + + public void start() { + ServletHandler servletHandler = new ServletHandler(); + server.setHandler(servletHandler); + servletHandler.addServletWithMapping(TestBlockingServlet.class, "/status"); + new Thread(() -> { + try { + server.start(); + } catch (Exception e) { + throw new RuntimeException(e); + } + }).start(); + } + + public void stop() { + try { + server.stop(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static void main(String[] args) { + TestJettyServer jettyServer; + jettyServer = new TestJettyServer(); + try { + jettyServer.start(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + +} diff --git a/logger/pom.xml b/logger/pom.xml new file mode 100644 index 0000000..8f40c97 --- /dev/null +++ b/logger/pom.xml @@ -0,0 +1,35 @@ + + + + me.bvn13.openfeign.logger + feign-normalized-logger + 0.1.5-SNAPSHOT + + 4.0.0 + + logger + + + 1.8 + 1.8 + UTF-8 + + + + + io.github.openfeign + feign-core + ${feign.version} + provided + + + org.slf4j + slf4j-api + ${slf4j.version} + provided + + + + \ No newline at end of file diff --git a/src/main/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLogger.java b/logger/src/main/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLogger.java similarity index 98% rename from src/main/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLogger.java rename to logger/src/main/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLogger.java index 3fc388f..255f3ac 100644 --- a/src/main/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLogger.java +++ b/logger/src/main/java/me/bvn13/openfeign/logger/normalized/NormalizedFeignLogger.java @@ -18,7 +18,7 @@ import java.util.concurrent.ConcurrentHashMap; *
  * {@code
  *
- * normalized feign request (HERE-IS-CLASS-AND-METHOD): [
+ * Normalized feign request (HERE-ARE-CLASS-AND-METHOD): [
  *
  * ] has response [
  *
diff --git a/pom.xml b/pom.xml
index 54bcb27..24fa613 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,12 @@
     feign-normalized-logger
     0.1.5-SNAPSHOT
 
-    jar
+    
+        logger
+        logger-testing
+    
+
+    pom
 
     OpenFeign Normalized Logger
     Normalized Logger for OpenFeign
@@ -42,8 +47,13 @@
         1.6.13
         1.6
         1.18.0
-    
 
+        
+        5.9.0
+        11.0.11
+        1.35
+        4.5.13
+    
 
     
         
@@ -53,28 +63,6 @@
         
     
 
-    
-        
-            io.github.openfeign
-            feign-core
-            ${feign.version}
-            provided
-        
-        
-            org.slf4j
-            slf4j-api
-            ${slf4j.version}
-            provided
-        
-
-        
-            junit
-            junit
-            4.12
-            test
-        
-    
-
     
         feign-normalized-logger