mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-10-25 11:03:14 +01:00
Three Phase 0 seams, each with the current database behaviour as its only backend: - StreamSource: the stream row, this node's streams_servers row and the stream options a node reads before running a stream. The launcher (live, VOD and LLOD starts), MonitorCommand, ProxyCommand, ScannerCommand and live.php's fanout proxy hand-off ran these queries themselves. - StreamRowMerge: MAIN's side of a node's runtime state. StreamStateWriter's SQL backend now calls it; later it merges `stream.state` events keyed by the reporting node. eventFields() keeps only runtime columns and redacts the source URL. - StreamCacheBuilder: the stream_<id> cache entry (columns, server rows, the direct-source rule), extracted from cron:cache_engine so the R2 stream delta can build the same shape. OndemandCommand's stop path also still wrote streams_servers and signals with raw SQL. It now uses StreamStateWriter and SignalDispatcher, like the rest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Es8UhyPS8MNjuYTagqfGWi
48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use XcVm\Domain\Stream\StreamRowMerge;
|
|
|
|
/**
|
|
* MAIN merges a node's stream runtime state into that node's row only, and
|
|
* only into runtime-state columns.
|
|
*/
|
|
final class StreamRowMergeTest extends TestCase {
|
|
|
|
private function recorder(): object {
|
|
return new class {
|
|
/** @var list<array{string, list<mixed>}> */
|
|
public array $rQueries = [];
|
|
public function query(string $rSql, mixed ...$rParams): bool {
|
|
$this->rQueries[] = [$rSql, $rParams];
|
|
return true;
|
|
}
|
|
};
|
|
}
|
|
|
|
public function testMergeIsKeyedByTheReportingNode(): void {
|
|
$rDb = $this->recorder();
|
|
StreamRowMerge::mergeNode(7, 42, ['pid' => 100, 'stream_status' => 0], $rDb);
|
|
$this->assertSame([['UPDATE `streams_servers` SET `pid` = ?, `stream_status` = ? WHERE `stream_id` = ? AND `server_id` = ?', [100, 0, 42, 7]]], $rDb->rQueries);
|
|
}
|
|
|
|
public function testMergeRowAndNothingToMerge(): void {
|
|
$rDb = $this->recorder();
|
|
StreamRowMerge::mergeRow(9, ['bitrate' => null], $rDb);
|
|
StreamRowMerge::mergeRow(9, [], $rDb);
|
|
$this->assertSame([['UPDATE `streams_servers` SET `bitrate` = ? WHERE `server_stream_id` = ?', [null, 9]]], $rDb->rQueries);
|
|
}
|
|
|
|
public function testDesiredStateIsRefused(): void {
|
|
$this->expectException(InvalidArgumentException::class);
|
|
StreamRowMerge::mergeNode(1, 1, ['on_demand' => 1], $this->recorder());
|
|
}
|
|
|
|
public function testEventFieldsDropForeignKeysAndRedactTheSource(): void {
|
|
$this->assertSame(
|
|
['pid' => 5, 'current_source' => 'http://src/live/***/***/1.ts'],
|
|
StreamRowMerge::eventFields(['pid' => 5, 'server_id' => 3, 'parent_id' => 2, 'current_source' => 'http://src/live/u/p/1.ts'])
|
|
);
|
|
}
|
|
}
|