fix(media): propagate async FFmpeg results and failures
This commit is contained in:
@@ -53,16 +53,19 @@ class MetadataServiceTest {
|
||||
private ClipOptions runMetadata() throws Exception {
|
||||
return metadataService.getVideoMetadata(INPUT).get();
|
||||
}
|
||||
|
||||
private void assertMetadataFailsWith(String messageFragment) {
|
||||
private void assertMetadataFailsWith(Class<? extends Throwable> exceptionType, String messageFragment) {
|
||||
assertThatThrownBy(() -> metadataService.getVideoMetadata(INPUT).get())
|
||||
.satisfies(thrown -> {
|
||||
Throwable cause = thrown instanceof ExecutionException ? thrown.getCause() : thrown;
|
||||
assertThat(cause).isInstanceOf(FFMPEGException.class);
|
||||
assertThat(cause).isInstanceOf(exceptionType);
|
||||
assertThat(cause.getMessage()).contains(messageFragment);
|
||||
});
|
||||
}
|
||||
|
||||
private void assertMetadataFailsWith(String messageFragment) {
|
||||
assertMetadataFailsWith(FFMPEGException.class, messageFragment);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Happy path / parsing behavior
|
||||
// ---------------------------------------------------------------
|
||||
@@ -246,10 +249,10 @@ class MetadataServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getVideoMetadata_commandThrowsIOException_throwsFFMPEGException() throws Exception {
|
||||
void getVideoMetadata_commandThrowsIOException_completesExceptionally() throws Exception {
|
||||
when(commandRunner.run(anyList())).thenThrow(new IOException("ffprobe boom"));
|
||||
|
||||
assertMetadataFailsWith("Error while getting video metadata");
|
||||
assertMetadataFailsWith(IOException.class, "ffprobe boom");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -291,7 +294,7 @@ class MetadataServiceTest {
|
||||
void getVideoMetadata_plainIOException_doesNotSetThreadInterruptFlag() throws Exception {
|
||||
when(commandRunner.run(anyList())).thenThrow(new IOException("ffprobe boom"));
|
||||
|
||||
assertMetadataFailsWith("Error while getting video metadata");
|
||||
assertMetadataFailsWith(IOException.class, "ffprobe boom");
|
||||
|
||||
assertThat(Thread.currentThread().isInterrupted())
|
||||
.as("a plain IOException must not leave the calling thread's interrupt flag set")
|
||||
@@ -302,7 +305,7 @@ class MetadataServiceTest {
|
||||
void getVideoMetadata_interruptedException_setsThreadInterruptFlag() throws Exception {
|
||||
when(commandRunner.run(anyList())).thenThrow(new InterruptedException("interrupted"));
|
||||
|
||||
assertMetadataFailsWith("Error while getting video metadata");
|
||||
assertMetadataFailsWith(InterruptedException.class, "interrupted");
|
||||
|
||||
assertThat(Thread.currentThread().isInterrupted()).isTrue();
|
||||
}
|
||||
|
||||
@@ -268,17 +268,18 @@ class StreamActionsServiceTest {
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
void saveSection_success_buildsExpectedCommandAndCompletesWithOutputFile() throws Exception {
|
||||
void saveSection_success_buildsExpectedCommandAndCompletesWithCommandOutput() throws Exception {
|
||||
Path segmentA = Path.of("/tmp/streams/a.ts");
|
||||
Path segmentB = Path.of("/tmp/streams/b.ts");
|
||||
Path output = Path.of("/tmp/out/clip.mp4");
|
||||
ProgressTracker progress = new ProgressTracker();
|
||||
CommandOutput commandOutput = new CommandOutput();
|
||||
|
||||
when(commandRunner.run(anyList(), any())).thenReturn(new CommandOutput());
|
||||
when(commandRunner.run(anyList(), any())).thenReturn(commandOutput);
|
||||
|
||||
var future = service.saveSection(List.of(segmentA, segmentB), 5.0f, 12.0f, output, progress);
|
||||
|
||||
assertThat(future.get()).isEqualTo(output);
|
||||
assertThat(future.get()).isSameAs(commandOutput);
|
||||
assertThat(progress.isComplete()).isTrue();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -310,14 +311,16 @@ class StreamActionsServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveSection_emptySegmentList_throwsIllegalStateException() {
|
||||
void saveSection_emptySegmentList_completesExceptionallyWithIllegalStateException() {
|
||||
Path output = Path.of("/tmp/out/clip.mp4");
|
||||
ProgressTracker progress = new ProgressTracker();
|
||||
|
||||
var future = service.saveSection(List.of(), 0f, 10f, output, progress);
|
||||
|
||||
assertThatThrownBy(future::get).isInstanceOf(ExecutionException.class);
|
||||
|
||||
assertThatThrownBy(future::get)
|
||||
.isInstanceOf(ExecutionException.class)
|
||||
.hasCauseInstanceOf(IllegalStateException.class);
|
||||
assertThat(progress.isComplete()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -326,6 +329,9 @@ class StreamActionsServiceTest {
|
||||
|
||||
var future = service.saveSection(List.of(Path.of("/tmp/a.ts")), 0f, 10f, null, progress);
|
||||
|
||||
assertThatThrownBy(future::get).isInstanceOf(ExecutionException.class);
|
||||
assertThatThrownBy(future::get)
|
||||
.isInstanceOf(ExecutionException.class)
|
||||
.hasCauseInstanceOf(NullPointerException.class);
|
||||
assertThat(progress.isComplete()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user