feat: add journaled transfer materialization
This commit is contained in:
+35
-1
@@ -4,7 +4,12 @@ import os
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
from archive_clients.state import ClientStore, CommandConflict, JobConflict
|
||||
from archive_clients.state import (
|
||||
ClientStore,
|
||||
CommandConflict,
|
||||
FileOperationConflict,
|
||||
JobConflict,
|
||||
)
|
||||
|
||||
|
||||
class ClientStoreTests(unittest.TestCase):
|
||||
@@ -86,6 +91,35 @@ class ClientStoreTests(unittest.TestCase):
|
||||
command_id, 2, "ready", '{"sequence":2,"changed":true}'
|
||||
)
|
||||
|
||||
def test_file_operation_journal_is_idempotent_and_content_addressed(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
store = ClientStore(Path(directory) / "state.db")
|
||||
store.initialize()
|
||||
first = store.begin_file_operation(
|
||||
"operation-1", "job-1", '{"destination":"a","source":"b"}'
|
||||
)
|
||||
repeated = store.begin_file_operation(
|
||||
"operation-1", "job-1", '{"source":"b","destination":"a"}'
|
||||
)
|
||||
self.assertEqual(first["state"], "intent")
|
||||
self.assertEqual(repeated["state"], "intent")
|
||||
completed = store.complete_file_operation(
|
||||
"operation-1", '{"method":1}'
|
||||
)
|
||||
duplicate = store.complete_file_operation(
|
||||
"operation-1", '{"method":1}'
|
||||
)
|
||||
self.assertEqual(completed["state"], "completed")
|
||||
self.assertEqual(duplicate["result_json"], '{"method":1}')
|
||||
with self.assertRaises(FileOperationConflict):
|
||||
store.begin_file_operation(
|
||||
"operation-1", "job-1", '{"source":"other"}'
|
||||
)
|
||||
with self.assertRaises(FileOperationConflict):
|
||||
store.complete_file_operation(
|
||||
"operation-1", '{"method":2}'
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user