review-followup Wave 3 라운드 3(P22): Redis runtime·SDK 분리, 좁은 semantic 포트, startup rule, lease fencing 계약
- pub/sub 표면 삭제(G-6b·G-4i — 소비자 0, capability 규칙 3): SDK pub/sub·runtime gateway·PUBSUB lane·env 키 2개 - runtime을 `…cache.redis.runtime`으로(split package 해소), runtime은 소비자가 쓰는 8개 명령(`SemanticRedisCommands`)만, 118개 메서드 gateway는 redis-sdk가 확장. SDK의 blocking·transaction·admin lane은 코드로 조립(env 키 4개 삭제) - EVALSHA+NOSCRIPT 재로드 헬퍼 하나(메시지에만 NOSCRIPT가 온 경우도 재로드 — `LeaseScriptsTest` FAIL→PASS) - startup rule 목록 + runner 하나(환경 검사 8개, exit code·문구 유지), Redis secret 요구는 모듈이 기여, ratelimit 정책을 cache-redis 밖으로, lease fencing 계약 테스트(fake·어댑터·실제 Redis) - 통합: redis-sdk 테스트 2개가 옛 split package 경로를 보던 것 수정(ORCH-new-4) 검증: ./gradlew check architectureCheck verifyDependencyLocks :app-bootstrap:verifyEnvKeys configContractCheck :app-bootstrap:integrationTest :sample-portfolio:integrationTest :sample-portfolio:systemTest --continue 통과(682 task), Redis 7.4 standalone topology lane: runtime 7 · sdk 14 · cache-redis 19, 실패·skip 0 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
486d85a603
commit
4f4bd1fd34
+24
@@ -0,0 +1,24 @@
|
||||
package dev.caskeleton.adapter.outbound.support.startup;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* The production secrets a module needs, given what this deployment selected.
|
||||
*
|
||||
* <p>Contributed as a bean by the module that owns the secrets and read by the composition root's
|
||||
* secret-source guard, which checks each named secret resolves under the {@code prod} profile. The
|
||||
* guard does not know which roles a module has or which secret each one needs; before this it
|
||||
* spelled out every Redis role's selector and secret prefix itself.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface RequiredProductionSecrets {
|
||||
|
||||
/**
|
||||
* Names the secrets the selected capabilities need.
|
||||
*
|
||||
* @param environment the resolved environment
|
||||
* @return the secret names; empty when nothing the module owns is selected
|
||||
*/
|
||||
List<String> requiredSecrets(Environment environment);
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package dev.caskeleton.adapter.outbound.support.startup;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* One fail-fast startup rule over the resolved environment.
|
||||
*
|
||||
* <p>A rule only finds violations; it never throws and never decides when it runs. The {@link
|
||||
* StartupRuleRunner} runs every rule a module contributed — each is an ordinary bean — once, after
|
||||
* all singletons exist, and raises the violations of a rule as the typed startup failure of its
|
||||
* {@link #phase()}. Before this, sixteen validators across the composition root and the JPA module
|
||||
* each implemented {@code SmartInitializingSingleton}, opened their own validation context and
|
||||
* chose their own way to throw; the rule a module adds is now a list of messages and nothing else.
|
||||
*
|
||||
* <p>A check that needs a bean other than the environment — a secret source, the datasource, the
|
||||
* bean factory — is not a rule and stays a bean of its own.
|
||||
*/
|
||||
public interface StartupRule {
|
||||
|
||||
/**
|
||||
* The phase a violation of this rule belongs to, which decides the exit code.
|
||||
*
|
||||
* @return the phase
|
||||
*/
|
||||
StartupPhase phase();
|
||||
|
||||
/**
|
||||
* What the failure message leads with: the thing being validated, not that validation failed.
|
||||
*
|
||||
* @return the summary
|
||||
*/
|
||||
String summary();
|
||||
|
||||
/**
|
||||
* What the operator should do, printed after the violations.
|
||||
*
|
||||
* @return the remedy, or {@code null} for none
|
||||
*/
|
||||
default String remedy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds every violation in the environment.
|
||||
*
|
||||
* @param environment the resolved environment
|
||||
* @return operator-facing descriptions of what is wrong; empty when nothing is
|
||||
*/
|
||||
List<String> violations(Environment environment);
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package dev.caskeleton.adapter.outbound.support.startup;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* The one startup-rule runner, arriving with the support module every capability already depends
|
||||
* on, so a module contributes rules as beans and never a runner of its own.
|
||||
*/
|
||||
@AutoConfiguration
|
||||
public class StartupRuleAutoConfiguration {
|
||||
|
||||
/**
|
||||
* The runner over every contributed rule.
|
||||
*
|
||||
* @param environment the resolved environment
|
||||
* @param rules the rules modules contributed
|
||||
* @return the runner
|
||||
*/
|
||||
@Bean
|
||||
public StartupRuleRunner startupRuleRunner(
|
||||
Environment environment, ObjectProvider<StartupRule> rules) {
|
||||
return new StartupRuleRunner(environment, rules.orderedStream().toList());
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package dev.caskeleton.adapter.outbound.support.startup;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* Runs every {@link StartupRule} the context holds, once, after all singletons are instantiated and
|
||||
* before the context finishes refreshing.
|
||||
*
|
||||
* <p>The one place a rule's violations become a failure: a {@link StartupValidationContext} opened
|
||||
* for the rule's phase, so the exit code, the {@code error.code} field and the {@code
|
||||
* startup.phase} log field follow from the rule's declaration. Rules run in bean order and the
|
||||
* first rule with violations stops the boot, reporting all of that rule's violations at once.
|
||||
*/
|
||||
public final class StartupRuleRunner implements SmartInitializingSingleton {
|
||||
|
||||
private final Environment environment;
|
||||
|
||||
private final List<StartupRule> rules;
|
||||
|
||||
/**
|
||||
* Creates the runner.
|
||||
*
|
||||
* @param environment the resolved environment
|
||||
* @param rules every rule the context holds
|
||||
*/
|
||||
public StartupRuleRunner(Environment environment, List<StartupRule> rules) {
|
||||
this.environment = Objects.requireNonNull(environment, "environment must be non-null");
|
||||
this.rules = List.copyOf(Objects.requireNonNull(rules, "rules must be non-null"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterSingletonsInstantiated() {
|
||||
for (StartupRule rule : rules) {
|
||||
enforce(rule, environment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs one rule and raises its violations as its phase's typed failure.
|
||||
*
|
||||
* @param rule the rule
|
||||
* @param environment the resolved environment
|
||||
* @throws StartupFailureException when the rule found a violation
|
||||
*/
|
||||
public static void enforce(StartupRule rule, Environment environment) {
|
||||
StartupValidationContext.forPhase(rule.phase())
|
||||
.rejectAll(rule.violations(environment))
|
||||
.failIfViolated(rule.summary(), rule.remedy());
|
||||
}
|
||||
}
|
||||
+1
@@ -1,2 +1,3 @@
|
||||
dev.caskeleton.adapter.outbound.support.OutboundSupportConfig
|
||||
dev.caskeleton.adapter.outbound.support.messaging.IntegrationEventEncoderAutoConfiguration
|
||||
dev.caskeleton.adapter.outbound.support.startup.StartupRuleAutoConfiguration
|
||||
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
package dev.caskeleton.adapter.outbound.support.startup;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
class StartupRuleRunnerTest {
|
||||
|
||||
private final ApplicationContextRunner runner =
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(StartupRuleAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
@DisplayName("규칙의 위반 전부를 그 규칙 phase의 종료 코드로 한 번에 보고한다")
|
||||
void aRulesViolationsFailTheBootWithItsPhasesExitCode() {
|
||||
runner
|
||||
.withBean(
|
||||
StartupRule.class,
|
||||
() -> rule(StartupPhase.PROFILE_CHECK, "prod forbids these", List.of("a=1", "b=2")))
|
||||
.run(
|
||||
context ->
|
||||
assertThat(context.getStartupFailure())
|
||||
.isInstanceOf(StartupFailureException.class)
|
||||
.hasMessage("prod forbids these: a=1; b=2")
|
||||
.extracting(failure -> ((StartupFailureException) failure).errorCode())
|
||||
.isEqualTo(StartupErrorCode.PROFILE_MISMATCH));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aContextWhoseRulesFindNothingStarts() {
|
||||
runner
|
||||
.withBean(
|
||||
StartupRule.class, () -> rule(StartupPhase.ENV_VALIDATION, "nothing wrong", List.of()))
|
||||
.run(context -> assertThat(context).hasNotFailed());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRuleReadsTheResolvedEnvironment() {
|
||||
// given
|
||||
List<String> seen = new ArrayList<>();
|
||||
StartupRule reading =
|
||||
new StartupRule() {
|
||||
@Override
|
||||
public StartupPhase phase() {
|
||||
return StartupPhase.ENV_VALIDATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String summary() {
|
||||
return "reads";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> violations(Environment environment) {
|
||||
seen.add(environment.getProperty("probe.value"));
|
||||
return List.of();
|
||||
}
|
||||
};
|
||||
|
||||
// when
|
||||
runner
|
||||
.withPropertyValues("probe.value=resolved")
|
||||
.withBean(StartupRule.class, () -> reading)
|
||||
.run(context -> {});
|
||||
|
||||
// then
|
||||
assertThat(seen).containsExactly("resolved");
|
||||
}
|
||||
|
||||
private static StartupRule rule(StartupPhase phase, String summary, List<String> violations) {
|
||||
return new StartupRule() {
|
||||
@Override
|
||||
public StartupPhase phase() {
|
||||
return phase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String summary() {
|
||||
return summary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> violations(Environment environment) {
|
||||
return violations;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user