fusen-render/start_test.go

188 lines
3.7 KiB
Go
Raw Normal View History

2023-07-28 11:04:21 +00:00
package fusenrender_test
2023-07-29 22:50:58 +00:00
import (
"context"
"fusenrender"
"log"
2023-07-31 09:09:23 +00:00
2023-07-29 22:50:58 +00:00
"testing"
"time"
2023-07-31 09:09:23 +00:00
"github.com/google/uuid"
2023-07-29 22:50:58 +00:00
"github.com/lni/goutils/syncutil"
)
func init() {
log.SetFlags(log.Llongfile)
}
func TestStartNodeA(t *testing.T) {
svc, err := fusenrender.LoadConfig("etc/etc_a.yaml")
if err != nil {
panic(err)
}
2023-07-31 09:09:23 +00:00
nh := fusenrender.StartNode(svc.ServerID, 128, svc.Address())
2023-07-29 22:50:58 +00:00
raftStopper := syncutil.NewStopper()
// ch := make(chan string, 16)
raftStopper.RunWorker(func() {
// this goroutine makes a linearizable read every 10 second. it returns the
// Count value maintained in IStateMachine. see datastore.go for details.
2023-07-31 09:09:23 +00:00
cs := nh.GetNoOPSession(128)
ticker := time.NewTicker(100 * time.Millisecond)
2023-07-29 22:50:58 +00:00
for {
select {
case <-ticker.C:
2023-07-31 09:09:23 +00:00
item := &fusenrender.QueueItem{
Group: "test",
Priority: uint32(2),
CreateAt: time.Now(),
Data: uuid.New().String(),
}
2023-07-29 22:50:58 +00:00
cmd := fusenrender.Command{
Name: "enqueue",
Group: "test",
Item: item,
}
data, err := cmd.Encode()
if err != nil {
log.Println(err)
}
2023-07-31 09:09:23 +00:00
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
_, err = nh.SyncPropose(ctx, cs, data)
2023-07-29 22:50:58 +00:00
if err != nil {
log.Println(err)
}
2023-07-31 09:09:23 +00:00
// log.Println("enqueue", len(result.Data))
2023-07-29 22:50:58 +00:00
cancel()
case <-raftStopper.ShouldStop():
return
}
}
})
raftStopper.Wait()
}
func TestStartNodeB(t *testing.T) {
svc, err := fusenrender.LoadConfig("etc/etc_b.yaml")
if err != nil {
panic(err)
}
nh := fusenrender.StartNode(svc.ServerID, 128, svc.Address())
raftStopper := syncutil.NewStopper()
// ch := make(chan string, 16)
raftStopper.RunWorker(func() {
// this goroutine makes a linearizable read every 10 second. it returns the
// Count value maintained in IStateMachine. see datastore.go for details.
cs := nh.GetNoOPSession(128)
2023-07-31 09:09:23 +00:00
ticker := time.NewTicker(100 * time.Millisecond)
2023-07-29 22:50:58 +00:00
for {
select {
case <-ticker.C:
2023-07-31 09:09:23 +00:00
item := &fusenrender.QueueItem{
Group: "test",
Priority: uint32(1),
CreateAt: time.Now(),
Data: uuid.New().String(),
}
2023-07-29 22:50:58 +00:00
cmd := fusenrender.Command{
Name: "enqueue",
Group: "test",
Item: item,
}
data, err := cmd.Encode()
if err != nil {
log.Println(err)
}
2023-07-31 09:09:23 +00:00
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
_, err = nh.SyncPropose(ctx, cs, data)
2023-07-29 22:50:58 +00:00
if err != nil {
log.Println(err)
2023-07-31 09:09:23 +00:00
} else {
// log.Println("enqueue", len(result.Data))
2023-07-29 22:50:58 +00:00
}
cancel()
case <-raftStopper.ShouldStop():
return
}
}
})
raftStopper.Wait()
}
func TestStartNodeC(t *testing.T) {
svc, err := fusenrender.LoadConfig("etc/etc_c.yaml")
if err != nil {
panic(err)
}
nh := fusenrender.StartNode(svc.ServerID, 128, svc.Address())
2023-07-31 09:09:23 +00:00
log.Println(nh)
2023-07-29 22:50:58 +00:00
raftStopper := syncutil.NewStopper()
raftStopper.RunWorker(func() {
// this goroutine makes a linearizable read every 10 second. it returns the
// Count value maintained in IStateMachine. see datastore.go for details.
2023-07-31 09:09:23 +00:00
// cs := nh.GetNoOPSession(128)
ticker := time.NewTicker(5 * time.Second)
2023-07-29 22:50:58 +00:00
for {
select {
case <-ticker.C:
2023-07-31 09:09:23 +00:00
// for {
// ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
// cmd := fusenrender.Command{
// Name: "dequeue",
// Group: "test",
// }
// data, err := cmd.Encode()
// if err != nil {
// log.Println(err)
// }
// result, err := nh.SyncPropose(ctx, cs, data)
// if err != nil {
// log.Println(err)
// }
// log.Println(len(result.Data), string(result.Data))
// cancel()
// if len(result.Data) == 0 {
// break
// }
// }
2023-07-29 22:50:58 +00:00
case <-raftStopper.ShouldStop():
return
}
}
})
raftStopper.Wait()
}