@@ -24,21 +24,30 @@ import (
24
24
25
25
"github.com/dgraph-io/dgo/v240"
26
26
"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"
28
29
"github.com/hypermodeinc/dgraph/v24/x"
29
30
)
30
31
31
32
type state struct {
32
- dg * dgo. Dgraph
33
+ dg * dgraphapi. GrpcClient
33
34
}
34
35
35
36
var s state
36
37
37
38
func TestMain (m * testing.M ) {
38
39
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 ()
41
46
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 ))
42
51
s .dg = dg
43
52
_ = m .Run ()
44
53
}
@@ -713,25 +722,23 @@ query countAnswers($num: int) {
713
722
)
714
723
715
724
func 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 ." ))
720
727
721
728
// Expected edge count of 0x100: 1
722
- txn0 := dg .NewTxn ()
729
+ txn0 := s . dg .NewTxn ()
723
730
mu := api.Mutation {SetNquads : []byte ("<0x100> <answer> <0x200> ." )}
724
- _ , err = txn0 .Mutate (ctxb , & mu )
731
+ _ , err : = txn0 .Mutate (ctxb , & mu )
725
732
require .NoError (t , err )
726
733
require .NoError (t , txn0 .Commit (ctxb ))
727
734
728
735
// The following two mutations are in separate interleaved txns.
729
- txn1 := dg .NewTxn ()
736
+ txn1 := s . dg .NewTxn ()
730
737
mu = api.Mutation {SetNquads : []byte ("<0x1> <answer> <0x2> ." )}
731
738
_ , err = txn1 .Mutate (ctxb , & mu )
732
739
require .NoError (t , err )
733
740
734
- txn2 := dg .NewTxn ()
741
+ txn2 := s . dg .NewTxn ()
735
742
mu = api.Mutation {SetNquads : []byte ("<0x1> <answer> <0x3> ." )}
736
743
_ , err = txn2 .Mutate (ctxb , & mu )
737
744
require .NoError (t , err )
@@ -741,21 +748,21 @@ func TestCountIndexConcurrentTxns(t *testing.T) {
741
748
"the txn2 should be aborted due to concurrent update on the count index of <0x01>" )
742
749
743
750
// retry the mutation
744
- txn3 := dg .NewTxn ()
751
+ txn3 := s . dg .NewTxn ()
745
752
_ , err = txn3 .Mutate (ctxb , & mu )
746
753
require .NoError (t , err )
747
754
require .NoError (t , txn3 .Commit (ctxb ))
748
755
749
756
// Verify count queries
750
- txn := dg .NewReadOnlyTxn ()
757
+ txn := s . dg .NewReadOnlyTxn ()
751
758
vars := map [string ]string {"$num" : "1" }
752
759
resp , err := txn .QueryWithVars (ctxb , countQuery , vars )
753
760
require .NoError (t , err )
754
761
js := string (resp .GetJson ())
755
762
require .JSONEq (t ,
756
763
`{"me": [{"count(answer)": 1, "uid": "0x100"}]}` ,
757
764
js )
758
- txn = dg .NewReadOnlyTxn ()
765
+ txn = s . dg .NewReadOnlyTxn ()
759
766
vars = map [string ]string {"$num" : "2" }
760
767
resp , err = txn .QueryWithVars (ctxb , countQuery , vars )
761
768
require .NoError (t , err )
@@ -766,43 +773,41 @@ func TestCountIndexConcurrentTxns(t *testing.T) {
766
773
}
767
774
768
775
func 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 ." ))
773
778
774
779
// Expected Edge count of 0x100: 1
775
- txn0 := dg .NewTxn ()
780
+ txn0 := s . dg .NewTxn ()
776
781
mu := api.Mutation {SetNquads : []byte ("<0x100> <answer> <0x200> ." )}
777
- _ , err = txn0 .Mutate (ctxb , & mu )
782
+ _ , err : = txn0 .Mutate (ctxb , & mu )
778
783
require .NoError (t , err )
779
784
require .NoError (t , txn0 .Commit (ctxb ))
780
785
781
786
// Expected edge count of 0x1: 2
782
787
// This should NOT appear in the query result
783
788
// The following two mutations are in serial txns.
784
- txn1 := dg .NewTxn ()
789
+ txn1 := s . dg .NewTxn ()
785
790
mu = api.Mutation {SetNquads : []byte ("<0x1> <answer> <0x2> ." )}
786
791
_ , err = txn1 .Mutate (ctxb , & mu )
787
792
require .NoError (t , err )
788
793
require .NoError (t , txn1 .Commit (ctxb ))
789
794
790
- txn2 := dg .NewTxn ()
795
+ txn2 := s . dg .NewTxn ()
791
796
mu = api.Mutation {SetNquads : []byte ("<0x1> <answer> <0x3> ." )}
792
797
_ , err = txn2 .Mutate (ctxb , & mu )
793
798
require .NoError (t , err )
794
799
require .NoError (t , txn2 .Commit (ctxb ))
795
800
796
801
// Verify query
797
- txn := dg .NewReadOnlyTxn ()
802
+ txn := s . dg .NewReadOnlyTxn ()
798
803
vars := map [string ]string {"$num" : "1" }
799
804
resp , err := txn .QueryWithVars (ctxb , countQuery , vars )
800
805
require .NoError (t , err )
801
806
js := string (resp .GetJson ())
802
807
require .JSONEq (t ,
803
808
`{"me": [{"count(answer)": 1, "uid": "0x100"}]}` ,
804
809
js )
805
- txn = dg .NewReadOnlyTxn ()
810
+ txn = s . dg .NewReadOnlyTxn ()
806
811
vars = map [string ]string {"$num" : "2" }
807
812
resp , err = txn .QueryWithVars (ctxb , countQuery , vars )
808
813
require .NoError (t , err )
@@ -813,22 +818,20 @@ func TestCountIndexSerialTxns(t *testing.T) {
813
818
}
814
819
815
820
func 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 ." ))
820
823
821
824
// Expected Edge count of 0x100: 1
822
- txn0 := dg .NewTxn ()
825
+ txn0 := s . dg .NewTxn ()
823
826
mu := api.Mutation {SetNquads : []byte ("<0x100> <answer> <0x200> ." )}
824
- _ , err = txn0 .Mutate (ctxb , & mu )
827
+ _ , err : = txn0 .Mutate (ctxb , & mu )
825
828
require .NoError (t , err )
826
829
require .NoError (t , txn0 .Commit (ctxb ))
827
830
828
831
// Expected edge count of 0x1: 2
829
832
// This should NOT appear in the query result
830
833
// The following two mutations are in the same txn.
831
- txn1 := dg .NewTxn ()
834
+ txn1 := s . dg .NewTxn ()
832
835
mu = api.Mutation {SetNquads : []byte ("<0x1> <answer> <0x2> ." )}
833
836
_ , err = txn1 .Mutate (ctxb , & mu )
834
837
require .NoError (t , err )
@@ -838,15 +841,15 @@ func TestCountIndexSameTxn(t *testing.T) {
838
841
require .NoError (t , txn1 .Commit (ctxb ))
839
842
840
843
// Verify query
841
- txn := dg .NewReadOnlyTxn ()
844
+ txn := s . dg .NewReadOnlyTxn ()
842
845
vars := map [string ]string {"$num" : "1" }
843
846
resp , err := txn .QueryWithVars (ctxb , countQuery , vars )
844
847
require .NoError (t , err )
845
848
js := string (resp .GetJson ())
846
849
require .JSONEq (t ,
847
850
`{"me": [{"count(answer)": 1, "uid": "0x100"}]}` ,
848
851
js )
849
- txn = dg .NewReadOnlyTxn ()
852
+ txn = s . dg .NewReadOnlyTxn ()
850
853
vars = map [string ]string {"$num" : "2" }
851
854
resp , err = txn .QueryWithVars (ctxb , countQuery , vars )
852
855
require .NoError (t , err )
@@ -857,9 +860,8 @@ func TestCountIndexSameTxn(t *testing.T) {
857
860
}
858
861
859
862
func 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 ." ))
863
865
txn := s .dg .NewTxn ()
864
866
defer func () { require .NoError (t , txn .Discard (context .Background ())) }()
865
867
@@ -893,8 +895,8 @@ func TestConcurrentQueryMutate(t *testing.T) {
893
895
}
894
896
895
897
func 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 ." ) )
898
900
899
901
txn := s .dg .NewTxn ()
900
902
mu := & api.Mutation {
0 commit comments