Skip to content

Commit

Permalink
test: change the order
Browse files Browse the repository at this point in the history
  • Loading branch information
kwkwc committed Jun 20, 2024
1 parent e09a76b commit 868c4fe
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 62 deletions.
14 changes: 7 additions & 7 deletions examples/cluster/cluster_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ func main() {

flag.Parse()

scheduler := &agscheduler.Scheduler{}

store := &stores.MemoryStore{}
err := scheduler.SetStore(store)
if err != nil {
slog.Error(fmt.Sprintf("Failed to set store: %s", err))
os.Exit(1)
}

cn := &agscheduler.ClusterNode{
EndpointMain: *endpointMain,
Expand All @@ -52,13 +59,6 @@ func main() {
Queue: *queue,
Mode: *mode,
}

scheduler := &agscheduler.Scheduler{}
err := scheduler.SetStore(store)
if err != nil {
slog.Error(fmt.Sprintf("Failed to set store: %s", err))
os.Exit(1)
}
err = scheduler.SetClusterNode(context.TODO(), cn)
if err != nil {
slog.Error(fmt.Sprintf("Failed to set cluster node: %s", err))
Expand Down
4 changes: 2 additions & 2 deletions examples/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ func main() {
agscheduler.FuncPkg{Func: examples.PrintMsg},
)

store := &stores.MemoryStore{}

scheduler := &agscheduler.Scheduler{}

store := &stores.MemoryStore{}
err := scheduler.SetStore(store)
if err != nil {
slog.Error(fmt.Sprintf("Failed to set store: %s", err))
Expand Down
4 changes: 2 additions & 2 deletions examples/grpc/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func main() {
agscheduler.FuncPkg{Func: examples.PrintMsg},
)

store := &stores.MemoryStore{}

scheduler := &agscheduler.Scheduler{}

store := &stores.MemoryStore{}
err := scheduler.SetStore(store)
if err != nil {
slog.Error(fmt.Sprintf("Failed to set store: %s", err))
Expand Down
4 changes: 2 additions & 2 deletions examples/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ func main() {
agscheduler.FuncPkg{Func: examples.PrintMsg},
)

store := &stores.MemoryStore{}

scheduler := &agscheduler.Scheduler{}

store := &stores.MemoryStore{}
err := scheduler.SetStore(store)
if err != nil {
slog.Error(fmt.Sprintf("Failed to set store: %s", err))
Expand Down
4 changes: 2 additions & 2 deletions examples/http/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func main() {
agscheduler.FuncPkg{Func: examples.PrintMsg},
)

store := &stores.MemoryStore{}

scheduler := &agscheduler.Scheduler{}

store := &stores.MemoryStore{}
err := scheduler.SetStore(store)
if err != nil {
slog.Error(fmt.Sprintf("Failed to set store: %s", err))
Expand Down
4 changes: 3 additions & 1 deletion examples/queues/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ func runExample(brk *agscheduler.Broker) {
agscheduler.FuncPkg{Func: examples.PrintMsgSleep},
)

sto := &stores.MemoryStore{}
s := &agscheduler.Scheduler{}

sto := &stores.MemoryStore{}
err := s.SetStore(sto)
if err != nil {
slog.Error(fmt.Sprintf("Failed to set store: %s", err))
os.Exit(1)
}

ctx, cancel := context.WithCancel(ctx)
err = s.SetBroker(ctx, brk)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions examples/stores/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func runExample(sto agscheduler.Store) {
)

s := &agscheduler.Scheduler{}

err := s.SetStore(sto)
if err != nil {
slog.Error(fmt.Sprintf("Failed to set store: %s", err))
Expand Down
3 changes: 2 additions & 1 deletion queues/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ func runTest(t *testing.T, brk *agscheduler.Broker) {
agscheduler.FuncPkg{Func: runQueuesSleep},
)

sto := &stores.MemoryStore{}
s := &agscheduler.Scheduler{}

sto := &stores.MemoryStore{}
err := s.SetStore(sto)
assert.NoError(t, err)

Expand Down
18 changes: 9 additions & 9 deletions raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ func TestRaft(t *testing.T) {

store := &stores.MemoryStore{}

schedulerMain := &agscheduler.Scheduler{}
err := schedulerMain.SetStore(store)
assert.NoError(t, err)
cnMain := &agscheduler.ClusterNode{
EndpointMain: "127.0.0.1:36387",
Endpoint: "127.0.0.1:36387",
EndpointGRPC: "127.0.0.1:36367",
EndpointHTTP: "127.0.0.1:36377",
Mode: "HA",
}
schedulerMain := &agscheduler.Scheduler{}
err := schedulerMain.SetStore(store)
assert.NoError(t, err)
err = schedulerMain.SetClusterNode(ctx, cnMain)
assert.NoError(t, err)
cserviceMain := &services.ClusterService{Cn: cnMain}
Expand All @@ -39,32 +39,32 @@ func TestRaft(t *testing.T) {

time.Sleep(2 * time.Second)

schedulerNode := &agscheduler.Scheduler{}
err = schedulerNode.SetStore(store)
assert.NoError(t, err)
cnNode := &agscheduler.ClusterNode{
EndpointMain: cnMain.Endpoint,
Endpoint: "127.0.0.1:36388",
EndpointGRPC: "127.0.0.1:36368",
EndpointHTTP: "127.0.0.1:36378",
Mode: "HA",
}
schedulerNode := &agscheduler.Scheduler{}
err = schedulerNode.SetStore(store)
assert.NoError(t, err)
err = schedulerNode.SetClusterNode(ctx, cnNode)
assert.NoError(t, err)
cserviceNode := &services.ClusterService{Cn: cnNode}
err = cserviceNode.Start()
assert.NoError(t, err)

schedulerNode2 := &agscheduler.Scheduler{}
err = schedulerNode2.SetStore(store)
assert.NoError(t, err)
cnNode2 := &agscheduler.ClusterNode{
EndpointMain: cnMain.Endpoint,
Endpoint: "127.0.0.1:36389",
EndpointGRPC: "127.0.0.1:36369",
EndpointHTTP: "127.0.0.1:36379",
Mode: "HA",
}
schedulerNode2 := &agscheduler.Scheduler{}
err = schedulerNode2.SetStore(store)
assert.NoError(t, err)
err = schedulerNode2.SetClusterNode(ctx, cnNode2)
assert.NoError(t, err)
cserviceNode2 := &services.ClusterService{Cn: cnNode2}
Expand Down
14 changes: 7 additions & 7 deletions recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func TestPbRecordsPtrToRecords(t *testing.T) {

func TestRecorderRecordMetadata(t *testing.T) {
j := agscheduler.Job{Id: "1"}
rec := getRecorder()
s := &agscheduler.Scheduler{}
rec := getRecorder()
err := s.SetRecorder(rec)
assert.NoError(t, err)

Expand All @@ -101,8 +101,8 @@ func TestRecorderRecordMetadata(t *testing.T) {

func TestRecorderRecordResult(t *testing.T) {
j := agscheduler.Job{Id: "1"}
rec := getRecorder()
s := &agscheduler.Scheduler{}
rec := getRecorder()
err := s.SetRecorder(rec)
assert.NoError(t, err)

Expand All @@ -119,8 +119,8 @@ func TestRecorderRecordResult(t *testing.T) {

func TestRecorderGetRecords(t *testing.T) {
j := agscheduler.Job{Id: "1"}
rec := getRecorder()
s := &agscheduler.Scheduler{}
rec := getRecorder()
err := s.SetRecorder(rec)
assert.NoError(t, err)

Expand All @@ -141,8 +141,8 @@ func TestRecorderGetRecords(t *testing.T) {
func TestRecorderGetAllRecords(t *testing.T) {
j := agscheduler.Job{Id: "1"}
j2 := agscheduler.Job{Id: "2"}
rec := getRecorder()
s := &agscheduler.Scheduler{}
rec := getRecorder()
err := s.SetRecorder(rec)
assert.NoError(t, err)

Expand Down Expand Up @@ -176,8 +176,8 @@ func TestRecorderGetAllRecords(t *testing.T) {

func TestRecorderDeleteRecords(t *testing.T) {
j := agscheduler.Job{Id: "1"}
rec := getRecorder()
s := &agscheduler.Scheduler{}
rec := getRecorder()
err := s.SetRecorder(rec)
assert.NoError(t, err)

Expand All @@ -196,8 +196,8 @@ func TestRecorderDeleteRecords(t *testing.T) {

func TestRecorderDeleteAllRecords(t *testing.T) {
j := agscheduler.Job{Id: "1"}
rec := getRecorder()
s := &agscheduler.Scheduler{}
rec := getRecorder()
err := s.SetRecorder(rec)
assert.NoError(t, err)

Expand All @@ -216,8 +216,8 @@ func TestRecorderDeleteAllRecords(t *testing.T) {

func TestRecorderClear(t *testing.T) {
j := agscheduler.Job{Id: "1"}
rec := getRecorder()
s := &agscheduler.Scheduler{}
rec := getRecorder()
err := s.SetRecorder(rec)
assert.NoError(t, err)

Expand Down
33 changes: 14 additions & 19 deletions scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func runSchedulerPanic(ctx context.Context, j agscheduler.Job) (result string) {
func dryCallbackScheduler(ep agscheduler.EventPkg) {}

func getSchedulerWithStore(t *testing.T) *agscheduler.Scheduler {
store := &stores.MemoryStore{}
scheduler := &agscheduler.Scheduler{}
store := &stores.MemoryStore{}
err := scheduler.SetStore(store)
assert.NoError(t, err)

Expand Down Expand Up @@ -90,67 +90,62 @@ func getListener() *agscheduler.Listener {
}

func TestSchedulerSetStore(t *testing.T) {
store := &stores.MemoryStore{}
s := &agscheduler.Scheduler{}

assert.Nil(t, agscheduler.GetStore(s))

store := &stores.MemoryStore{}
err := s.SetStore(store)
assert.NoError(t, err)

assert.NotNil(t, agscheduler.GetStore(s))
}

func TestSchedulerSetClusterNode(t *testing.T) {
cn := getClusterNode()
s := &agscheduler.Scheduler{}

assert.Nil(t, agscheduler.GetClusterNode(s))

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cn := getClusterNode()
err := s.SetClusterNode(ctx, cn)
assert.NoError(t, err)

assert.NotNil(t, agscheduler.GetClusterNode(s))
}

func TestSchedulerSetBroker(t *testing.T) {
brk := &agscheduler.Broker{}
s := &agscheduler.Scheduler{}

assert.Nil(t, agscheduler.GetBroker(s))

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
brk := &agscheduler.Broker{}
err := s.SetBroker(ctx, brk)
assert.NoError(t, err)

assert.NotNil(t, agscheduler.GetBroker(s))
}

func TestSchedulerSetListener(t *testing.T) {
lis := getListener()
func TestSchedulerSetRecorder(t *testing.T) {
s := &agscheduler.Scheduler{}
assert.Nil(t, agscheduler.GetRecorder(s))

assert.Nil(t, agscheduler.GetListener(s))

err := s.SetListener(lis)
rec := getRecorder()
err := s.SetRecorder(rec)
assert.NoError(t, err)

assert.NotNil(t, agscheduler.GetListener(s))
assert.NotNil(t, agscheduler.GetRecorder(s))
}

func TestSchedulerSetRecorder(t *testing.T) {
rec := getRecorder()
func TestSchedulerSetListener(t *testing.T) {
s := &agscheduler.Scheduler{}
assert.Nil(t, agscheduler.GetListener(s))

assert.Nil(t, agscheduler.GetRecorder(s))

err := s.SetRecorder(rec)
lis := getListener()
err := s.SetListener(lis)
assert.NoError(t, err)

assert.NotNil(t, agscheduler.GetRecorder(s))
assert.NotNil(t, agscheduler.GetListener(s))
}

func TestSchedulerAddJob(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions services/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import (
func TestClusterService(t *testing.T) {
gin.SetMode(gin.ReleaseMode)

store := &stores.MemoryStore{}
cnMain := &agscheduler.ClusterNode{
EndpointMain: "127.0.0.1:36380",
}
scheduler := &agscheduler.Scheduler{}

store := &stores.MemoryStore{}
err := scheduler.SetStore(store)
assert.NoError(t, err)

cnMain := &agscheduler.ClusterNode{
EndpointMain: "127.0.0.1:36380",
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err = scheduler.SetClusterNode(ctx, cnMain)
Expand Down
14 changes: 8 additions & 6 deletions services/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ func TestClusterProxy(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

schedulerMain := &agscheduler.Scheduler{}

store := &stores.MemoryStore{}
err := schedulerMain.SetStore(store)
assert.NoError(t, err)

cnMain := &agscheduler.ClusterNode{
EndpointMain: "127.0.0.1:36380",
Endpoint: "127.0.0.1:36380",
EndpointGRPC: "127.0.0.1:36360",
EndpointHTTP: "127.0.0.1:36370",
}
schedulerMain := &agscheduler.Scheduler{}
err := schedulerMain.SetStore(store)
assert.NoError(t, err)
err = schedulerMain.SetClusterNode(ctx, cnMain)
assert.NoError(t, err)
cserviceMain := &ClusterService{Cn: cnMain}
Expand All @@ -42,16 +43,17 @@ func TestClusterProxy(t *testing.T) {

time.Sleep(2 * time.Second)

scheduler := &agscheduler.Scheduler{}
err = scheduler.SetStore(store)
assert.NoError(t, err)

cnNode := &agscheduler.ClusterNode{
EndpointMain: cnMain.Endpoint,
Endpoint: "127.0.0.1:36381",
EndpointGRPC: "127.0.0.1:36361",
EndpointHTTP: "127.0.0.1:36371",
Queue: "node",
}
scheduler := &agscheduler.Scheduler{}
err = scheduler.SetStore(store)
assert.NoError(t, err)
err = scheduler.SetClusterNode(ctx, cnNode)
assert.NoError(t, err)
cservice := &ClusterService{Cn: cnNode}
Expand Down
Loading

0 comments on commit 868c4fe

Please sign in to comment.