parent
8dca680c3c
commit
6ee88fea7e
@ -1,4 +1,4 @@
|
||||
package discovery_register
|
||||
package discoveryregister
|
||||
|
||||
import (
|
||||
"context"
|
@ -0,0 +1,407 @@
|
||||
package discoveryregister
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/OpenIMSDK/tools/discoveryregistry"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func TestNewDiscoveryRegister(t *testing.T) {
|
||||
type args struct {
|
||||
envType string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want discoveryregistry.SvcDiscoveryRegistry
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := NewDiscoveryRegister(tt.args.envType)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("NewDiscoveryRegister() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("NewDiscoveryRegister() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewK8sDiscoveryRegister(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
want discoveryregistry.SvcDiscoveryRegistry
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := NewK8sDiscoveryRegister()
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("NewK8sDiscoveryRegister() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("NewK8sDiscoveryRegister() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestK8sDR_Register(t *testing.T) {
|
||||
type fields struct {
|
||||
options []grpc.DialOption
|
||||
rpcRegisterAddr string
|
||||
}
|
||||
type args struct {
|
||||
serviceName string
|
||||
host string
|
||||
port int
|
||||
opts []grpc.DialOption
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cli := &K8sDR{
|
||||
options: tt.fields.options,
|
||||
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
|
||||
}
|
||||
if err := cli.Register(tt.args.serviceName, tt.args.host, tt.args.port, tt.args.opts...); (err != nil) != tt.wantErr {
|
||||
t.Errorf("K8sDR.Register() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestK8sDR_UnRegister(t *testing.T) {
|
||||
type fields struct {
|
||||
options []grpc.DialOption
|
||||
rpcRegisterAddr string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cli := &K8sDR{
|
||||
options: tt.fields.options,
|
||||
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
|
||||
}
|
||||
if err := cli.UnRegister(); (err != nil) != tt.wantErr {
|
||||
t.Errorf("K8sDR.UnRegister() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestK8sDR_CreateRpcRootNodes(t *testing.T) {
|
||||
type fields struct {
|
||||
options []grpc.DialOption
|
||||
rpcRegisterAddr string
|
||||
}
|
||||
type args struct {
|
||||
serviceNames []string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cli := &K8sDR{
|
||||
options: tt.fields.options,
|
||||
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
|
||||
}
|
||||
if err := cli.CreateRpcRootNodes(tt.args.serviceNames); (err != nil) != tt.wantErr {
|
||||
t.Errorf("K8sDR.CreateRpcRootNodes() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestK8sDR_RegisterConf2Registry(t *testing.T) {
|
||||
type fields struct {
|
||||
options []grpc.DialOption
|
||||
rpcRegisterAddr string
|
||||
}
|
||||
type args struct {
|
||||
key string
|
||||
conf []byte
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cli := &K8sDR{
|
||||
options: tt.fields.options,
|
||||
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
|
||||
}
|
||||
if err := cli.RegisterConf2Registry(tt.args.key, tt.args.conf); (err != nil) != tt.wantErr {
|
||||
t.Errorf("K8sDR.RegisterConf2Registry() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestK8sDR_GetConfFromRegistry(t *testing.T) {
|
||||
type fields struct {
|
||||
options []grpc.DialOption
|
||||
rpcRegisterAddr string
|
||||
}
|
||||
type args struct {
|
||||
key string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want []byte
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cli := &K8sDR{
|
||||
options: tt.fields.options,
|
||||
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
|
||||
}
|
||||
got, err := cli.GetConfFromRegistry(tt.args.key)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("K8sDR.GetConfFromRegistry() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("K8sDR.GetConfFromRegistry() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestK8sDR_GetConns(t *testing.T) {
|
||||
type fields struct {
|
||||
options []grpc.DialOption
|
||||
rpcRegisterAddr string
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
serviceName string
|
||||
opts []grpc.DialOption
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want []*grpc.ClientConn
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cli := &K8sDR{
|
||||
options: tt.fields.options,
|
||||
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
|
||||
}
|
||||
got, err := cli.GetConns(tt.args.ctx, tt.args.serviceName, tt.args.opts...)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("K8sDR.GetConns() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("K8sDR.GetConns() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestK8sDR_GetConn(t *testing.T) {
|
||||
type fields struct {
|
||||
options []grpc.DialOption
|
||||
rpcRegisterAddr string
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
serviceName string
|
||||
opts []grpc.DialOption
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want *grpc.ClientConn
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cli := &K8sDR{
|
||||
options: tt.fields.options,
|
||||
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
|
||||
}
|
||||
got, err := cli.GetConn(tt.args.ctx, tt.args.serviceName, tt.args.opts...)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("K8sDR.GetConn() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("K8sDR.GetConn() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestK8sDR_GetSelfConnTarget(t *testing.T) {
|
||||
type fields struct {
|
||||
options []grpc.DialOption
|
||||
rpcRegisterAddr string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
want string
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cli := &K8sDR{
|
||||
options: tt.fields.options,
|
||||
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
|
||||
}
|
||||
if got := cli.GetSelfConnTarget(); got != tt.want {
|
||||
t.Errorf("K8sDR.GetSelfConnTarget() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestK8sDR_AddOption(t *testing.T) {
|
||||
type fields struct {
|
||||
options []grpc.DialOption
|
||||
rpcRegisterAddr string
|
||||
}
|
||||
type args struct {
|
||||
opts []grpc.DialOption
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cli := &K8sDR{
|
||||
options: tt.fields.options,
|
||||
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
|
||||
}
|
||||
cli.AddOption(tt.args.opts...)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestK8sDR_CloseConn(t *testing.T) {
|
||||
type fields struct {
|
||||
options []grpc.DialOption
|
||||
rpcRegisterAddr string
|
||||
}
|
||||
type args struct {
|
||||
conn *grpc.ClientConn
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cli := &K8sDR{
|
||||
options: tt.fields.options,
|
||||
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
|
||||
}
|
||||
cli.CloseConn(tt.args.conn)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestK8sDR_GetClientLocalConns(t *testing.T) {
|
||||
type fields struct {
|
||||
options []grpc.DialOption
|
||||
rpcRegisterAddr string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
want map[string][]*grpc.ClientConn
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cli := &K8sDR{
|
||||
options: tt.fields.options,
|
||||
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
|
||||
}
|
||||
if got := cli.GetClientLocalConns(); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("K8sDR.GetClientLocalConns() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestK8sDR_Close(t *testing.T) {
|
||||
type fields struct {
|
||||
options []grpc.DialOption
|
||||
rpcRegisterAddr string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cli := &K8sDR{
|
||||
options: tt.fields.options,
|
||||
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
|
||||
}
|
||||
cli.Close()
|
||||
})
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package ginPrometheus
|
||||
package ginprometheus
|
||||
|
||||
import (
|
||||
"bytes"
|
@ -1,15 +0,0 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package locker // import "github.com/openimsdk/open-im-server/v3/pkg/common/locker"
|
@ -1,72 +0,0 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package locker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
||||
)
|
||||
|
||||
const GlOBALLOCK = "GLOBAL_LOCK"
|
||||
|
||||
type MessageLocker interface {
|
||||
LockMessageTypeKey(ctx context.Context, clientMsgID, typeKey string) (err error)
|
||||
UnLockMessageTypeKey(ctx context.Context, clientMsgID string, typeKey string) error
|
||||
LockGlobalMessage(ctx context.Context, clientMsgID string) (err error)
|
||||
UnLockGlobalMessage(ctx context.Context, clientMsgID string) (err error)
|
||||
}
|
||||
type LockerMessage struct {
|
||||
cache cache.MsgModel
|
||||
}
|
||||
|
||||
func NewLockerMessage(cache cache.MsgModel) *LockerMessage {
|
||||
return &LockerMessage{cache: cache}
|
||||
}
|
||||
|
||||
func (l *LockerMessage) LockMessageTypeKey(ctx context.Context, clientMsgID, typeKey string) (err error) {
|
||||
for i := 0; i < 3; i++ {
|
||||
err = l.cache.LockMessageTypeKey(ctx, clientMsgID, typeKey)
|
||||
if err != nil {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (l *LockerMessage) LockGlobalMessage(ctx context.Context, clientMsgID string) (err error) {
|
||||
for i := 0; i < 3; i++ {
|
||||
err = l.cache.LockMessageTypeKey(ctx, clientMsgID, GlOBALLOCK)
|
||||
if err != nil {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (l *LockerMessage) UnLockMessageTypeKey(ctx context.Context, clientMsgID string, typeKey string) error {
|
||||
return l.cache.UnLockMessageTypeKey(ctx, clientMsgID, typeKey)
|
||||
}
|
||||
|
||||
func (l *LockerMessage) UnLockGlobalMessage(ctx context.Context, clientMsgID string) error {
|
||||
return l.cache.UnLockMessageTypeKey(ctx, clientMsgID, GlOBALLOCK)
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package prom_metrics
|
||||
package prommetrics
|
||||
|
||||
import ginProm "github.com/openimsdk/open-im-server/v3/pkg/common/ginPrometheus"
|
||||
import ginProm "github.com/openimsdk/open-im-server/v3/pkg/common/ginprometheus"
|
||||
|
||||
/*
|
||||
labels := prometheus.Labels{"label_one": "any", "label_two": "value"}
|
@ -1,4 +1,4 @@
|
||||
package prom_metrics
|
||||
package prommetrics
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
@ -1,4 +1,4 @@
|
||||
package prom_metrics
|
||||
package prommetrics
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
@ -1,4 +1,4 @@
|
||||
package prom_metrics
|
||||
package prommetrics
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
@ -1,4 +1,4 @@
|
||||
package prom_metrics
|
||||
package prommetrics
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
@ -1,4 +1,4 @@
|
||||
package prom_metrics
|
||||
package prommetrics
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
Loading…
Reference in new issue