|
|
@@ -135,6 +135,37 @@ class VideoPreparedSqlTransactionTest {
|
|
|
SecurityContextHolder.clearContext();
|
|
|
}
|
|
|
|
|
|
+ @Test void secondPrecisionStoragePreservesDeadlineAcrossStatusStopAndReplay() throws Exception {
|
|
|
+ // Reproduce the deployed timestamp precision at the real SQL adapter, not in business mocks.
|
|
|
+ sql.execute("ALTER TABLE app_user.video_play_session ALTER COLUMN start_deadline TIMESTAMP(0)");
|
|
|
+ context.getBean(MutableClock.class).now = Instant.parse("2026-11-10T08:00:00.584Z");
|
|
|
+ when(media.post(eq("/internal/video/lifecycle/status"), any())).thenAnswer(call -> {
|
|
|
+ Map<String, Object> body = call.getArgument(1);
|
|
|
+ assertEquals(start.get().get("generation"), body.get("generation"));
|
|
|
+ assertEquals(start.get().get("startDeadline"), body.get("startDeadline"),
|
|
|
+ "SQL round-trip must not change the immutable provider deadline");
|
|
|
+ return Map.of("generation", body.get("generation"), "status", "ACTIVE", "media",
|
|
|
+ Map.of("stream", "sql_stream", "mediaServerId", "node-sql", "flv", "https://media.invalid/sql.flv"));
|
|
|
+ });
|
|
|
+ when(media.post(eq("/internal/video/lifecycle/cancel"), any())).thenAnswer(call -> {
|
|
|
+ Map<String, Object> body = call.getArgument(1); cancel.set(new LinkedHashMap<>(body));
|
|
|
+ assertEquals(start.get().get("startDeadline"), body.get("startDeadline"),
|
|
|
+ "stop must use the deadline originally dispatched to the provider");
|
|
|
+ return Map.of("generation", body.get("generation"), "status", "STOPPED");
|
|
|
+ });
|
|
|
+ JSONObject first = prepare();
|
|
|
+ action(first, "live").andExpect(status().isOk()).andExpect(jsonPath("$.data.status").value("ACTIVE"));
|
|
|
+ String firstGeneration = (String) start.get().get("generation");
|
|
|
+ action(first, "status").andExpect(status().isOk()).andExpect(jsonPath("$.data.status").value("ACTIVE"));
|
|
|
+ action(first, "stop").andExpect(status().isOk()).andExpect(jsonPath("$.data.status").value("STOPPED"));
|
|
|
+ JSONObject second = prepare();
|
|
|
+ action(second, "live").andExpect(status().isOk()).andExpect(jsonPath("$.data.status").value("ACTIVE"));
|
|
|
+ assertNotEquals(firstGeneration, start.get().get("generation"));
|
|
|
+ action(second, "status").andExpect(status().isOk());
|
|
|
+ action(second, "stop").andExpect(status().isOk()).andExpect(jsonPath("$.data.status").value("STOPPED"));
|
|
|
+ assertEquals(Instant.parse("2026-11-10T08:00:30Z").toEpochMilli(), start.get().get("startDeadline"));
|
|
|
+ }
|
|
|
+
|
|
|
@Test void activeSqlFailureCompensatesTheAlreadyStartedGenerationBeforeReturning() throws Exception {
|
|
|
JSONObject viewer = prepare();
|
|
|
// This is a real failed SQL statement AFTER identity/STARTING commit and AFTER media start.
|