diff --git a/frameworks/Java/micronaut/.mvn/jvm.config b/frameworks/Java/micronaut/.mvn/jvm.config deleted file mode 100644 index 4967c447ae5..00000000000 --- a/frameworks/Java/micronaut/.mvn/jvm.config +++ /dev/null @@ -1 +0,0 @@ --noverify -XX:TieredStopAtLevel=1 \ No newline at end of file diff --git a/frameworks/Java/micronaut/.mvn/wrapper/MavenWrapperDownloader.java b/frameworks/Java/micronaut/.mvn/wrapper/MavenWrapperDownloader.java deleted file mode 100644 index d475a89ce1d..00000000000 --- a/frameworks/Java/micronaut/.mvn/wrapper/MavenWrapperDownloader.java +++ /dev/null @@ -1,110 +0,0 @@ -/* -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ - -import java.net.*; -import java.io.*; -import java.nio.channels.*; -import java.util.Properties; - -public class MavenWrapperDownloader { - - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; - - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; - - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; - - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: : " + url); - - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } - - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } - -} diff --git a/frameworks/Java/micronaut/.mvn/wrapper/maven-wrapper.jar b/frameworks/Java/micronaut/.mvn/wrapper/maven-wrapper.jar deleted file mode 100644 index 08ebbb67f08..00000000000 Binary files a/frameworks/Java/micronaut/.mvn/wrapper/maven-wrapper.jar and /dev/null differ diff --git a/frameworks/Java/micronaut/.mvn/wrapper/maven-wrapper.properties b/frameworks/Java/micronaut/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index 42fa4da2199..00000000000 --- a/frameworks/Java/micronaut/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1 +0,0 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip \ No newline at end of file diff --git a/frameworks/Java/micronaut/README.md b/frameworks/Java/micronaut/README.md index 6d37e476ea5..fd8fd90e1a2 100755 --- a/frameworks/Java/micronaut/README.md +++ b/frameworks/Java/micronaut/README.md @@ -1,4 +1,4 @@ -# [Micronaut](http://micronaut.io) Benchmarking Test (2.3.1) +# [Micronaut](http://micronaut.io) Benchmarking Test (3.1.1) ### Test Type Implementation Source Code @@ -12,6 +12,7 @@ ## Important Libraries The tests were run with: * [OpenJDK Java 11](http://jdk.java.net/11/) +* [GraalVM CE 21.3.0 (Java 11)](https://www.graalvm.org) ## Test URLs ### JSON diff --git a/frameworks/Java/micronaut/benchmark_config.json b/frameworks/Java/micronaut/benchmark_config.json index 515a2885617..57ec0b0533f 100755 --- a/frameworks/Java/micronaut/benchmark_config.json +++ b/frameworks/Java/micronaut/benchmark_config.json @@ -24,6 +24,29 @@ "display_name": "Micronaut", "notes": "", "versus": "None" + }, + "native": { + "json_url": "/json", + "plaintext_url": "/plaintext", + "db_url": "/db", + "query_url": "/queries?queries=", + "fortune_url": "/fortunes", + "update_url": "/updates?queries=", + "port": 8080, + "approach": "Realistic", + "classification": "Micro", + "database": "Postgres", + "framework": "Micronaut", + "language": "Java", + "flavor": "None", + "orm": "raw", + "platform": "Netty", + "webserver": "None", + "os": "Linux", + "database_os": "Linux", + "display_name": "micronaut-graalvm", + "notes": "", + "versus": "None" } } ] diff --git a/frameworks/Java/micronaut/build.gradle b/frameworks/Java/micronaut/build.gradle new file mode 100644 index 00000000000..e454e44e18f --- /dev/null +++ b/frameworks/Java/micronaut/build.gradle @@ -0,0 +1,88 @@ +plugins { + id 'java' + id "io.micronaut.application" version "2.0.6" + id "com.fizzed.rocker" version "1.3.0" +} + +group 'org.example' +version '1.0-SNAPSHOT' + +repositories { + mavenLocal() + mavenCentral() +} + +micronaut { + version '3.1.1' + processing { + incremental true + } +} + +nativeImage { + args "--initialize-at-build-time=" + + "views," + + "io.vertx.core.logging.LoggerFactory," + + "io.vertx.core.logging.SLF4JLogDelegateFactory," + + "io.vertx.core.logging.SLF4JLogDelegate," + + "io.vertx.pgclient.impl.codec.DataTypeCodec" +} + +sourceSets { + main { + rocker { + srcDir('src/main/resources') + } + } +} + +rocker { + skip false + // Base directory for generated java sources, actual target is sub directory + // with the name of the source set. The value is passed through project.file(). + outputBaseDirectory = "$buildDir/generated/rocker" + // Base directory for the directory where the hot reload feature + // will (re)compile classes to at runtime (and where `rocker-compiler.conf` + // is generated, which is used by RockerRuntime.getInstance().setReloading(true)). + // The actual target is a sub directory with the name of the source set. + // The value is passed through project.file(). + classBaseDirectory = "$buildDir/classes" + failOnError true + skipTouch true + // must not be empty when skipTouch is equal to false + touchFile "" + javaVersion '11' + optimize true +} + +mainClassName = 'benchmark.Application' + +ext { + set('vertxVersion', '4.1.5') + set('micronautVersion', '3.1.1') + set('javaxAnnotationApi', '1.3.2') + set('rockerVersion', '1.3.0') +} + +dependencies { + implementation("io.micronaut:micronaut-inject:${micronautVersion}") + implementation("io.micronaut:micronaut-management:${micronautVersion}") + implementation("io.micronaut:micronaut-http-server-netty:${micronautVersion}") + implementation("io.micronaut.rxjava3:micronaut-rxjava3") + implementation("io.micronaut.sql:micronaut-vertx-pg-client") + implementation("io.micronaut.sql:micronaut-jdbc-hikari:4.0.2") + implementation("io.micronaut.views:micronaut-views-rocker") + implementation("com.fizzed:rocker-runtime:${rockerVersion}") + implementation("io.vertx:vertx-core:${vertxVersion}") + implementation("io.vertx:vertx-rx-java2:${vertxVersion}") + implementation("io.vertx:vertx-rx-java3:${vertxVersion}") + implementation("io.vertx:vertx-pg-client:${vertxVersion}") + + runtimeOnly("ch.qos.logback:logback-classic") + testImplementation("io.micronaut.test:micronaut-test-junit5") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/frameworks/Java/micronaut/config.toml b/frameworks/Java/micronaut/config.toml index ba928fd39e1..8c4a7118faf 100644 --- a/frameworks/Java/micronaut/config.toml +++ b/frameworks/Java/micronaut/config.toml @@ -12,8 +12,27 @@ approach = "Realistic" classification = "Micro" database = "Postgres" database_os = "Linux" +display_name = "micronaut" os = "Linux" orm = "raw" platform = "Netty" webserver = "None" versus = "None" + +[native] +urls.plaintext = "/plaintext" +urls.json = "/json" +urls.db = "/db" +urls.query = "/queries?queries=" +urls.update = "/updates?queries=" +urls.fortune = "/fortunes" +approach = "Realistic" +classification = "Micro" +database = "Postgres" +database_os = "Linux" +display_name = "micronaut-graalvm" +os = "Linux" +orm = "raw" +platform = "Netty" +webserver = "None" +versus = "micronaut" diff --git a/frameworks/Java/micronaut/gradle/wrapper/gradle-wrapper.jar b/frameworks/Java/micronaut/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000000..7454180f2ae Binary files /dev/null and b/frameworks/Java/micronaut/gradle/wrapper/gradle-wrapper.jar differ diff --git a/frameworks/Java/micronaut/gradle/wrapper/gradle-wrapper.properties b/frameworks/Java/micronaut/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000000..3ab0b725efc --- /dev/null +++ b/frameworks/Java/micronaut/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/frameworks/Java/micronaut/gradlew b/frameworks/Java/micronaut/gradlew new file mode 100644 index 00000000000..744e882ed57 --- /dev/null +++ b/frameworks/Java/micronaut/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MSYS* | MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/frameworks/Java/micronaut/gradlew.bat b/frameworks/Java/micronaut/gradlew.bat new file mode 100644 index 00000000000..ac1b06f9382 --- /dev/null +++ b/frameworks/Java/micronaut/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/frameworks/Java/micronaut/micronaut-cli.yml b/frameworks/Java/micronaut/micronaut-cli.yml deleted file mode 100644 index 63dfab097d4..00000000000 --- a/frameworks/Java/micronaut/micronaut-cli.yml +++ /dev/null @@ -1,6 +0,0 @@ -applicationType: default -defaultPackage: com.example -testFramework: junit -sourceLanguage: java -buildTool: maven -features: [annotation-api, app-name, http-client, java, java-application, junit, logback, maven, netty-server, readme, shade, yaml] diff --git a/frameworks/Java/micronaut/micronaut-native.dockerfile b/frameworks/Java/micronaut/micronaut-native.dockerfile new file mode 100644 index 00000000000..cdb2139dc50 --- /dev/null +++ b/frameworks/Java/micronaut/micronaut-native.dockerfile @@ -0,0 +1,13 @@ +FROM ghcr.io/graalvm/graalvm-ce:java11-21.3.0 +RUN gu install native-image +WORKDIR /micronaut +COPY build.gradle build.gradle +COPY settings.gradle settings.gradle +COPY gradlew gradlew +COPY gradle gradle +COPY src src +RUN sh ./gradlew build nativeImage --no-daemon + +EXPOSE 8080 + +CMD ["/micronaut/build/native-image/application", "-Dmicronaut.environments=benchmark", "-Dlog-root-level=OFF"] \ No newline at end of file diff --git a/frameworks/Java/micronaut/micronaut.dockerfile b/frameworks/Java/micronaut/micronaut.dockerfile index 9aacd855179..c45a7df3a14 100644 --- a/frameworks/Java/micronaut/micronaut.dockerfile +++ b/frameworks/Java/micronaut/micronaut.dockerfile @@ -1,13 +1,16 @@ -FROM adoptopenjdk/maven-openjdk11:latest as maven +FROM gradle:6.9-jdk11 as build WORKDIR /micronaut COPY src src -COPY pom.xml pom.xml -RUN mvn package -q +COPY build.gradle build.gradle +COPY settings.gradle settings.gradle +RUN gradle build buildLayers --no-daemon -FROM adoptopenjdk/openjdk11:jdk-11.0.3_7-slim +FROM openjdk:11-jre-slim WORKDIR /micronaut -COPY --from=maven /micronaut/target/hello-micronaut-0.1.jar app.jar +COPY --from=build /micronaut/build/docker/layers/libs /home/app/libs +COPY --from=build /micronaut/build/docker/layers/resources /home/app/resources +COPY --from=build /micronaut/build/docker/layers/application.jar /home/app/application.jar EXPOSE 8080 -CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-Dmicronaut.environments=benchmark", "-Dlog-root-level=OFF", "-jar", "app.jar"] +CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-Dmicronaut.environments=benchmark", "-Dlog-root-level=OFF", "-jar", "/home/app/application.jar"] diff --git a/frameworks/Java/micronaut/mvnw b/frameworks/Java/micronaut/mvnw deleted file mode 100755 index 961a8250013..00000000000 --- a/frameworks/Java/micronaut/mvnw +++ /dev/null @@ -1,286 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven2 Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" - # TODO classpath? -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar" - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - wget "$jarUrl" -O "$wrapperJarPath" - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - curl -o "$wrapperJarPath" "$jarUrl" - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/frameworks/Java/micronaut/mvnw.cmd b/frameworks/Java/micronaut/mvnw.cmd deleted file mode 100755 index 03d90e960b5..00000000000 --- a/frameworks/Java/micronaut/mvnw.cmd +++ /dev/null @@ -1,161 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven2 Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar" -FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - echo Found %WRAPPER_JAR% -) else ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" - echo Finished downloading %WRAPPER_JAR% -) -@REM End of extension - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/frameworks/Java/micronaut/pom.xml b/frameworks/Java/micronaut/pom.xml deleted file mode 100644 index ae6ab042c48..00000000000 --- a/frameworks/Java/micronaut/pom.xml +++ /dev/null @@ -1,167 +0,0 @@ - - - 4.0.0 - benchmark - hello-micronaut - 0.1 - ${packaging} - - - io.micronaut - micronaut-parent - 2.3.1 - - - - jar - 11 - 11 - 2.3.1 - benchmark.Application - netty - - - - - jcenter.bintray.com - https://jcenter.bintray.com - - - - - - io.micronaut - micronaut-inject - compile - - - io.micronaut - micronaut-validation - compile - - - io.micronaut - micronaut-http-server-netty - compile - - - io.micronaut - micronaut-http-client - compile - - - io.micronaut - micronaut-runtime - compile - - - javax.annotation - javax.annotation-api - compile - - - io.micronaut.views - micronaut-views-rocker - compile - - - javax.annotation - javax.annotation-api - compile - - - javax.xml.bind - jaxb-api - 2.3.0 - - - io.vertx - vertx-core - 3.9.2 - compile - - - io.vertx - vertx-pg-client - 3.9.2 - compile - - - io.vertx - vertx-codegen - 3.9.2 - compile - - - io.vertx - vertx-rx-java2 - 3.9.2 - compile - - - com.fizzed - rocker-runtime - 1.3.0 - - - ch.qos.logback - logback-classic - runtime - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - io.micronaut.test - micronaut-test-junit5 - test - - - - - - io.micronaut.build - micronaut-maven-plugin - - - org.apache.maven.plugins - maven-compiler-plugin - - - - - - - -Amicronaut.processing.group=com.example - -Amicronaut.processing.module=demo - - - - - com.fizzed - rocker-maven-plugin - 1.3.0 - - - generate-rocker-templates - generate-sources - - generate - - - true - - - - - - - diff --git a/frameworks/Java/micronaut/settings.gradle b/frameworks/Java/micronaut/settings.gradle new file mode 100644 index 00000000000..842ddd3b67b --- /dev/null +++ b/frameworks/Java/micronaut/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'hello-micronaut' + diff --git a/frameworks/Java/micronaut/src/main/java/benchmark/Application.java b/frameworks/Java/micronaut/src/main/java/benchmark/Application.java index ee6657b6326..e817ee3abac 100644 --- a/frameworks/Java/micronaut/src/main/java/benchmark/Application.java +++ b/frameworks/Java/micronaut/src/main/java/benchmark/Application.java @@ -3,8 +3,8 @@ import io.micronaut.runtime.Micronaut; public class Application { - public static void main(String[] args) { - Micronaut.run(Application.class); + Micronaut.build(args) + .run(Application.class); } } \ No newline at end of file diff --git a/frameworks/Java/micronaut/src/main/java/benchmark/Database.java b/frameworks/Java/micronaut/src/main/java/benchmark/controller/EntityController.java similarity index 64% rename from frameworks/Java/micronaut/src/main/java/benchmark/Database.java rename to frameworks/Java/micronaut/src/main/java/benchmark/controller/EntityController.java index 6821266d645..2a0a03adb3d 100644 --- a/frameworks/Java/micronaut/src/main/java/benchmark/Database.java +++ b/frameworks/Java/micronaut/src/main/java/benchmark/controller/EntityController.java @@ -1,16 +1,16 @@ -package benchmark; +package benchmark.controller; import benchmark.entity.Fortune; import benchmark.entity.World; -import benchmark.repository.DbRepository; +import benchmark.repository.EntityRepository; import io.micronaut.http.HttpResponse; import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; import io.micronaut.http.annotation.QueryValue; import io.micronaut.views.rocker.RockerWritable; -import io.reactivex.Flowable; -import io.reactivex.Single; -import benchmark.views.fortunes; +import io.reactivex.rxjava3.core.Flowable; +import io.reactivex.rxjava3.core.Single; +import views.fortunes; import java.util.Arrays; import java.util.List; @@ -19,32 +19,31 @@ import static java.util.Comparator.comparing; @Controller("/") -public class Database { +public class EntityController { + private final EntityRepository entityRepository; - private final DbRepository dbRepository; - - public Database(DbRepository dbRepository) { - this.dbRepository = dbRepository; + public EntityController(EntityRepository entityRepository) { + this.entityRepository = entityRepository; } @Get("/db") public Single db() { - return dbRepository.getWorld(randomWorldNumber()); + return entityRepository.getWorld(randomWorldNumber()); } @Get("/queries") public Single> queries(@QueryValue String queries) { - Flowable[] worlds = new Flowable[parseQueryCount(queries)]; - Arrays.setAll(worlds, i -> dbRepository.getWorld(randomWorldNumber()).toFlowable()); + final Flowable[] worlds = new Flowable[parseQueryCount(queries)]; + Arrays.setAll(worlds, i -> entityRepository.getWorld(randomWorldNumber()).toFlowable()); return Flowable.merge(Arrays.asList(worlds)).toList(); } @Get(value = "/fortunes") public Single> fortune() { - return dbRepository.fortunes().toList().map(fortuneList -> { + return entityRepository.fortunes().toList().map(fortuneList -> { fortuneList.add(new Fortune(0, "Additional fortune added at request time.")); - fortuneList.sort(comparing(fortune -> fortune.message)); + fortuneList.sort(comparing(Fortune::getMessage)); return HttpResponse.ok(new RockerWritable(fortunes.template(fortuneList))) .contentType("text/html;charset=utf-8"); }); @@ -52,10 +51,10 @@ public Single> fortune() { @Get("/updates") public Single> updates(@QueryValue String queries) { - Flowable[] worlds = new Flowable[parseQueryCount(queries)]; + final Flowable[] worlds = new Flowable[parseQueryCount(queries)]; Arrays.setAll(worlds, i -> - dbRepository.findAndUpdateWorld(randomWorldNumber(), randomWorldNumber()).toFlowable() + entityRepository.findAndUpdateWorld(randomWorldNumber(), randomWorldNumber()).toFlowable() ); return Flowable.merge(Arrays.asList(worlds)).toList(); @@ -64,6 +63,7 @@ public Single> updates(@QueryValue String queries) { private int randomWorldNumber() { return 1 + ThreadLocalRandom.current().nextInt(10000); } + private int parseQueryCount(String textValue) { if (textValue == null) { return 1; diff --git a/frameworks/Java/micronaut/src/main/java/benchmark/JsonSerialization.java b/frameworks/Java/micronaut/src/main/java/benchmark/controller/JsonSerializationController.java similarity index 56% rename from frameworks/Java/micronaut/src/main/java/benchmark/JsonSerialization.java rename to frameworks/Java/micronaut/src/main/java/benchmark/controller/JsonSerializationController.java index b5fc0359fba..645dcacb09f 100644 --- a/frameworks/Java/micronaut/src/main/java/benchmark/JsonSerialization.java +++ b/frameworks/Java/micronaut/src/main/java/benchmark/controller/JsonSerializationController.java @@ -1,18 +1,17 @@ -package benchmark; +package benchmark.controller; import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; -import io.reactivex.Single; import java.util.HashMap; import java.util.Map; @Controller("/json") -public class JsonSerialization { +public class JsonSerializationController { - @Get("/") - Map getJson() { - Map map = new HashMap<>(); + @Get + public Map getJson() { + final Map map = new HashMap<>(); map.put("message", "Hello, World!"); return map; } diff --git a/frameworks/Java/micronaut/src/main/java/benchmark/PlainText.java b/frameworks/Java/micronaut/src/main/java/benchmark/controller/PlainTextController.java similarity index 59% rename from frameworks/Java/micronaut/src/main/java/benchmark/PlainText.java rename to frameworks/Java/micronaut/src/main/java/benchmark/controller/PlainTextController.java index 5f0f94e9e6e..52926036e70 100644 --- a/frameworks/Java/micronaut/src/main/java/benchmark/PlainText.java +++ b/frameworks/Java/micronaut/src/main/java/benchmark/controller/PlainTextController.java @@ -1,19 +1,15 @@ -package benchmark; +package benchmark.controller; import io.micronaut.http.MediaType; import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; -import io.micronaut.scheduling.TaskExecutors; -import io.micronaut.scheduling.annotation.ExecuteOn; @Controller("/plaintext") -@ExecuteOn(TaskExecutors.IO) -public class PlainText { - +public class PlainTextController { private static final String TEXT = "Hello, World!"; @Get(value = "/", produces = MediaType.TEXT_PLAIN) - String getPlainText() { + public String getPlainText() { return TEXT; } } diff --git a/frameworks/Java/micronaut/src/main/java/benchmark/entity/Fortune.java b/frameworks/Java/micronaut/src/main/java/benchmark/entity/Fortune.java index 0242edd0a1c..353bf2cfbcc 100644 --- a/frameworks/Java/micronaut/src/main/java/benchmark/entity/Fortune.java +++ b/frameworks/Java/micronaut/src/main/java/benchmark/entity/Fortune.java @@ -1,17 +1,15 @@ package benchmark.entity; -import java.util.Objects; +import io.micronaut.core.annotation.Introspected; -/** - * The model for the "fortune" database table. - */ -public final class Fortune { +import java.util.Objects; - public int id; - public String message; +@Introspected +public class Fortune { + private int id; + private String message; public Fortune() { - super(); } public Fortune(int id, String message) { @@ -37,9 +35,13 @@ public void setMessage(String message) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Fortune fortune = (Fortune) o; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final Fortune fortune = (Fortune) o; return id == fortune.id && Objects.equals(message, fortune.message); } diff --git a/frameworks/Java/micronaut/src/main/java/benchmark/entity/World.java b/frameworks/Java/micronaut/src/main/java/benchmark/entity/World.java index c7e358ad96a..db30fe1982e 100644 --- a/frameworks/Java/micronaut/src/main/java/benchmark/entity/World.java +++ b/frameworks/Java/micronaut/src/main/java/benchmark/entity/World.java @@ -1,17 +1,15 @@ package benchmark.entity; -import java.util.Objects; +import io.micronaut.core.annotation.Introspected; -/** - * The model for the "world" database table. - */ -public final class World { +import java.util.Objects; - public int id; - public int randomNumber; +@Introspected +public class World { + private int id; + private int randomNumber; public World() { - super(); } public World(int id, int randomNumber) { @@ -37,15 +35,18 @@ public void setRandomNumber(int randomNumber) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - World world = (World) o; - return id == world.id && - randomNumber == world.randomNumber; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final World world = (World) o; + return id == world.id && randomNumber == world.randomNumber; } @Override public int hashCode() { return Objects.hash(id, randomNumber); } -} \ No newline at end of file +} diff --git a/frameworks/Java/micronaut/src/main/java/benchmark/repository/DbRepository.java b/frameworks/Java/micronaut/src/main/java/benchmark/repository/EntityRepository.java similarity index 65% rename from frameworks/Java/micronaut/src/main/java/benchmark/repository/DbRepository.java rename to frameworks/Java/micronaut/src/main/java/benchmark/repository/EntityRepository.java index 9642ba1cfc9..4e47dff47a6 100644 --- a/frameworks/Java/micronaut/src/main/java/benchmark/repository/DbRepository.java +++ b/frameworks/Java/micronaut/src/main/java/benchmark/repository/EntityRepository.java @@ -2,10 +2,10 @@ import benchmark.entity.Fortune; import benchmark.entity.World; -import io.reactivex.Flowable; -import io.reactivex.Single; +import io.reactivex.rxjava3.core.Flowable; +import io.reactivex.rxjava3.core.Single; -public interface DbRepository { +public interface EntityRepository { Single getWorld(int id); Single findAndUpdateWorld(int id, int randomNumber); diff --git a/frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClientConfig.java b/frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClientConfig.java deleted file mode 100644 index 8bd25c9f677..00000000000 --- a/frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClientConfig.java +++ /dev/null @@ -1,53 +0,0 @@ -package benchmark.repository; - -import io.micronaut.context.annotation.ConfigurationProperties; - -@ConfigurationProperties("database") -public class PgClientConfig { - private String name; - private String host; - private int port; - private String username; - private String password; - - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } -} diff --git a/frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClientDbRepository.java b/frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClientEntityRepository.java similarity index 57% rename from frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClientDbRepository.java rename to frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClientEntityRepository.java index a682424c81a..36deda55b5c 100644 --- a/frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClientDbRepository.java +++ b/frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClientEntityRepository.java @@ -2,27 +2,26 @@ import benchmark.entity.Fortune; import benchmark.entity.World; -import io.reactivex.BackpressureStrategy; -import io.reactivex.Flowable; -import io.reactivex.Single; +import io.reactivex.rxjava3.core.BackpressureStrategy; +import io.reactivex.rxjava3.core.Flowable; +import io.reactivex.rxjava3.core.Single; +import io.vertx.reactivex.pgclient.PgPool; import io.vertx.reactivex.sqlclient.Row; import io.vertx.reactivex.sqlclient.Tuple; - -import javax.inject.Singleton; +import jakarta.inject.Singleton; @Singleton -public class PgClientDbRepository implements DbRepository { - - private final PgClients pgClients; +public class PgClientEntityRepository implements EntityRepository { + private final PgPool pgClient; - public PgClientDbRepository(PgClients pgClients) { - this.pgClients = pgClients; + public PgClientEntityRepository(PgPool pgClient) { + this.pgClient = pgClient; } @Override public Single getWorld(int id) { return Single.create(sink -> - pgClients.getOne().preparedQuery("SELECT * FROM world WHERE id = $1").execute(Tuple.of(id), ar -> { + pgClient.preparedQuery("SELECT * FROM world WHERE id = $1").execute(Tuple.of(id), ar -> { if (ar.failed()) { sink.onError(ar.cause()); } else { @@ -34,19 +33,20 @@ public Single getWorld(int id) { } private Single updateWorld(World world) { - return Single.create(sink -> pgClients.getOne().preparedQuery("UPDATE world SET randomnumber = $1 WHERE id = $2").execute(Tuple.of(world.randomNumber, world.id), ar -> { - if (ar.failed()) { - sink.onError(ar.cause()); - } else { - sink.onSuccess(world); - } - })); + return Single.create(sink -> pgClient.preparedQuery("UPDATE world SET randomnumber = $1 WHERE id = $2") + .execute(Tuple.of(world.getRandomNumber(), world.getId()), ar -> { + if (ar.failed()) { + sink.onError(ar.cause()); + } else { + sink.onSuccess(world); + } + })); } @Override public Single findAndUpdateWorld(int id, int randomNumber) { return getWorld(id).flatMap(world -> { - world.randomNumber = randomNumber; + world.setRandomNumber(randomNumber); return updateWorld(world); }); } @@ -54,7 +54,7 @@ public Single findAndUpdateWorld(int id, int randomNumber) { @Override public Flowable fortunes() { return Flowable.create(sink -> - pgClients.getOne().preparedQuery("SELECT * FROM fortune").execute(ar -> { + pgClient.preparedQuery("SELECT * FROM fortune").execute(ar -> { if (ar.failed()) { sink.onError(ar.cause()); return; diff --git a/frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClientFactory.java b/frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClientFactory.java deleted file mode 100644 index bbee6f2e939..00000000000 --- a/frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClientFactory.java +++ /dev/null @@ -1,51 +0,0 @@ -package benchmark.repository; - -import io.micronaut.context.annotation.Factory; -import io.vertx.pgclient.PgConnectOptions; -import io.vertx.reactivex.core.Vertx; -import io.vertx.reactivex.pgclient.PgPool; -import io.vertx.sqlclient.PoolOptions; - -import javax.inject.Singleton; -import java.util.ArrayList; -import java.util.List; - -@Factory -public class PgClientFactory { - - private final PgClientConfig config; - - public PgClientFactory(PgClientConfig config) { - this.config = config; - } - - @Singleton - public Vertx vertx() { - return Vertx.vertx(); - } - - @Singleton - public PgClients pgClients(Vertx vertx) { - List clients = new ArrayList<>(); - - for (int i = 0; i < Runtime.getRuntime().availableProcessors(); i++) { - clients.add(pgClient(vertx)); - } - - return new PgClients(clients); - } - - - private PgPool pgClient(Vertx vertx) { - PgConnectOptions connectOptions = new PgConnectOptions(); - connectOptions.setDatabase(config.getName()); - connectOptions.setHost(config.getHost()); - connectOptions.setPort(config.getPort()); - connectOptions.setUser(config.getUsername()); - connectOptions.setPassword(config.getPassword()); - connectOptions.setCachePreparedStatements(true); - PoolOptions poolOptions = new PoolOptions(); - poolOptions.setMaxSize(1); - return PgPool.pool(vertx, connectOptions, poolOptions); - } -} diff --git a/frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClients.java b/frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClients.java deleted file mode 100644 index a5a836c21d1..00000000000 --- a/frameworks/Java/micronaut/src/main/java/benchmark/repository/PgClients.java +++ /dev/null @@ -1,19 +0,0 @@ -package benchmark.repository; - -import io.vertx.reactivex.pgclient.PgPool; - -import java.util.Collection; -import java.util.Iterator; -import java.util.stream.Stream; - -class PgClients { - private final Iterator iterator; - - PgClients(Collection clients) { - iterator = Stream.generate(() -> clients).flatMap(Collection::stream).iterator(); - } - - synchronized PgPool getOne() { - return iterator.next(); - } -} diff --git a/frameworks/Java/micronaut/src/main/resources/application-benchmark-local.yml b/frameworks/Java/micronaut/src/main/resources/application-benchmark-local.yml index 1be6f6674cb..56cff32c3e8 100644 --- a/frameworks/Java/micronaut/src/main/resources/application-benchmark-local.yml +++ b/frameworks/Java/micronaut/src/main/resources/application-benchmark-local.yml @@ -1,6 +1,9 @@ -database: - name: hello_world - host: localhost - port: 5432 - username: benchmarkdbuser - password: benchmarkdbpass +vertx: + pg: + client: + port: 5432 + host: localhost + database: hello_world + user: benchmarkdbuser + password: benchmarkdbpass + maxSize: 5 diff --git a/frameworks/Java/micronaut/src/main/resources/application-benchmark.yml b/frameworks/Java/micronaut/src/main/resources/application-benchmark.yml index 3ff94afb123..0ffe912c40e 100644 --- a/frameworks/Java/micronaut/src/main/resources/application-benchmark.yml +++ b/frameworks/Java/micronaut/src/main/resources/application-benchmark.yml @@ -1,7 +1,9 @@ -database: - name: hello_world - host: tfb-database - port: 5432 - username: benchmarkdbuser - password: benchmarkdbpass - +vertx: + pg: + client: + port: 5432 + host: tfb-database + database: hello_world + user: benchmarkdbuser + password: benchmarkdbpass + maxSize: 5 diff --git a/frameworks/Java/micronaut/src/main/java/benchmark/views/fortunes.rocker.html b/frameworks/Java/micronaut/src/main/resources/views/fortunes.rocker.html similarity index 100% rename from frameworks/Java/micronaut/src/main/java/benchmark/views/fortunes.rocker.html rename to frameworks/Java/micronaut/src/main/resources/views/fortunes.rocker.html