mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 15:25:49 +00:00
updated tests
This commit is contained in:
parent
f4191cbbf7
commit
28feaae451
13 changed files with 171 additions and 68 deletions
|
@ -4,11 +4,11 @@ receivers:
|
|||
grpc:
|
||||
http:
|
||||
|
||||
extensions:
|
||||
basicauth/client:
|
||||
client_auth:
|
||||
username: 738734
|
||||
password: glc_eyJvIjoiOTQzMDk3IiwibiI6Im90bHAtb3RscCIsImsiOiJEWnhpNTFsZVZWMHJYcTg5MTVqODJOOEgiLCJtIjp7InIiOiJ1cyJ9fQ==
|
||||
#extensions:
|
||||
# basicauth/client:
|
||||
# client_auth:
|
||||
# username: 738734
|
||||
# password: glc_eyJvIjoiOTQzMDk3IiwibiI6Im90bHAtb3RscCIsImsiOiJEWnhpNTFsZVZWMHJYcTg5MTVqODJOOEgiLCJtIjp7InIiOiJ1cyJ9fQ==
|
||||
|
||||
exporters:
|
||||
otlp/jaeger:
|
||||
|
@ -16,15 +16,15 @@ exporters:
|
|||
tls:
|
||||
insecure: true
|
||||
|
||||
prometheus:
|
||||
endpoint: "0.0.0.0:8889"
|
||||
# prometheus:
|
||||
# endpoint: "0.0.0.0:8889"
|
||||
|
||||
otlphttp/grafana:
|
||||
endpoint: https://otlp-gateway-prod-us-east-0.grafana.net/otlp
|
||||
auth:
|
||||
authenticator: basicauth/client
|
||||
tls:
|
||||
insecure: false
|
||||
# otlphttp/grafana:
|
||||
# endpoint: https://otlp-gateway-prod-us-east-0.grafana.net/otlp
|
||||
# auth:
|
||||
# authenticator: basicauth/client
|
||||
# tls:
|
||||
# insecure: false
|
||||
|
||||
otlp/digma:
|
||||
endpoint: ${OTLP_EXPORTER_DIGMA_COLLECTOR_API}
|
||||
|
@ -35,13 +35,14 @@ processors:
|
|||
batch:
|
||||
|
||||
service:
|
||||
extensions: [basicauth/client]
|
||||
#extensions: [basicauth/client]
|
||||
pipelines:
|
||||
traces:
|
||||
receivers: [otlp]
|
||||
exporters: [otlphttp/grafana,otlp/jaeger]
|
||||
processors: [batch]
|
||||
metrics:
|
||||
receivers: [otlp]
|
||||
exporters: [prometheus]
|
||||
# exporters: [otlphttp/grafana,otlp/jaeger]
|
||||
exporters: [otlp/jaeger,otlp/digma]
|
||||
processors: [batch]
|
||||
# metrics:
|
||||
# receivers: [otlp]
|
||||
# exporters: [prometheus]
|
||||
# processors: [batch]
|
||||
|
|
|
@ -2,7 +2,7 @@ version: "3.6"
|
|||
|
||||
services:
|
||||
jaeger:
|
||||
image: jaegertracing/all-in-one:latest
|
||||
image: jaegertracing/all-in-one:1.45.0
|
||||
container_name: jaeger
|
||||
volumes:
|
||||
- badger_data:/badger
|
||||
|
@ -12,34 +12,40 @@ services:
|
|||
- "16686:16686"
|
||||
- "14250"
|
||||
- "0.0.0.0:14268:14268"
|
||||
command: |
|
||||
--query.additional-headers "Access-Control-Allow-Origin: *"
|
||||
environment:
|
||||
- SPAN_STORAGE_TYPE=badger
|
||||
- COLLECTOR_OTLP_ENABLED=true
|
||||
- BADGER_EPHEMERAL=false
|
||||
- BADGER_SPAN_STORE_TTL=2000h
|
||||
- BADGER_DIRECTORY_VALUE=/badger/data
|
||||
- BADGER_DIRECTORY_KEY=/badger/key
|
||||
- BADGER_SPAN_STORE_TTL=336h0m0s
|
||||
- COLLECTOR_GRPC_PORT=5317
|
||||
- COLLECTOR_OTLP_GRPC_MAX_MESSAGE_SIZE=41943040
|
||||
restart: unless-stopped
|
||||
|
||||
grafana:
|
||||
container_name: grafana
|
||||
volumes:
|
||||
- ./grafana/provisioning:/etc/grafana/provisioning
|
||||
image: grafana/grafana-oss:latest
|
||||
ports:
|
||||
- 3000:3000
|
||||
environment:
|
||||
- GF_SECURITY_ADMIN_USER=admin
|
||||
- GF_SECURITY_ADMIN_PASSWORD=admin
|
||||
- GF_USERS_ALLOW_SIGN_UP=false
|
||||
# grafana:
|
||||
# container_name: grafana
|
||||
# volumes:
|
||||
# - ./grafana/provisioning:/etc/grafana/provisioning
|
||||
# image: grafana/grafana-oss:latest
|
||||
# ports:
|
||||
# - 3000:3000
|
||||
# environment:
|
||||
# - GF_SECURITY_ADMIN_USER=admin
|
||||
# - GF_SECURITY_ADMIN_PASSWORD=admin
|
||||
# - GF_USERS_ALLOW_SIGN_UP=false
|
||||
|
||||
prometheus:
|
||||
container_name: prometheus
|
||||
image: prom/prometheus:latest
|
||||
volumes:
|
||||
- ./prometheus.yaml:/etc/prometheus/prometheus.yml
|
||||
ports:
|
||||
- "9090:9090"
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
# prometheus:
|
||||
# container_name: prometheus
|
||||
# image: prom/prometheus:latest
|
||||
# volumes:
|
||||
# - ./prometheus.yaml:/etc/prometheus/prometheus.yml
|
||||
# ports:
|
||||
# - "9090:9090"
|
||||
# extra_hosts:
|
||||
# - "host.docker.internal:host-gateway"
|
||||
|
||||
collector:
|
||||
image: otel/opentelemetry-collector-contrib
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -38,6 +38,10 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-testcontainers</artifactId>
|
||||
|
|
|
@ -16,9 +16,33 @@
|
|||
|
||||
package org.springframework.samples.petclinic;
|
||||
|
||||
import io.opentelemetry.api.GlobalOpenTelemetry;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import jakarta.servlet.AsyncEvent;
|
||||
import jakarta.servlet.AsyncListener;
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ImportRuntimeHints;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.util.ContentCachingRequestWrapper;
|
||||
import org.springframework.web.util.ContentCachingResponseWrapper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* PetClinic Spring Boot Application.
|
||||
|
@ -35,3 +59,5 @@ public class PetClinicApplication {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package org.springframework.samples.petclinic.adapters;
|
||||
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PetVaccinationRequestMessage {
|
||||
|
||||
private final KafkaTemplate<String, String> kafkaTemplate;
|
||||
|
||||
public PetVaccinationRequestMessage(KafkaTemplate<String, String> kafkaTemplate){
|
||||
|
||||
this.kafkaTemplate = kafkaTemplate;
|
||||
}
|
||||
public void Send(){
|
||||
//template.convertAndSend("petVaccineRequests", "Hello, world!");
|
||||
kafkaTemplate.send("petVaccineRequests","test");
|
||||
}
|
||||
|
||||
}
|
|
@ -34,11 +34,12 @@ public class OwnerValidation {
|
|||
public void ValidateOwnerWithExternalService(Owner owner) {
|
||||
|
||||
this.AuthServiceValidateUser(owner);
|
||||
this.NewFunction();
|
||||
}
|
||||
|
||||
@WithSpan
|
||||
private void NewFunction() {
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@WithSpan
|
||||
|
@ -52,7 +53,6 @@ public class OwnerValidation {
|
|||
|
||||
}
|
||||
|
||||
|
||||
// This function and classes were generated by ChatGPT
|
||||
@WithSpan
|
||||
public boolean ValidateUserAccess(String usr, String pswd, String sysCode) {
|
||||
|
@ -93,15 +93,49 @@ public class OwnerValidation {
|
|||
return true;
|
||||
}
|
||||
|
||||
String usr;
|
||||
String pswd;
|
||||
String sysCode;
|
||||
|
||||
|
||||
|
||||
@WithSpan
|
||||
private synchronized void AuthServiceValidateUser(Owner owner) {
|
||||
// This is the actual Root Cause!!
|
||||
try {
|
||||
Thread.sleep(4200 + ThreadLocalRandom.current().nextInt(90, 1100 + 1));
|
||||
boolean vldUsr = usrValSvc.vldtUsr(usr);
|
||||
if (!vldUsr) {
|
||||
return;
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
boolean vldPswd = pwdUtils.vldtPswd(usr, pswd);
|
||||
if (!vldPswd) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean vldUsrRole = roleSvc.vldtUsrRole(usr, sysCode);
|
||||
if (!vldUsrRole) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean is2FASuccess = twoFASvc.init2FA(usr);
|
||||
if (!is2FASuccess) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean is2FATokenValid = false;
|
||||
int retry = 0;
|
||||
while (retry < 3 && !is2FATokenValid) {
|
||||
String token = twoFASvc.getTokenInput();
|
||||
is2FATokenValid = twoFASvc.vldtToken(usr, token);
|
||||
retry++;
|
||||
}
|
||||
|
||||
if (!is2FATokenValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
@WithSpan
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package org.springframework.samples.petclinic.domain;
|
||||
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.annotations.WithSpan;
|
||||
|
||||
public class TwoFactorAuthenticationService {
|
||||
|
||||
@WithSpan
|
||||
public boolean init2FA(String usr) {
|
||||
try {
|
||||
Thread.sleep(400);
|
||||
|
|
|
@ -52,6 +52,7 @@ class OwnerController {
|
|||
private OwnerValidation validator;
|
||||
|
||||
public OwnerController(OwnerRepository clinicService) {
|
||||
|
||||
this.owners = clinicService;
|
||||
var otelTracer = getTracer("OwnerController");
|
||||
validator = new OwnerValidation(otelTracer);
|
||||
|
@ -79,12 +80,13 @@ class OwnerController {
|
|||
// }
|
||||
|
||||
@GetMapping("/owners/new")
|
||||
public String initCreationForm(Map<String, Object> model) {
|
||||
public String initCreationForm(Map<String, Object> model) throws NoSuchMethodException {
|
||||
|
||||
// if (model!=null){
|
||||
// throw new RuntimeException();
|
||||
//
|
||||
// }
|
||||
|
||||
// if (model!=null){
|
||||
// throw new RuntimeException();
|
||||
//
|
||||
// }
|
||||
Owner owner = new Owner();
|
||||
validator.ValidateOwnerWithExternalService(owner);
|
||||
|
||||
|
@ -112,8 +114,8 @@ class OwnerController {
|
|||
}
|
||||
|
||||
@GetMapping("/owners")
|
||||
public String processFindForm(@RequestParam(defaultValue = "1") int page, Owner owner, BindingResult result,
|
||||
Model model) {
|
||||
public String processFindForm(@RequestParam(defaultValue = "1") int page, Owner owner,
|
||||
BindingResult result, Model model) {
|
||||
validator.ValidateUserAccess("admin", "pwd", "fullaccess");
|
||||
// if (owner.getLastName()!=null){
|
||||
// throw new RuntimeException();
|
||||
|
@ -124,7 +126,6 @@ class OwnerController {
|
|||
owner.setLastName(""); // empty string signifies broadest possible search
|
||||
}
|
||||
|
||||
|
||||
// find owners by last name
|
||||
Page<Owner> ownersResults = findPaginatedForOwnersLastName(page, owner.getLastName());
|
||||
if (ownersResults.isEmpty()) {
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
*/
|
||||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
@ -24,6 +22,7 @@ import java.util.concurrent.Executors;
|
|||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.samples.petclinic.adapters.PetVaccinationRequestMessage;
|
||||
import org.springframework.samples.petclinic.domain.PetVaccinationStatusService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
|
@ -51,14 +50,17 @@ class PetController implements InitializingBean {
|
|||
private static final String VIEWS_PETS_CREATE_OR_UPDATE_FORM = "pets/createOrUpdatePetForm";
|
||||
|
||||
private final OwnerRepository owners;
|
||||
private final PetVaccinationRequestMessage vaccinationRequestMessage;
|
||||
|
||||
@Autowired
|
||||
private PetVaccinationStatusService petVaccinationStatus;
|
||||
|
||||
private ExecutorService executorService;
|
||||
|
||||
public PetController(OwnerRepository owners) {
|
||||
public PetController(OwnerRepository owners,
|
||||
PetVaccinationRequestMessage petVaccinationRequestMessage) {
|
||||
this.owners = owners;
|
||||
this.vaccinationRequestMessage = petVaccinationRequestMessage;
|
||||
}
|
||||
|
||||
@ModelAttribute("types")
|
||||
|
@ -111,16 +113,17 @@ class PetController implements InitializingBean {
|
|||
this.owners.save(owner);
|
||||
// var pets = owner.getPets().toArray(Pet[]::new);
|
||||
|
||||
var petRequests = owner.getPets()
|
||||
.stream()
|
||||
.map(x -> new PetVaccinationStatusService.UpdateVaccineStatusRequest(owner.getId(), x.getId()))
|
||||
.toList();
|
||||
// var petRequests = owner.getPets()
|
||||
// .stream()
|
||||
// .map(x -> new PetVaccinationStatusService.UpdateVaccineStatusRequest(owner.getId(), x.getId()))
|
||||
// .toList().subList(0,1);
|
||||
// executorService.submit(() ->
|
||||
// petVaccinationStatus.updateVaccinationStatus(petRequests)).get();
|
||||
executorService.submit(() -> petVaccinationStatus.updateVaccinationStatus(petRequests));
|
||||
//executorService.submit(() -> petVaccinationStatus.updateVaccinationStatus(petRequests));
|
||||
//petVaccinationStatus.updateVaccinationStatus(petRequests.subList(0,1));
|
||||
//
|
||||
// BackgroundJob.enqueue(() ->
|
||||
// petVaccinationStatus.updateVaccinationStatus(petRequests));
|
||||
|
||||
vaccinationRequestMessage.Send();
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
|
||||
|
|
|
@ -15,12 +15,16 @@ spring.messages.basename=messages/messages
|
|||
|
||||
# Actuator
|
||||
management.endpoints.web.exposure.include=*
|
||||
management.metrics.distribution.slo.http.server.requests=50ms, 100ms, 200ms, 400ms
|
||||
management.metrics.distribution.percentiles.http.server.requests=0.5, 0.9, 0.95, 0.99, 0.999
|
||||
management.metrics.web.server.request.autotime.percentiles=0.95
|
||||
management.metrics.distribution.percentiles-histogram.http.server.requests=true
|
||||
|
||||
spring.rabbitmq.host=localhost
|
||||
spring.rabbitmq.port=5672
|
||||
spring.rabbitmq.username=guest
|
||||
spring.rabbitmq.password=guest
|
||||
|
||||
spring.kafka.bootstrap-servers=localhost:9092
|
||||
spring.kafka.consumer.group-id=myGroup
|
||||
# Logging
|
||||
logging.level.org.springframework=INFO
|
||||
# logging.level.org.springframework.web=DEBUG
|
||||
|
|
|
@ -104,6 +104,8 @@ class OwnerControllerTests {
|
|||
.statusCode(200)
|
||||
.body(ownerLinkMatcher, Matchers.notNullValue());
|
||||
|
||||
assertThat(false).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
|
|
@ -33,6 +33,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
|
@ -64,6 +65,7 @@ class OwnerControllerTests {
|
|||
private OwnerRepository owners;
|
||||
|
||||
private Owner george() {
|
||||
|
||||
Owner george = new Owner();
|
||||
george.setId(TEST_OWNER_ID);
|
||||
george.setFirstName("George");
|
||||
|
|
Loading…
Reference in a new issue