@@ -24,21 +24,30 @@ import (
2424
2525 "github.com/dgraph-io/dgo/v240"
2626 "github.com/dgraph-io/dgo/v240/protos/api"
27- "github.com/hypermodeinc/dgraph/v24/testutil"
27+ "github.com/hypermodeinc/dgraph/v24/dgraphapi"
28+ "github.com/hypermodeinc/dgraph/v24/dgraphtest"
2829 "github.com/hypermodeinc/dgraph/v24/x"
2930)
3031
3132type state struct {
32- dg * dgo. Dgraph
33+ dg * dgraphapi. GrpcClient
3334}
3435
3536var s state
3637
3738func TestMain (m * testing.M ) {
3839 log .SetFlags (log .LstdFlags | log .Lshortfile )
39- x .Panic (testutil .AssignUids (200 ))
40- dg , err := testutil .DgraphClientWithGroot (testutil .SockAddr )
40+ conf := dgraphtest .NewClusterConfig ().WithNumAlphas (1 ).WithNumZeros (1 ).WithReplicas (1 ).WithACL (time .Hour )
41+ c , err := dgraphtest .NewLocalCluster (conf )
42+
43+ x .Panic (err )
44+ x .Panic (c .Start ())
45+ dg , cleanup , err := c .Client ()
4146 x .Panic (err )
47+ defer cleanup ()
48+
49+ x .Panic (dg .Login (context .Background (), dgraphapi .DefaultUser , dgraphapi .DefaultPassword ))
50+ x .Panic (c .AssignUids (dg .Dgraph , 200 ))
4251 s .dg = dg
4352 _ = m .Run ()
4453}
@@ -713,25 +722,23 @@ query countAnswers($num: int) {
713722)
714723
715724func TestCountIndexConcurrentTxns (t * testing.T ) {
716- dg , err := testutil .DgraphClientWithGroot (testutil .SockAddr )
717- require .NoError (t , err )
718- testutil .DropAll (t , dg )
719- alterSchema (t , dg , "answer: [uid] @count ." )
725+ require .NoError (t , s .dg .DropAll ())
726+ require .NoError (t , s .dg .SetupSchema ("answer: [uid] @count ." ))
720727
721728 // Expected edge count of 0x100: 1
722- txn0 := dg .NewTxn ()
729+ txn0 := s . dg .NewTxn ()
723730 mu := api.Mutation {SetNquads : []byte ("<0x100> <answer> <0x200> ." )}
724- _ , err = txn0 .Mutate (ctxb , & mu )
731+ _ , err : = txn0 .Mutate (ctxb , & mu )
725732 require .NoError (t , err )
726733 require .NoError (t , txn0 .Commit (ctxb ))
727734
728735 // The following two mutations are in separate interleaved txns.
729- txn1 := dg .NewTxn ()
736+ txn1 := s . dg .NewTxn ()
730737 mu = api.Mutation {SetNquads : []byte ("<0x1> <answer> <0x2> ." )}
731738 _ , err = txn1 .Mutate (ctxb , & mu )
732739 require .NoError (t , err )
733740
734- txn2 := dg .NewTxn ()
741+ txn2 := s . dg .NewTxn ()
735742 mu = api.Mutation {SetNquads : []byte ("<0x1> <answer> <0x3> ." )}
736743 _ , err = txn2 .Mutate (ctxb , & mu )
737744 require .NoError (t , err )
@@ -741,21 +748,21 @@ func TestCountIndexConcurrentTxns(t *testing.T) {
741748 "the txn2 should be aborted due to concurrent update on the count index of <0x01>" )
742749
743750 // retry the mutation
744- txn3 := dg .NewTxn ()
751+ txn3 := s . dg .NewTxn ()
745752 _ , err = txn3 .Mutate (ctxb , & mu )
746753 require .NoError (t , err )
747754 require .NoError (t , txn3 .Commit (ctxb ))
748755
749756 // Verify count queries
750- txn := dg .NewReadOnlyTxn ()
757+ txn := s . dg .NewReadOnlyTxn ()
751758 vars := map [string ]string {"$num" : "1" }
752759 resp , err := txn .QueryWithVars (ctxb , countQuery , vars )
753760 require .NoError (t , err )
754761 js := string (resp .GetJson ())
755762 require .JSONEq (t ,
756763 `{"me": [{"count(answer)": 1, "uid": "0x100"}]}` ,
757764 js )
758- txn = dg .NewReadOnlyTxn ()
765+ txn = s . dg .NewReadOnlyTxn ()
759766 vars = map [string ]string {"$num" : "2" }
760767 resp , err = txn .QueryWithVars (ctxb , countQuery , vars )
761768 require .NoError (t , err )
@@ -766,43 +773,41 @@ func TestCountIndexConcurrentTxns(t *testing.T) {
766773}
767774
768775func TestCountIndexSerialTxns (t * testing.T ) {
769- dg , err := testutil .DgraphClientWithGroot (testutil .SockAddr )
770- require .NoError (t , err )
771- testutil .DropAll (t , dg )
772- alterSchema (t , dg , "answer: [uid] @count ." )
776+ require .NoError (t , s .dg .DropAll ())
777+ require .NoError (t , s .dg .SetupSchema ("answer: [uid] @count ." ))
773778
774779 // Expected Edge count of 0x100: 1
775- txn0 := dg .NewTxn ()
780+ txn0 := s . dg .NewTxn ()
776781 mu := api.Mutation {SetNquads : []byte ("<0x100> <answer> <0x200> ." )}
777- _ , err = txn0 .Mutate (ctxb , & mu )
782+ _ , err : = txn0 .Mutate (ctxb , & mu )
778783 require .NoError (t , err )
779784 require .NoError (t , txn0 .Commit (ctxb ))
780785
781786 // Expected edge count of 0x1: 2
782787 // This should NOT appear in the query result
783788 // The following two mutations are in serial txns.
784- txn1 := dg .NewTxn ()
789+ txn1 := s . dg .NewTxn ()
785790 mu = api.Mutation {SetNquads : []byte ("<0x1> <answer> <0x2> ." )}
786791 _ , err = txn1 .Mutate (ctxb , & mu )
787792 require .NoError (t , err )
788793 require .NoError (t , txn1 .Commit (ctxb ))
789794
790- txn2 := dg .NewTxn ()
795+ txn2 := s . dg .NewTxn ()
791796 mu = api.Mutation {SetNquads : []byte ("<0x1> <answer> <0x3> ." )}
792797 _ , err = txn2 .Mutate (ctxb , & mu )
793798 require .NoError (t , err )
794799 require .NoError (t , txn2 .Commit (ctxb ))
795800
796801 // Verify query
797- txn := dg .NewReadOnlyTxn ()
802+ txn := s . dg .NewReadOnlyTxn ()
798803 vars := map [string ]string {"$num" : "1" }
799804 resp , err := txn .QueryWithVars (ctxb , countQuery , vars )
800805 require .NoError (t , err )
801806 js := string (resp .GetJson ())
802807 require .JSONEq (t ,
803808 `{"me": [{"count(answer)": 1, "uid": "0x100"}]}` ,
804809 js )
805- txn = dg .NewReadOnlyTxn ()
810+ txn = s . dg .NewReadOnlyTxn ()
806811 vars = map [string ]string {"$num" : "2" }
807812 resp , err = txn .QueryWithVars (ctxb , countQuery , vars )
808813 require .NoError (t , err )
@@ -813,22 +818,20 @@ func TestCountIndexSerialTxns(t *testing.T) {
813818}
814819
815820func TestCountIndexSameTxn (t * testing.T ) {
816- dg , err := testutil .DgraphClientWithGroot (testutil .SockAddr )
817- require .NoError (t , err )
818- testutil .DropAll (t , dg )
819- alterSchema (t , dg , "answer: [uid] @count ." )
821+ require .NoError (t , s .dg .DropAll ())
822+ require .NoError (t , s .dg .SetupSchema ("answer: [uid] @count ." ))
820823
821824 // Expected Edge count of 0x100: 1
822- txn0 := dg .NewTxn ()
825+ txn0 := s . dg .NewTxn ()
823826 mu := api.Mutation {SetNquads : []byte ("<0x100> <answer> <0x200> ." )}
824- _ , err = txn0 .Mutate (ctxb , & mu )
827+ _ , err : = txn0 .Mutate (ctxb , & mu )
825828 require .NoError (t , err )
826829 require .NoError (t , txn0 .Commit (ctxb ))
827830
828831 // Expected edge count of 0x1: 2
829832 // This should NOT appear in the query result
830833 // The following two mutations are in the same txn.
831- txn1 := dg .NewTxn ()
834+ txn1 := s . dg .NewTxn ()
832835 mu = api.Mutation {SetNquads : []byte ("<0x1> <answer> <0x2> ." )}
833836 _ , err = txn1 .Mutate (ctxb , & mu )
834837 require .NoError (t , err )
@@ -838,15 +841,15 @@ func TestCountIndexSameTxn(t *testing.T) {
838841 require .NoError (t , txn1 .Commit (ctxb ))
839842
840843 // Verify query
841- txn := dg .NewReadOnlyTxn ()
844+ txn := s . dg .NewReadOnlyTxn ()
842845 vars := map [string ]string {"$num" : "1" }
843846 resp , err := txn .QueryWithVars (ctxb , countQuery , vars )
844847 require .NoError (t , err )
845848 js := string (resp .GetJson ())
846849 require .JSONEq (t ,
847850 `{"me": [{"count(answer)": 1, "uid": "0x100"}]}` ,
848851 js )
849- txn = dg .NewReadOnlyTxn ()
852+ txn = s . dg .NewReadOnlyTxn ()
850853 vars = map [string ]string {"$num" : "2" }
851854 resp , err = txn .QueryWithVars (ctxb , countQuery , vars )
852855 require .NoError (t , err )
@@ -857,9 +860,8 @@ func TestCountIndexSameTxn(t *testing.T) {
857860}
858861
859862func TestConcurrentQueryMutate (t * testing.T ) {
860- testutil .DropAll (t , s .dg )
861- alterSchema (t , s .dg , "name: string ." )
862-
863+ require .NoError (t , s .dg .DropAll ())
864+ require .NoError (t , s .dg .SetupSchema ("name: string ." ))
863865 txn := s .dg .NewTxn ()
864866 defer func () { require .NoError (t , txn .Discard (context .Background ())) }()
865867
@@ -893,8 +895,8 @@ func TestConcurrentQueryMutate(t *testing.T) {
893895}
894896
895897func TestTxnDiscardBeforeCommit (t * testing.T ) {
896- testutil . DropAll (t , s .dg )
897- alterSchema (t , s .dg , "name: string ." )
898+ require . NoError (t , s .dg . DropAll () )
899+ require . NoError (t , s .dg . SetupSchema ( "name: string ." ) )
898900
899901 txn := s .dg .NewTxn ()
900902 mu := & api.Mutation {
0 commit comments