├── spring-jooq-gradle ├── settings.gradle ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── moditect │ │ │ └── jfrunit │ │ │ └── demos │ │ │ └── spring_jooq │ │ │ ├── SpringJooqGradleApplication.java │ │ │ └── TestUserService.java │ └── test │ │ └── java │ │ └── org │ │ └── moditect │ │ └── jfrunit │ │ └── demos │ │ └── spring_jooq │ │ ├── ExecuteContextSqlConverter.java │ │ └── SpringJooqGradleApplicationTests.java ├── init.sql ├── docker-compose.yaml ├── README.md ├── jooq-probes.xml ├── gradlew.bat ├── build.gradle └── gradlew ├── quarkus-hibernate-maven ├── user-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── application.properties │ │ │ │ └── META-INF │ │ │ │ │ └── resources │ │ │ │ │ └── index.html │ │ │ ├── java │ │ │ │ └── org │ │ │ │ │ └── moditect │ │ │ │ │ └── jfrunit │ │ │ │ │ └── demos │ │ │ │ │ └── user │ │ │ │ │ ├── User.java │ │ │ │ │ └── UserResource.java │ │ │ └── docker │ │ │ │ ├── Dockerfile.native │ │ │ │ ├── Dockerfile.jvm │ │ │ │ └── Dockerfile.fast-jar │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── moditect │ │ │ └── jfrunit │ │ │ └── demos │ │ │ └── user │ │ │ ├── NativeGreetingResourceIT.java │ │ │ └── UserResourceTest.java │ ├── .dockerignore │ ├── README.md │ └── pom.xml ├── example-service │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── init.sql │ │ │ │ ├── META-INF │ │ │ │ │ └── resources │ │ │ │ │ │ └── index.html │ │ │ │ └── application.properties │ │ │ ├── java │ │ │ │ └── org │ │ │ │ │ └── moditect │ │ │ │ │ └── jfrunit │ │ │ │ │ └── demos │ │ │ │ │ └── todo │ │ │ │ │ ├── User.java │ │ │ │ │ ├── Todo.java │ │ │ │ │ ├── TodoDetail.java │ │ │ │ │ ├── TodoWithAvatar.java │ │ │ │ │ ├── TodoWithDetails.java │ │ │ │ │ └── TodoResource.java │ │ │ └── docker │ │ │ │ ├── Dockerfile.native │ │ │ │ └── Dockerfile.jvm │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── moditect │ │ │ └── jfrunit │ │ │ └── demos │ │ │ └── todo │ │ │ ├── HelloJfrUnitTest.java │ │ │ ├── testutil │ │ │ ├── MatchesJson.java │ │ │ └── PostgresResource.java │ │ │ ├── TodoResourceSqlStatementsTest.java │ │ │ ├── TodoResourceMemoryAllocationTest.java │ │ │ └── TodoResourceSocketIoTest.java │ ├── .dockerignore │ ├── hibernate-probes.xml │ └── pom.xml ├── docker-compose.yaml └── README.md ├── .gitignore ├── README.md └── LICENSE.txt /spring-jooq-gradle/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'spring_jooq' 2 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/user-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/main/resources/init.sql: -------------------------------------------------------------------------------- 1 | create schema todo; 2 | 3 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/.dockerignore: -------------------------------------------------------------------------------- 1 | * 2 | !target/*-runner 3 | !target/*-runner.jar 4 | !target/lib/* -------------------------------------------------------------------------------- /quarkus-hibernate-maven/user-service/.dockerignore: -------------------------------------------------------------------------------- 1 | * 2 | !target/*-runner 3 | !target/*-runner.jar 4 | !target/lib/* 5 | !target/quarkus-app/* -------------------------------------------------------------------------------- /quarkus-hibernate-maven/user-service/README.md: -------------------------------------------------------------------------------- 1 | # User service (Quarkus) 2 | 3 | This service is used by the [example-service](../example-service/). 4 | -------------------------------------------------------------------------------- /spring-jooq-gradle/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:postgresql://localhost:5433/tododb 2 | spring.datasource.username=todouser 3 | spring.datasource.password=todopw 4 | -------------------------------------------------------------------------------- /spring-jooq-gradle/init.sql: -------------------------------------------------------------------------------- 1 | create schema todo; 2 | 3 | create table if not exists test_user 4 | ( 5 | id bigserial primary key, 6 | username text not null, 7 | age int not null 8 | ); 9 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/main/resources/META-INF/resources/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /spring-jooq-gradle/src/test/java/org/moditect/jfrunit/demos/spring_jooq/ExecuteContextSqlConverter.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.spring_jooq; 2 | 3 | import org.jooq.ExecuteContext; 4 | 5 | public class ExecuteContextSqlConverter { 6 | public static String convert(ExecuteContext ctx) { 7 | return ctx.sql(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/user-service/src/test/java/org/moditect/jfrunit/demos/user/NativeGreetingResourceIT.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.user; 2 | 3 | import io.quarkus.test.junit.NativeImageTest; 4 | 5 | @NativeImageTest 6 | public class NativeGreetingResourceIT extends UserResourceTest { 7 | 8 | // Execute the same tests but in native mode. 9 | } -------------------------------------------------------------------------------- /quarkus-hibernate-maven/user-service/src/main/java/org/moditect/jfrunit/demos/user/User.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.user; 2 | 3 | public class User { 4 | public long id; 5 | public String name; 6 | 7 | public User() { 8 | } 9 | 10 | public User(long id, String name) { 11 | this.id = id; 12 | this.name = name; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/main/java/org/moditect/jfrunit/demos/todo/User.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.todo; 2 | 3 | public class User { 4 | public long id; 5 | public String name; 6 | 7 | public User() { 8 | } 9 | 10 | public User(long id, String name) { 11 | this.id = id; 12 | this.name = name; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Eclipse 2 | .project 3 | .classpath 4 | .factorypath 5 | .settings/ 6 | bin/ 7 | 8 | /.idea/ 9 | 10 | # NetBeans 11 | nb-configuration.xml 12 | 13 | # Visual Studio Code 14 | .vscode 15 | 16 | # OSX 17 | .DS_Store 18 | 19 | # Vim 20 | *.swp 21 | *.swo 22 | 23 | # patch 24 | *.orig 25 | *.rej 26 | 27 | # Maven 28 | target/ 29 | 30 | # Gradle 31 | build/ 32 | .gradle/ 33 | gradle/ 34 | -------------------------------------------------------------------------------- /spring-jooq-gradle/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3.5' 2 | 3 | services: 4 | 5 | todo-db: 6 | image: postgres:13 7 | ports: 8 | - 5433:5432 9 | environment: 10 | - POSTGRES_USER=todouser 11 | - POSTGRES_PASSWORD=todopw 12 | - POSTGRES_DB=tododb 13 | volumes: 14 | - ./init.sql:/docker-entrypoint-initdb.d/init.sql 15 | networks: 16 | - my-network 17 | networks: 18 | my-network: 19 | name: flight-recorder-network2 20 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3.5' 2 | 3 | services: 4 | 5 | todo-db: 6 | image: postgres:13 7 | ports: 8 | - 5432:5432 9 | environment: 10 | - POSTGRES_USER=todouser 11 | - POSTGRES_PASSWORD=todopw 12 | - POSTGRES_DB=tododb 13 | volumes: 14 | - ./example-service/src/main/resources/init.sql:/docker-entrypoint-initdb.d/init.sql 15 | networks: 16 | - my-network 17 | networks: 18 | my-network: 19 | name: flight-recorder-network 20 | -------------------------------------------------------------------------------- /spring-jooq-gradle/src/main/java/org/moditect/jfrunit/demos/spring_jooq/SpringJooqGradleApplication.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.spring_jooq; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringJooqGradleApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringJooqGradleApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-jooq-gradle/README.md: -------------------------------------------------------------------------------- 1 | # Gradle + Spring Boot + JOOQ Example 2 | 3 | This example shows how to emit JFR events from jOOQ upon the execution of SQL queries. 4 | It uses [Gradle JVM toolchains](https://docs.gradle.org/current/userguide/toolchains.html) and Java 17. 5 | 6 | To run this example: 7 | 8 | ```shell 9 | cd examples/spring-jooq-gradle 10 | docker-compose up -d # Start the Postgres container on port 5433 11 | 12 | ./gradlew downloadFile # Download jmc-agent to ./build/jmc-agent 13 | ./gradlew test # Compile and test 14 | ``` 15 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/user-service/src/test/java/org/moditect/jfrunit/demos/user/UserResourceTest.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.user; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import static org.hamcrest.CoreMatchers.containsString; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | import io.quarkus.test.junit.QuarkusTest; 9 | 10 | @QuarkusTest 11 | public class UserResourceTest { 12 | 13 | @Test 14 | public void testHelloEndpoint() { 15 | given() 16 | .when().get("/users/2") 17 | .then() 18 | .statusCode(200) 19 | .body(containsString("Alice")); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | quarkus.datasource.db-kind=postgresql 2 | quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/tododb 3 | # quarkus.datasource.driver=org.postgresql.Driver 4 | quarkus.datasource.username=todouser 5 | quarkus.datasource.password=todopw 6 | #quarkus.hibernate-orm.log.sql=true 7 | 8 | quarkus.hibernate-orm.database.generation=drop-and-create 9 | # quarkus.hibernate-orm.database.generation=update 10 | quarkus.hibernate-orm.database.default-schema=todo 11 | quarkus.log.level=INFO 12 | quarkus.log.min-level=INFO 13 | quarkus.log.console.enable=true 14 | quarkus.log.console.format=%d{HH:mm:ss} %-5p [%c] %s%e%n -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Examples for JfrUnit 2 | 3 | Some examples for spotting potential performance regressions using [JfrUnit](https://github.com/moditect/jfrunit). 4 | 5 | There are currently two examples: 6 | | Example | Technology | Description | 7 | | --- | --- | --- | 8 | | [quarkus-hibernate-maven](./quarkus-hibernate-maven) | Maven, Quarkus, Hibernate, JMC Agent, JUnit | Service Testing GC, object allocation, socket I/O, and Hibernate HQL/SQL events | 9 | | [spring-jooq-gradle](./examples/spring-jooq-gradle) | Gradle, Spring Boot, jOOQ, JMC Agent, JUnit | Service Demonstrating launching Gradle tests with the JMC Agent to test queries executed with the jOOQ DSL | 10 | 11 | ## License 12 | 13 | This code base is available under the Apache License, version 2. 14 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/main/docker/Dockerfile.native: -------------------------------------------------------------------------------- 1 | #### 2 | # This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode 3 | # 4 | # Before building the docker image run: 5 | # 6 | # mvn package -Pnative -Dquarkus.native.container-build=true 7 | # 8 | # Then, build the image with: 9 | # 10 | # docker build -f src/main/docker/Dockerfile.native -t quarkus/flight-recorder-demo . 11 | # 12 | # Then run the container using: 13 | # 14 | # docker run -i --rm -p 8080:8080 quarkus/flight-recorder-demo 15 | # 16 | ### 17 | FROM registry.access.redhat.com/ubi8/ubi-minimal 18 | WORKDIR /work/ 19 | COPY target/*-runner /work/application 20 | RUN chmod 775 /work 21 | EXPOSE 8080 22 | CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] -------------------------------------------------------------------------------- /quarkus-hibernate-maven/user-service/src/main/docker/Dockerfile.native: -------------------------------------------------------------------------------- 1 | #### 2 | # This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode 3 | # 4 | # Before building the container image run: 5 | # 6 | # ./mvnw package -Pnative 7 | # 8 | # Then, build the image with: 9 | # 10 | # docker build -f src/main/docker/Dockerfile.native -t quarkus/user-service . 11 | # 12 | # Then run the container using: 13 | # 14 | # docker run -i --rm -p 8080:8080 quarkus/user-service 15 | # 16 | ### 17 | FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3 18 | WORKDIR /work/ 19 | RUN chown 1001 /work \ 20 | && chmod "g+rwX" /work \ 21 | && chown 1001:root /work 22 | COPY --chown=1001:root target/*-runner /work/application 23 | 24 | EXPOSE 8080 25 | USER 1001 26 | 27 | CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] 28 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/main/java/org/moditect/jfrunit/demos/todo/Todo.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.todo; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | import javax.persistence.SequenceGenerator; 8 | 9 | import io.quarkus.hibernate.orm.panache.PanacheEntityBase; 10 | 11 | @Entity 12 | public class Todo extends PanacheEntityBase { 13 | 14 | @Id 15 | @SequenceGenerator( 16 | name = "todoSequence", 17 | sequenceName = "todo_id_seq", 18 | allocationSize = 10, 19 | initialValue = 1) 20 | @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "todoSequence") 21 | public Long id; 22 | 23 | public String title; 24 | public int priority; 25 | public boolean completed; 26 | public long userId; 27 | public String userName; 28 | } 29 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/main/java/org/moditect/jfrunit/demos/todo/TodoDetail.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.todo; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | import javax.persistence.ManyToOne; 8 | import javax.persistence.SequenceGenerator; 9 | 10 | import com.fasterxml.jackson.annotation.JsonIgnore; 11 | 12 | import io.quarkus.hibernate.orm.panache.PanacheEntityBase; 13 | 14 | @Entity 15 | public class TodoDetail extends PanacheEntityBase { 16 | 17 | @Id 18 | @SequenceGenerator( 19 | name = "todoDetailSequence", 20 | sequenceName = "todo_detail_id_seq", 21 | allocationSize = 10, 22 | initialValue = 1) 23 | @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "todoDetailSequence") 24 | public Long id; 25 | 26 | @ManyToOne 27 | @JsonIgnore 28 | public TodoWithDetails todo; 29 | public String title; 30 | } 31 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/main/java/org/moditect/jfrunit/demos/todo/TodoWithAvatar.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.todo; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | import javax.persistence.Lob; 8 | import javax.persistence.SequenceGenerator; 9 | 10 | import io.quarkus.hibernate.orm.panache.PanacheEntityBase; 11 | 12 | @Entity 13 | public class TodoWithAvatar extends PanacheEntityBase { 14 | 15 | @Id 16 | @SequenceGenerator( 17 | name = "todoWithAvatarSequence", 18 | sequenceName = "todo_with_avatar_id_seq", 19 | allocationSize = 10, 20 | initialValue = 1) 21 | @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "todoWithAvatarSequence") 22 | public Long id; 23 | 24 | public String title; 25 | public int priority; 26 | public boolean completed; 27 | public long userId; 28 | public String userName; 29 | 30 | @Lob 31 | public byte[] avatar; 32 | } 33 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/user-service/src/main/java/org/moditect/jfrunit/demos/user/UserResource.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.user; 2 | 3 | import javax.ws.rs.GET; 4 | import javax.ws.rs.NotFoundException; 5 | import javax.ws.rs.Path; 6 | import javax.ws.rs.PathParam; 7 | import javax.ws.rs.Produces; 8 | import javax.ws.rs.core.MediaType; 9 | 10 | @Path("/users") 11 | public class UserResource { 12 | 13 | @GET 14 | @Produces(MediaType.APPLICATION_JSON) 15 | @Path("/{id}") 16 | public User getUser(@PathParam("id") long id) { 17 | if (id == 1) { 18 | return new User(1, "Bob"); 19 | } 20 | else if (id == 2) { 21 | return new User(2, "Alice"); 22 | } 23 | else if (id == 3) { 24 | return new User(3, "Sarah"); 25 | } 26 | else if (id == 4) { 27 | return new User(4, "Brandon"); 28 | } 29 | else if (id == 5) { 30 | return new User(5, "Megan"); 31 | } 32 | else { 33 | throw new NotFoundException("No user with id " + id); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/test/java/org/moditect/jfrunit/demos/todo/HelloJfrUnitTest.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.todo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import org.moditect.jfrunit.EnableEvent; 6 | import org.moditect.jfrunit.JfrEventTest; 7 | import org.moditect.jfrunit.JfrEvents; 8 | import static org.moditect.jfrunit.JfrEventsAssert.*; 9 | 10 | import java.time.Duration; 11 | 12 | import static org.moditect.jfrunit.ExpectedEvent.*; 13 | 14 | @JfrEventTest 15 | public class HelloJfrUnitTest { 16 | 17 | public JfrEvents events = new JfrEvents(); 18 | 19 | @Test 20 | @EnableEvent("jdk.GarbageCollection") 21 | @EnableEvent("jdk.ThreadSleep") 22 | public void basicTest() throws Exception { 23 | System.gc(); 24 | Thread.sleep(1_000); 25 | 26 | events.awaitEvents(); 27 | 28 | assertThat(events).contains(event("jdk.GarbageCollection")); 29 | assertThat(events).contains(event("jdk.ThreadSleep").with("time", Duration.ofSeconds(1))); 30 | 31 | events.events() 32 | .forEach(e -> System.out.println(e)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-jooq-gradle/src/main/java/org/moditect/jfrunit/demos/spring_jooq/TestUserService.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.spring_jooq; 2 | 3 | import org.jooq.DSLContext; 4 | import org.moditect.jfrunit.demos.spring_jooq.generated.tables.TestUser; 5 | import org.moditect.jfrunit.demos.spring_jooq.generated.tables.records.TestUserRecord; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service 10 | public class TestUserService { 11 | 12 | private final DSLContext dsl; 13 | 14 | @Autowired 15 | public TestUserService(DSLContext dsl) { 16 | this.dsl = dsl; 17 | } 18 | 19 | public boolean createUser(String username, int age) { 20 | int numInserted = dsl.insertInto(TestUser.TEST_USER) 21 | .set(TestUser.TEST_USER.USERNAME, username) 22 | .set(TestUser.TEST_USER.AGE, age) 23 | .execute(); 24 | return numInserted == 1; 25 | } 26 | 27 | public TestUserRecord getUserByUsername(String username) { 28 | return dsl.selectFrom(TestUser.TEST_USER) 29 | .where(TestUser.TEST_USER.USERNAME.eq(username)) 30 | .fetchOne(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/test/java/org/moditect/jfrunit/demos/todo/testutil/MatchesJson.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.todo.testutil; 2 | 3 | import org.hamcrest.Description; 4 | import org.hamcrest.Matcher; 5 | import org.hamcrest.TypeSafeMatcher; 6 | import org.json.JSONException; 7 | import org.skyscreamer.jsonassert.JSONAssert; 8 | 9 | public class MatchesJson extends TypeSafeMatcher { 10 | 11 | private String expected; 12 | 13 | public MatchesJson(String expected) { 14 | this.expected = expected; 15 | } 16 | 17 | @Override 18 | protected boolean matchesSafely(String json) { 19 | try { 20 | JSONAssert.assertEquals(expected, json, false); 21 | return true; 22 | } 23 | catch(AssertionError ae) { 24 | return false; 25 | } 26 | catch (JSONException e) { 27 | throw new RuntimeException(e); 28 | } 29 | } 30 | 31 | @Override 32 | public void describeTo(Description description) { 33 | description.appendText("matches JSON " + expected); 34 | } 35 | 36 | public static Matcher matchesJson(String expected) { 37 | return new MatchesJson(expected); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/test/java/org/moditect/jfrunit/demos/todo/testutil/PostgresResource.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.todo.testutil; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.testcontainers.containers.BindMode; 7 | import org.testcontainers.containers.PostgreSQLContainer; 8 | 9 | import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; 10 | 11 | public class PostgresResource implements QuarkusTestResourceLifecycleManager { 12 | 13 | static PostgreSQLContainer db = new PostgreSQLContainer<>("postgres:13") 14 | .withDatabaseName("tododb") 15 | .withUsername("todouser") 16 | .withPassword("todopw") 17 | .withReuse(true) 18 | .withClasspathResourceMapping("init.sql", 19 | "/docker-entrypoint-initdb.d/init.sql", 20 | BindMode.READ_ONLY); 21 | 22 | @Override 23 | public Map start() { 24 | db.start(); 25 | 26 | Map props = new HashMap<>(); 27 | props.put("quarkus.datasource.jdbc.url", db.getJdbcUrl()); 28 | props.put("jfrunit.database.port", String.valueOf(db.getFirstMappedPort())); 29 | 30 | return props; 31 | } 32 | 33 | @Override 34 | public void stop() { 35 | db.stop(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/main/java/org/moditect/jfrunit/demos/todo/TodoWithDetails.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.todo; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import javax.persistence.CascadeType; 7 | import javax.persistence.Entity; 8 | import javax.persistence.FetchType; 9 | import javax.persistence.GeneratedValue; 10 | import javax.persistence.GenerationType; 11 | import javax.persistence.Id; 12 | import javax.persistence.OneToMany; 13 | import javax.persistence.OrderColumn; 14 | import javax.persistence.SequenceGenerator; 15 | 16 | import org.hibernate.annotations.LazyCollection; 17 | import org.hibernate.annotations.LazyCollectionOption; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnore; 20 | 21 | import io.quarkus.hibernate.orm.panache.PanacheEntityBase; 22 | 23 | @Entity 24 | public class TodoWithDetails extends PanacheEntityBase { 25 | 26 | @Id 27 | @SequenceGenerator( 28 | name = "todoWithDetailsSequence", 29 | sequenceName = "todo_with_details_id_seq", 30 | allocationSize = 10, 31 | initialValue = 1) 32 | @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "todoWithDetailsSequence") 33 | public Long id; 34 | 35 | @OneToMany(cascade = CascadeType.ALL, mappedBy = "todo", fetch = FetchType.LAZY) 36 | @LazyCollection(LazyCollectionOption.EXTRA) 37 | @OrderColumn 38 | @JsonIgnore 39 | public List details = new ArrayList<>(); 40 | public String title; 41 | public int priority; 42 | public boolean completed; 43 | public long userId; 44 | public String userName; 45 | } 46 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/main/docker/Dockerfile.jvm: -------------------------------------------------------------------------------- 1 | #### 2 | # This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode 3 | # 4 | # Before building the docker image run: 5 | # 6 | # mvn package 7 | # 8 | # Then, build the image with: 9 | # 10 | # docker build -f src/main/docker/Dockerfile.jvm -t quarkus/flight-recorder-demo-jvm . 11 | # 12 | # Then run the container using: 13 | # 14 | # docker run -i --rm -p 8080:8080 quarkus/flight-recorder-demo-jvm 15 | # 16 | ### 17 | # FROM fabric8/java-alpine-openjdk8-jre:1.6.5 18 | # ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" 19 | # ENV AB_ENABLED=jmx_exporter 20 | 21 | # Be prepared for running in OpenShift too 22 | # RUN adduser -G root --no-create-home --disabled-password 1001 \ 23 | # && chown -R 1001 /deployments \ 24 | # && chmod -R "g+rwX" /deployments \ 25 | # && chown -R 1001:root /deployments 26 | 27 | FROM fedora:32 28 | 29 | RUN mkdir /tmp/jdk \ 30 | && cd /tmp/jdk \ 31 | && curl -O https://download.java.net/java/GA/jdk15/779bf45e88a44cbd9ea6621d33e33db1/36/GPL/openjdk-15_linux-x64_bin.tar.gz \ 32 | && tar -xvf openjdk-15_linux-x64_bin.tar.gz 33 | 34 | COPY target/lib/* /deployments/lib/ 35 | COPY target/*-runner.jar /deployments/app.jar 36 | EXPOSE 8080 37 | 38 | # run with user 1001 39 | # USER 1001 40 | 41 | ENTRYPOINT [ "/tmp/jdk/jdk-15/bin/java", "-Dcom.sun.management.jmxremote", "-Dcom.sun.management.jmxremote.port=1898", "-Dcom.sun.management.jmxremote.rmi.port=1898", "-Djava.rmi.server.hostname=0.0.0.0", "-Dcom.sun.management.jmxremote.ssl=false", "-Dcom.sun.management.jmxremote.authenticate=false", "-Dcom.sun.management.jmxremote.local.only=false", "-jar", "/deployments/app.jar", "-Dquarkus.http.host=0.0.0.0", "-Djava.util.logging.manager=org.jboss.logmanager.LogManager" ] 42 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/README.md: -------------------------------------------------------------------------------- 1 | # Example service (Quarkus + Hibernate) 2 | 3 | ## Prerequisites 4 | 5 | This project requires OpenJDK 17 and Apache Maven for its build. 6 | 7 | ## Build 8 | 9 | Run the following to build the project: 10 | 11 | ```shell 12 | cd user-service 13 | mvn clean verify 14 | java -Dquarkus.http.port=8082 -jar target/quarkus-app/quarkus-run.jar 15 | ``` 16 | 17 | This starts the "user" service, which is accessed by the example service within one of the regression scenarios. 18 | Then build the example service itself: 19 | 20 | ```shell 21 | cd example-service 22 | mvn clean verify 23 | ``` 24 | 25 | In each test class, there's a method `...Regression()` which is commented out. 26 | When commenting it in, this test should fail due to a performance "regresssion", 27 | e.g. due to higher memory allocation than expected, more IO, or more SQL statements. 28 | 29 | [JMC Agent](https://developers.redhat.com/blog/2020/10/29/collect-jdk-flight-recorder-events-at-runtime-with-jmc-agent) is used in the `TodoResourceSqlStatementsTest` 30 | for emitting JFR events from Hibernate / its connection pool. 31 | As JMC Agent isn't available as a Maven dependency on Maven Central, 32 | it is retrieved using the `download-maven-plugin` from the https://github.com/adoptium/jmc-overrides/releases[Adoptium JMC Overrides project]. 33 | 34 | ## Running in the IDE 35 | 36 | When running the `TodoResourceSqlStatementsTest` in your IDE, make sure to specify the correct JMC Agent configuration, 37 | as seen in the _example-service/pom.xml_ file. 38 | 39 | ## Running the Application 40 | 41 | For manual testing, build the application, start a separate Postgres instance via Docker Compose and launch the app like so: 42 | 43 | ```shell 44 | docker-compose up 45 | cd example-service 46 | clean verify -DskipTests=true 47 | java -jar ./examples/example-service/target/quarkus-app/quarkus-run.jar 48 | 49 | # Testing, e.g. via httpie 50 | http POST localhost:8080/todo title=Test priority=2 completed=true 51 | ``` 52 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/user-service/src/main/docker/Dockerfile.jvm: -------------------------------------------------------------------------------- 1 | #### 2 | # This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode 3 | # 4 | # Before building the container image run: 5 | # 6 | # ./mvnw package 7 | # 8 | # Then, build the image with: 9 | # 10 | # docker build -f src/main/docker/Dockerfile.jvm -t quarkus/user-service-jvm . 11 | # 12 | # Then run the container using: 13 | # 14 | # docker run -i --rm -p 8080:8080 quarkus/user-service-jvm 15 | # 16 | # If you want to include the debug port into your docker image 17 | # you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5050 18 | # 19 | # Then run the container using : 20 | # 21 | # docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/user-service-jvm 22 | # 23 | ### 24 | FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3 25 | 26 | ARG JAVA_PACKAGE=java-11-openjdk-headless 27 | ARG RUN_JAVA_VERSION=1.3.8 28 | ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' 29 | # Install java and the run-java script 30 | # Also set up permissions for user `1001` 31 | RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \ 32 | && microdnf update \ 33 | && microdnf clean all \ 34 | && mkdir /deployments \ 35 | && chown 1001 /deployments \ 36 | && chmod "g+rwX" /deployments \ 37 | && chown 1001:root /deployments \ 38 | && curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \ 39 | && chown 1001 /deployments/run-java.sh \ 40 | && chmod 540 /deployments/run-java.sh \ 41 | && echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security 42 | 43 | # Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. 44 | ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" 45 | COPY target/lib/* /deployments/lib/ 46 | COPY target/*-runner.jar /deployments/app.jar 47 | 48 | EXPOSE 8080 49 | USER 1001 50 | 51 | ENTRYPOINT [ "/deployments/run-java.sh" ] 52 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/user-service/src/main/docker/Dockerfile.fast-jar: -------------------------------------------------------------------------------- 1 | #### 2 | # This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode 3 | # 4 | # Before building the container image run: 5 | # 6 | # ./mvnw package -Dquarkus.package.type=fast-jar 7 | # 8 | # Then, build the image with: 9 | # 10 | # docker build -f src/main/docker/Dockerfile.fast-jar -t quarkus/user-service-fast-jar . 11 | # 12 | # Then run the container using: 13 | # 14 | # docker run -i --rm -p 8080:8080 quarkus/user-service-fast-jar 15 | # 16 | # If you want to include the debug port into your docker image 17 | # you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5050 18 | # 19 | # Then run the container using : 20 | # 21 | # docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/user-service-fast-jar 22 | # 23 | ### 24 | FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3 25 | 26 | ARG JAVA_PACKAGE=java-11-openjdk-headless 27 | ARG RUN_JAVA_VERSION=1.3.8 28 | ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' 29 | # Install java and the run-java script 30 | # Also set up permissions for user `1001` 31 | RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \ 32 | && microdnf update \ 33 | && microdnf clean all \ 34 | && mkdir /deployments \ 35 | && chown 1001 /deployments \ 36 | && chmod "g+rwX" /deployments \ 37 | && chown 1001:root /deployments \ 38 | && curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \ 39 | && chown 1001 /deployments/run-java.sh \ 40 | && chmod 540 /deployments/run-java.sh \ 41 | && echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security 42 | 43 | # Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. 44 | ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" 45 | # We make four distinct layers so if there are application changes the library layers can be re-used 46 | COPY --chown=1001 target/quarkus-app/lib/ /deployments/lib/ 47 | COPY --chown=1001 target/quarkus-app/*.jar /deployments/ 48 | COPY --chown=1001 target/quarkus-app/app/ /deployments/app/ 49 | COPY --chown=1001 target/quarkus-app/quarkus/ /deployments/quarkus/ 50 | 51 | EXPOSE 8080 52 | USER 1001 53 | 54 | ENTRYPOINT [ "/deployments/run-java.sh" ] 55 | -------------------------------------------------------------------------------- /spring-jooq-gradle/src/test/java/org/moditect/jfrunit/demos/spring_jooq/SpringJooqGradleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.spring_jooq; 2 | 3 | import java.util.concurrent.ThreadLocalRandom; 4 | import jdk.jfr.consumer.RecordedEvent; 5 | import org.assertj.core.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | import org.moditect.jfrunit.JfrEventTest; 8 | import org.moditect.jfrunit.JfrEvents; 9 | import org.moditect.jfrunit.demos.spring_jooq.generated.tables.records.TestUserRecord; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | @SpringBootTest 14 | @JfrEventTest 15 | public class SpringJooqGradleApplicationTests { 16 | 17 | @Autowired 18 | public TestUserService testUserService; 19 | 20 | public JfrEvents jfrEvents = new JfrEvents(); 21 | 22 | @Test 23 | public void contextLoads() { 24 | } 25 | 26 | @Test 27 | public void createUser() { 28 | boolean success = testUserService.createUser(String.valueOf(ThreadLocalRandom.current().nextLong()), 29 | ThreadLocalRandom.current().nextInt()); 30 | Assertions.assertThat(success).isTrue(); 31 | 32 | jfrEvents.awaitEvents(); 33 | Assertions.assertThat(jfrEvents.events().filter(this::isQueryEvent).count()).isEqualTo(1); 34 | } 35 | 36 | @Test 37 | public void createAndFindUser() { 38 | final String username = String.valueOf(ThreadLocalRandom.current().nextLong()); 39 | final int age = ThreadLocalRandom.current().nextInt(); 40 | boolean success = testUserService.createUser(username, 41 | age); 42 | Assertions.assertThat(success).isTrue(); 43 | 44 | jfrEvents.awaitEvents(); 45 | Assertions.assertThat(jfrEvents.events().filter(this::isQueryEvent).count()).isEqualTo(1); 46 | 47 | TestUserRecord ourUser = testUserService.getUserByUsername(username); 48 | Assertions.assertThat(ourUser).isNotNull(); 49 | Assertions.assertThat(ourUser.getUsername()).isEqualTo(username); 50 | Assertions.assertThat(ourUser.getAge()).isEqualTo(age); 51 | 52 | jfrEvents.awaitEvents(); 53 | Assertions.assertThat(jfrEvents.events().filter(this::isQueryEvent).count()).isEqualTo(2); 54 | } 55 | 56 | private boolean isQueryEvent(RecordedEvent event) { 57 | return event.getEventType().getName().equals("jooq.AbstractQuery") || 58 | event.getEventType().getName().equals("jooq.AbstractResultQuery"); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /spring-jooq-gradle/jooq-probes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | __JFREvent 7 | true 8 | true 9 | 10 | 11 | 12 | 13 | org.jooq.impl.AbstractQuery 14 | Emitted when jOOQ executes a statement, may contain the rendered SQL 15 | JDBC 16 | true 17 | false 18 | WRAP 19 | 20 | execute 21 | (Lorg/jooq/ExecuteContext;Lorg/jooq/ExecuteListener;)I 22 | 23 | 24 | SQL 25 | Rendered SQL String, may be null 26 | None 27 | org.moditect.jfrunit.demos.spring_jooq.ExecuteContextSqlConverter 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.jooq.impl.AbstractResultQuery 35 | Emitted when jOOQ executes a statement, may contain the rendered SQL 36 | JDBC 37 | true 38 | false 39 | WRAP 40 | 41 | execute 42 | (Lorg/jooq/ExecuteContext;Lorg/jooq/ExecuteListener;)I 43 | 44 | 45 | SQL 46 | Rendered SQL String, may be null 47 | None 48 | org.moditect.jfrunit.demos.spring_jooq.ExecuteContextSqlConverter 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /spring-jooq-gradle/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /spring-jooq-gradle/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.6.3' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'nu.studer.jooq' version '7.1' 5 | id 'java' 6 | id "de.undercouch.download" version "5.0.1" 7 | } 8 | 9 | group = 'org.moditect.jfrunit.demos' 10 | version = '0.0.1-SNAPSHOT' 11 | 12 | java { 13 | toolchain { 14 | languageVersion = JavaLanguageVersion.of(17) 15 | } 16 | } 17 | 18 | repositories { 19 | mavenCentral() 20 | } 21 | 22 | configurations { 23 | jmcAgent 24 | } 25 | 26 | dependencies { 27 | implementation 'org.springframework.boot:spring-boot-starter-jooq' 28 | runtimeOnly 'org.postgresql:postgresql' 29 | jooqGenerator 'org.postgresql:postgresql' 30 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 31 | testImplementation 'org.moditect.jfrunit:jfrunit-core:1.0.0.Alpha2' 32 | } 33 | 34 | task downloadFile(type: Download) { 35 | src 'https://github.com/adoptium/jmc-overrides/releases/download/8.1.1/agent-1.0.1.jar' 36 | dest "$buildDir/jmc-agent/" 37 | } 38 | 39 | tasks.named('test') { 40 | jvmArgs += "-javaagent:$buildDir/jmc-agent=jooq-probes.xml" 41 | jvmArgs += "--add-opens" 42 | jvmArgs += "java.base/jdk.internal.misc=ALL-UNNAMED" 43 | useJUnitPlatform() 44 | } 45 | 46 | jooq { 47 | version = dependencyManagement.importedProperties['jooq.version'] 48 | edition = nu.studer.gradle.jooq.JooqEdition.OSS 49 | 50 | configurations { 51 | main { // name of the jOOQ configuration 52 | generateSchemaSourceOnCompilation = true 53 | 54 | generationTool { 55 | logging = org.jooq.meta.jaxb.Logging.WARN 56 | jdbc { 57 | driver = 'org.postgresql.Driver' 58 | url = 'jdbc:postgresql://localhost:5433/tododb' 59 | user = 'todouser' 60 | password = 'todopw' 61 | } 62 | generator { 63 | name = 'org.jooq.codegen.DefaultGenerator' 64 | database { 65 | name = 'org.jooq.meta.postgres.PostgresDatabase' 66 | inputSchema = 'public' 67 | forcedTypes { 68 | forcedType { 69 | name = 'varchar' 70 | includeExpression = '.*' 71 | includeTypes = 'JSONB?' 72 | } 73 | forcedType { 74 | name = 'varchar' 75 | includeExpression = '.*' 76 | includeTypes = 'INET' 77 | } 78 | } 79 | } 80 | generate { 81 | deprecated = false 82 | records = true 83 | immutablePojos = true 84 | fluentSetters = true 85 | } 86 | target { 87 | packageName = 'org.moditect.jfrunit.demos.spring_jooq.generated' 88 | directory = 'build/generated-src/jooq/main' // default (can be omitted) 89 | } 90 | strategy.name = 'org.jooq.codegen.DefaultGeneratorStrategy' 91 | } 92 | } 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/hibernate-probes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | __JFREvent 5 | true 6 | true 7 | 8 | 9 | 10 | 11 | Execution of a prepared query 12 | Hibernate 13 | true 14 | io.agroal.pool.wrapper.PreparedStatementWrapper 15 | 16 | executeQuery 17 | ()Ljava/sql/ResultSet; 18 | 19 | WRAP 20 | 21 | 22 | SQL Query 23 | The executed SQL query 24 | wrappedStatement 25 | 26 | 27 | 28 | 29 | 30 | 31 | Execution of a prepared update 32 | Hibernate 33 | true 34 | io.agroal.pool.wrapper.PreparedStatementWrapper 35 | 36 | executeUpdate 37 | ()I 38 | 39 | WRAP 40 | 41 | 42 | 43 | SQL Query 44 | The executed SQL query 45 | wrappedStatement 46 | 47 | 48 | 49 | 50 | 51 | 52 | Execution of a query 53 | Hibernate 54 | true 55 | io.agroal.pool.wrapper.StatementWrapper 56 | 57 | 58 | execute 59 | (Ljava/lang/String;)Z 60 | 61 | 62 | 63 | SQL Query 64 | The executed SQL query 65 | None 66 | 67 | 68 | 69 | 70 | WRAP 71 | 72 | 73 | 74 | 75 | Bind parameter of a prepared query 76 | Hibernate 77 | true 78 | org.hibernate.type.descriptor.sql.BasicBinder 79 | 80 | bind 81 | (Ljava/sql/PreparedStatement;Ljava/lang/Object;ILorg/hibernate/type/descriptor/WrapperOptions;)V 82 | 83 | 84 | 85 | Bind Parameter 86 | The bind parameter 87 | None 88 | 89 | 90 | Index 91 | The parameter index 92 | None 93 | 94 | 95 | 96 | ENTRY 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/user-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | org.moditect.jfrunit.demos 6 | jfrunit-demo-user 7 | 1.0.0-SNAPSHOT 8 | 9 | 2.22.1 10 | true 11 | 17 12 | 2.9.0.Final 13 | UTF-8 14 | quarkus-universe-bom 15 | UTF-8 16 | true 17 | 2.9.0.Final 18 | 3.8.1 19 | io.quarkus 20 | 21 | 22 | 23 | 24 | ${quarkus.platform.group-id} 25 | ${quarkus.platform.artifact-id} 26 | ${quarkus.platform.version} 27 | pom 28 | import 29 | 30 | 31 | 32 | 33 | 34 | io.quarkus 35 | quarkus-resteasy-jackson 36 | 37 | 38 | io.quarkus 39 | quarkus-arc 40 | 41 | 42 | io.quarkus 43 | quarkus-resteasy 44 | 45 | 46 | io.quarkus 47 | quarkus-junit5 48 | test 49 | 50 | 51 | io.rest-assured 52 | rest-assured 53 | test 54 | 55 | 56 | 57 | 58 | 59 | io.quarkus 60 | quarkus-maven-plugin 61 | ${quarkus-plugin.version} 62 | true 63 | 64 | 65 | 66 | build 67 | generate-code 68 | generate-code-tests 69 | 70 | 71 | 72 | 73 | 74 | maven-compiler-plugin 75 | ${compiler-plugin.version} 76 | 77 | 78 | maven-surefire-plugin 79 | ${surefire-plugin.version} 80 | 81 | 82 | org.jboss.logmanager.LogManager 83 | ${maven.home} 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | native 92 | 93 | 94 | native 95 | 96 | 97 | 98 | 99 | 100 | maven-failsafe-plugin 101 | ${surefire-plugin.version} 102 | 103 | 104 | 105 | integration-test 106 | verify 107 | 108 | 109 | 110 | ${project.build.directory}/${project.build.finalName}-runner 111 | org.jboss.logmanager.LogManager 112 | ${maven.home} 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | native 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/main/java/org/moditect/jfrunit/demos/todo/TodoResource.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.todo; 2 | 3 | import java.net.URI; 4 | import java.util.Base64; 5 | 6 | import javax.inject.Inject; 7 | import javax.persistence.EntityManager; 8 | import javax.transaction.Transactional; 9 | import javax.ws.rs.Consumes; 10 | import javax.ws.rs.GET; 11 | import javax.ws.rs.POST; 12 | import javax.ws.rs.Path; 13 | import javax.ws.rs.PathParam; 14 | import javax.ws.rs.Produces; 15 | import javax.ws.rs.core.MediaType; 16 | import javax.ws.rs.core.Response; 17 | import javax.ws.rs.core.Response.Status; 18 | 19 | import io.restassured.RestAssured; 20 | 21 | @Path("/todo") 22 | public class TodoResource { 23 | 24 | @Inject 25 | EntityManager em; 26 | 27 | public static void main(String[] args) { 28 | StringBuilder sb = new StringBuilder(); 29 | 30 | for(int i = 0; i < 20; i++) { 31 | sb.append("Hello World, hello JfrUnit! "); 32 | } 33 | System.out.println(Base64.getEncoder().encodeToString(sb.toString().getBytes())); 34 | } 35 | 36 | @POST 37 | @Consumes(MediaType.APPLICATION_JSON) 38 | @Produces(MediaType.APPLICATION_JSON) 39 | @Transactional 40 | public Response addTodo(Todo todo) { 41 | todo.persist(); 42 | 43 | return Response.created(URI.create("/todo/" + todo.id)) 44 | .entity(todo) 45 | .build(); 46 | } 47 | 48 | @POST 49 | @Consumes(MediaType.APPLICATION_JSON) 50 | @Produces(MediaType.APPLICATION_JSON) 51 | @Path("/todo-with-avatar") 52 | @Transactional 53 | public Response addTodoWithAvatar(TodoWithAvatar todo) { 54 | todo.persist(); 55 | 56 | return Response.created(URI.create("/todo-with-avatar/" + todo.id)) 57 | .entity(todo) 58 | .build(); 59 | } 60 | 61 | @POST 62 | @Consumes(MediaType.APPLICATION_JSON) 63 | @Produces(MediaType.APPLICATION_JSON) 64 | @Path("/todo-with-details") 65 | @Transactional 66 | public Response addTodoWithDetails(TodoWithDetails todo) { 67 | TodoDetail detail = new TodoDetail(); 68 | detail.todo = todo; 69 | detail.title = "Detail 1"; 70 | todo.details.add(detail); 71 | 72 | detail = new TodoDetail(); 73 | detail.todo = todo; 74 | detail.title = "Detail 2"; 75 | todo.details.add(detail); 76 | 77 | detail = new TodoDetail(); 78 | detail.todo = todo; 79 | detail.title = "Detail 3"; 80 | todo.details.add(detail); 81 | 82 | detail = new TodoDetail(); 83 | detail.todo = todo; 84 | detail.title = "Detail 4"; 85 | todo.details.add(detail); 86 | 87 | todo.persist(); 88 | 89 | return Response.created(URI.create("/todo/" + todo.id)) 90 | .entity(todo) 91 | .build(); 92 | } 93 | 94 | @GET 95 | @Transactional 96 | @Produces(MediaType.APPLICATION_JSON) 97 | @Path("/{id}") 98 | public Response get(@PathParam("id") long id) throws Exception { 99 | Todo todo = Todo.findById(id); 100 | 101 | return todo != null ? 102 | Response.ok().entity(todo).build() : 103 | Response.status(Status.NOT_FOUND).build(); 104 | } 105 | 106 | @GET 107 | @Transactional 108 | @Produces(MediaType.APPLICATION_JSON) 109 | @Path("/with-allocation-regression/{id}") 110 | public Response getWithAllocationRegression(@PathParam("id") long id) throws Exception { 111 | Todo todo = Todo.findById(id); 112 | 113 | User user = RestAssured 114 | .given() 115 | .port(8082) 116 | .when() 117 | .get("/users/" + todo.userId) 118 | .as(User.class); 119 | 120 | todo.userName = user.name; 121 | 122 | return todo != null ? 123 | Response.ok().entity(todo).build() : 124 | Response.status(Status.NOT_FOUND).build(); 125 | } 126 | 127 | @GET 128 | @Transactional 129 | @Produces(MediaType.APPLICATION_JSON) 130 | @Path("/with-io-regression/{id}") 131 | public Response getWithIoRegression(@PathParam("id") long id) throws Exception { 132 | TodoWithAvatar todo = TodoWithAvatar.findById(id); 133 | 134 | return todo != null ? 135 | Response.ok().entity(todo).build() : 136 | Response.status(Status.NOT_FOUND).build(); 137 | } 138 | 139 | @GET 140 | @Transactional 141 | @Produces(MediaType.APPLICATION_JSON) 142 | @Path("/with-sql-regression/{id}") 143 | public Response getWithSqlRegression(@PathParam("id") long id) throws Exception { 144 | TodoWithDetails todo = TodoWithDetails.findById(id); 145 | StringBuilder sb = new StringBuilder(); 146 | for (int i = 0; i < todo.details.size(); i++) { 147 | sb.append(todo.details.get(i).title); 148 | } 149 | 150 | return todo != null ? 151 | Response.ok().entity(todo).build() : 152 | Response.status(Status.NOT_FOUND).build(); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/test/java/org/moditect/jfrunit/demos/todo/TodoResourceSqlStatementsTest.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.todo; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import static org.assertj.core.api.Assertions.assertThat; 5 | import static org.moditect.jfrunit.EnableEvent.StacktracePolicy.INCLUDED; 6 | 7 | import java.util.Random; 8 | import java.util.stream.Collectors; 9 | 10 | import org.eclipse.microprofile.config.inject.ConfigProperty; 11 | import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; 12 | import org.junit.jupiter.api.Order; 13 | import org.junit.jupiter.api.Test; 14 | import org.junit.jupiter.api.TestMethodOrder; 15 | import org.moditect.jfrunit.EnableEvent; 16 | import org.moditect.jfrunit.JfrEvents; 17 | import org.moditect.jfrunit.demos.todo.testutil.PostgresResource; 18 | 19 | import io.quarkus.test.common.QuarkusTestResource; 20 | import io.quarkus.test.junit.QuarkusTest; 21 | import io.restassured.http.ContentType; 22 | import jdk.jfr.consumer.RecordedEvent; 23 | 24 | @QuarkusTest 25 | @QuarkusTestResource(PostgresResource.class) 26 | @TestMethodOrder(value = OrderAnnotation.class) 27 | public class TodoResourceSqlStatementsTest { 28 | 29 | private static final int ITERATIONS = 10; 30 | 31 | public JfrEvents jfrEvents = new JfrEvents(); 32 | 33 | @ConfigProperty(name="jfrunit.database.port") 34 | public int databasePort; 35 | 36 | @Test 37 | @Order(1) 38 | public void setupTodos() { 39 | Random r = new Random(); 40 | 41 | for (int i = 1; i<= 20; i++) { 42 | given() 43 | .when() 44 | .body(String.format(""" 45 | { 46 | "title" : "Learn Quarkus", 47 | "priority" : 1, 48 | "userId" : %s 49 | } 50 | """, 51 | r.nextInt(5) + 1) 52 | ) 53 | .contentType(ContentType.JSON) 54 | .post("/todo") 55 | .then() 56 | .statusCode(201); 57 | given() 58 | .when() 59 | .body(String.format(""" 60 | { 61 | "title" : "Learn Quarkus", 62 | "priority" : 1, 63 | "userId" : %s 64 | } 65 | """, 66 | r.nextInt(5) + 1) 67 | ) 68 | .contentType(ContentType.JSON) 69 | .post("/todo/todo-with-details") 70 | .then() 71 | .statusCode(201); 72 | } 73 | } 74 | 75 | // @Test 76 | @Order(2) 77 | public void retrieveTodoBaseline() throws Exception { 78 | Random r = new Random(); 79 | 80 | for (int i = 1; i<= ITERATIONS; i++) { 81 | int id = r.nextInt(20) + 1; 82 | 83 | given() 84 | .when() 85 | .contentType(ContentType.JSON) 86 | .get("/todo/" + id) 87 | .then() 88 | .statusCode(200); 89 | } 90 | 91 | jfrEvents.awaitEvents(); 92 | 93 | jfrEvents.filter(this::isQueryEvent) 94 | .forEach(System.out::println); 95 | 96 | long numberOfStatements = jfrEvents.filter(this::isQueryEvent) 97 | .count(); 98 | 99 | System.out.println("### Event count: " + numberOfStatements); 100 | } 101 | 102 | @Test 103 | @Order(3) 104 | public void retrieveTodoShouldYieldCorrectNumberOfSqlStatements() throws Exception { 105 | Random r = new Random(); 106 | 107 | for (int i = 1; i<= ITERATIONS; i++) { 108 | int id = r.nextInt(20) + 1; 109 | 110 | given() 111 | .when() 112 | .contentType(ContentType.JSON) 113 | .get("/todo/" + id) 114 | .then() 115 | .statusCode(200); 116 | } 117 | 118 | jfrEvents.awaitEvents(); 119 | 120 | long numberOfStatements = jfrEvents.filter(this::isQueryEvent) 121 | .count(); 122 | 123 | assertThat(numberOfStatements).isEqualTo(ITERATIONS); 124 | } 125 | 126 | // @Test 127 | @Order(4) 128 | @EnableEvent(value="jdk.SocketRead", threshold = 0, stackTrace=INCLUDED) 129 | @EnableEvent(value="jdk.SocketWrite", threshold = 0, stackTrace=INCLUDED) 130 | public void retrieveTodoSqlStatementRegression() throws Exception { 131 | Random r = new Random(); 132 | 133 | for (int i = 1; i<= ITERATIONS; i++) { 134 | int id = r.nextInt(20) + 1; 135 | 136 | given() 137 | .when() 138 | .contentType(ContentType.JSON) 139 | .get("/todo/with-sql-regression/" + id) 140 | .then() 141 | .statusCode(200); 142 | } 143 | 144 | jfrEvents.awaitEvents(); 145 | 146 | long numberOfStatements = jfrEvents.filter(this::isQueryEvent) 147 | .count(); 148 | 149 | // expected to fail 150 | assertThat(numberOfStatements) 151 | .describedAs("Expecting %s statements, but got these: %s", 152 | ITERATIONS, 153 | jfrEvents.filter(this::isQueryEvent) 154 | .map(e -> e.getString("SQLQuery")) 155 | .collect(Collectors.joining(System.lineSeparator()))) 156 | .isEqualTo(ITERATIONS); 157 | } 158 | 159 | private boolean isQueryEvent(RecordedEvent event) { 160 | return event.getEventType().getName().equals("jdbc.PreparedQuery"); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | org.moditect.jfrunit.demos 6 | jfrunit-demo-todo 7 | 1.0.0-SNAPSHOT 8 | 9 | 3.8.1 10 | true 11 | 17 12 | UTF-8 13 | UTF-8 14 | 2.9.0.Final 15 | quarkus-bom 16 | io.quarkus 17 | 2.9.0.Final 18 | 2.22.1 19 | 3.1.2 20 | 21 | 22 | 23 | 24 | ${quarkus.platform.group-id} 25 | ${quarkus.platform.artifact-id} 26 | ${quarkus.platform.version} 27 | pom 28 | import 29 | 30 | 31 | 32 | 33 | 34 | io.quarkus 35 | quarkus-resteasy 36 | 37 | 38 | io.quarkus 39 | quarkus-resteasy-jackson 40 | 41 | 42 | io.quarkus 43 | quarkus-jdbc-postgresql 44 | 45 | 46 | io.quarkus 47 | quarkus-hibernate-orm-panache 48 | 49 | 50 | 51 | io.quarkus 52 | quarkus-junit5 53 | test 54 | 55 | 56 | io.rest-assured 57 | rest-assured 58 | 59 | 60 | 61 | org.assertj 62 | assertj-core 63 | 3.22.0 64 | test 65 | 66 | 67 | org.testcontainers 68 | junit-jupiter 69 | test 70 | 71 | 72 | org.testcontainers 73 | postgresql 74 | test 75 | 76 | 77 | org.skyscreamer 78 | jsonassert 79 | 1.5.0 80 | test 81 | 82 | 83 | org.moditect.jfrunit 84 | jfrunit-core 85 | 1.0.0.Alpha2 86 | test 87 | 88 | 89 | 90 | 91 | 92 | com.googlecode.maven-download-plugin 93 | download-maven-plugin 94 | 1.6.7 95 | 96 | 97 | install-jmc-agent 98 | generate-test-sources 99 | 100 | wget 101 | 102 | 103 | 104 | 105 | https://github.com/adoptium/jmc-overrides/releases/download/8.1.1/agent-1.0.1.jar 106 | ${project.build.directory}/jmc-agent/ 107 | d42b1b8d55cfbee4b320a4996157bb49 108 | 109 | 110 | 111 | io.quarkus 112 | quarkus-maven-plugin 113 | ${quarkus-plugin.version} 114 | 115 | 116 | 117 | build 118 | 119 | 120 | 121 | 122 | 123 | maven-compiler-plugin 124 | ${compiler-plugin.version} 125 | 126 | 127 | 128 | maven-surefire-plugin 129 | ${surefire-plugin.version} 130 | 131 | -javaagent:${project.build.directory}/jmc-agent/agent-1.0.1.jar=hibernate-probes.xml --add-opens=java.base/jdk.internal.misc=ALL-UNNAMED 132 | 133 | org.jboss.logmanager.LogManager 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | native 142 | 143 | 144 | native 145 | 146 | 147 | 148 | 149 | 150 | maven-failsafe-plugin 151 | ${surefire-plugin.version} 152 | 153 | 154 | 155 | integration-test 156 | verify 157 | 158 | 159 | 160 | ${project.build.directory}/${project.build.finalName}-runner 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | native 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/test/java/org/moditect/jfrunit/demos/todo/TodoResourceMemoryAllocationTest.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.todo; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import static org.assertj.core.api.Assertions.assertThat; 5 | 6 | import java.io.IOException; 7 | import java.net.URI; 8 | import java.net.URISyntaxException; 9 | import java.net.http.HttpClient; 10 | import java.net.http.HttpRequest; 11 | import java.net.http.HttpResponse; 12 | import java.util.Locale; 13 | import java.util.Random; 14 | 15 | import org.junit.jupiter.api.Order; 16 | import org.junit.jupiter.api.Test; 17 | import org.junit.jupiter.api.TestMethodOrder; 18 | import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; 19 | import org.moditect.jfrunit.demos.todo.testutil.PostgresResource; 20 | 21 | import org.moditect.jfrunit.EnableEvent; 22 | import org.moditect.jfrunit.JfrEvents; 23 | import io.quarkus.test.common.QuarkusTestResource; 24 | import io.quarkus.test.junit.QuarkusTest; 25 | import io.restassured.http.ContentType; 26 | import jdk.jfr.consumer.RecordedEvent; 27 | 28 | @QuarkusTest 29 | @QuarkusTestResource(PostgresResource.class) 30 | @TestMethodOrder(value = OrderAnnotation.class) 31 | public class TodoResourceMemoryAllocationTest { 32 | 33 | private static final int ITERATIONS = 10_000; 34 | private static final int WARMUP_ITERATIONS = 20_000; 35 | 36 | public JfrEvents jfrEvents = new JfrEvents(); 37 | 38 | @Test 39 | @Order(1) 40 | public void setupTodos() { 41 | Random r = new Random(); 42 | 43 | for (int i = 1; i<= 20; i++) { 44 | given() 45 | .when() 46 | .body(String.format(""" 47 | { 48 | "title" : "Learn Quarkus", 49 | "priority" : 1, 50 | "userId" : %s 51 | } 52 | """, r.nextInt(5) + 1)) 53 | .contentType(ContentType.JSON) 54 | .post("/todo") 55 | .then() 56 | .statusCode(201); 57 | } 58 | } 59 | 60 | // @Test 61 | @Order(2) 62 | @EnableEvent("jdk.ObjectAllocationInNewTLAB") 63 | @EnableEvent("jdk.ObjectAllocationOutsideTLAB") 64 | public void retrieveTodoBaseline() throws Exception { 65 | Random r = new Random(); 66 | 67 | HttpClient client = HttpClient.newBuilder() 68 | .build(); 69 | 70 | for (int i = 1; i<= 100_000; i++) { 71 | executeRequest(r.nextInt(20) + 1, client); 72 | 73 | if (i % 10_000 == 0) { 74 | jfrEvents.awaitEvents(); 75 | 76 | long sum = jfrEvents.filter(this::isObjectAllocationEvent) 77 | .filter(this::isRelevantThread) 78 | .mapToLong(this::getAllocationSize) 79 | .sum(); 80 | 81 | System.out.printf(Locale.ENGLISH, "Requests executed: %s, memory allocated: %s bytes/request%n", i, sum/10_000); 82 | jfrEvents.reset(); 83 | } 84 | } 85 | } 86 | 87 | @Test 88 | @Order(3) 89 | @EnableEvent("jdk.ObjectAllocationInNewTLAB") 90 | @EnableEvent("jdk.ObjectAllocationOutsideTLAB") 91 | public void retrieveTodoShouldYieldExpectedAllocation() throws Exception { 92 | Random r = new Random(); 93 | 94 | HttpClient client = HttpClient.newBuilder() 95 | .build(); 96 | 97 | // warm-up 98 | for (int i = 1; i<= WARMUP_ITERATIONS; i++) { 99 | if (i % 1000 == 0) { 100 | System.out.println(i); 101 | } 102 | executeRequest(r.nextInt(20) + 1, client); 103 | } 104 | 105 | jfrEvents.awaitEvents(); 106 | jfrEvents.reset(); 107 | 108 | for (int i = 1; i<= ITERATIONS; i++) { 109 | if (i % 1000 == 0) { 110 | System.out.println(i); 111 | } 112 | executeRequest(r.nextInt(20) + 1, client); 113 | } 114 | 115 | jfrEvents.awaitEvents(); 116 | 117 | long sum = jfrEvents.filter(this::isObjectAllocationEvent) 118 | .filter(this::isRelevantThread) 119 | .mapToLong(this::getAllocationSize) 120 | .sum(); 121 | 122 | assertThat(sum / ITERATIONS).isLessThan(33_000); 123 | } 124 | 125 | // @Test 126 | @Order(4) 127 | @EnableEvent("jdk.ObjectAllocationInNewTLAB") 128 | @EnableEvent("jdk.ObjectAllocationOutsideTLAB") 129 | public void retrieveTodoAllocationRegression() throws Exception { 130 | Random r = new Random(); 131 | 132 | HttpClient client = HttpClient.newBuilder() 133 | .build(); 134 | 135 | // warm-up 136 | for (int i = 1; i<= WARMUP_ITERATIONS; i++) { 137 | if (i % 1_000 == 0) { 138 | System.out.println(i); 139 | } 140 | executeRequest("with-allocation-regression/", r.nextInt(20) + 1, client); 141 | } 142 | 143 | jfrEvents.awaitEvents(); 144 | jfrEvents.reset(); 145 | 146 | for (int i = 1; i<= ITERATIONS; i++) { 147 | if (i % 1_000 == 0) { 148 | System.out.println(i); 149 | } 150 | executeRequest("with-allocation-regression/", r.nextInt(20) + 1, client); 151 | } 152 | 153 | jfrEvents.awaitEvents(); 154 | 155 | long sum = jfrEvents.filter(this::isObjectAllocationEvent) 156 | .filter(this::isRelevantThread) 157 | .mapToLong(this::getAllocationSize) 158 | .sum(); 159 | 160 | // expected to fail 161 | assertThat(sum / ITERATIONS).isLessThan(33_000); 162 | } 163 | 164 | private void executeRequest(long id, HttpClient client) throws URISyntaxException, IOException, InterruptedException { 165 | executeRequest("", id, client); 166 | } 167 | 168 | private void executeRequest(String pathPrefix, long id, HttpClient client) throws URISyntaxException, IOException, InterruptedException { 169 | HttpRequest request = HttpRequest.newBuilder() 170 | .uri(new URI("http://localhost:8081/todo/" + pathPrefix + id)) 171 | .headers("Content-Type", "application/json") 172 | .GET() 173 | .build(); 174 | 175 | HttpResponse response = client 176 | .send(request, HttpResponse.BodyHandlers.ofString()); 177 | 178 | assertThat(response.statusCode()).isEqualTo(200); 179 | } 180 | 181 | private long getAllocationSize(RecordedEvent re) { 182 | return re.getEventType().getName().equals("jdk.ObjectAllocationInNewTLAB") ? re.getLong("tlabSize") : re.getLong("allocationSize"); 183 | } 184 | 185 | private boolean isObjectAllocationEvent(RecordedEvent re) { 186 | return re.getEventType().getName().equals("jdk.ObjectAllocationInNewTLAB") || 187 | re.getEventType().getName().equals("jdk.ObjectAllocationOutsideTLAB"); 188 | } 189 | 190 | private boolean isRelevantThread(RecordedEvent re) { 191 | return re.getThread().getJavaName().startsWith("vert.x-eventloop") || 192 | re.getThread().getJavaName().startsWith("executor-thread"); 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/user-service/src/main/resources/META-INF/resources/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | user-service - 1.0.0-SNAPSHOT 6 | 176 | 177 | 178 | 179 | 182 | 183 |
184 |
185 |

Congratulations, you have created a new Quarkus cloud application.

186 | 187 |

Why do you see this?

188 | 189 |

This page is served by Quarkus. The source is in 190 | src/main/resources/META-INF/resources/index.html.

191 | 192 |

What can I do from here?

193 | 194 |

If not already done, run the application in dev mode using: ./mvnw compile quarkus:dev. 195 |

196 |
    197 |
  • Play with your example code in src/main/java: 198 |
    199 |
    200 |
    201 |

    RESTEasy JAX-RS

    202 | Guide 203 |
    204 |
    205 |

    A Hello World RESTEasy resource

    206 | 207 |
    208 |
    209 | GET /hello-resteasy 210 |
    211 |
    212 | 213 |
    214 |
  • 215 |
  • Your static assets are located in src/main/resources/META-INF/resources.
  • 216 |
  • Configure your application in src/main/resources/application.properties.
  • 217 |
218 |

Do you like Quarkus?

219 |

Go give it a star on GitHub.

220 |
221 |
222 |
223 |

Application

224 |
    225 |
  • GroupId: dev.morling.demos
  • 226 |
  • ArtifactId: user-service
  • 227 |
  • Version: 1.0.0-SNAPSHOT
  • 228 |
  • Quarkus Version: 1.10.2.Final
  • 229 |
230 |
231 |
232 |

Next steps

233 | 238 |
239 |
240 |
241 | 242 | -------------------------------------------------------------------------------- /spring-jooq-gradle/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /quarkus-hibernate-maven/example-service/src/test/java/org/moditect/jfrunit/demos/todo/TodoResourceSocketIoTest.java: -------------------------------------------------------------------------------- 1 | package org.moditect.jfrunit.demos.todo; 2 | 3 | import static org.moditect.jfrunit.EnableEvent.StacktracePolicy.INCLUDED; 4 | import static io.restassured.RestAssured.given; 5 | import static org.assertj.core.api.Assertions.assertThat; 6 | 7 | import java.io.IOException; 8 | import java.net.URI; 9 | import java.net.URISyntaxException; 10 | import java.net.http.HttpClient; 11 | import java.net.http.HttpRequest; 12 | import java.net.http.HttpResponse; 13 | import java.util.Random; 14 | 15 | import org.eclipse.microprofile.config.inject.ConfigProperty; 16 | import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; 17 | import org.moditect.jfrunit.demos.todo.testutil.PostgresResource; 18 | import org.junit.jupiter.api.Order; 19 | import org.junit.jupiter.api.Test; 20 | import org.junit.jupiter.api.TestMethodOrder; 21 | 22 | import org.moditect.jfrunit.EnableEvent; 23 | import org.moditect.jfrunit.JfrEvents; 24 | import io.quarkus.test.common.QuarkusTestResource; 25 | import io.quarkus.test.junit.QuarkusTest; 26 | import io.restassured.http.ContentType; 27 | import jdk.jfr.consumer.RecordedEvent; 28 | 29 | @QuarkusTest 30 | @QuarkusTestResource(PostgresResource.class) 31 | @TestMethodOrder(value = OrderAnnotation.class) 32 | public class TodoResourceSocketIoTest { 33 | 34 | private static final int ITERATIONS = 10; 35 | 36 | public JfrEvents jfrEvents = new JfrEvents(); 37 | 38 | @ConfigProperty(name="jfrunit.database.port") 39 | public int databasePort; 40 | 41 | @Test 42 | @Order(1) 43 | public void setupTodos() { 44 | Random r = new Random(); 45 | 46 | for (int i = 1; i<= 20; i++) { 47 | given() 48 | .when() 49 | .body(String.format(""" 50 | { 51 | "title" : "Learn Quarkus", 52 | "priority" : 1, 53 | "userId" : %s 54 | } 55 | """, 56 | r.nextInt(5) + 1) 57 | ) 58 | .contentType(ContentType.JSON) 59 | .post("/todo") 60 | .then() 61 | .statusCode(201); 62 | given() 63 | .when() 64 | .body(String.format(""" 65 | { 66 | "title" : "Learn Quarkus", 67 | "priority" : 1, 68 | "userId" : %s, 69 | "avatar" : "%s" 70 | } 71 | """, 72 | r.nextInt(5) + 1, 73 | "SGVsbG8gV29ybGQsIGhlbGxvIEpmclVuaXQhIEhlbGxvIFdvcmxkLCBoZWxsbyBKZnJVbml0ISBIZWxsbyBXb3JsZCwgaGVsbG8gSmZyVW5pdCEg" + 74 | "SGVsbG8gV29ybGQsIGhlbGxvIEpmclVuaXQhIEhlbGxvIFdvcmxkLCBoZWxsbyBKZnJVbml0ISBIZWxsbyBXb3JsZCwgaGVsbG8gSmZyVW5pdCEg" + 75 | "SGVsbG8gV29ybGQsIGhlbGxvIEpmclVuaXQhIEhlbGxvIFdvcmxkLCBoZWxsbyBKZnJVbml0ISBIZWxsbyBXb3JsZCwgaGVsbG8gSmZyVW5pdCEg" + 76 | "SGVsbG8gV29ybGQsIGhlbGxvIEpmclVuaXQhIEhlbGxvIFdvcmxkLCBoZWxsbyBKZnJVbml0ISBIZWxsbyBXb3JsZCwgaGVsbG8gSmZyVW5pdCEg" + 77 | "SGVsbG8gV29ybGQsIGhlbGxvIEpmclVuaXQhIEhlbGxvIFdvcmxkLCBoZWxsbyBKZnJVbml0ISBIZWxsbyBXb3JsZCwgaGVsbG8gSmZyVW5pdCEg" + 78 | "SGVsbG8gV29ybGQsIGhlbGxvIEpmclVuaXQhIEhlbGxvIFdvcmxkLCBoZWxsbyBKZnJVbml0ISBIZWxsbyBXb3JsZCwgaGVsbG8gSmZyVW5pdCEg" + 79 | "SGVsbG8gV29ybGQsIGhlbGxvIEpmclVuaXQhIEhlbGxvIFdvcmxkLCBoZWxsbyBKZnJVbml0ISBIZWxsbyBXb3JsZCwgaGVsbG8gSmZyVW5pdCEg" + 80 | "SGVsbG8gV29ybGQsIGhlbGxvIEpmclVuaXQhIEhlbGxvIFdvcmxkLCBoZWxsbyBKZnJVbml0ISBIZWxsbyBXb3JsZCwgaGVsbG8gSmZyVW5pdCEg" + 81 | "SGVsbG8gV29ybGQsIGhlbGxvIEpmclVuaXQhIEhlbGxvIFdvcmxkLCBoZWxsbyBKZnJVbml0ISBIZWxsbyBXb3JsZCwgaGVsbG8gSmZyVW5pdCEg" + 82 | "SGVsbG8gV29ybGQsIGhlbGxvIEpmclVuaXQhIEhlbGxvIFdvcmxkLCBoZWxsbyBKZnJVbml0ISBIZWxsbyBXb3JsZCwgaGVsbG8gSmZyVW5pdCEg" + 83 | "SGVsbG8gV29ybGQsIGhlbGxvIEpmclVuaXQhIEhlbGxvIFdvcmxkLCBoZWxsbyBKZnJVbml0ISBIZWxsbyBXb3JsZCwgaGVsbG8gSmZyVW5pdCEg" + 84 | "SGVsbG8gV29ybGQsIGhlbGxvIEpmclVuaXQhIEhlbGxvIFdvcmxkLCBoZWxsbyBKZnJVbml0ISBIZWxsbyBXb3JsZCwgaGVsbG8gSmZyVW5pdCEg" + 85 | "SGVsbG8gV29ybGQsIGhlbGxvIEpmclVuaXQhIEhlbGxvIFdvcmxkLCBoZWxsbyBKZnJVbml0ISA=") 86 | ) 87 | .contentType(ContentType.JSON) 88 | .post("/todo/todo-with-avatar") 89 | .then() 90 | .statusCode(201); 91 | } 92 | } 93 | 94 | // @Test 95 | @Order(2) 96 | @EnableEvent(value="jdk.SocketRead", stackTrace=INCLUDED) 97 | @EnableEvent(value="jdk.SocketWrite", stackTrace=INCLUDED) 98 | public void retrieveTodoBaseline() throws Exception { 99 | Random r = new Random(); 100 | 101 | for (int i = 1; i<= ITERATIONS; i++) { 102 | int id = r.nextInt(20) + 1; 103 | 104 | given() 105 | .when() 106 | .contentType(ContentType.JSON) 107 | .get("/todo/" + id) 108 | .then() 109 | .statusCode(200); 110 | } 111 | 112 | jfrEvents.awaitEvents(); 113 | 114 | jfrEvents.filter(this::isDatabaseIoEvent) 115 | .forEach(System.out::println); 116 | 117 | long sum = jfrEvents.filter(this::isDatabaseIoEvent) 118 | .mapToLong(this::getBytesReadOrWritten) 119 | .sum(); 120 | 121 | System.out.println("### Event count: " + jfrEvents.filter(this::isDatabaseIoEvent).count()); 122 | System.out.println("### I/O bytes sum: " + sum); 123 | System.out.println("### I/O bytes per request: " + sum / ITERATIONS); 124 | } 125 | 126 | @Test 127 | @Order(3) 128 | @EnableEvent(value="jdk.SocketRead", threshold = 0, stackTrace=INCLUDED) 129 | @EnableEvent(value="jdk.SocketWrite", threshold = 0, stackTrace=INCLUDED) 130 | public void retrieveTodoShouldYieldExpectedIo() throws Exception { 131 | Random r = new Random(); 132 | HttpClient client = HttpClient.newBuilder() 133 | .build(); 134 | 135 | for (int i = 1; i<= ITERATIONS; i++) { 136 | executeRequest(r.nextInt(20) + 1, client); 137 | } 138 | 139 | jfrEvents.awaitEvents(); 140 | 141 | long count = jfrEvents.filter(this::isDatabaseIoEvent).count(); 142 | assertThat(count / ITERATIONS).isEqualTo(4).describedAs("write + read per statement, write + read per commit"); 143 | 144 | long bytesReadOrWritten = jfrEvents.filter(this::isDatabaseIoEvent) 145 | .mapToLong(this::getBytesReadOrWritten) 146 | .sum(); 147 | 148 | assertThat(bytesReadOrWritten / ITERATIONS).isLessThan(480); 149 | } 150 | 151 | // @Test 152 | @Order(4) 153 | @EnableEvent(value="jdk.SocketRead", threshold = 0, stackTrace=INCLUDED) 154 | @EnableEvent(value="jdk.SocketWrite", threshold = 0, stackTrace=INCLUDED) 155 | public void retrieveTodoIoRegression() throws Exception { 156 | Random r = new Random(); 157 | HttpClient client = HttpClient.newBuilder() 158 | .build(); 159 | 160 | for (int i = 1; i<= ITERATIONS; i++) { 161 | executeRequest("with-io-regression/", r.nextInt(20) + 1, client); 162 | } 163 | 164 | jfrEvents.awaitEvents(); 165 | 166 | long count = jfrEvents.filter(this::isDatabaseIoEvent).count(); 167 | 168 | // expected to fail 169 | assertThat(count / ITERATIONS).isEqualTo(4).describedAs("write + read per statement, write + read per commit"); 170 | 171 | long bytesReadOrWritten = jfrEvents.filter(this::isDatabaseIoEvent) 172 | .mapToLong(this::getBytesReadOrWritten) 173 | .sum(); 174 | 175 | // expected to fail 176 | assertThat(bytesReadOrWritten / ITERATIONS).isLessThan(500); 177 | } 178 | 179 | private long getBytesReadOrWritten(RecordedEvent re) { 180 | return re.getEventType().getName().equals("jdk.SocketRead") ? re.getLong("bytesRead") : re.getLong("bytesWritten"); 181 | } 182 | 183 | private boolean isDatabaseIoEvent(RecordedEvent re) { 184 | return ((re.getEventType().getName().equals("jdk.SocketRead") || 185 | re.getEventType().getName().equals("jdk.SocketWrite")) && 186 | re.getInt("port") == databasePort); 187 | } 188 | 189 | private void executeRequest(long id, HttpClient client) throws URISyntaxException, IOException, InterruptedException { 190 | executeRequest("", id, client); 191 | } 192 | 193 | private void executeRequest(String pathPrefix, long id, HttpClient client) throws URISyntaxException, IOException, InterruptedException { 194 | HttpRequest request = HttpRequest.newBuilder() 195 | .uri(new URI("http://localhost:8081/todo/" + pathPrefix + id)) 196 | .headers("Content-Type", "application/json") 197 | .GET() 198 | .build(); 199 | 200 | HttpResponse response = client 201 | .send(request, HttpResponse.BodyHandlers.ofString()); 202 | 203 | assertThat(response.statusCode()).isEqualTo(200); 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. --------------------------------------------------------------------------------