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