Browse Source

Upgrade vertx-web to represent the current library versions + API (#5805)

Signed-off-by: Paulo Lopes <[email protected]>
Paulo Lopes 5 years ago
parent
commit
4418a52de1

+ 28 - 11
frameworks/Java/vertx-web/pom.xml

@@ -7,7 +7,7 @@
 
 
   <groupId>io.vertx</groupId>
   <groupId>io.vertx</groupId>
   <artifactId>vertx-web-benchmark</artifactId>
   <artifactId>vertx-web-benchmark</artifactId>
-  <version>3.7.0</version>
+  <version>3.9.0</version>
 
 
   <properties>
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -46,14 +46,13 @@
     </dependency>
     </dependency>
 
 
     <dependency>
     <dependency>
-      <groupId>io.reactiverse</groupId>
-      <artifactId>reactive-pg-client</artifactId>
-      <version>0.11.3</version>
+      <groupId>io.vertx</groupId>
+      <artifactId>vertx-pg-client</artifactId>
     </dependency>
     </dependency>
 
 
     <dependency>
     <dependency>
       <groupId>io.vertx</groupId>
       <groupId>io.vertx</groupId>
-      <artifactId>vertx-web-templ-handlebars</artifactId>
+      <artifactId>vertx-web-templ-rocker</artifactId>
     </dependency>
     </dependency>
 
 
     <dependency>
     <dependency>
@@ -77,7 +76,7 @@
     <dependency>
     <dependency>
       <groupId>com.fasterxml.jackson.module</groupId>
       <groupId>com.fasterxml.jackson.module</groupId>
       <artifactId>jackson-module-afterburner</artifactId>
       <artifactId>jackson-module-afterburner</artifactId>
-      <version>2.9.9</version>
+      <version>2.10.2</version>
     </dependency>
     </dependency>
 
 
     <dependency>
     <dependency>
@@ -103,12 +102,30 @@
       </plugins>
       </plugins>
     </pluginManagement>
     </pluginManagement>
 
 
-    <!--
-    You only need the part below if you want to build your application into a fat executable jar.
-    This is a jar that contains all the dependencies required to run it, so you can just run it with
-    java -jar
-    -->
     <plugins>
     <plugins>
+      <plugin>
+        <groupId>com.fizzed</groupId>
+        <artifactId>rocker-maven-plugin</artifactId>
+        <version>1.3.0</version>
+        <executions>
+          <execution>
+            <id>generate-rocker-templates</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>generate</goal>
+            </goals>
+            <configuration>
+              <templateDirectory>${project.basedir}/src/main/resources</templateDirectory>
+              <optimize>true</optimize>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <!--
+      You only need the part below if you want to build your application into a fat executable jar.
+      This is a jar that contains all the dependencies required to run it, so you can just run it with
+      java -jar
+      -->
       <plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-shade-plugin</artifactId>
         <artifactId>maven-shade-plugin</artifactId>

+ 39 - 28
frameworks/Java/vertx-web/src/main/java/io/vertx/benchmark/App.java

@@ -6,7 +6,6 @@ import com.github.susom.database.ConfigFrom;
 import com.github.susom.database.DatabaseProviderVertx;
 import com.github.susom.database.DatabaseProviderVertx;
 import com.github.susom.database.DatabaseProviderVertx.Builder;
 import com.github.susom.database.DatabaseProviderVertx.Builder;
 import com.github.susom.database.SqlInsert;
 import com.github.susom.database.SqlInsert;
-import io.reactiverse.pgclient.*;
 import io.vertx.benchmark.model.Fortune;
 import io.vertx.benchmark.model.Fortune;
 import io.vertx.benchmark.model.Message;
 import io.vertx.benchmark.model.Message;
 import io.vertx.benchmark.model.World;
 import io.vertx.benchmark.model.World;
@@ -17,7 +16,10 @@ import io.vertx.core.json.JsonObject;
 import io.vertx.ext.mongo.MongoClient;
 import io.vertx.ext.mongo.MongoClient;
 import io.vertx.ext.web.Router;
 import io.vertx.ext.web.Router;
 import io.vertx.ext.web.RoutingContext;
 import io.vertx.ext.web.RoutingContext;
-import io.vertx.ext.web.templ.handlebars.HandlebarsTemplateEngine;
+import io.vertx.ext.web.templ.rocker.RockerTemplateEngine;
+import io.vertx.pgclient.PgConnectOptions;
+import io.vertx.pgclient.PgPool;
+import io.vertx.sqlclient.*;
 
 
 import java.time.ZonedDateTime;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatter;
@@ -40,7 +42,7 @@ public class App extends AbstractVerticle {
 
 
     private final MongoClient database;
     private final MongoClient database;
     // In order to use a template we first need to create an engine
     // In order to use a template we first need to create an engine
-    private final HandlebarsTemplateEngine engine;
+    private final RockerTemplateEngine engine;
 
 
     public MongoDBBenchmark(Vertx vertx, JsonObject config) {
     public MongoDBBenchmark(Vertx vertx, JsonObject config) {
       final JsonObject mongoConfig = config.copy();
       final JsonObject mongoConfig = config.copy();
@@ -50,7 +52,7 @@ public class App extends AbstractVerticle {
       mongoConfig.remove("password");
       mongoConfig.remove("password");
 
 
       this.database = MongoClient.createShared(vertx, mongoConfig);
       this.database = MongoClient.createShared(vertx, mongoConfig);
-      this.engine = HandlebarsTemplateEngine.create(vertx);
+      this.engine = RockerTemplateEngine.create();
     }
     }
 
 
     public final void dbHandler(final RoutingContext ctx) {
     public final void dbHandler(final RoutingContext ctx) {
@@ -121,7 +123,7 @@ public class App extends AbstractVerticle {
         ctx.put("fortunes", fortunes);
         ctx.put("fortunes", fortunes);
 
 
         // and now delegate to the engine to render it.
         // and now delegate to the engine to render it.
-        engine.render(ctx.data(), "templates/fortunes.hbs", res -> {
+        engine.render(ctx.data(), "templates/Fortunes.rocker.html", res -> {
           if (res.succeeded()) {
           if (res.succeeded()) {
             ctx.response()
             ctx.response()
                 .putHeader(HttpHeaders.SERVER, SERVER)
                 .putHeader(HttpHeaders.SERVER, SERVER)
@@ -192,27 +194,30 @@ public class App extends AbstractVerticle {
     private static final String SELECT_WORLD = "SELECT id, randomnumber from WORLD where id=$1";
     private static final String SELECT_WORLD = "SELECT id, randomnumber from WORLD where id=$1";
     private static final String SELECT_FORTUNE = "SELECT id, message from FORTUNE";
     private static final String SELECT_FORTUNE = "SELECT id, message from FORTUNE";
 
 
-    private final PgClient client;
+    private final PgPool client;
 
 
     // In order to use a template we first need to create an engine
     // In order to use a template we first need to create an engine
-    private final HandlebarsTemplateEngine engine;
+    private final RockerTemplateEngine engine;
 
 
     public PgClientBenchmark(Vertx vertx, JsonObject config) {
     public PgClientBenchmark(Vertx vertx, JsonObject config) {
-      PgPoolOptions options = new PgPoolOptions();
-      options.setDatabase(config.getString("database"));
-      options.setHost(config.getString("host"));
-      options.setPort(config.getInteger("port", 5432));
-      options.setUser(config.getString("username"));
-      options.setPassword(config.getString("password"));
-      options.setCachePreparedStatements(true);
-      client = PgClient.pool(vertx, new PgPoolOptions(options).setMaxSize(4));
-      this.engine = HandlebarsTemplateEngine.create(vertx);
+      PgConnectOptions options = new PgConnectOptions()
+        .setCachePreparedStatements(true)
+        .setHost(config.getString("host"))
+        .setPort(config.getInteger("port", 5432))
+        .setUser(config.getString("username"))
+        .setPassword(config.getString("password"))
+        .setDatabase(config.getString("database"));
+
+      client = PgPool.pool(vertx, options, new PoolOptions().setMaxSize(4));
+      this.engine = RockerTemplateEngine.create();
     }
     }
 
 
     public final void dbHandler(final RoutingContext ctx) {
     public final void dbHandler(final RoutingContext ctx) {
-      client.preparedQuery(SELECT_WORLD, Tuple.of(randomWorld()), res -> {
+      client
+        .preparedQuery(SELECT_WORLD)
+        .execute(Tuple.of(randomWorld()), res -> {
         if (res.succeeded()) {
         if (res.succeeded()) {
-          final PgIterator resultSet = res.result().iterator();
+          final RowIterator<Row> resultSet = res.result().iterator();
           if (!resultSet.hasNext()) {
           if (!resultSet.hasNext()) {
             ctx.response()
             ctx.response()
               .setStatusCode(404)
               .setStatusCode(404)
@@ -226,6 +231,7 @@ public class App extends AbstractVerticle {
             .putHeader(HttpHeaders.CONTENT_TYPE, "application/json")
             .putHeader(HttpHeaders.CONTENT_TYPE, "application/json")
             .end(Json.encodeToBuffer(new World(row.getInteger(0), row.getInteger(1))));
             .end(Json.encodeToBuffer(new World(row.getInteger(0), row.getInteger(1))));
         } else {
         } else {
+          res.cause().printStackTrace();
           ctx.fail(res.cause());
           ctx.fail(res.cause());
         }
         }
       });
       });
@@ -239,7 +245,7 @@ public class App extends AbstractVerticle {
       final int[] cnt = { 0 };
       final int[] cnt = { 0 };
 
 
       for (int i = 0; i < queries; i++) {
       for (int i = 0; i < queries; i++) {
-        client.preparedQuery(SELECT_WORLD, Tuple.of(randomWorld()), res -> {
+        client.preparedQuery(SELECT_WORLD).execute(Tuple.of(randomWorld()), res -> {
           if (!failed[0]) {
           if (!failed[0]) {
             if (res.failed()) {
             if (res.failed()) {
               failed[0] = true;
               failed[0] = true;
@@ -266,9 +272,9 @@ public class App extends AbstractVerticle {
 
 
     public final void fortunesHandler(final RoutingContext ctx) {
     public final void fortunesHandler(final RoutingContext ctx) {
 
 
-      client.preparedQuery(SELECT_FORTUNE, ar -> {
+      client.preparedQuery(SELECT_FORTUNE).execute(ar -> {
           if (ar.succeeded()) {
           if (ar.succeeded()) {
-            final PgIterator resultSet = ar.result().iterator();
+            final RowIterator<Row> resultSet = ar.result().iterator();
             if (!resultSet.hasNext()) {
             if (!resultSet.hasNext()) {
               ctx.fail(404);
               ctx.fail(404);
               return;
               return;
@@ -287,7 +293,7 @@ public class App extends AbstractVerticle {
             ctx.put("fortunes", fortunes);
             ctx.put("fortunes", fortunes);
 
 
             // and now delegate to the engine to render it.
             // and now delegate to the engine to render it.
-            engine.render(ctx.data(), "templates/fortunes.hbs", res -> {
+            engine.render(ctx.data(), "templates/Fortunes.rocker.html", res -> {
               if (res.succeeded()) {
               if (res.succeeded()) {
                 ctx.response()
                 ctx.response()
                         .putHeader(HttpHeaders.SERVER, SERVER)
                         .putHeader(HttpHeaders.SERVER, SERVER)
@@ -313,7 +319,7 @@ public class App extends AbstractVerticle {
 
 
          for (int i = 0; i < worlds.length; i++) {
          for (int i = 0; i < worlds.length; i++) {
            int id = randomWorld();
            int id = randomWorld();
-           client.preparedQuery(SELECT_WORLD, Tuple.of(id), ar2 -> {
+           client.preparedQuery(SELECT_WORLD).execute(Tuple.of(id), ar2 -> {
              if (!failed[0]) {
              if (!failed[0]) {
                if (ar2.failed()) {
                if (ar2.failed()) {
                  failed[0] = true;
                  failed[0] = true;
@@ -332,7 +338,7 @@ public class App extends AbstractVerticle {
                    batch.add(Tuple.of(world.getRandomNumber(), world.getId()));
                    batch.add(Tuple.of(world.getRandomNumber(), world.getId()));
                  }
                  }
 
 
-                 client.preparedBatch(UPDATE_WORLD, batch, ar3 -> {
+                 client.preparedQuery(UPDATE_WORLD).executeBatch(batch, ar3 -> {
                    if (ar3.failed()) {
                    if (ar3.failed()) {
                      ctx.fail(ar3.cause());
                      ctx.fail(ar3.cause());
                      return;
                      return;
@@ -358,7 +364,7 @@ public class App extends AbstractVerticle {
     private final Builder dbBuilder;
     private final Builder dbBuilder;
 
 
     // In order to use a template we first need to create an engine
     // In order to use a template we first need to create an engine
-    private final HandlebarsTemplateEngine engine;
+    private final RockerTemplateEngine engine;
 
 
     DatabaseSqlBenchmark(Vertx vertx, JsonObject jsonConfig) {
     DatabaseSqlBenchmark(Vertx vertx, JsonObject jsonConfig) {
       Config config = ConfigFrom.firstOf().custom(jsonConfig::getString)
       Config config = ConfigFrom.firstOf().custom(jsonConfig::getString)
@@ -368,7 +374,7 @@ public class App extends AbstractVerticle {
           .value("database.url", "jdbc:postgresql://" + jsonConfig.getString("host") + "/" + jsonConfig.getString("database"))
           .value("database.url", "jdbc:postgresql://" + jsonConfig.getString("host") + "/" + jsonConfig.getString("database"))
           .get();
           .get();
       dbBuilder = DatabaseProviderVertx.pooledBuilder(vertx, config);
       dbBuilder = DatabaseProviderVertx.pooledBuilder(vertx, config);
-      engine = HandlebarsTemplateEngine.create(vertx);
+      engine = RockerTemplateEngine.create();
     }
     }
 
 
     void dbHandler(final RoutingContext ctx) {
     void dbHandler(final RoutingContext ctx) {
@@ -436,7 +442,7 @@ public class App extends AbstractVerticle {
             ctx.fail(404);
             ctx.fail(404);
           } else {
           } else {
             ctx.put("fortunes", call.result());
             ctx.put("fortunes", call.result());
-            engine.render(ctx.data(), "templates/fortunes.hbs", res -> {
+            engine.render(ctx.data(), "templates/Fortunes.rocker.html", res -> {
               if (res.succeeded()) {
               if (res.succeeded()) {
                 ctx.response()
                 ctx.response()
                     .putHeader(HttpHeaders.SERVER, SERVER)
                     .putHeader(HttpHeaders.SERVER, SERVER)
@@ -568,6 +574,11 @@ public class App extends AbstractVerticle {
           .end("Hello, World!");
           .end("Hello, World!");
     });
     });
 
 
-    vertx.createHttpServer().requestHandler(app::accept).listen(8080);
+    vertx.createHttpServer().requestHandler(app).listen(8080, listen -> {
+      if (listen.failed()) {
+        listen.cause().printStackTrace();
+        System.exit(1);
+      }
+    });
   }
   }
 }
 }

+ 21 - 0
frameworks/Java/vertx-web/src/main/resources/templates/Fortunes.rocker.html

@@ -0,0 +1,21 @@
+@import java.util.*
+@import io.vertx.benchmark.model.*
+@args(List fortunes)
+<!DOCTYPE html>
+<html>
+<head><title>Fortunes</title></head>
+<body>
+<table>
+    <tr>
+        <th>id</th>
+        <th>message</th>
+    </tr>
+    @for ((ForIterator i, Fortune fortune) : fortunes) {
+    <tr>
+        <td>@fortune.getId()</td>
+        <td>@fortune.getMessage()</td>
+    </tr>
+    }
+</table>
+</body>
+</html>

+ 1 - 1
frameworks/Java/vertx-web/vertx-web-mongodb.dockerfile

@@ -18,7 +18,7 @@ CMD java \
     -Dvertx.disableTCCL=true                          \
     -Dvertx.disableTCCL=true                          \
     -Dvertx.disableHttpHeadersValidation=true         \
     -Dvertx.disableHttpHeadersValidation=true         \
     -jar                                              \
     -jar                                              \
-    target/vertx-web-benchmark-3.7.0-fat.jar          \
+    target/vertx-web-benchmark-3.9.0-fat.jar          \
     --instances                                       \
     --instances                                       \
     `grep --count ^processor /proc/cpuinfo`           \
     `grep --count ^processor /proc/cpuinfo`           \
     --conf                                            \
     --conf                                            \

+ 1 - 1
frameworks/Java/vertx-web/vertx-web-postgres.dockerfile

@@ -18,7 +18,7 @@ CMD java \
     -Dvertx.disableTCCL=true                          \
     -Dvertx.disableTCCL=true                          \
     -Dvertx.disableHttpHeadersValidation=true         \
     -Dvertx.disableHttpHeadersValidation=true         \
     -jar                                              \
     -jar                                              \
-    target/vertx-web-benchmark-3.7.0-fat.jar          \
+    target/vertx-web-benchmark-3.9.0-fat.jar          \
     --instances                                       \
     --instances                                       \
     `grep --count ^processor /proc/cpuinfo`           \
     `grep --count ^processor /proc/cpuinfo`           \
     --conf                                            \
     --conf                                            \

+ 1 - 1
frameworks/Java/vertx-web/vertx-web-susom-postgres.dockerfile

@@ -18,7 +18,7 @@ CMD java \
     -Dvertx.disableTCCL=true                          \
     -Dvertx.disableTCCL=true                          \
     -Dvertx.disableHttpHeadersValidation=true         \
     -Dvertx.disableHttpHeadersValidation=true         \
     -jar                                              \
     -jar                                              \
-    target/vertx-web-benchmark-3.7.0-fat.jar          \
+    target/vertx-web-benchmark-3.9.0-fat.jar          \
     --instances                                       \
     --instances                                       \
     `grep --count ^processor /proc/cpuinfo`           \
     `grep --count ^processor /proc/cpuinfo`           \
     --conf                                            \
     --conf                                            \

+ 1 - 1
frameworks/Java/vertx-web/vertx-web.dockerfile

@@ -18,7 +18,7 @@ CMD java \
     -Dvertx.disableTCCL=true                          \
     -Dvertx.disableTCCL=true                          \
     -Dvertx.disableHttpHeadersValidation=true         \
     -Dvertx.disableHttpHeadersValidation=true         \
     -jar                                              \
     -jar                                              \
-    target/vertx-web-benchmark-3.7.0-fat.jar          \
+    target/vertx-web-benchmark-3.9.0-fat.jar          \
     --instances                                       \
     --instances                                       \
     `grep --count ^processor /proc/cpuinfo`           \
     `grep --count ^processor /proc/cpuinfo`           \
     --conf                                            \
     --conf                                            \