11package rqd_test
22
33import (
4- "bytes"
5- "context"
4+ "github.com/RealFax/RedQueen/api/serverpb"
65 red "github.com/RealFax/RedQueen/internal/rqd"
7- "github.com/RealFax/RedQueen/pkg/collapsar"
8- "io"
9- "strconv"
106 "testing"
11- "time"
12-
13- "github.com/hashicorp/raft"
14- "google.golang.org/protobuf/proto"
15-
16- "github.com/RealFax/RedQueen/api/serverpb"
177)
188
199var raftLogPayloadMessage = & serverpb.RaftLogPayload {
@@ -30,56 +20,6 @@ func TestRaftLogPayloadKey(t *testing.T) {
3020 t .Logf ("Payload key: %d" , red .RaftLogPayloadKey (raftLogPayloadMessage ))
3121}
3222
33- func TestRaftMultipleLogApply_Apply (t * testing.T ) {
34- rm := red .NewRaftMultipleLogApply (
35- context .Background (),
36- 3 ,
37- time .Millisecond * 300 ,
38- time .Millisecond * 300 ,
39- func (cmd []byte , timeout time.Duration ) raft.ApplyFuture {
40- r , err := collapsar .NewReader (bytes .NewReader (cmd [4 :]))
41- if err != nil {
42- t .Fatal (err )
43- }
44-
45- for {
46- pack , rErr := r .Next ()
47- if rErr != nil {
48- if rErr == io .EOF {
49- break
50- }
51- t .Fatal (err )
52- }
53- m := & serverpb.RaftLogPayload {}
54- if err = proto .Unmarshal (pack , m ); err != nil {
55- t .Fatal (err )
56- }
57- t .Log (m .String ())
58- }
59- return nil
60- })
61-
62- for i := 0 ; i < 3 ; i ++ {
63- ctx := context .Background ()
64- if err := rm .Apply (& ctx , raftLogPayloadMessage , 0 ); err != nil {
65- t .Fatal (err )
66- }
67- }
68-
69- time .Sleep (time .Second * 1 )
70-
71- for i := 0 ; i < 3 ; i ++ {
72- ctx := context .Background ()
73- raftLogPayloadMessage .Key = []byte ("test_key" + strconv .Itoa (i ))
74- if err := rm .Apply (& ctx , raftLogPayloadMessage , 0 ); err != nil {
75- t .Fatal (err )
76- }
77- }
78-
79- time .Sleep (time .Second * 1 )
80-
81- }
82-
8323func BenchmarkRaftLogPayloadKey (b * testing.B ) {
8424 for i := 0 ; i < b .N ; i ++ {
8525 red .RaftLogPayloadKey (raftLogPayloadMessage )
0 commit comments