MCPcopy
hub / github.com/dgraph-io/dgraph / TestCacheAfterDeltaUpdateRecieved

Function TestCacheAfterDeltaUpdateRecieved

posting/mvcc_test.go:59–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

57}
58
59func TestCacheAfterDeltaUpdateRecieved(t *testing.T) {
60 attr := x.AttrInRootNamespace("cache")
61 key := x.IndexKey(attr, "temp")
62
63 // Create a delta from 5->15. Mimick how a follower recieves a delta.
64 p := new(pb.PostingList)
65 p.Postings = []*pb.Posting{{
66 Uid: 1,
67 StartTs: 5,
68 CommitTs: 15,
69 Op: 1,
70 }}
71 delta, err := proto.Marshal(p)
72 require.NoError(t, err)
73
74 // Write delta to disk and call update
75 txn := Oracle().RegisterStartTs(5)
76 txn.cache.deltas[string(key)] = delta
77
78 writer := NewTxnWriter(pstore)
79 require.NoError(t, txn.CommitToDisk(writer, 15))
80 require.NoError(t, writer.Flush())
81
82 txn.UpdateCachedKeys(15)
83
84 // Read key at timestamp 10. Make sure cache is not updated by this, as there is a later read.
85 l, err := GetNoStore(key, 10)
86 require.NoError(t, err)
87 require.Equal(t, l.mutationMap.listLen(10), 0)
88
89 // Read at 20 should show the value
90 l1, err := GetNoStore(key, 20)
91 require.NoError(t, err)
92 require.Equal(t, l1.mutationMap.listLen(20), 1)
93}
94
95func BenchmarkTestCache(b *testing.B) {
96 dir, err := os.MkdirTemp("", "storetest_")

Callers

nothing calls this directly

Calls 10

FlushMethod · 0.95
AttrInRootNamespaceFunction · 0.92
IndexKeyFunction · 0.92
NewTxnWriterFunction · 0.85
GetNoStoreFunction · 0.85
RegisterStartTsMethod · 0.80
CommitToDiskMethod · 0.80
UpdateCachedKeysMethod · 0.80
listLenMethod · 0.80
OracleFunction · 0.70

Tested by

no test coverage detected