refactor: 리펙토링 진행중 의존성 gradle은 얇게 유지, 각 모듈에서 처리하고 있는 부분에 대해서 리펙토링

This commit is contained in:
donghyeon-ka
2026-09-23 17:27:09 +09:00
parent f412efff73
commit ba8a8c171c
98 changed files with 1999 additions and 939 deletions
@@ -1,6 +1,6 @@
package dev.caskeleton.messaging.admin.runtime;
import dev.caskeleton.messaging.admin.AdminApproval;
import dev.caskeleton.messaging.admin.VerifiedApproval;
import dev.caskeleton.messaging.admin.DestructiveOperation;
import dev.caskeleton.messaging.api.destination.DestinationName;
import java.time.Duration;
@@ -24,7 +24,7 @@ public interface DestructiveMessagingAdmin {
record Approved(
DestructiveOperation operation,
DestinationName destination,
AdminApproval approval,
VerifiedApproval approval,
long estimatedMessagesAffected) {
public Approved {
@@ -13,13 +13,10 @@ import java.util.Optional;
/**
* Re-reads a destination from an earlier position.
*
* <p>An isolated replay reads alongside the live consumer and needs no approval, because it changes
* nothing: a throwaway group has its own offsets. Replaying into an existing production group is a
* different operation entirely — it rewinds a live consumer and reprocesses everything since — so
* it goes through the destructive guard.
*
* <p>Making the safe form free and the destructive form approved is what keeps operators from
* reaching for the destructive one out of convenience.
* <p>The request carries an {@code isolatedConsumerGroup} intent flag, but a caller-supplied
* boolean is not proof that the executor actually created or used an isolated broker group.
* Therefore every non-dry-run replay goes through the destructive guard until the runtime can
* attest isolation itself. Dry-run remains approval-free because it changes no broker state.
*/
public final class ReplayService {
@@ -55,13 +52,8 @@ public final class ReplayService {
Objects.requireNonNull(request, "request must not be null");
Objects.requireNonNull(approval, "approval must not be null");
boolean needsApproval = !request.isolatedConsumerGroup();
guard.authorize(
DestructiveOperation.REPLAY,
request.destination(),
approval,
request.dryRun() || !needsApproval,
now);
DestructiveOperation.REPLAY, request.destination(), approval, request.dryRun(), now);
if (request.dryRun()) {
return new ReplayReport(request.replayId(), 0, true);
@@ -74,7 +66,7 @@ public final class ReplayService {
"REPLAY",
subject,
request.destination().value(),
approval.map(VerifiedApproval::ticket).orElse("isolated"),
approval.map(VerifiedApproval::ticket).orElse("dry-run"),
now,
Map.of(
"replayId", request.replayId().toString(),
@@ -187,6 +187,18 @@ class ApprovalForgeryTest {
.isInstanceOf(IllegalArgumentException.class);
}
@Test
@DisplayName("destructive admin plans can only carry a verified approval")
void destructiveAdminUsesTheUnforgeableApprovalType() {
assertThat(
java.util.Arrays.stream(DestructiveMessagingAdmin.Approved.class.getRecordComponents())
.filter(component -> component.getName().equals("approval"))
.findFirst()
.orElseThrow()
.getType())
.isEqualTo(VerifiedApproval.class);
}
@Test
@DisplayName("a correctly issued approval executes")
void aCorrectlyIssuedApprovalExecutes() {
@@ -0,0 +1,77 @@
package dev.caskeleton.messaging.admin.runtime;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import dev.caskeleton.messaging.admin.DestructiveOperationGuard;
import dev.caskeleton.messaging.admin.ReplayRequest;
import dev.caskeleton.messaging.api.destination.DestinationName;
import dev.caskeleton.messaging.api.error.MessageAuthorizationException;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
class ReplayServiceTest {
private static final Instant NOW = Instant.parse("2026-09-21T00:00:00Z");
private static final DestinationName DESTINATION = new DestinationName("orders.v1");
@Test
void callerClaimedIsolationDoesNotBypassApprovalForARealReplay() {
AtomicInteger executions = new AtomicInteger();
ReplayService service =
new ReplayService(
new DestructiveOperationGuard(true),
request -> {
executions.incrementAndGet();
return 1;
},
event -> {});
ReplayRequest request =
new ReplayRequest(
UUID.fromString("0199aaaa-bbbb-7ccc-8ddd-eeeeffff1000"),
DESTINATION,
NOW.minus(Duration.ofHours(1)),
Optional.empty(),
true,
false);
assertThatThrownBy(() -> service.replay(request, Optional.empty(), "operator", NOW))
.isInstanceOfSatisfying(
MessageAuthorizationException.class,
failure -> assertThat(failure.failure().code()).isEqualTo("APPROVAL_REQUIRED"));
assertThat(executions).hasValue(0);
}
@Test
void dryRunRemainsApprovalFreeEvenWhenIsolationIsOnlyAnIntentFlag() {
AtomicInteger executions = new AtomicInteger();
ReplayService service =
new ReplayService(
new DestructiveOperationGuard(true),
request -> {
executions.incrementAndGet();
return 1;
},
event -> {});
ReplayRequest request =
new ReplayRequest(
UUID.fromString("0199aaaa-bbbb-7ccc-8ddd-eeeeffff1001"),
DESTINATION,
NOW.minus(Duration.ofHours(1)),
Optional.empty(),
true,
true);
ReplayReport report = service.replay(request, Optional.empty(), "operator", NOW);
assertThat(report.dryRun()).isTrue();
assertThat(report.replayed()).isZero();
assertThat(executions).hasValue(0);
}
}