Spring Cloud Quality Control & Assurance 4 — Questions and Answers
Question 1: When a Spring Cloud Contract stub is published to a Maven repository, which classifier is used by convention?
- stubs (Correct answer)
- contracts
- wiremock
- test-stubs
Correct answer: stubs
By convention, Spring Cloud Contract packages stubs as a JAR with the 'stubs' classifier, e.g., my-service-1.0.0-stubs.jar.
Question 2: Which property in Spring Cloud Sleuth controls the percentage of requests that are traced (sampling rate)?
- spring.sleuth.sampler.probability (Correct answer)
- spring.sleuth.trace.rate
- spring.zipkin.sample.percent
- management.tracing.sampling.probability
Correct answer: spring.sleuth.sampler.probability
spring.sleuth.sampler.probability accepts a value between 0.0 and 1.0, where 1.0 means 100% of requests are traced.
Question 3: Which Testcontainers integration is used in Spring Boot tests to spin up a real database for integration testing?
- @Testcontainers and @Container with a database image (Correct answer)
- @MockBean with a database DataSource
- @DataJpaTest with H2 in-memory database
- @SpringBootTest with embedded PostgreSQL
Correct answer: @Testcontainers and @Container with a database image
@Testcontainers activates Testcontainers lifecycle management and @Container defines the Docker container (e.g., PostgreSQLContainer) to start for the test.
Question 4: In Resilience4j, what is the difference between a Retry and a Circuit Breaker when used together in Spring Cloud?
- Retry retries individual calls; Circuit Breaker stops calls after a threshold of failures (Correct answer)
- Circuit Breaker retries calls; Retry tracks failure counts
- They are interchangeable and serve the same purpose
- Retry only works with synchronous calls; Circuit Breaker works with reactive
Correct answer: Retry retries individual calls; Circuit Breaker stops calls after a threshold of failures
Retry automatically re-attempts a failed call a configured number of times, while Circuit Breaker opens and short-circuits calls entirely after failure thresholds are exceeded.
Question 5: What Spring Boot mechanism allows you to verify that Actuator health indicators report the correct status in tests?
- TestRestTemplate or WebTestClient calling /actuator/health and asserting the JSON body (Correct answer)
- Mocking HealthIndicator beans with @MockBean
- Using @HealthCheck annotation on test methods
- Asserting HealthContributor registry directly
Correct answer: TestRestTemplate or WebTestClient calling /actuator/health and asserting the JSON body
Using TestRestTemplate or WebTestClient to call /actuator/health in an integration test gives you the full JSON health response for assertion.
Question 6: Which Spring Cloud feature allows externalized configuration values to be encrypted at rest in the config repository?
- Spring Cloud Config encryption with {cipher} prefix (Correct answer)
- Spring Security @EncryptValue annotation
- Vault Transit engine via Spring Cloud Vault
- Jasypt encryption library integration
Correct answer: Spring Cloud Config encryption with {cipher} prefix
Spring Cloud Config Server supports symmetric or asymmetric encryption; encrypted values are stored with a {cipher} prefix and decrypted on the fly.
Question 7: Which quality control practice does Spring Cloud Contract's 'provider state' feature support?
- Setting up specific server-side state before a contract scenario runs (Correct answer)
- Validating provider authentication tokens
- Generating state diagrams from contracts
- Enforcing provider SLA thresholds
Correct answer: Setting up specific server-side state before a contract scenario runs
Provider states allow the consumer to declare what state the producer must be in (e.g., 'a user with ID 1 exists') before the interaction in the contract is valid.
When a Spring Cloud Contract stub is published to a Maven repository, which classifier is used by convention?