chyezh fda720b880
enhance: streaming service grpc utilities (#34436)
issue: #33285

- add two grpc resolver (by session and by streaming coord assignment
service)
- add one grpc balancer (by serverID and roundrobin)
- add lazy conn to avoid block by first service discovery
- add some utility function for streaming service

Signed-off-by: chyezh <chyezh@outlook.com>
2024-07-15 20:49:38 +08:00

44 lines
1.3 KiB
Go

package attributes
import (
"testing"
"github.com/milvus-io/milvus/internal/util/sessionutil"
"github.com/milvus-io/milvus/pkg/streaming/util/types"
"github.com/stretchr/testify/assert"
)
func TestAttributes(t *testing.T) {
attr := new(Attributes)
serverID := GetServerID(attr)
assert.Nil(t, serverID)
assert.Nil(t, GetChannelAssignmentInfoFromAttributes(attr))
assert.Nil(t, GetSessionFromAttributes(attr))
attr = new(Attributes)
attr = WithChannelAssignmentInfo(attr, &types.StreamingNodeAssignment{
NodeInfo: types.StreamingNodeInfo{
ServerID: 1,
Address: "localhost:8080",
},
})
assert.NotNil(t, GetServerID(attr))
assert.Equal(t, int64(1), *GetServerID(attr))
assert.NotNil(t, GetChannelAssignmentInfoFromAttributes(attr))
assert.Equal(t, "localhost:8080", GetChannelAssignmentInfoFromAttributes(attr).NodeInfo.Address)
attr = new(Attributes)
attr = WithSession(attr, &sessionutil.SessionRaw{
ServerID: 1,
})
assert.NotNil(t, GetServerID(attr))
assert.Equal(t, int64(1), *GetServerID(attr))
assert.NotNil(t, GetSessionFromAttributes(attr))
assert.Equal(t, int64(1), GetSessionFromAttributes(attr).ServerID)
attr = new(Attributes)
attr = WithServerID(attr, 1)
serverID = GetServerID(attr)
assert.Equal(t, int64(1), *GetServerID(attr))
}