diff --git a/apps/backend/crydaq-service/src/test/java/com/opentest/service/grpc/replay/RecordedMeasurementReplaySessionTest.java b/apps/backend/crydaq-service/src/test/java/com/opentest/service/grpc/replay/RecordedMeasurementReplaySessionTest.java index 03ad0096..bad30eda 100644 --- a/apps/backend/crydaq-service/src/test/java/com/opentest/service/grpc/replay/RecordedMeasurementReplaySessionTest.java +++ b/apps/backend/crydaq-service/src/test/java/com/opentest/service/grpc/replay/RecordedMeasurementReplaySessionTest.java @@ -39,6 +39,10 @@ import com.opentest.dashboard.api.pipeline.SinkProcessor; import com.opentest.dashboard.api.pipeline.StartControlProcessor; import com.opentest.dashboard.api.pipeline.StopControlProcessor; +import com.opentest.dashboard.api.pipeline.Processor; +import com.opentest.dashboard.api.channel.ChannelMetadata; +import com.opentest.dashboard.standard.result.PersistResultSinkProcessor; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -196,6 +200,46 @@ public void execute(ExecutionPreparation preparation,Map,Object> servic } } + /** B020004: an FS spectrum frame reached a saved Vrms target and stopped the pipeline while the WAV still had input. */ + @Test void multiFrameReplayFailureReportsTheProcessorFailureThatStoppedInput() throws Exception { + var row = channel(); row.setVchId("Ch1"); row.setSamplingRate(192000); row.setBitDepth(32); row.setVp(2.8D); + var channel = MeasureProviderInputs.channel(row); + var wav = directory.resolve("Ch1.wav"); + var samples = new double[192000 * 10]; + for (int index = 0; index < samples.length; index++) samples[index] = .5 * Math.sin(2 * Math.PI * 1000 * index / 192000D); + try (var writer = new WavWriter(directory.toString(), wav.getFileName().toString(), false)) { + writer.appendData(new WavData(wav.getFileName().toString(), samples, 192000, 32, 2.8D, 1D)); + } + var target = new ResultRequirement(101L, "FFT Spectrum", "hash", Map.of(), "Ch1", "Hz", "Vrms"); + var plan = new RecordedMeasurementReplayPlan("test:replay", Map.of(), ExecutionInputPurpose.RECORDED_STREAM, + new ExecutionOutputs(1, 2, 3, List.of(channel), List.of(target), List.of()), + Map.of(new MeasurementResultMemberFacts.Key(101, "Ch1"), mock(MeasurementResultMemberFacts.Fact.class)), + List.of(new RecordedMeasurementReplayPlan.InputClock(channel, 0, 0, (long) samples.length))); + var plugins = mock(PluginMeasureExecutor.class); + when(plugins.bindMeasurement(anyString(), anyMap(), anyMap(), any(), any(), any())).thenReturn(new BoundMeasurementExecution() { + @Override public String configurationVersion() { return "1"; } + @Override public Map, Object> pipelineCapabilities() { return Map.of(); } + @Override public void execute(ExecutionPreparation preparation, Map, Object> services) throws Exception { + var prepared = preparation.prepare(); + prepared.compile(outputs -> spectrumPipeline(outputs.channels())); + prepared.ready(); + prepared.run(); + } + }); + var pressure = new ReplayPressureController(4, 64L * 1024 * 1024); + var timeline = new DashboardWavTimelineReader(List.of(new DashboardWavSource(row, + FileSystems.getFileSystem("local:///"), List.of(wav.toString()))), 10_000D, List.of("Ch1")); + RuntimeException failure; + try (var session = new RecordedMeasurementReplaySession(plan, plugins, new DashboardWavReplayRunner(), Map.of(), + frame -> { throw new AssertionError("An FS frame must not reach the Vrms target"); }, curves -> { }, + CompletableFuture.completedFuture(null))) { + failure = assertThrows(RuntimeException.class, () -> session.run(timeline, new DashboardReplayCancellationToken(), + pressure, new ReplayWriteTracker(pressure), null)); + } + assertTrue(failure.getMessage().contains("no unique saved result target"), failure::toString); + assertInstanceOf(IllegalArgumentException.class, failure.getCause()); + } + private static PluginMeasureExecutor provider(List facts, AtomicBoolean resourceClosed, AtomicReference> packageReleased) { return provider(facts,resourceClosed,packageReleased,services -> { }); @@ -242,6 +286,35 @@ private static ProcessorPipelineBuilder pipeline(List facts,boolean w return builder; } + /** Emits one FS spectrum per 2048 samples, as the ordinary FFT processor does, into the standard result sink. */ + private static ProcessorPipelineBuilder spectrumPipeline(List channels) { + var spectrum = new Processor() { + private final double[] window = new double[2048]; + private int used; + @Override public void onFrame(ChannelFrame frame) { + for (double sample : frame.samples()) { + window[used++] = sample; + if (used < window.length) continue; + used = 0; + var output = ResultFrame.explicitX("FFT Spectrum", "hash", "Ch1", "Hz", "FS", + new double[] {0, 93.75}, new double[] {window[0], window[1]}, 0D, null); + try { context().emit(output.withDashboardResultId(101L)); } finally { output.release(); } + } + } + }; + var persist = new PersistResultSinkProcessor(1, 2, 3, channels); + return ProcessorPipelineBuilder.create() + .startControl(new StartControlProcessor() { + @Override public void onFrame(ChannelFrame frame) { context().emit(frame.retain()); } + }, 2, QueueOverflowPolicy.WAIT_FOR_CAPACITY) + .stopControl(new StopControlProcessor() { + @Override public void onFrame(ChannelFrame frame) { context().emit(frame.retain()); } + }, 2, QueueOverflowPolicy.WAIT_FOR_CAPACITY) + .addProcessor("spectrum", spectrum).addProcessor("persist", persist) + .connectInput("Ch1", spectrum, 4, QueueOverflowPolicy.WAIT_FOR_CAPACITY) + .connect(spectrum, persist, 4, QueueOverflowPolicy.WAIT_FOR_CAPACITY); + } + private static ChannelDto channel() { var channel = new ChannelDto(); channel.setVchId("input"); diff --git a/apps/backend/opentest-dashboard-api/src/main/java/com/opentest/dashboard/api/pipeline/DefaultProcessorPipeline.java b/apps/backend/opentest-dashboard-api/src/main/java/com/opentest/dashboard/api/pipeline/DefaultProcessorPipeline.java index 5265f3a8..709e868f 100644 --- a/apps/backend/opentest-dashboard-api/src/main/java/com/opentest/dashboard/api/pipeline/DefaultProcessorPipeline.java +++ b/apps/backend/opentest-dashboard-api/src/main/java/com/opentest/dashboard/api/pipeline/DefaultProcessorPipeline.java @@ -205,7 +205,7 @@ public void accept(ChannelFrame frame) { synchronized (inputGate) { if (!accepting.get()) { frame.release(); - throw new IllegalStateException("ProcessorPipeline no longer accepts input"); + throw rejectedInput(); } if (inputMode == PipelineInputMode.CONTROLLED_REALTIME) { rawStartConnection.offer(frame, true); @@ -215,13 +215,20 @@ public void accept(ChannelFrame frame) { } if (!accepting.get()) { frame.release(); - throw new IllegalStateException("ProcessorPipeline no longer accepts input"); + throw rejectedInput(); } dispatchOwned(frame, matchingFormalConnections(frame), true); } } } + /** Keeps the processor failure that stopped input; callers otherwise only see this later rejection. */ + private IllegalStateException rejectedInput() { + Throwable cause = failure.get(); + String message = "ProcessorPipeline no longer accepts input"; + return new IllegalStateException(cause == null ? message : message + ": " + cause, cause); + } + @Override public void stop() { if (!stopping.compareAndSet(false, true)) { diff --git a/apps/backend/opentest-dashboard-api/src/test/java/com/opentest/dashboard/api/pipeline/ProcessorErrorPolicyContractTest.java b/apps/backend/opentest-dashboard-api/src/test/java/com/opentest/dashboard/api/pipeline/ProcessorErrorPolicyContractTest.java index 35df2842..00bd0731 100644 --- a/apps/backend/opentest-dashboard-api/src/test/java/com/opentest/dashboard/api/pipeline/ProcessorErrorPolicyContractTest.java +++ b/apps/backend/opentest-dashboard-api/src/test/java/com/opentest/dashboard/api/pipeline/ProcessorErrorPolicyContractTest.java @@ -150,6 +150,16 @@ public void onFrame(ChannelFrame frame) { } Map.of(PipelineStopCoordinator.class, (PipelineStopCoordinator) failed -> { inputStopped.set(true); return List.of(tail); })))); assertTrue(inputStopped.get()); assertEquals(0, startFailure.getSuppressed().length); assertEquals(1, released.get()); } + /** Replay sources keep feeding after a sink failure; the rejection must still name the failure that stopped input. */ + @Test void inputRejectedAfterProcessorFailureCarriesThatFailure() throws Exception { + var original = new IllegalArgumentException("Recorded frame has no unique saved result target"); + var processor = new SinkProcessor() { public void onFrame(ChannelFrame frame) { throw original; } }; + var pipeline = compile(processor); pipeline.accept(frame(1)); + assertThrows(ExecutionException.class, () -> pipeline.completion().toCompletableFuture().get(2, TimeUnit.SECONDS)); + var rejected = assertThrows(IllegalStateException.class, () -> pipeline.accept(frame(2))); + assertSame(original, rejected.getCause()); + assertTrue(rejected.getMessage().contains(original.getMessage())); + } private ProcessorPipeline compile(Processor processor) { return compile(processor, Map.of()); } private ProcessorPipeline compile(Processor processor, Map, Object> capabilities) { var builder = ProcessorPipelineBuilder.create().addProcessor("processor", processor)