Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x - Dbclient Integration Tests Fixed #4860

Merged
merged 8 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion etc/scripts/includes/mysql.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2021 Oracle and/or its affiliates.
# Copyright (c) 2021, 2023 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,5 +33,6 @@ readonly DOCKER_ENV="-e MYSQL_USER=${DB_USER} -e MYSQL_DATABASE=${DB_NAME} -e MY
readonly DOCKER_IMG='mysql:8'

readonly DB_PROFILE='mysql'
readonly DB_PROPERTY='db=mysql'

echo " - Database URL: ${DB_URL}"
3 changes: 2 additions & 1 deletion etc/scripts/includes/pgsql.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2021 Oracle and/or its affiliates.
# Copyright (c) 2021, 2023 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,5 +31,6 @@ readonly DOCKER_ENV="-e POSTGRES_USER=${DB_USER} -e POSTGRES_DB=${DB_NAME} -e PO
readonly DOCKER_IMG='postgres'

readonly DB_PROFILE='pgsql'
readonly DB_PROPERTY='db=pgsql'

echo " - Database URL: ${DB_URL}"
63 changes: 57 additions & 6 deletions tests/integration/dbclient/appl/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2021, 2022 Oracle and/or its affiliates.
Copyright (c) 2021, 2023 Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,6 +54,10 @@
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-yaml</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.logging</groupId>
<artifactId>helidon-logging-jul</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.reactive.webserver</groupId>
<artifactId>helidon-reactive-webserver</artifactId>
Expand All @@ -66,6 +70,10 @@
<groupId>io.helidon.reactive.media</groupId>
<artifactId>helidon-reactive-media-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.reactive.health</groupId>
<artifactId>helidon-reactive-health</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.reactive.dbclient</groupId>
<artifactId>helidon-reactive-dbclient-jdbc</artifactId>
Expand All @@ -86,6 +94,15 @@
<groupId>io.helidon.tests.integration.tools</groupId>
<artifactId>helidon-tests-integration-tools-service</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.reactive.metrics</groupId>
<artifactId>helidon-reactive-metrics</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.reactive.webclient</groupId>
<artifactId>helidon-reactive-webclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.tests.integration.tools</groupId>
<artifactId>helidon-tests-integration-tools-client</artifactId>
Expand All @@ -109,11 +126,6 @@
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.helidon.reactive.webclient</groupId>
<artifactId>helidon-reactive-webclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down Expand Up @@ -239,8 +251,41 @@
</build>
</profile>

<profile>
<id>h2</id>
<activation>
<property>
<name>!db</name>
</property>
</activation>
<properties>
<app.config>h2.yaml</app.config>
<db.database>test</db.database>
<db.user>sa</db.user>
<db.password/>
<db.url>jdbc:h2:mem:${db.database};INIT=SET TRACE_LEVEL_FILE=4;DATABASE_TO_UPPER=FALSE</db.url>
</properties>
<dependencies>
<dependency>
<groupId>io.helidon.integrations.db</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>

<profile>
<id>mysql</id>
<activation>
<property>
<name>db</name>
<value>mysql</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>io.helidon.integrations.db</groupId>
Expand All @@ -257,6 +302,12 @@

<profile>
<id>pgsql</id>
<activation>
<property>
<name>db</name>
<value>pgsql</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>io.helidon.integrations.db</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,20 +17,17 @@

import java.util.Map;
import java.util.Optional;
import java.util.logging.Logger;

import io.helidon.reactive.dbclient.DbClient;
import io.helidon.tests.integration.tools.service.RemoteTestException;
import io.helidon.reactive.webserver.ServerRequest;
import io.helidon.reactive.webserver.Service;
import io.helidon.tests.integration.tools.service.RemoteTestException;

/**
* Common web service code for testing application.
*/
public abstract class AbstractService implements Service {

private static final Logger LOGGER = Logger.getLogger(AbstractService.class.getName());

/** Query parameter for name of Pokemon, Type, etc. */
public static final String QUERY_NAME_PARAM = "name";
/** Query parameter for ID of Pokemon, Type, etc. */
Expand All @@ -50,7 +47,7 @@ public abstract class AbstractService implements Service {
* @param dbClient DbClient instance
* @param statements statements from configuration file
*/
public AbstractService(final DbClient dbClient, final Map<String, String> statements) {
public AbstractService(DbClient dbClient, Map<String, String> statements) {
this.dbClient = dbClient;
this.statements = statements;
}
Expand All @@ -70,7 +67,7 @@ public DbClient dbClient() {
* @param name statement configuration property name
* @return statement from configuration file
*/
public String statement(final String name) {
public String statement(String name) {
return statements.get(name);
}

Expand All @@ -82,7 +79,7 @@ public String statement(final String name) {
* @return query parameter value
* @throws RemoteTestException when no parameter with given name exists in request
*/
public static final String param( final ServerRequest request, final String name) {
public static String param(ServerRequest request, String name) {
Optional<String> maybeParam = request.queryParams().first(name);
if (maybeParam.isPresent()) {
return maybeParam.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,10 +15,9 @@
*/
package io.helidon.tests.integration.dbclient.appl;

import java.lang.System.Logger.Level;
import java.util.Map;
import java.util.logging.Logger;

import io.helidon.logging.common.LogConfig;
import io.helidon.config.Config;
import io.helidon.config.ConfigSources;
import io.helidon.reactive.dbclient.DbClient;
Expand All @@ -29,7 +28,9 @@
import io.helidon.reactive.health.HealthSupport;
import io.helidon.reactive.media.jsonb.JsonbSupport;
import io.helidon.reactive.media.jsonp.JsonpSupport;
import io.helidon.metrics.MetricsSupport;
import io.helidon.reactive.metrics.MetricsSupport;
import io.helidon.reactive.webserver.Routing;
import io.helidon.reactive.webserver.WebServer;
import io.helidon.tests.integration.dbclient.appl.health.HealthCheckService;
import io.helidon.tests.integration.dbclient.appl.interceptor.InterceptorService;
import io.helidon.tests.integration.dbclient.appl.mapping.MapperService;
Expand All @@ -48,22 +49,20 @@
import io.helidon.tests.integration.dbclient.appl.transaction.TransactionInsertService;
import io.helidon.tests.integration.dbclient.appl.transaction.TransactionQueriesService;
import io.helidon.tests.integration.dbclient.appl.transaction.TransactionUpdateService;
import io.helidon.reactive.webserver.Routing;
import io.helidon.reactive.webserver.WebServer;

/**
* Main class.
* Testing application entry point.
*/
public class ApplMain {

private static final Logger LOGGER = Logger.getLogger(ApplMain.class.getName());
private static final System.Logger LOGGER = System.getLogger(ApplMain.class.getName());

private static final String CONFIG_PROPERTY_NAME="app.config";

private static final String DEFAULT_CONFIG_FILE="test.yaml";

private static WebServer startServer(final String configFile) {
private static void startServer(String configFile) {

final Config config = Config.create(ConfigSources.classpath(configFile));
final Config dbConfig = config.get("db");
Expand All @@ -76,7 +75,7 @@ private static WebServer startServer(final String configFile) {
.statementTypes(DbStatementType.GET))
.build();
final HealthSupport health = HealthSupport.builder()
.addLiveness(DbClientHealthCheck
.add(DbClientHealthCheck
.builder(dbClient)
//.dml()
.statementName("ping")
Expand Down Expand Up @@ -123,8 +122,7 @@ private static WebServer startServer(final String configFile) {
.build();

// Prepare routing for the server
final WebServer.Builder serverBuilder = WebServer.builder()
.routing(routing)
final WebServer.Builder serverBuilder = WebServer.builder(routing)
// Get webserver config from the "server" section of application.yaml
.config(config.get("server"));

Expand All @@ -136,16 +134,13 @@ private static WebServer startServer(final String configFile) {
exitResource.setServer(server);

// Start the server and print some info.
server.start().thenAccept(ws -> {
System.out.println(
"WEB server is up! http://localhost:" + ws.port() + "/");
});
server.start()
.thenAccept(ws -> System.out.println("WEB server is up! http://localhost:" + ws.port() + "/"));

// Server threads are not daemon. NO need to block. Just react.
server.whenShutdown().thenRun(
() -> System.out.println("WEB server is DOWN. Good bye!"));
server.whenShutdown()
.thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));

return server;
}

/**
Expand All @@ -161,9 +156,8 @@ public static void main(String[] args) {
} else {
configFile = System.getProperty(CONFIG_PROPERTY_NAME, DEFAULT_CONFIG_FILE);
}
LOGGER.info(() -> String.format("Configuration file: %s", configFile));
LOGGER.log(Level.INFO, () -> String.format("Configuration file: %s", configFile));

LogConfig.configureRuntime();
startServer(configFile);

}
Expand Down
Loading