@@ -394,7 +394,67 @@ func TestScalarPredicateCount(t *testing.T) {
394394 l .RUnlock ()
395395}
396396
397- func TestSingleUid (t * testing.T ) {
397+ func TestSingleUidReplacement (t * testing.T ) {
398+ dir , err := os .MkdirTemp ("" , "storetest_" )
399+ x .Check (err )
400+ defer os .RemoveAll (dir )
401+
402+ opt := badger .DefaultOptions (dir )
403+ ps , err := badger .OpenManaged (opt )
404+ x .Check (err )
405+ pstore = ps
406+ posting .Init (ps , 0 , false )
407+ Init (ps )
408+ err = schema .ParseBytes ([]byte ("singleUidReplaceTest: uid ." ), 1 )
409+ require .NoError (t , err )
410+
411+ ctx := context .Background ()
412+ txn := posting .Oracle ().RegisterStartTs (5 )
413+ attr := x .GalaxyAttr ("singleUidReplaceTest" )
414+
415+ // Txn 1. Set 1 -> 2
416+ x .Check (runMutation (ctx , & pb.DirectedEdge {
417+ ValueId : 2 ,
418+ Attr : attr ,
419+ Entity : 1 ,
420+ Op : pb .DirectedEdge_SET ,
421+ }, txn ))
422+
423+ txn .Update ()
424+ writer := posting .NewTxnWriter (pstore )
425+ require .NoError (t , txn .CommitToDisk (writer , 7 ))
426+ require .NoError (t , writer .Flush ())
427+ txn .UpdateCachedKeys (7 )
428+
429+ // Txn 2. Set 1 -> 3
430+ txn = posting .Oracle ().RegisterStartTs (9 )
431+
432+ x .Check (runMutation (ctx , & pb.DirectedEdge {
433+ ValueId : 3 ,
434+ Attr : attr ,
435+ Entity : 1 ,
436+ Op : pb .DirectedEdge_SET ,
437+ }, txn ))
438+
439+ txn .Update ()
440+ writer = posting .NewTxnWriter (pstore )
441+ require .NoError (t , txn .CommitToDisk (writer , 11 ))
442+ require .NoError (t , writer .Flush ())
443+ txn .UpdateCachedKeys (11 )
444+
445+ key := x .DataKey (attr , 1 )
446+
447+ // Reading the david index, we should see 2 inserted, 1 deleted
448+ txn = posting .Oracle ().RegisterStartTs (15 )
449+ l , err := txn .Get (key )
450+ require .NoError (t , err )
451+
452+ uids , err := l .Uids (posting.ListOptions {ReadTs : 15 })
453+ require .NoError (t , err )
454+ require .Equal (t , uids .Uids , []uint64 {3 })
455+ }
456+
457+ func TestSingleString (t * testing.T ) {
398458 dir , err := os .MkdirTemp ("" , "storetest_" )
399459 x .Check (err )
400460 defer os .RemoveAll (dir )
0 commit comments