41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
<?php
|
|
|
|
use Tempo\Integration\WarehouseInbox;
|
|
|
|
require __DIR__.'/../Support/InboxFixture.php';
|
|
|
|
if (getenv('INBOX_TEST_PG') !== '1') {
|
|
throw new LogicException('Executor limitado à prova PostgreSQL descartável.');
|
|
}
|
|
$mode = $argv[1] ?? '';
|
|
if ($mode === 'prepare') {
|
|
$db = inboxDatabase();
|
|
$inbox = new WarehouseInbox($db, 'synthetic-sgc-a', 7, 99, 'reader');
|
|
$inbox->accept(inboxPage([], 'cursor-start'), 0, null);
|
|
echo json_encode(['checkpoint' => $inbox->checkpoint()], JSON_THROW_ON_ERROR);
|
|
exit;
|
|
}
|
|
$db = inboxConnection();
|
|
$inbox = new WarehouseInbox($db, 'synthetic-sgc-a', 7, 99, 'reader');
|
|
if ($mode === 'hold') {
|
|
$db->beginTransaction();
|
|
$db->query('SELECT version FROM sgc_exchange_streams FOR UPDATE')->fetchColumn();
|
|
echo 'locked';
|
|
flush();
|
|
usleep(1500000);
|
|
$db->commit();
|
|
}
|
|
if (! in_array($mode, ['hold', 'run', 'exit-after-commit'], true)) {
|
|
throw new LogicException('Modo inválido.');
|
|
}
|
|
$id = (int) ($argv[2] ?? 1);
|
|
try {
|
|
$result = $inbox->accept(inboxPage([inboxEvent($id)], 'cursor-'.$id), 1, 'cursor-start');
|
|
if ($mode === 'exit-after-commit') {
|
|
exit(42); // committed, acknowledgement intentionally lost
|
|
}
|
|
echo json_encode(['result' => 'accepted', ...$result], JSON_THROW_ON_ERROR);
|
|
} catch (RuntimeException $e) {
|
|
echo json_encode(['result' => 'conflict'], JSON_THROW_ON_ERROR);
|
|
}
|