milvus/internal/util/componentutil/component_service_test.go
chyezh bef06e5acf
enhance: add streaming coord and node grpc service register (#34655)
issue: #33285

- register streaming coord service into datacoord.
- add new streaming node role.
- add global static switch to enable streaming service or not.

Signed-off-by: chyezh <chyezh@outlook.com>
2024-07-25 12:19:44 +08:00

47 lines
1.5 KiB
Go

package componentutil
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
)
func TestComponentStateService(t *testing.T) {
ctx := context.Background()
s := NewComponentStateService("role")
resp, err := s.GetComponentStates(ctx, &milvuspb.GetComponentStatesRequest{})
assert.NoError(t, err)
assert.Equal(t, commonpb.StateCode_StandBy, resp.State.StateCode)
s.OnInitializing()
resp, err = s.GetComponentStates(ctx, &milvuspb.GetComponentStatesRequest{})
assert.NoError(t, err)
assert.Equal(t, commonpb.StateCode_Initializing, resp.State.StateCode)
s.OnInitialized(1)
resp, err = s.GetComponentStates(ctx, &milvuspb.GetComponentStatesRequest{})
assert.NoError(t, err)
assert.Equal(t, commonpb.StateCode_Healthy, resp.State.StateCode)
assert.Equal(t, "role", resp.State.Role)
assert.Equal(t, int64(1), resp.State.NodeID)
s.OnAbnormal()
resp, err = s.GetComponentStates(ctx, &milvuspb.GetComponentStatesRequest{})
assert.NoError(t, err)
assert.Equal(t, commonpb.StateCode_Abnormal, resp.State.StateCode)
s.OnHealthy()
resp, err = s.GetComponentStates(ctx, &milvuspb.GetComponentStatesRequest{})
assert.NoError(t, err)
assert.Equal(t, commonpb.StateCode_Healthy, resp.State.StateCode)
s.OnStopping()
resp, err = s.GetComponentStates(ctx, &milvuspb.GetComponentStatesRequest{})
assert.NoError(t, err)
assert.Equal(t, commonpb.StateCode_Stopping, resp.State.StateCode)
}