aboutsummaryrefslogtreecommitdiff
path: root/internal/storage/pebble_store_batch_durability_test.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-26 14:46:02 -0800
committerFuwn <[email protected]>2026-02-26 14:48:52 -0800
commit0099d621e97b6048971fadb5c71918cc9f2b5a09 (patch)
treea38ba31585200bacd61f453ef7158de7f0aaf7a3 /internal/storage/pebble_store_batch_durability_test.go
parentInitial commit (diff)
downloadplutia-test-0099d621e97b6048971fadb5c71918cc9f2b5a09.tar.xz
plutia-test-0099d621e97b6048971fadb5c71918cc9f2b5a09.zip
feat: initial Plutia release — verifiable high-performance PLC mirror (mirror + resolver modes)
Diffstat (limited to 'internal/storage/pebble_store_batch_durability_test.go')
-rw-r--r--internal/storage/pebble_store_batch_durability_test.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/internal/storage/pebble_store_batch_durability_test.go b/internal/storage/pebble_store_batch_durability_test.go
new file mode 100644
index 0000000..9d881c3
--- /dev/null
+++ b/internal/storage/pebble_store_batch_durability_test.go
@@ -0,0 +1,66 @@
+package storage
+
+import (
+ "testing"
+ "time"
+
+ "github.com/Fuwn/plutia/internal/types"
+)
+
+func TestApplyOperationsBatch_DurabilityBetweenBatches(t *testing.T) {
+ tmp := t.TempDir()
+ store, err := OpenPebble(tmp)
+ if err != nil {
+ t.Fatalf("open pebble: %v", err)
+ }
+
+ makeMutation := func(did string, seq uint64) OperationMutation {
+ return OperationMutation{
+ State: types.StateV1{
+ Version: 1,
+ DID: did,
+ DIDDocument: []byte(`{"id":"` + did + `"}`),
+ ChainTipHash: "sha256:tip",
+ LatestOpSeq: seq,
+ UpdatedAt: time.Now().UTC(),
+ },
+ Ref: &types.BlockRefV1{
+ Version: 1,
+ BlockID: 1,
+ OpSeq: seq,
+ DID: did,
+ CID: "sha256:cid",
+ },
+ }
+ }
+
+ if err := store.ApplyOperationsBatch([]OperationMutation{
+ makeMutation("did:plc:a", 1),
+ makeMutation("did:plc:b", 2),
+ }, []BlockHashEntry{{BlockID: 1, Hash: "abc"}}); err != nil {
+ t.Fatalf("apply first batch: %v", err)
+ }
+ if err := store.Close(); err != nil {
+ t.Fatalf("close store: %v", err)
+ }
+
+ // Simulate a crash before the second batch commit by reopening without applying it.
+ reopened, err := OpenPebble(tmp)
+ if err != nil {
+ t.Fatalf("reopen pebble: %v", err)
+ }
+ defer reopened.Close()
+
+ seq, err := reopened.GetGlobalSeq()
+ if err != nil {
+ t.Fatalf("get global seq: %v", err)
+ }
+ if seq != 2 {
+ t.Fatalf("global seq mismatch after simulated crash: got %d want 2", seq)
+ }
+ if _, ok, err := reopened.GetOpSeqRef(3); err != nil {
+ t.Fatalf("get opseq 3: %v", err)
+ } else if ok {
+ t.Fatalf("unexpected opseq ref for uncommitted sequence 3")
+ }
+}