Skip to content
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
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description = "Experiments with Java"

allprojects {
group = "io.github.mfvanek"
version = "0.2.0"
version = "0.2.1"

repositories {
mavenLocal()
Expand All @@ -19,7 +19,7 @@ allprojects {

tasks {
wrapper {
gradleVersion = "8.7"
gradleVersion = "8.10.2"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ dependencies {

testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")

errorprone("com.google.errorprone:error_prone_core:2.26.1")
errorprone("jp.skypencil.errorprone.slf4j:errorprone-slf4j:0.1.23")
errorprone("com.google.errorprone:error_prone_core:2.33.0")
errorprone("jp.skypencil.errorprone.slf4j:errorprone-slf4j:0.1.28")
}

java {
Expand Down
2 changes: 1 addition & 1 deletion common-internal-bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies {
api(platform("org.assertj:assertj-bom:3.26.3"))
api(platform("org.testcontainers:testcontainers-bom:1.20.2"))
api(platform("org.junit:junit-bom:5.11.2"))
api(platform("io.github.mfvanek:pg-index-health-bom:0.13.0"))
api(platform("io.github.mfvanek:pg-index-health-bom:0.13.1"))

constraints {
api("org.liquibase:liquibase-core:4.29.2")
Expand Down
6 changes: 3 additions & 3 deletions docker/docker-compose-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
- jaeger-example

zookeeper1:
image: confluentinc/cp-zookeeper:7.5.3
image: confluentinc/cp-zookeeper:7.7.1
hostname: zookeeper1
container_name: zookeeper1
ports:
Expand All @@ -35,7 +35,7 @@ services:
- jaeger-example

kafka1:
image: confluentinc/cp-kafka:7.5.3
image: confluentinc/cp-kafka:7.7.1
hostname: kafka1
container_name: kafka1
ports:
Expand Down Expand Up @@ -86,7 +86,7 @@ services:

postgres:
container_name: postgres
image: postgres:16.2
image: postgres:16.4
shm_size: "2gb"
environment:
POSTGRES_DB: "otel_demo_db"
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
5 changes: 4 additions & 1 deletion spring-boot-2-demo-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ plugins {

dependencies {
implementation(platform(project(":common-internal-bom")))
implementation(platform("org.springdoc:springdoc-openapi:1.7.0"))
implementation(platform("org.springdoc:springdoc-openapi:1.7.0")) {
because("version 1.8.0 brings incompatible logging library")
}
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.7.18"))
implementation(platform("org.springframework.cloud:spring-cloud-dependencies:2021.0.9"))
implementation(platform("org.springframework.cloud:spring-cloud-sleuth-otel-dependencies:1.1.4"))
Expand Down Expand Up @@ -40,6 +42,7 @@ dependencies {
testImplementation("org.testcontainers:kafka")
testImplementation("org.springframework.kafka:spring-kafka-test")
testImplementation("org.awaitility:awaitility")
testImplementation("io.github.mfvanek:pg-index-health-test-starter")
}

springBoot {
Expand Down
5 changes: 3 additions & 2 deletions spring-boot-2-demo-app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ spring:
enable-logging: true
log-level: INFO
includes: QUERY
template:
query-timeout: 1 # 1 second
jdbc:
template:
query-timeout: 1s

management:
server:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.github.mfvanek.spring.boot2.test;

import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnHost;
import io.github.mfvanek.pg.common.maintenance.Diagnostic;
import io.github.mfvanek.pg.model.DbObject;
import io.github.mfvanek.pg.model.column.Column;
import io.github.mfvanek.pg.model.table.Table;
import io.github.mfvanek.spring.boot2.test.support.TestBase;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.list;

class IndexesMaintenanceTest extends TestBase {

@Autowired
private List<DatabaseCheckOnHost<? extends DbObject>> checks;

@Test
@DisplayName("Always check PostgreSQL version in your tests")
void checkPostgresVersion() {
final String pgVersion = jdbcTemplate.queryForObject("select version();", String.class);
assertThat(pgVersion)
.startsWith("PostgreSQL 16.4");
}

@Test
void databaseStructureCheckForPublicSchema() {
assertThat(checks)
.hasSameSizeAs(Diagnostic.values());

checks.forEach(check -> {
switch (check.getDiagnostic()) {
case TABLES_WITHOUT_PRIMARY_KEY, TABLES_WITHOUT_DESCRIPTION -> assertThat(check.check())
.asInstanceOf(list(Table.class))
.hasSize(1)
.containsExactly(Table.of("databasechangelog", 0L));

case COLUMNS_WITHOUT_DESCRIPTION -> assertThat(check.check())
.asInstanceOf(list(Column.class))
.hasSize(14)
.allSatisfy(column -> assertThat(column.getTableName()).isEqualTo("databasechangelog"));

case TABLES_WITH_MISSING_INDEXES -> assertThat(check.check())
.hasSizeLessThanOrEqualTo(1); // TODO skip runtime checks after https://github.com/mfvanek/pg-index-health/issues/456

default -> assertThat(check.check())
.as(check.getDiagnostic().name())
.isEmpty();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class KafkaInitializer implements ApplicationContextInitializer<Configura
private static final String KAFKA_USER_NAME = "sb-ot-demo-user";
private static final String KAFKA_USER_PASSWORD = "pwdForSbOtDemoApp";

private static final DockerImageName IMAGE_NAME = DockerImageName.parse("confluentinc/cp-kafka:7.5.3");
private static final DockerImageName IMAGE_NAME = DockerImageName.parse("confluentinc/cp-kafka:7.7.1");

private static final KafkaContainer KAFKA_CONTAINER = new KafkaContainer(IMAGE_NAME)
.withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "PLAINTEXT:SASL_PLAINTEXT,BROKER:PLAINTEXT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class PostgresInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

private static final DockerImageName IMAGE = DockerImageName.parse("postgres:16.2");
private static final DockerImageName IMAGE = DockerImageName.parse("postgres:16.4");
private static final Network NETWORK = Network.newNetwork();
private static final PostgreSQLContainer<?> CONTAINER = new PostgreSQLContainer<>(IMAGE);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
spring:
jdbc:
template:
query-timeout: 1 # 1 second
5 changes: 3 additions & 2 deletions spring-boot-3-demo-app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
plugins {
id("sb-ot-demo.java-conventions")
id("sb-ot-demo.docker")
id("org.springframework.boot") version "3.3.2"
id("org.springframework.boot") version "3.3.4"
id("io.freefair.lombok")
}

dependencies {
implementation(platform(project(":common-internal-bom")))
implementation(platform("org.springdoc:springdoc-openapi:2.6.0"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:3.3.2"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:3.3.4"))

implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-actuator")
Expand All @@ -34,6 +34,7 @@ dependencies {
testImplementation("org.testcontainers:kafka")
testImplementation("org.springframework.kafka:spring-kafka-test")
testImplementation("org.awaitility:awaitility")
testImplementation("io.github.mfvanek:pg-index-health-test-starter")
}

springBoot {
Expand Down
5 changes: 3 additions & 2 deletions spring-boot-3-demo-app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ spring:
sasl:
mechanism: PLAIN
jaas.config: org.apache.kafka.common.security.plain.PlainLoginModule required username="${demo.kafka.opentelemetry.username}" password="${demo.kafka.opentelemetry.password}";
jdbc:
template:
query-timeout: 1s

management:
server:
Expand Down Expand Up @@ -118,8 +121,6 @@ jdbc:
enable-logging: true
log-level: INFO
includes: QUERY
template:
query-timeout: 1 # 1 second

---

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.github.mfvanek.spring.boot3.test;

import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnHost;
import io.github.mfvanek.pg.common.maintenance.Diagnostic;
import io.github.mfvanek.pg.model.DbObject;
import io.github.mfvanek.pg.model.column.Column;
import io.github.mfvanek.pg.model.table.Table;
import io.github.mfvanek.spring.boot3.test.support.TestBase;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.list;

class IndexesMaintenanceTest extends TestBase {

@Autowired
private List<DatabaseCheckOnHost<? extends DbObject>> checks;

@Test
@DisplayName("Always check PostgreSQL version in your tests")
void checkPostgresVersion() {
final String pgVersion = jdbcTemplate.queryForObject("select version();", String.class);
assertThat(pgVersion)
.startsWith("PostgreSQL 16.4");
}

@Test
void databaseStructureCheckForPublicSchema() {
assertThat(checks)
.hasSameSizeAs(Diagnostic.values());

checks.forEach(check -> {
switch (check.getDiagnostic()) {
case TABLES_WITHOUT_PRIMARY_KEY, TABLES_WITHOUT_DESCRIPTION -> assertThat(check.check())
.asInstanceOf(list(Table.class))
.hasSize(1)
.containsExactly(Table.of("databasechangelog", 0L));

case COLUMNS_WITHOUT_DESCRIPTION -> assertThat(check.check())
.asInstanceOf(list(Column.class))
.hasSize(14)
.allSatisfy(column -> assertThat(column.getTableName()).isEqualTo("databasechangelog"));

case TABLES_WITH_MISSING_INDEXES -> assertThat(check.check())
.hasSizeLessThanOrEqualTo(1); // TODO skip runtime checks after https://github.com/mfvanek/pg-index-health/issues/456

default -> assertThat(check.check())
.as(check.getDiagnostic().name())
.isEmpty();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TimeControllerTest extends TestBase {
@Autowired
private Clock clock;
@Autowired
private NamedParameterJdbcTemplate jdbcTemplate;
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

@BeforeAll
void setUpKafkaConsumer() {
Expand All @@ -64,7 +64,7 @@ void tearDownKafkaConsumer() {

@BeforeEach
void cleanUpDatabase() {
jdbcTemplate.getJdbcTemplate().execute("truncate table otel_demo.storage");
jdbcTemplate.execute("truncate table otel_demo.storage");
}

@SneakyThrows
Expand Down Expand Up @@ -111,14 +111,14 @@ void spanShouldBeReportedInLogs(@Nonnull final CapturedOutput output) {
.until(() -> countRecordsInTable() >= 1L);
assertThat(output.getAll())
.contains("Received record: " + received.value() + " with traceId " + traceId);
final String messageFromDb = jdbcTemplate.queryForObject("select message from otel_demo.storage where trace_id = :traceId",
final String messageFromDb = namedParameterJdbcTemplate.queryForObject("select message from otel_demo.storage where trace_id = :traceId",
Map.of("traceId", traceId), String.class);
assertThat(messageFromDb)
.isEqualTo(received.value());
}

private long countRecordsInTable() {
final Long queryResult = jdbcTemplate.getJdbcTemplate().queryForObject("select count(*) from otel_demo.storage", Long.class);
final Long queryResult = jdbcTemplate.queryForObject("select count(*) from otel_demo.storage", Long.class);
return Objects.requireNonNullElse(queryResult, 0L);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class KafkaInitializer implements ApplicationContextInitializer<Configura
private static final String KAFKA_USER_NAME = "sb-ot-demo-user";
private static final String KAFKA_USER_PASSWORD = "pwdForSbOtDemoApp";

private static final DockerImageName IMAGE_NAME = DockerImageName.parse("confluentinc/cp-kafka:7.5.3");
private static final DockerImageName IMAGE_NAME = DockerImageName.parse("confluentinc/cp-kafka:7.7.1");

private static final KafkaContainer KAFKA_CONTAINER = new KafkaContainer(IMAGE_NAME)
.withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "PLAINTEXT:SASL_PLAINTEXT,BROKER:PLAINTEXT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class PostgresInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

private static final DockerImageName IMAGE = DockerImageName.parse("postgres:16.2");
private static final DockerImageName IMAGE = DockerImageName.parse("postgres:16.4");
private static final Network NETWORK = Network.newNetwork();
private static final PostgreSQLContainer<?> CONTAINER = new PostgreSQLContainer<>(IMAGE);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
spring:
jdbc:
template:
query-timeout: 1 # 1 second