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.1"
version = "0.2.2"

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

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

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.3"))
api(platform("org.junit:junit-bom:5.11.3"))
api(platform("io.github.mfvanek:pg-index-health-bom:0.13.2"))
api(platform("io.github.mfvanek:pg-index-health-bom:0.13.3"))

constraints {
api("org.liquibase:liquibase-core:4.30.0")
Expand Down
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.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package io.github.mfvanek.spring.boot2.test.controllers;

import java.time.Clock;
import java.util.Optional;

import io.github.mfvanek.spring.boot2.test.service.KafkaSendingService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
Expand All @@ -13,7 +10,9 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Clock;
import java.time.LocalDateTime;
import java.util.Optional;

@Slf4j
@RestController
Expand All @@ -29,14 +28,14 @@ public class TimeController {
@GetMapping(path = "/current-time")
public LocalDateTime getNow() {
final var traceId = Optional.ofNullable(tracer.currentSpan())
.map(Span::context)
.map(TraceContext::traceId)
.orElse(null);
.map(Span::context)
.map(TraceContext::traceId)
.orElse(null);
log.info("Called method getNow. TraceId = {}", traceId);
final LocalDateTime now = LocalDateTime.now(clock);
kafkaSendingService.sendNotification("Current time = " + now)
.thenRun(() -> log.info("Awaiting acknowledgement from Kafka"))
.get();
.thenRun(() -> log.info("Awaiting acknowledgement from Kafka"))
.get();
return now;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.stereotype.Component;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
@RequiredArgsConstructor
Expand All @@ -23,7 +23,7 @@ public class TraceIdInResponseServletFilter implements Filter {

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
throws IOException, ServletException {
final Span currentSpan = tracer.currentSpan();
if (currentSpan != null) {
HttpServletResponse resp = (HttpServletResponse) response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public void listen(ConsumerRecord<UUID, String> message, Acknowledgment ack) {
final String traceId = currentSpan != null ? currentSpan.context().traceId() : "";
log.info("Received record: {} with traceId {}", message.value(), traceId);
jdbcTemplate.update("insert into otel_demo.storage(message, trace_id, created_at) values(:msg, :traceId, :createdAt);",
Map.ofEntries(
Map.entry("msg", message.value()),
Map.entry("traceId", traceId),
Map.entry("createdAt", LocalDateTime.now(clock))
)
Map.ofEntries(
Map.entry("msg", message.value()),
Map.entry("traceId", traceId),
Map.entry("createdAt", LocalDateTime.now(clock))
)
);
ack.acknowledge();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import org.springframework.kafka.support.SendResult;
import org.springframework.stereotype.Service;

import javax.annotation.Nonnull;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import javax.annotation.Nonnull;

@Slf4j
@Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,82 +26,82 @@ class ActuatorEndpointTest extends TestBase {
@BeforeEach
void setUp() {
this.actuatorClient = WebTestClient.bindToServer()
.baseUrl("http://localhost:" + actuatorPort + "/actuator/")
.build();
.baseUrl("http://localhost:" + actuatorPort + "/actuator/")
.build();
}

@Test
void actuatorShouldBeRunOnSeparatePort() {
assertThat(actuatorPort)
.isNotEqualTo(port);
.isNotEqualTo(port);
}

@ParameterizedTest
@CsvSource(value = {
"prometheus|jvm_threads_live_threads|text/plain",
"health|{\"status\":\"UP\",\"groups\":[\"liveness\",\"readiness\"]}|application/json",
"health/liveness|{\"status\":\"UP\"}|application/json",
"health/readiness|{\"status\":\"UP\"}|application/json",
"info|\"version\":|application/json"}, delimiter = '|')
"prometheus|jvm_threads_live_threads|text/plain",
"health|{\"status\":\"UP\",\"groups\":[\"liveness\",\"readiness\"]}|application/json",
"health/liveness|{\"status\":\"UP\"}|application/json",
"health/readiness|{\"status\":\"UP\"}|application/json",
"info|\"version\":|application/json"}, delimiter = '|')
void actuatorEndpointShouldReturnOk(@Nonnull final String endpointName,
@Nonnull final String expectedSubstring,
@Nonnull final String mediaType) {
final var result = actuatorClient.get()
.uri(uriBuilder -> uriBuilder
.path(endpointName)
.build())
.accept(MediaType.valueOf(mediaType))
.exchange()
.expectStatus().isOk()
.expectBody(String.class)
.returnResult()
.getResponseBody();
.uri(uriBuilder -> uriBuilder
.path(endpointName)
.build())
.accept(MediaType.valueOf(mediaType))
.exchange()
.expectStatus().isOk()
.expectBody(String.class)
.returnResult()
.getResponseBody();
assertThat(result)
.contains(expectedSubstring);
.contains(expectedSubstring);
}

@Test
void swaggerUiEndpointShouldReturnFound() {
final var result = actuatorClient.get()
.uri(uriBuilder -> uriBuilder
.pathSegment("swagger-ui")
.build())
.accept(MediaType.TEXT_HTML)
.exchange()
.expectStatus().isFound()
.expectHeader().location("/actuator/swagger-ui/index.html")
.expectBody()
.returnResult()
.getResponseBody();
.uri(uriBuilder -> uriBuilder
.pathSegment("swagger-ui")
.build())
.accept(MediaType.TEXT_HTML)
.exchange()
.expectStatus().isFound()
.expectHeader().location("/actuator/swagger-ui/index.html")
.expectBody()
.returnResult()
.getResponseBody();
assertThat(result).isNull();
}

@Test
void readinessProbeShouldBeCollectedFromApplicationMainPort() {
final var result = webTestClient.get()
.uri(uriBuilder -> uriBuilder
.pathSegment("readyz")
.build())
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus().isOk()
.expectBody(String.class)
.returnResult()
.getResponseBody();
.uri(uriBuilder -> uriBuilder
.pathSegment("readyz")
.build())
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus().isOk()
.expectBody(String.class)
.returnResult()
.getResponseBody();
assertThat(result)
.isEqualTo("{\"status\":\"UP\"}");
.isEqualTo("{\"status\":\"UP\"}");

final String metricsResult = actuatorClient.get()
.uri(uriBuilder -> uriBuilder
.path("prometheus")
.build())
.accept(MediaType.valueOf("text/plain"))
.exchange()
.expectStatus().isOk()
.expectBody(String.class)
.returnResult()
.getResponseBody();
.uri(uriBuilder -> uriBuilder
.path("prometheus")
.build())
.accept(MediaType.valueOf("text/plain"))
.exchange()
.expectStatus().isOk()
.expectBody(String.class)
.returnResult()
.getResponseBody();
assertThat(metricsResult)
.contains("http_server_requests_seconds_bucket");
.contains("http_server_requests_seconds_bucket");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import io.github.mfvanek.pg.common.maintenance.Diagnostic;
import io.github.mfvanek.pg.model.DbObject;
import io.github.mfvanek.pg.model.PgContext;
import io.github.mfvanek.pg.model.table.TableNameAware;
import io.github.mfvanek.pg.model.predicates.SkipLiquibaseTablesPredicate;
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 java.util.function.Predicate;

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

Expand All @@ -35,17 +34,9 @@ void databaseStructureCheckForPublicSchema() {

checks.stream()
.filter(DatabaseCheckOnHost::isStatic)
.forEach(check -> {
final Predicate<DbObject> skipLiquibaseTables = dbObject -> {
if (dbObject instanceof TableNameAware t) {
return !t.getTableName().equalsIgnoreCase("databasechangelog");
}
return true;
};
final List<? extends DbObject> objects = check.check(PgContext.ofPublic(), skipLiquibaseTables);
assertThat(objects)
.forEach(check ->
assertThat(check.check(PgContext.ofPublic(), SkipLiquibaseTablesPredicate.ofPublic()))
.as(check.getDiagnostic().name())
.isEmpty();
});
.isEmpty());
}
}
Loading