fix(interrupts): metadata service not setting interrupt bit
This commit is contained in:
@@ -5,7 +5,6 @@ import com.ddf.vodsystem.dto.ClipOptions;
|
|||||||
import com.ddf.vodsystem.exceptions.FFMPEGException;
|
import com.ddf.vodsystem.exceptions.FFMPEGException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.api.client.json.Json;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
@@ -53,7 +52,9 @@ public class MetadataService {
|
|||||||
|
|
||||||
JsonNode node = mapper.readTree(outputBuilder.toString());
|
JsonNode node = mapper.readTree(outputBuilder.toString());
|
||||||
return CompletableFuture.completedFuture(parseVideoMetadata(node));
|
return CompletableFuture.completedFuture(parseVideoMetadata(node));
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException e) {
|
||||||
|
throw new FFMPEGException("Error while getting video metadata: " + e);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
throw new FFMPEGException("Error while getting video metadata: " + e);
|
throw new FFMPEGException("Error while getting video metadata: " + e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -287,24 +287,8 @@ class MetadataServiceTest {
|
|||||||
assertThat(options.getFileSize()).isEqualTo(exactBytes);
|
assertThat(options.getFileSize()).isEqualTo(exactBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
|
||||||
// Design/best-practice expectations.
|
|
||||||
//
|
|
||||||
// These encode what a metadata parser *should* do rather than what
|
|
||||||
// MetadataService currently does. They are intentionally left failing
|
|
||||||
// (MetadataService is off-limits to edit) to document real bugs found
|
|
||||||
// while writing this suite, rather than being adjusted to match
|
|
||||||
// whatever the implementation happens to produce.
|
|
||||||
// ---------------------------------------------------------------
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getVideoMetadata_plainIOException_doesNotSetThreadInterruptFlag() throws Exception {
|
void getVideoMetadata_plainIOException_doesNotSetThreadInterruptFlag() throws Exception {
|
||||||
// The catch block treats IOException and InterruptedException identically and
|
|
||||||
// calls Thread.currentThread().interrupt() for both. That's correct for an
|
|
||||||
// actual InterruptedException (see the companion test below) but wrong for a
|
|
||||||
// plain IOException -- e.g. ffprobe exiting non-zero -- which has nothing to do
|
|
||||||
// with thread interruption. Spuriously setting the flag can cause unrelated
|
|
||||||
// interruption checks elsewhere (in the same worker thread/pool) to misfire.
|
|
||||||
when(commandRunner.run(anyList())).thenThrow(new IOException("ffprobe boom"));
|
when(commandRunner.run(anyList())).thenThrow(new IOException("ffprobe boom"));
|
||||||
|
|
||||||
assertMetadataFailsWith("Error while getting video metadata");
|
assertMetadataFailsWith("Error while getting video metadata");
|
||||||
@@ -316,8 +300,6 @@ class MetadataServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getVideoMetadata_interruptedException_setsThreadInterruptFlag() throws Exception {
|
void getVideoMetadata_interruptedException_setsThreadInterruptFlag() throws Exception {
|
||||||
// Contrast case: a real InterruptedException should restore the interrupt flag,
|
|
||||||
// per standard Java concurrency practice. This one is expected to pass.
|
|
||||||
when(commandRunner.run(anyList())).thenThrow(new InterruptedException("interrupted"));
|
when(commandRunner.run(anyList())).thenThrow(new InterruptedException("interrupted"));
|
||||||
|
|
||||||
assertMetadataFailsWith("Error while getting video metadata");
|
assertMetadataFailsWith("Error while getting video metadata");
|
||||||
|
|||||||
Reference in New Issue
Block a user