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
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,11 @@ public ExtractedContext extract() {
}

// Only Sampled=1 and Sampled=0 are authoritative; anything else (missing or unusable) is undecided.
var sampling =
switch (sampled == null ? "" : sampled) {
case "1" -> ExtractedContext.Sampling.SAMPLED;
case "0" -> ExtractedContext.Sampling.NOT_SAMPLED;
default -> ExtractedContext.Sampling.UNDECIDED;
};
var sampling = switch (sampled == null ? "" : sampled) {
case "1" -> ExtractedContext.Sampling.SAMPLED;
case "0" -> ExtractedContext.Sampling.NOT_SAMPLED;
default -> ExtractedContext.Sampling.UNDECIDED;
};

return new ExtractedContext(traceId, parentSpanId, sampling);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,13 @@ void rejectsBothViewsBeforeEmissionAndLeavesContextUntouched(String path, boolea
var second = plugin(!reversed, exporter);
var providers = List.of(new ExecutionOtelPluginProvider(), new InvocationOtelPluginProvider());
var names = reversed ? "otel-execution,otel-invocation" : "otel-invocation,otel-execution";
var plugins =
switch (path) {
case "dynamic" -> DynamicPluginLoader.loadConfiguredPlugins(names, providers, List.of());
case "mixed" ->
DynamicPluginLoader.loadConfiguredPlugins(
reversed ? "otel-execution" : "otel-invocation", providers, List.of(second));
default -> List.of(first, second);
};
var plugins = switch (path) {
case "dynamic" -> DynamicPluginLoader.loadConfiguredPlugins(names, providers, List.of());
case "mixed" ->
DynamicPluginLoader.loadConfiguredPlugins(
reversed ? "otel-execution" : "otel-invocation", providers, List.of(second));
default -> List.of(first, second);
};
var ambient = Span.wrap(SpanContext.create(
"12345678901234567890123456789012",
"1234567890123456",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,17 @@ static Stream<Arguments> preparationEndFailures() {
@MethodSource("preparationEndFailures")
void preparationAndEndFailuresRetainCallerIdentityAndCleanupDiagnostics(
boolean executionView, String preparationKind, String endKind) {
Throwable original =
switch (preparationKind) {
case "vm", "wrapped-vm" -> new InternalError("preparation fatal");
case "death" -> new ThreadDeath();
default -> new IllegalStateException("preparation ordinary");
};
Throwable original = switch (preparationKind) {
case "vm", "wrapped-vm" -> new InternalError("preparation fatal");
case "death" -> new ThreadDeath();
default -> new IllegalStateException("preparation ordinary");
};
Throwable preparation = preparationKind.equals("wrapped-vm") ? new CompletionException(original) : original;
Error cleanup =
switch (endKind) {
case "vm" -> new InternalError("End fatal");
case "death" -> new ThreadDeath();
default -> new AssertionError("End error");
};
Error cleanup = switch (endKind) {
case "vm" -> new InternalError("End fatal");
case "death" -> new ThreadDeath();
default -> new AssertionError("End error");
};
var ends = new AtomicInteger();
var seen = new AtomicReference<InvocationEndInfo>();
var serDes = new SerDes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,13 @@ private static InvocationEndInfo end(boolean first) {
"death,ordinary"
})
void flushPreservesTheExistingEndFailurePriority(String rootKind, String flushKind) {
Throwable rootFailure =
switch (rootKind) {
case "linkage" -> new LinkageError("root linkage");
case "assertion" -> new AssertionError("root assertion");
case "vm" -> new InternalError("root fatal");
case "death" -> new ThreadDeath();
default -> new IllegalStateException("root ordinary");
};
Throwable rootFailure = switch (rootKind) {
case "linkage" -> new LinkageError("root linkage");
case "assertion" -> new AssertionError("root assertion");
case "vm" -> new InternalError("root fatal");
case "death" -> new ThreadDeath();
default -> new IllegalStateException("root ordinary");
};
Throwable flushFailure = flushKind.equals("fatal")
? new InternalError("flush fatal")
: new IllegalArgumentException("flush ordinary");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ private static void runWithoutPlugins(ExecutorService executor, String outcome)
return "done";
},
config);
var expected =
switch (outcome) {
case "failure", "inputFailure" -> ExecutionStatus.FAILED;
case "suspension" -> ExecutionStatus.PENDING;
default -> ExecutionStatus.SUCCEEDED;
};
var expected = switch (outcome) {
case "failure", "inputFailure" -> ExecutionStatus.FAILED;
case "suspension" -> ExecutionStatus.PENDING;
default -> ExecutionStatus.SUCCEEDED;
};
assertEquals(expected, runner.run("input").getStatus());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ class InvocationEndFailureTest {
@SuppressWarnings("removal")
void restoresContextWhenInvocationEndFails(boolean executionView, String phase, String failureKind)
throws Exception {
Throwable failure =
switch (failureKind) {
case "exception" -> new IllegalStateException("telemetry failed");
case "linkage" -> new NoClassDefFoundError("incompatible telemetry dependency");
case "fatal" -> new InternalError("fatal telemetry failure");
default -> new ThreadDeath();
};
Throwable failure = switch (failureKind) {
case "exception" -> new IllegalStateException("telemetry failed");
case "linkage" -> new NoClassDefFoundError("incompatible telemetry dependency");
case "fatal" -> new InternalError("fatal telemetry failure");
default -> new ThreadDeath();
};
var processor = new FailingProcessor(phase, failure);
var builder = SdkTracerProvider.builder().addSpanProcessor(processor);
var config = OtelPluginConfig.builder()
Expand Down Expand Up @@ -92,20 +91,18 @@ public void onInvocationEnd(InvocationEndInfo info) {
@MethodSource("combinedFailures")
void preservesCombinedFinalizationAndScopeFailures(boolean executionView, String phase, String pair)
throws Exception {
Throwable primary =
switch (pair.split("-")[0]) {
case "fatal" -> new InternalError("primary finalization");
case "assert" -> new AssertionError("primary finalization");
case "linkage" -> new NoClassDefFoundError("primary finalization");
default -> new IllegalStateException("primary finalization");
};
Throwable cleanup =
switch (pair.split("-")[1]) {
case "fatal" -> new InternalError("scope cleanup");
case "assert" -> new AssertionError("scope cleanup");
case "same" -> primary;
default -> new IllegalStateException("scope cleanup");
};
Throwable primary = switch (pair.split("-")[0]) {
case "fatal" -> new InternalError("primary finalization");
case "assert" -> new AssertionError("primary finalization");
case "linkage" -> new NoClassDefFoundError("primary finalization");
default -> new IllegalStateException("primary finalization");
};
Throwable cleanup = switch (pair.split("-")[1]) {
case "fatal" -> new InternalError("scope cleanup");
case "assert" -> new AssertionError("scope cleanup");
case "same" -> primary;
default -> new IllegalStateException("scope cleanup");
};
var cleanupWins = List.of("runtime-fatal", "assert-fatal", "runtime-assert", "linkage-assert")
.contains(pair);
var expected = cleanupWins ? cleanup : primary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,19 +433,17 @@ public void onInvocationEnd(InvocationEndInfo info) {
})
void preparationAndEndFailuresRetainPrimaryAndFatalIdentity(
String preparationKind, String endKind, boolean serializeFailure, boolean inline) throws Exception {
Throwable original =
switch (preparationKind) {
case "vm", "wrapped" -> new InternalError("preparation fatal");
case "death" -> new ThreadDeath();
default -> new IllegalStateException("preparation failure");
};
Throwable original = switch (preparationKind) {
case "vm", "wrapped" -> new InternalError("preparation fatal");
case "death" -> new ThreadDeath();
default -> new IllegalStateException("preparation failure");
};
var delivery = preparationKind.equals("wrapped") ? new CompletionException(original) : original;
Error endFailure =
switch (endKind) {
case "vm" -> new InternalError("end fatal");
case "death" -> new ThreadDeath();
default -> new AssertionError("end failure");
};
Error endFailure = switch (endKind) {
case "vm" -> new InternalError("end fatal");
case "death" -> new ThreadDeath();
default -> new AssertionError("end failure");
};
var expected = preparationKind.equals("ordinary") && endKind.equals("vm") ? endFailure : original;
var suppressed = expected == endFailure ? original : endFailure;
var ends = new CopyOnWriteArrayList<InvocationEndInfo>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,12 @@ void workerMdcRestorationFailureCannotStrandTheInvocation(boolean ambientMdc, bo
var original = MDC.getMDCAdapter();
var injected = new AtomicBoolean();
var plugin = new RecordingPlugin();
Throwable failure =
switch (failureKind) {
case "fatal" -> new InternalError("worker MDC restoration failed");
case "assertion" -> new AssertionError("worker MDC restoration failed");
case "linkage" -> new NoClassDefFoundError("worker MDC restoration failed");
default -> new IllegalStateException("worker MDC restoration failed");
};
Throwable failure = switch (failureKind) {
case "fatal" -> new InternalError("worker MDC restoration failed");
case "assertion" -> new AssertionError("worker MDC restoration failed");
case "linkage" -> new NoClassDefFoundError("worker MDC restoration failed");
default -> new IllegalStateException("worker MDC restoration failed");
};
var ownerFailure = new AtomicReference<Throwable>();
var observed = new CountDownLatch(1);
var workers = Executors.newSingleThreadExecutor(task -> {
Expand Down Expand Up @@ -164,14 +163,13 @@ static Stream<Arguments> postEndFatalCases() {
void postEndFatalReachesCallerAndWorkerWithoutChangingEnd(
boolean inline, boolean suspend, boolean death, String wrapper) throws Exception {
Error fatal = death ? new ThreadDeath() : new InternalError("post-End restore fatal");
Throwable failure =
switch (wrapper) {
case "completion" -> new CompletionException(fatal);
case "execution" -> new ExecutionException(fatal);
case "reflection" -> new InvocationTargetException(fatal);
case "proxy" -> new UndeclaredThrowableException(fatal);
default -> fatal;
};
Throwable failure = switch (wrapper) {
case "completion" -> new CompletionException(fatal);
case "execution" -> new ExecutionException(fatal);
case "reflection" -> new InvocationTargetException(fatal);
case "proxy" -> new UndeclaredThrowableException(fatal);
default -> fatal;
};
exercisePostEndFailure(inline, suspend, failure, fatal, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,24 @@ class MdcFatalInitializationTest {
void fatalCaptureSettlesCallerThenEscapesOwnerBeforeAnyHook(String mode, boolean death, String wrapper)
throws Exception {
Error fatal = death ? new ThreadDeath() : new InternalError("fatal capture");
Throwable failure =
switch (wrapper) {
case "completion" -> new CompletionException(fatal);
case "nested" -> new CompletionException(new ExecutionException(fatal));
case "reflection" -> new InvocationTargetException(fatal);
case "proxy" -> new UndeclaredThrowableException(fatal);
default -> fatal;
};
Throwable failure = switch (wrapper) {
case "completion" -> new CompletionException(fatal);
case "nested" -> new CompletionException(new ExecutionException(fatal));
case "reflection" -> new InvocationTargetException(fatal);
case "proxy" -> new UndeclaredThrowableException(fatal);
default -> fatal;
};
runCapture(mode, failure, fatal);
}

@ParameterizedTest
@MethodSource("ordinaryCases")
void nonfatalInitializationKeepsItsDurableFailurePolicy(String mode, String kind) throws Exception {
Throwable failure =
switch (kind) {
case "assertion" -> new AssertionError("ordinary capture");
case "application-cause" ->
new IllegalStateException("ordinary capture", new InternalError("diagnostic"));
default -> new IllegalStateException("ordinary capture");
};
Throwable failure = switch (kind) {
case "assertion" -> new AssertionError("ordinary capture");
case "application-cause" -> new IllegalStateException("ordinary capture", new InternalError("diagnostic"));
default -> new IllegalStateException("ordinary capture");
};
runCapture(mode, failure, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,18 @@ private static void exercise(String markerPhase, boolean suspend, String kind, E
var failed = new AtomicBoolean();
var clearTried = new AtomicBoolean();
var restoreFailure = new IllegalStateException("restore failed");
Error clearFatal =
switch (kind) {
case "vm", "wrapped-vm" -> new InternalError("fallback fatal");
case "death", "wrapped-death" -> new ThreadDeath();
default -> null;
};
Throwable clearFailure =
switch (kind) {
case "ordinary" -> new IllegalArgumentException("clear failed");
case "assertion" -> new AssertionError("clear failed");
case "same" -> restoreFailure;
case "wrapped-vm", "wrapped-death" -> new CompletionException(new ExecutionException(clearFatal));
default -> clearFatal;
};
Error clearFatal = switch (kind) {
case "vm", "wrapped-vm" -> new InternalError("fallback fatal");
case "death", "wrapped-death" -> new ThreadDeath();
default -> null;
};
Throwable clearFailure = switch (kind) {
case "ordinary" -> new IllegalArgumentException("clear failed");
case "assertion" -> new AssertionError("clear failed");
case "same" -> restoreFailure;
case "wrapped-vm", "wrapped-death" -> new CompletionException(new ExecutionException(clearFatal));
default -> clearFatal;
};
Error expectedFatal = selectedFatal != null ? selectedFatal : clearFatal;
var escaped = new CountDownLatch(1);
var failedWorker = new AtomicReference<Thread>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ static Stream<Arguments> cleanupCases() {
void continuationFailureMustWakeBodyBeforeEndWaitsForCleanup(String mode, String kind) throws Exception {
boolean rejection = kind.equals("reject");
boolean withPlugin = true;
Throwable failure =
switch (kind) {
case "reject" -> new RejectedExecutionException("resumed worker rejected");
case "vm" -> new InternalError("resumed state fatal");
case "death" -> new ThreadDeath();
default -> new IllegalArgumentException("resumed state cannot deserialize");
};
Throwable failure = switch (kind) {
case "reject" -> new RejectedExecutionException("resumed worker rejected");
case "vm" -> new InternalError("resumed state fatal");
case "death" -> new ThreadDeath();
default -> new IllegalArgumentException("resumed state cannot deserialize");
};
var injectionThread = new AtomicReference<Thread>();
var handlerThread = new AtomicReference<Thread>();
var callerThread = new AtomicReference<Thread>();
Expand Down
Loading
Loading