Unverified Commit 4bf08b8b authored by randy's avatar randy Committed by GitHub

Merge pull request #3 from dubbogo/master

sync
parents 766406c4 d8e377a0
...@@ -74,43 +74,3 @@ jobs: ...@@ -74,43 +74,3 @@ jobs:
- name: Hello world - name: Hello world
run: echo Hello world ${{ secrets.DING_TOKEN }} ${{ secrets.DING_SIGN }} run: echo Hello world ${{ secrets.DING_TOKEN }} ${{ secrets.DING_SIGN }}
# Because the contexts of push and PR are different, there are two Notify.
# Notifications are triggered only in the dubbogo/gost repository.
- name: DingTalk Message Notify only Push
uses: zcong1993/actions-ding@v3.0.1
# Whether job is successful or not, always () is always true.
if: |
always() &&
github.event_name == 'push' &&
github.repository == 'dubbogo/gost'
with:
# DingDing bot token
dingToken: ${{ env.DING_TOKEN }}
secret: ${{ env.DING_SIGN }}
# Post Body to send
body: |
{
"msgtype": "markdown",
"markdown": {
"title": "Github Actions",
"text": "## Github Actions \n - name: CI \n - repository: ${{ github.repository }} \n - trigger: ${{ github.actor }} \n - event: ${{ github.event_name }} \n - ref: ${{ github.ref }} \n - status: [${{ job.status }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) \n - environment: ${{ runner.os }} \n > SHA: [${{ github.sha }}](${{ github.event.compare }})"
}
}
- name: DingTalk Message Notify only PR
uses: zcong1993/actions-ding@v3.0.1
if: |
always() &&
github.event_name == 'pull_request' &&
github.repository == 'dubbogo/gost'
with:
dingToken: ${{ env.DING_TOKEN }}
secret: ${{ env.DING_SIGN }}
body: |
{
"msgtype": "markdown",
"markdown": {
"title": "Github Actions",
"text": "## Github Actions \n - name: CI \n - repository: ${{ github.repository }} \n - pr_title: **${{ github.event.pull_request.title }}** \n - trigger: ${{ github.actor }} \n - event: ${{ github.event_name }} \n - ref: [${{ github.ref }}](${{ github.event.pull_request._links.html.href }}) \n - status: [${{ job.status }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) \n - environment: ${{ runner.os }} \n > SHA: [${{ github.sha }}](${{ github.event.pull_request._links.html.href }})"
}
}
...@@ -22,9 +22,7 @@ import ( ...@@ -22,9 +22,7 @@ import (
"sync" "sync"
) )
var ( var defaultPool *ObjectPool
defaultPool *ObjectPool
)
func init() { func init() {
defaultPool = NewObjectPool(func() PoolObject { defaultPool = NewObjectPool(func() PoolObject {
......
...@@ -22,9 +22,7 @@ const ( ...@@ -22,9 +22,7 @@ const (
maxShift = 18 maxShift = 18
) )
var ( var defaultSlicePool *SlicePool
defaultSlicePool *SlicePool
)
func init() { func init() {
defaultSlicePool = NewSlicePool() defaultSlicePool = NewSlicePool()
......
...@@ -74,7 +74,7 @@ func TestSlicePoolMediumBytes(t *testing.T) { ...@@ -74,7 +74,7 @@ func TestSlicePoolMediumBytes(t *testing.T) {
t.Errorf("Expect get the slab size (%d) from pool, but got %d", 1<<uint(i+1), cap(*bp)) t.Errorf("Expect get the slab size (%d) from pool, but got %d", 1<<uint(i+1), cap(*bp))
} }
//Puts the bytes to pool // Puts the bytes to pool
pool.Put(bp) pool.Put(bp)
} }
} }
......
...@@ -56,9 +56,11 @@ func (set *HashSet) Contains(items ...interface{}) bool { ...@@ -56,9 +56,11 @@ func (set *HashSet) Contains(items ...interface{}) bool {
} }
return true return true
} }
func (set *HashSet) Empty() bool { func (set *HashSet) Empty() bool {
return set.Size() == 0 return set.Size() == 0
} }
func (set *HashSet) Size() int { func (set *HashSet) Size() int {
return len(set.Items) return len(set.Items)
} }
...@@ -76,6 +78,7 @@ func (set *HashSet) Values() []interface{} { ...@@ -76,6 +78,7 @@ func (set *HashSet) Values() []interface{} {
} }
return values return values
} }
func (set *HashSet) String() string { func (set *HashSet) String() string {
str := "HashSet\n" str := "HashSet\n"
var items []string var items []string
......
...@@ -23,9 +23,7 @@ import ( ...@@ -23,9 +23,7 @@ import (
type ValueContextKeyType int32 type ValueContextKeyType int32
var ( var defaultCtxKey = ValueContextKeyType(1)
defaultCtxKey = ValueContextKeyType(1)
)
type Values struct { type Values struct {
m map[interface{}]interface{} m map[interface{}]interface{}
......
...@@ -41,16 +41,16 @@ var ( ...@@ -41,16 +41,16 @@ var (
// NewConfigClient create new Client // NewConfigClient create new Client
func NewConfigClient(opts ...Option) *Client { func NewConfigClient(opts ...Option) *Client {
options := &Options{ options := &Options{
heartbeat: 1, // default heartbeat Heartbeat: 1, // default Heartbeat
} }
for _, opt := range opts { for _, opt := range opts {
opt(options) opt(options)
} }
newClient, err := NewClient(options.name, options.endpoints, options.timeout, options.heartbeat) newClient, err := NewClient(options.Name, options.Endpoints, options.Timeout, options.Heartbeat)
if err != nil { if err != nil {
log.Printf("new etcd client (name{%s}, etcd addresses{%v}, timeout{%d}) = error{%v}", log.Printf("new etcd client (Name{%s}, etcd addresses{%v}, Timeout{%d}) = error{%v}",
options.name, options.endpoints, options.timeout, err) options.Name, options.Endpoints, options.Timeout, err)
} }
return newClient return newClient
} }
...@@ -84,7 +84,6 @@ func NewClient(name string, endpoints []string, timeout time.Duration, heartbeat ...@@ -84,7 +84,6 @@ func NewClient(name string, endpoints []string, timeout time.Duration, heartbeat
DialTimeout: timeout, DialTimeout: timeout,
DialOptions: []grpc.DialOption{grpc.WithBlock()}, DialOptions: []grpc.DialOption{grpc.WithBlock()},
}) })
if err != nil { if err != nil {
cancel() cancel()
return nil, perrors.WithMessage(err, "new raw client block connect to server") return nil, perrors.WithMessage(err, "new raw client block connect to server")
...@@ -136,6 +135,11 @@ func (c *Client) stop() bool { ...@@ -136,6 +135,11 @@ func (c *Client) stop() bool {
} }
} }
// GetCtx return client context
func (c *Client) GetCtx() context.Context {
return c.ctx
}
// Close close client // Close close client
func (c *Client) Close() { func (c *Client) Close() {
if c == nil { if c == nil {
...@@ -155,7 +159,7 @@ func (c *Client) Close() { ...@@ -155,7 +159,7 @@ func (c *Client) Close() {
if c.rawClient != nil { if c.rawClient != nil {
c.clean() c.clean()
} }
log.Printf("etcd client{name:%s, endpoints:%s} exit now.", c.name, c.endpoints) log.Printf("etcd client{Name:%s, Endpoints:%s} exit now.", c.name, c.endpoints)
} }
func (c *Client) keepSession() error { func (c *Client) keepSession() error {
...@@ -173,7 +177,7 @@ func (c *Client) keepSession() error { ...@@ -173,7 +177,7 @@ func (c *Client) keepSession() error {
func (c *Client) keepSessionLoop(s *concurrency.Session) { func (c *Client) keepSessionLoop(s *concurrency.Session) {
defer func() { defer func() {
c.Wait.Done() c.Wait.Done()
log.Printf("etcd client {endpoints:%v, name:%s} keep goroutine game over.", c.endpoints, c.name) log.Printf("etcd client {Endpoints:%v, Name:%s} keep goroutine game over.", c.endpoints, c.name)
}() }()
for { for {
...@@ -194,16 +198,22 @@ func (c *Client) keepSessionLoop(s *concurrency.Session) { ...@@ -194,16 +198,22 @@ func (c *Client) keepSessionLoop(s *concurrency.Session) {
} }
} }
func (c *Client) getRawClient() *clientv3.Client { // GetRawClient return etcd raw client
func (c *Client) GetRawClient() *clientv3.Client {
c.lock.RLock() c.lock.RLock()
defer c.lock.RUnlock() defer c.lock.RUnlock()
return c.rawClient return c.rawClient
} }
// GetEndPoints return etcd endpoints
func (c *Client) GetEndPoints() []string {
return c.endpoints
}
// if k not exist will put k/v in etcd, otherwise return nil // if k not exist will put k/v in etcd, otherwise return nil
func (c *Client) put(k string, v string, opts ...clientv3.OpOption) error { func (c *Client) put(k string, v string, opts ...clientv3.OpOption) error {
rawClient := c.getRawClient() rawClient := c.GetRawClient()
if rawClient == nil { if rawClient == nil {
return ErrNilETCDV3Client return ErrNilETCDV3Client
...@@ -219,7 +229,7 @@ func (c *Client) put(k string, v string, opts ...clientv3.OpOption) error { ...@@ -219,7 +229,7 @@ func (c *Client) put(k string, v string, opts ...clientv3.OpOption) error {
// if k not exist will put k/v in etcd // if k not exist will put k/v in etcd
// if k is already exist in etcd, replace it // if k is already exist in etcd, replace it
func (c *Client) update(k string, v string, opts ...clientv3.OpOption) error { func (c *Client) update(k string, v string, opts ...clientv3.OpOption) error {
rawClient := c.getRawClient() rawClient := c.GetRawClient()
if rawClient == nil { if rawClient == nil {
return ErrNilETCDV3Client return ErrNilETCDV3Client
...@@ -233,7 +243,7 @@ func (c *Client) update(k string, v string, opts ...clientv3.OpOption) error { ...@@ -233,7 +243,7 @@ func (c *Client) update(k string, v string, opts ...clientv3.OpOption) error {
} }
func (c *Client) delete(k string) error { func (c *Client) delete(k string) error {
rawClient := c.getRawClient() rawClient := c.GetRawClient()
if rawClient == nil { if rawClient == nil {
return ErrNilETCDV3Client return ErrNilETCDV3Client
...@@ -244,7 +254,7 @@ func (c *Client) delete(k string) error { ...@@ -244,7 +254,7 @@ func (c *Client) delete(k string) error {
} }
func (c *Client) get(k string) (string, error) { func (c *Client) get(k string) (string, error) {
rawClient := c.getRawClient() rawClient := c.GetRawClient()
if rawClient == nil { if rawClient == nil {
return "", ErrNilETCDV3Client return "", ErrNilETCDV3Client
...@@ -264,7 +274,7 @@ func (c *Client) get(k string) (string, error) { ...@@ -264,7 +274,7 @@ func (c *Client) get(k string) (string, error) {
// CleanKV delete all key and value // CleanKV delete all key and value
func (c *Client) CleanKV() error { func (c *Client) CleanKV() error {
rawClient := c.getRawClient() rawClient := c.GetRawClient()
if rawClient == nil { if rawClient == nil {
return ErrNilETCDV3Client return ErrNilETCDV3Client
...@@ -274,8 +284,9 @@ func (c *Client) CleanKV() error { ...@@ -274,8 +284,9 @@ func (c *Client) CleanKV() error {
return err return err
} }
func (c *Client) getChildren(k string) ([]string, []string, error) { // GetChildren return node children
rawClient := c.getRawClient() func (c *Client) GetChildren(k string) ([]string, []string, error) {
rawClient := c.GetRawClient()
if rawClient == nil { if rawClient == nil {
return nil, nil, ErrNilETCDV3Client return nil, nil, ErrNilETCDV3Client
...@@ -300,7 +311,7 @@ func (c *Client) getChildren(k string) ([]string, []string, error) { ...@@ -300,7 +311,7 @@ func (c *Client) getChildren(k string) ([]string, []string, error) {
} }
func (c *Client) watchWithPrefix(prefix string) (clientv3.WatchChan, error) { func (c *Client) watchWithPrefix(prefix string) (clientv3.WatchChan, error) {
rawClient := c.getRawClient() rawClient := c.GetRawClient()
if rawClient == nil { if rawClient == nil {
return nil, ErrNilETCDV3Client return nil, ErrNilETCDV3Client
...@@ -310,7 +321,7 @@ func (c *Client) watchWithPrefix(prefix string) (clientv3.WatchChan, error) { ...@@ -310,7 +321,7 @@ func (c *Client) watchWithPrefix(prefix string) (clientv3.WatchChan, error) {
} }
func (c *Client) watch(k string) (clientv3.WatchChan, error) { func (c *Client) watch(k string) (clientv3.WatchChan, error) {
rawClient := c.getRawClient() rawClient := c.GetRawClient()
if rawClient == nil { if rawClient == nil {
return nil, ErrNilETCDV3Client return nil, ErrNilETCDV3Client
...@@ -320,7 +331,7 @@ func (c *Client) watch(k string) (clientv3.WatchChan, error) { ...@@ -320,7 +331,7 @@ func (c *Client) watch(k string) (clientv3.WatchChan, error) {
} }
func (c *Client) keepAliveKV(k string, v string) error { func (c *Client) keepAliveKV(k string, v string) error {
rawClient := c.getRawClient() rawClient := c.GetRawClient()
if rawClient == nil { if rawClient == nil {
return ErrNilETCDV3Client return ErrNilETCDV3Client
...@@ -389,7 +400,7 @@ func (c *Client) RegisterTemp(k, v string) error { ...@@ -389,7 +400,7 @@ func (c *Client) RegisterTemp(k, v string) error {
// GetChildrenKVList gets children kv list by @k // GetChildrenKVList gets children kv list by @k
func (c *Client) GetChildrenKVList(k string) ([]string, []string, error) { func (c *Client) GetChildrenKVList(k string) ([]string, []string, error) {
kList, vList, err := c.getChildren(k) kList, vList, err := c.GetChildren(k)
return kList, vList, perrors.WithMessagef(err, "get key children (key %s)", k) return kList, vList, perrors.WithMessagef(err, "get key children (key %s)", k)
} }
......
...@@ -83,7 +83,6 @@ type ClientTestSuite struct { ...@@ -83,7 +83,6 @@ type ClientTestSuite struct {
// start etcd server // start etcd server
func (suite *ClientTestSuite) SetupSuite() { func (suite *ClientTestSuite) SetupSuite() {
t := suite.T() t := suite.T()
DefaultListenPeerURLs := "http://localhost:2382" DefaultListenPeerURLs := "http://localhost:2382"
...@@ -138,7 +137,6 @@ func (suite *ClientTestSuite) SetupTest() { ...@@ -138,7 +137,6 @@ func (suite *ClientTestSuite) SetupTest() {
} }
func (suite *ClientTestSuite) TestClientClose() { func (suite *ClientTestSuite) TestClientClose() {
c := suite.client c := suite.client
t := suite.T() t := suite.T()
...@@ -149,7 +147,6 @@ func (suite *ClientTestSuite) TestClientClose() { ...@@ -149,7 +147,6 @@ func (suite *ClientTestSuite) TestClientClose() {
} }
func (suite *ClientTestSuite) TestClientValid() { func (suite *ClientTestSuite) TestClientValid() {
c := suite.client c := suite.client
t := suite.T() t := suite.T()
...@@ -163,7 +160,6 @@ func (suite *ClientTestSuite) TestClientValid() { ...@@ -163,7 +160,6 @@ func (suite *ClientTestSuite) TestClientValid() {
} }
func (suite *ClientTestSuite) TestClientDone() { func (suite *ClientTestSuite) TestClientDone() {
c := suite.client c := suite.client
go func() { go func() {
...@@ -179,7 +175,6 @@ func (suite *ClientTestSuite) TestClientDone() { ...@@ -179,7 +175,6 @@ func (suite *ClientTestSuite) TestClientDone() {
} }
func (suite *ClientTestSuite) TestClientCreateKV() { func (suite *ClientTestSuite) TestClientCreateKV() {
tests := tests tests := tests
c := suite.client c := suite.client
...@@ -210,7 +205,6 @@ func (suite *ClientTestSuite) TestClientCreateKV() { ...@@ -210,7 +205,6 @@ func (suite *ClientTestSuite) TestClientCreateKV() {
} }
func (suite *ClientTestSuite) TestClientDeleteKV() { func (suite *ClientTestSuite) TestClientDeleteKV() {
tests := tests tests := tests
c := suite.client c := suite.client
t := suite.T() t := suite.T()
...@@ -240,11 +234,9 @@ func (suite *ClientTestSuite) TestClientDeleteKV() { ...@@ -240,11 +234,9 @@ func (suite *ClientTestSuite) TestClientDeleteKV() {
t.Fatal(err) t.Fatal(err)
} }
} }
} }
func (suite *ClientTestSuite) TestClientGetChildrenKVList() { func (suite *ClientTestSuite) TestClientGetChildrenKVList() {
tests := tests tests := tests
c := suite.client c := suite.client
...@@ -278,11 +270,9 @@ func (suite *ClientTestSuite) TestClientGetChildrenKVList() { ...@@ -278,11 +270,9 @@ func (suite *ClientTestSuite) TestClientGetChildrenKVList() {
} }
t.Fatalf("expect keylist %v but got %v expect valueList %v but got %v ", expectKList, kList, expectVList, vList) t.Fatalf("expect keylist %v but got %v expect valueList %v but got %v ", expectKList, kList, expectVList, vList)
} }
func (suite *ClientTestSuite) TestClientWatch() { func (suite *ClientTestSuite) TestClientWatch() {
tests := tests tests := tests
c := suite.client c := suite.client
...@@ -316,7 +306,6 @@ func (suite *ClientTestSuite) TestClientWatch() { ...@@ -316,7 +306,6 @@ func (suite *ClientTestSuite) TestClientWatch() {
var eCreate, eDelete mvccpb.Event var eCreate, eDelete mvccpb.Event
for e := range wc { for e := range wc {
for _, event := range e.Events { for _, event := range e.Events {
events = append(events, (mvccpb.Event)(*event)) events = append(events, (mvccpb.Event)(*event))
if event.Type == mvccpb.PUT { if event.Type == mvccpb.PUT {
...@@ -332,11 +321,9 @@ func (suite *ClientTestSuite) TestClientWatch() { ...@@ -332,11 +321,9 @@ func (suite *ClientTestSuite) TestClientWatch() {
assert.Equal(t, 2, len(events)) assert.Equal(t, 2, len(events))
assert.Contains(t, events, eCreate) assert.Contains(t, events, eCreate)
assert.Contains(t, events, eDelete) assert.Contains(t, events, eDelete)
} }
func (suite *ClientTestSuite) TestClientRegisterTemp() { func (suite *ClientTestSuite) TestClientRegisterTemp() {
c := suite.client c := suite.client
observeC := suite.setUpClient() observeC := suite.setUpClient()
t := suite.T() t := suite.T()
...@@ -360,7 +347,6 @@ func (suite *ClientTestSuite) TestClientRegisterTemp() { ...@@ -360,7 +347,6 @@ func (suite *ClientTestSuite) TestClientRegisterTemp() {
var eCreate, eDelete mvccpb.Event var eCreate, eDelete mvccpb.Event
for e := range wc { for e := range wc {
for _, event := range e.Events { for _, event := range e.Events {
events = append(events, (mvccpb.Event)(*event)) events = append(events, (mvccpb.Event)(*event))
if event.Type == mvccpb.DELETE { if event.Type == mvccpb.DELETE {
......
...@@ -26,19 +26,24 @@ const ( ...@@ -26,19 +26,24 @@ const (
ConnDelay = 3 ConnDelay = 3
// MaxFailTimes max failure times // MaxFailTimes max failure times
MaxFailTimes = 15 MaxFailTimes = 15
// RegistryETCDV3Client client name // RegistryETCDV3Client client Name
RegistryETCDV3Client = "etcd registry" RegistryETCDV3Client = "etcd registry"
// MetadataETCDV3Client client name // MetadataETCDV3Client client Name
MetadataETCDV3Client = "etcd metadata" MetadataETCDV3Client = "etcd metadata"
) )
// Options client configuration // Options client configuration
type Options struct { type Options struct {
name string // Name etcd server name
endpoints []string Name string
client *Client // Endpoints etcd endpoints
timeout time.Duration Endpoints []string
heartbeat int // heartbeat second // Client etcd client
Client *Client
// Timeout timeout
Timeout time.Duration
// Heartbeat second
Heartbeat int
} }
// Option will define a function of handling Options // Option will define a function of handling Options
...@@ -47,27 +52,27 @@ type Option func(*Options) ...@@ -47,27 +52,27 @@ type Option func(*Options)
// WithEndpoints sets etcd client endpoints // WithEndpoints sets etcd client endpoints
func WithEndpoints(endpoints ...string) Option { func WithEndpoints(endpoints ...string) Option {
return func(opt *Options) { return func(opt *Options) {
opt.endpoints = endpoints opt.Endpoints = endpoints
} }
} }
// WithName sets etcd client name // WithName sets etcd client name
func WithName(name string) Option { func WithName(name string) Option {
return func(opt *Options) { return func(opt *Options) {
opt.name = name opt.Name = name
} }
} }
// WithTimeout sets etcd client timeout // WithTimeout sets etcd client timeout
func WithTimeout(timeout time.Duration) Option { func WithTimeout(timeout time.Duration) Option {
return func(opt *Options) { return func(opt *Options) {
opt.timeout = timeout opt.Timeout = timeout
} }
} }
// WithHeartbeat sets etcd client heartbeat // WithHeartbeat sets etcd client heartbeat
func WithHeartbeat(heartbeat int) Option { func WithHeartbeat(heartbeat int) Option {
return func(opt *Options) { return func(opt *Options) {
opt.heartbeat = heartbeat opt.Heartbeat = heartbeat
} }
} }
This diff is collapsed.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 gxzookeeper
import (
"strconv"
"testing"
"time"
)
import (
"github.com/dubbogo/go-zookeeper/zk"
"github.com/stretchr/testify/assert"
)
func verifyEventStateOrder(t *testing.T, c <-chan zk.Event, expectedStates []zk.State, source string) {
for _, state := range expectedStates {
for {
event, ok := <-c
if !ok {
t.Fatalf("unexpected channel close for %s", source)
}
if event.Type != zk.EventSession {
continue
}
if event.State != state {
t.Fatalf("mismatched state order from %s, expected %v, received %v", source, state, event.State)
}
break
}
}
}
func Test_getZookeeperClient(t *testing.T) {
var err error
var tc *zk.TestCluster
var address []string
tc, err = zk.StartTestCluster(1, nil, nil, zk.WithRetryTimes(40))
assert.NoError(t, err)
assert.NotNil(t, tc.Servers[0])
address = append(address, "127.0.0.1:"+strconv.Itoa(tc.Servers[0].Port))
client1, err := NewZookeeperClient("test1", address, true, WithZkTimeOut(3*time.Second))
assert.Nil(t, err)
client2, err := NewZookeeperClient("test1", address, true, WithZkTimeOut(3*time.Second))
assert.Nil(t, err)
client3, err := NewZookeeperClient("test2", address, true, WithZkTimeOut(3*time.Second))
assert.Nil(t, err)
client4, err := NewZookeeperClient("test2", address, false, WithZkTimeOut(3*time.Second))
assert.Nil(t, err)
if client1 != client2 {
t.Fatalf("NewZookeeperClient failed")
}
if client1 == client3 {
t.Fatalf("NewZookeeperClient failed")
}
if client3 == client4 {
t.Fatalf("NewZookeeperClient failed")
}
client1.Close()
client2.Close()
client3.Close()
client4.Close()
tc.Stop()
}
func Test_Close(t *testing.T) {
var err error
var tc *zk.TestCluster
var address []string
tc, err = zk.StartTestCluster(1, nil, nil, zk.WithRetryTimes(40))
assert.NoError(t, err)
assert.NotNil(t, tc.Servers[0])
address = append(address, "127.0.0.1:"+strconv.Itoa(tc.Servers[0].Port))
client1, err := NewZookeeperClient("test1", address, true, WithZkTimeOut(3*time.Second))
assert.Nil(t, err)
client2, err := NewZookeeperClient("test1", address, true, WithZkTimeOut(3*time.Second))
assert.Nil(t, err)
if client1 != client2 {
t.Fatalf("NewZookeeperClient failed")
}
client1.Close()
client3, err := NewZookeeperClient("test1", address, true, WithZkTimeOut(3*time.Second))
assert.Nil(t, err)
if client2 != client3 {
t.Fatalf("NewZookeeperClient failed")
}
client2.Close()
assert.Equal(t, client1.activeNumber, uint32(1))
client1.Close()
assert.Equal(t, client1.activeNumber, uint32(0))
client4, err := NewZookeeperClient("test1", address, true, WithZkTimeOut(3*time.Second))
assert.Nil(t, err)
assert.Equal(t, client4.activeNumber, uint32(1))
if client4 == client3 {
t.Fatalf("NewZookeeperClient failed")
}
client5, err := NewZookeeperClient("test1", address, false, WithZkTimeOut(3*time.Second))
assert.Nil(t, err)
client6, err := NewZookeeperClient("test1", address, false, WithZkTimeOut(3*time.Second))
assert.Nil(t, err)
if client5 == client6 {
t.Fatalf("NewZookeeperClient failed")
}
client5.Close()
assert.Equal(t, client5.activeNumber, uint32(0))
assert.Equal(t, client5.Conn, (*zk.Conn)(nil))
assert.NotEqual(t, client6.Conn, nil)
client6.Close()
assert.Equal(t, client6.activeNumber, uint32(0))
assert.Equal(t, client6.Conn, (*zk.Conn)(nil))
tc.Stop()
}
func Test_newMockZookeeperClient(t *testing.T) {
ts, _, event, err := NewMockZookeeperClient("test", 15*time.Second)
assert.NoError(t, err)
defer func() {
err := ts.Stop()
assert.Nil(t, err)
}()
states := []zk.State{zk.StateConnecting, zk.StateConnected, zk.StateHasSession}
verifyEventStateOrder(t, event, states, "event channel")
}
func TestCreate(t *testing.T) {
ts, z, event, err := NewMockZookeeperClient("test", 15*time.Second)
assert.NoError(t, err)
defer func() {
_ = ts.Stop()
assert.Nil(t, err)
}()
err = z.Create("test1/test2/test3/test4")
assert.NoError(t, err)
states := []zk.State{zk.StateConnecting, zk.StateConnected, zk.StateHasSession}
verifyEventStateOrder(t, event, states, "event channel")
}
func TestCreateDelete(t *testing.T) {
ts, z, event, err := NewMockZookeeperClient("test", 15*time.Second)
assert.NoError(t, err)
defer func() {
_ = ts.Stop()
assert.Nil(t, err)
}()
states := []zk.State{zk.StateConnecting, zk.StateConnected, zk.StateHasSession}
verifyEventStateOrder(t, event, states, "event channel")
err = z.Create("/test1/test2/test3/test4")
assert.NoError(t, err)
err = z.Delete("/test1/test2/test3/test4")
assert.NoError(t, err)
// verifyEventOrder(t, event, []zk.EventType{zk.EventNodeCreated}, "event channel")
}
func TestRegisterTemp(t *testing.T) {
ts, z, event, err := NewMockZookeeperClient("test", 15*time.Second)
assert.NoError(t, err)
defer func() {
_ = ts.Stop()
assert.Nil(t, err)
}()
err = z.Create("/test1/test2/test3")
assert.NoError(t, err)
tmpath, err := z.RegisterTemp("/test1/test2/test3", "test4")
assert.NoError(t, err)
assert.Equal(t, "/test1/test2/test3/test4", tmpath)
states := []zk.State{zk.StateConnecting, zk.StateConnected, zk.StateHasSession}
verifyEventStateOrder(t, event, states, "event channel")
}
func TestRegisterTempSeq(t *testing.T) {
ts, z, event, err := NewMockZookeeperClient("test", 15*time.Second)
assert.NoError(t, err)
defer func() {
_ = ts.Stop()
assert.Nil(t, err)
}()
err = z.Create("/test1/test2/test3")
assert.NoError(t, err)
tmpath, err := z.RegisterTempSeq("/test1/test2/test3", []byte("test"))
assert.NoError(t, err)
assert.Equal(t, "/test1/test2/test3/0000000000", tmpath)
states := []zk.State{zk.StateConnecting, zk.StateConnected, zk.StateHasSession}
verifyEventStateOrder(t, event, states, "event channel")
}
func Test_UnregisterEvent(t *testing.T) {
client := &ZookeeperClient{}
client.eventRegistry = make(map[string][]*chan struct{})
array := []*chan struct{}{}
array = append(array, new(chan struct{}))
client.eventRegistry["test"] = array
client.UnregisterEvent("test", new(chan struct{}))
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 gxzookeeper
import (
"time"
)
import (
"github.com/dubbogo/go-zookeeper/zk"
)
// nolint
type options struct {
ZkName string
Client *ZookeeperClient
Ts *zk.TestCluster
}
// Option will define a function of handling Options
type Option func(*options)
// WithZkName sets zk Client name
func WithZkName(name string) Option {
return func(opt *options) {
opt.ZkName = name
}
}
type zkClientOption func(*ZookeeperClient)
// WithZkEventHandler sets zk Client event
func WithZkEventHandler(handler ZkEventHandler) zkClientOption {
return func(opt *ZookeeperClient) {
opt.zkEventHandler = handler
}
}
// WithZkTimeOut sets zk Client timeout
func WithZkTimeOut(t time.Duration) zkClientOption {
return func(opt *ZookeeperClient) {
opt.Timeout = t
}
}
...@@ -169,7 +169,7 @@ func (jsp *jsonStructParser) json2Struct(jsonData []byte) interface{} { ...@@ -169,7 +169,7 @@ func (jsp *jsonStructParser) json2Struct(jsonData []byte) interface{} {
case reflect.TypeOf(""): case reflect.TypeOf(""):
v.Field(i).SetString(valStr) v.Field(i).SetString(valStr)
case reflect.TypeOf(time.Time{}): case reflect.TypeOf(time.Time{}):
//todo time support v.Field(i). // todo time support v.Field(i).
case reflect.TypeOf(float64(0)), reflect.TypeOf(float32(0)): case reflect.TypeOf(float64(0)), reflect.TypeOf(float32(0)):
if parsedFloat, err := strconv.ParseFloat(valStr, 64); err == nil { if parsedFloat, err := strconv.ParseFloat(valStr, 64); err == nil {
v.Field(i).SetFloat(parsedFloat) v.Field(i).SetFloat(parsedFloat)
......
...@@ -2,39 +2,48 @@ module github.com/dubbogo/gost ...@@ -2,39 +2,48 @@ module github.com/dubbogo/gost
require ( require (
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/coreos/bbolt v0.0.0-00010101000000-000000000000 // indirect github.com/coreos/bbolt v1.3.3 // indirect
github.com/coreos/etcd v3.3.25+incompatible github.com/coreos/etcd v3.3.25+incompatible
github.com/coreos/go-semver v0.3.0 // indirect github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/davecgh/go-spew v1.1.1 github.com/davecgh/go-spew v1.1.1
github.com/dubbogo/go-zookeeper v1.0.3
github.com/dubbogo/jsonparser v1.0.1 github.com/dubbogo/jsonparser v1.0.1
github.com/dustin/go-humanize v1.0.0 // indirect github.com/dustin/go-humanize v1.0.0 // indirect
github.com/go-ole/go-ole v1.2.4 // indirect github.com/go-ole/go-ole v1.2.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/google/uuid v1.2.0 // indirect github.com/google/uuid v1.2.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/k0kubun/pp v3.0.1+incompatible github.com/k0kubun/pp v3.0.1+incompatible
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.7 // indirect github.com/mattn/go-colorable v0.1.7 // indirect
github.com/mattn/go-isatty v0.0.12 github.com/mattn/go-isatty v0.0.12
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.9.0 // indirect github.com/prometheus/client_golang v1.9.0 // indirect
github.com/shirou/gopsutil v3.20.11-0.20201116082039-2fb5da2f2449+incompatible github.com/shirou/gopsutil v3.20.11-0.20201116082039-2fb5da2f2449+incompatible
github.com/stretchr/testify v1.6.1 github.com/stretchr/testify v1.6.1
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect
go.etcd.io/bbolt v1.3.4 // indirect
go.uber.org/atomic v1.7.0 go.uber.org/atomic v1.7.0
go.uber.org/zap v1.16.0 // indirect go.uber.org/zap v1.16.0 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
google.golang.org/grpc v1.33.1 google.golang.org/grpc v1.33.1
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect sigs.k8s.io/yaml v1.2.0 // indirect
) )
replace ( replace (
github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.4 github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.4
go.etcd.io/bbolt v1.3.4 => github.com/coreos/bbolt v1.3.4
google.golang.org/grpc v1.33.1 => google.golang.org/grpc v1.26.0 google.golang.org/grpc v1.33.1 => google.golang.org/grpc v1.26.0
) )
......
...@@ -41,6 +41,7 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk ...@@ -41,6 +41,7 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/coreos/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
github.com/coreos/etcd v3.3.25+incompatible h1:0GQEw6h3YnuOVdtwygkIfJ+Omx0tZ8/QkVyXI4LkbeY= github.com/coreos/etcd v3.3.25+incompatible h1:0GQEw6h3YnuOVdtwygkIfJ+Omx0tZ8/QkVyXI4LkbeY=
github.com/coreos/etcd v3.3.25+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.25+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
...@@ -54,12 +55,17 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbp ...@@ -54,12 +55,17 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbp
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dubbogo/go-zookeeper v1.0.2 h1:xmEnPL8SlCe3/+J5ZR9e8qE35LmFVYe8VVpDakjNM4A=
github.com/dubbogo/go-zookeeper v1.0.2/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c=
github.com/dubbogo/go-zookeeper v1.0.3 h1:UkuY+rBsxdT7Bs63QAzp9z7XqQ53W1j8E5rwl83me8g=
github.com/dubbogo/go-zookeeper v1.0.3/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c=
github.com/dubbogo/jsonparser v1.0.1 h1:sAIr8gk+gkahkIm6CnUxh9wTCkbgwLEQ8dTXTnAXyzo= github.com/dubbogo/jsonparser v1.0.1 h1:sAIr8gk+gkahkIm6CnUxh9wTCkbgwLEQ8dTXTnAXyzo=
github.com/dubbogo/jsonparser v1.0.1/go.mod h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU= github.com/dubbogo/jsonparser v1.0.1/go.mod h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
...@@ -137,6 +143,8 @@ github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z ...@@ -137,6 +143,8 @@ github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c h1:Lh2aW+HnU2Nbe1gqD9SOJLJxW1jBMmQOktN2acDyJk8= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c h1:Lh2aW+HnU2Nbe1gqD9SOJLJxW1jBMmQOktN2acDyJk8=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 h1:FlFbCRLd5Jr4iYXZufAvgWN6Ao0JrI5chLINnUXDDr0= github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 h1:FlFbCRLd5Jr4iYXZufAvgWN6Ao0JrI5chLINnUXDDr0=
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= github.com/grpc-ecosystem/go-grpc-middleware v1.2.2/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI=
...@@ -198,6 +206,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN ...@@ -198,6 +206,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
...@@ -234,6 +244,8 @@ github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzE ...@@ -234,6 +244,8 @@ github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzE
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
...@@ -329,6 +341,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 h1:uruHq4 ...@@ -329,6 +341,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 h1:uruHq4
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/wenxuwan/go-zookeeper v1.0.3-0.20210303051024-8a4fef629f1a h1:EG3JeqQNnLM6PUbnmfUl1ou4JDfF3H08CKifYHrcwlQ=
github.com/wenxuwan/go-zookeeper v1.0.3-0.20210303051024-8a4fef629f1a/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
...@@ -377,6 +391,8 @@ golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTk ...@@ -377,6 +391,8 @@ golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTk
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
...@@ -470,6 +486,7 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn ...@@ -470,6 +486,7 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a h1:CB3a9Nez8M13wwlr/E2YtwoU+qYHKfC+JrDa45RXXoQ= golang.org/x/tools v0.0.0-20210106214847-113979e3529a h1:CB3a9Nez8M13wwlr/E2YtwoU+qYHKfC+JrDa45RXXoQ=
...@@ -518,6 +535,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 ...@@ -518,6 +535,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
...@@ -534,6 +553,8 @@ gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= ...@@ -534,6 +553,8 @@ gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
......
...@@ -30,16 +30,16 @@ type info struct { ...@@ -30,16 +30,16 @@ type info struct {
} }
func TestPrettyString(t *testing.T) { func TestPrettyString(t *testing.T) {
var i = info{name: "hello", age: 23.5, m: map[string]string{"h": "w", "hello": "world"}} i := info{name: "hello", age: 23.5, m: map[string]string{"h": "w", "hello": "world"}}
fmt.Println(PrettyString(i)) fmt.Println(PrettyString(i))
} }
func TestColorPrint(t *testing.T) { func TestColorPrint(t *testing.T) {
var i = info{name: "hello", age: 23.5, m: map[string]string{"h": "w", "hello": "world"}} i := info{name: "hello", age: 23.5, m: map[string]string{"h": "w", "hello": "world"}}
ColorPrintln(i) ColorPrintln(i)
} }
func TestColorPrintf(t *testing.T) { func TestColorPrintf(t *testing.T) {
var i = info{name: "hello", age: 23.5, m: map[string]string{"h": "w", "hello": "world"}} i := info{name: "hello", age: 23.5, m: map[string]string{"h": "w", "hello": "world"}}
ColorPrintf("exapmle format:%s\n", i) ColorPrintf("exapmle format:%s\n", i)
} }
...@@ -265,7 +265,7 @@ func (d *Decimal) GetDigitsFrac() int8 { ...@@ -265,7 +265,7 @@ func (d *Decimal) GetDigitsFrac() int8 {
func (d *Decimal) String() string { func (d *Decimal) String() string {
tmp := *d tmp := *d
_ = tmp.Round(&tmp, int(tmp.resultFrac), ModeHalfEven) _ = tmp.Round(&tmp, int(tmp.resultFrac), ModeHalfEven)
//todo terror.Log(errors.Trace(err)) // todo terror.Log(errors.Trace(err))
return string(tmp.ToBytes()) return string(tmp.ToBytes())
} }
...@@ -1478,7 +1478,7 @@ func writeWord(b []byte, word int32, size int) { ...@@ -1478,7 +1478,7 @@ func writeWord(b []byte, word int32, size int) {
func (d *Decimal) Compare(to *Decimal) int { func (d *Decimal) Compare(to *Decimal) int {
if d.negative == to.negative { if d.negative == to.negative {
cmp, _ := doSub(d, to, nil) cmp, _ := doSub(d, to, nil)
//todo terror.Log(errors.Trace(err)) // todo terror.Log(errors.Trace(err))
return cmp return cmp
} }
if d.negative { if d.negative {
...@@ -1735,7 +1735,7 @@ func doAdd(from1, from2, to *Decimal) error { ...@@ -1735,7 +1735,7 @@ func doAdd(from1, from2, to *Decimal) error {
wordsInt2 = wordsIntTo wordsInt2 = wordsIntTo
} }
} }
var dec1, dec2 = from1, from2 dec1, dec2 := from1, from2
var idx1, idx2, stop, stop2 int var idx1, idx2, stop, stop2 int
/* part 1 - max(frac) ... min (frac) */ /* part 1 - max(frac) ... min (frac) */
if wordsFrac1 > wordsFrac2 { if wordsFrac1 > wordsFrac2 {
...@@ -2279,7 +2279,7 @@ func NewDecFromUint(i uint64) *Decimal { ...@@ -2279,7 +2279,7 @@ func NewDecFromUint(i uint64) *Decimal {
func NewDecFromFloatForTest(f float64) *Decimal { func NewDecFromFloatForTest(f float64) *Decimal {
dec := new(Decimal) dec := new(Decimal)
_ = dec.FromFloat64(f) _ = dec.FromFloat64(f)
//todo terror.Log(errors.Trace(err)) // todo terror.Log(errors.Trace(err))
return dec return dec
} }
...@@ -2287,7 +2287,7 @@ func NewDecFromFloatForTest(f float64) *Decimal { ...@@ -2287,7 +2287,7 @@ func NewDecFromFloatForTest(f float64) *Decimal {
func NewDecFromStringForTest(s string) *Decimal { func NewDecFromStringForTest(s string) *Decimal {
dec := new(Decimal) dec := new(Decimal)
_ = dec.FromBytes([]byte(s)) _ = dec.FromBytes([]byte(s))
//todo terror.Log(errors.Trace(err)) // todo terror.Log(errors.Trace(err))
return dec return dec
} }
...@@ -2305,6 +2305,6 @@ func NewMaxOrMinDec(negative bool, prec, frac int) *Decimal { ...@@ -2305,6 +2305,6 @@ func NewMaxOrMinDec(negative bool, prec, frac int) *Decimal {
str[1+prec-frac] = '.' str[1+prec-frac] = '.'
dec := new(Decimal) dec := new(Decimal)
_ = dec.FromBytes(str) _ = dec.FromBytes(str)
//todo terror.Log(errors.Trace(err)) // todo terror.Log(errors.Trace(err))
return dec return dec
} }
...@@ -154,8 +154,10 @@ func TestToHashKey(t *testing.T) { ...@@ -154,8 +154,10 @@ func TestToHashKey(t *testing.T) {
{[]string{"-1.1", "-1.1000", "-1.1000000", "-1.10000000000", "-01.1", "-0001.1", "-001.1000000"}}, {[]string{"-1.1", "-1.1000", "-1.1000000", "-1.10000000000", "-01.1", "-0001.1", "-001.1000000"}},
{[]string{".1", "0.1", "000000.1", ".10000", "0000.10000", "000000000000000000.1"}}, {[]string{".1", "0.1", "000000.1", ".10000", "0000.10000", "000000000000000000.1"}},
{[]string{"0", "0000", ".0", ".00000", "00000.00000", "-0", "-0000", "-.0", "-.00000", "-00000.00000"}}, {[]string{"0", "0000", ".0", ".00000", "00000.00000", "-0", "-0000", "-.0", "-.00000", "-00000.00000"}},
{[]string{".123456789123456789", ".1234567891234567890", ".12345678912345678900", ".123456789123456789000", ".1234567891234567890000", "0.123456789123456789", {[]string{
".1234567891234567890000000000", "0000000.123456789123456789000"}}, ".123456789123456789", ".1234567891234567890", ".12345678912345678900", ".123456789123456789000", ".1234567891234567890000", "0.123456789123456789",
".1234567891234567890000000000", "0000000.123456789123456789000",
}},
{[]string{"12345", "012345", "0012345", "0000012345", "0000000012345", "00000000000012345", "12345.", "12345.00", "12345.000000000", "000012345.0000"}}, {[]string{"12345", "012345", "0012345", "0000012345", "0000000012345", "00000000000012345", "12345.", "12345.00", "12345.000000000", "000012345.0000"}},
{[]string{"123E5", "12300000", "00123E5", "000000123E5", "12300000.00000000"}}, {[]string{"123E5", "12300000", "00123E5", "000000123E5", "12300000.00000000"}},
{[]string{"123E-2", "1.23", "00000001.23", "1.2300000000000000", "000000001.23000000000000"}}, {[]string{"123E-2", "1.23", "00000001.23", "1.2300000000000000", "000000001.23000000000000"}},
...@@ -178,23 +180,41 @@ func TestToHashKey(t *testing.T) { ...@@ -178,23 +180,41 @@ func TestToHashKey(t *testing.T) {
hashNumbers []string hashNumbers []string
binNumbers []string binNumbers []string
}{ }{
{[]string{"1.1", "1.1000", "1.1000000", "1.10000000000", "01.1", "0001.1", "001.1000000"}, {
[]string{"1.1", "0001.1", "01.1"}}, []string{"1.1", "1.1000", "1.1000000", "1.10000000000", "01.1", "0001.1", "001.1000000"},
{[]string{"-1.1", "-1.1000", "-1.1000000", "-1.10000000000", "-01.1", "-0001.1", "-001.1000000"}, []string{"1.1", "0001.1", "01.1"},
[]string{"-1.1", "-0001.1", "-01.1"}}, },
{[]string{".1", "0.1", "000000.1", ".10000", "0000.10000", "000000000000000000.1"}, {
[]string{".1", "0.1", "000000.1", "00.1"}}, []string{"-1.1", "-1.1000", "-1.1000000", "-1.10000000000", "-01.1", "-0001.1", "-001.1000000"},
{[]string{"0", "0000", ".0", ".00000", "00000.00000", "-0", "-0000", "-.0", "-.00000", "-00000.00000"}, []string{"-1.1", "-0001.1", "-01.1"},
[]string{"0", "0000", "00", "-0", "-00", "-000000"}}, },
{[]string{".123456789123456789", ".1234567891234567890", ".12345678912345678900", ".123456789123456789000", ".1234567891234567890000", "0.123456789123456789", {
".1234567891234567890000000000", "0000000.123456789123456789000"}, []string{".1", "0.1", "000000.1", ".10000", "0000.10000", "000000000000000000.1"},
[]string{".123456789123456789", "0.123456789123456789", "0000.123456789123456789", "0000000.123456789123456789"}}, []string{".1", "0.1", "000000.1", "00.1"},
{[]string{"12345", "012345", "0012345", "0000012345", "0000000012345", "00000000000012345", "12345.", "12345.00", "12345.000000000", "000012345.0000"}, },
[]string{"12345", "012345", "000012345", "000000000000012345"}}, {
{[]string{"123E5", "12300000", "00123E5", "000000123E5", "12300000.00000000"}, []string{"0", "0000", ".0", ".00000", "00000.00000", "-0", "-0000", "-.0", "-.00000", "-00000.00000"},
[]string{"12300000", "123E5", "00123E5", "0000000000123E5"}}, []string{"0", "0000", "00", "-0", "-00", "-000000"},
{[]string{"123E-2", "1.23", "00000001.23", "1.2300000000000000", "000000001.23000000000000"}, },
[]string{"123E-2", "1.23", "000001.23", "0000000000001.23"}}, {
[]string{
".123456789123456789", ".1234567891234567890", ".12345678912345678900", ".123456789123456789000", ".1234567891234567890000", "0.123456789123456789",
".1234567891234567890000000000", "0000000.123456789123456789000",
},
[]string{".123456789123456789", "0.123456789123456789", "0000.123456789123456789", "0000000.123456789123456789"},
},
{
[]string{"12345", "012345", "0012345", "0000012345", "0000000012345", "00000000000012345", "12345.", "12345.00", "12345.000000000", "000012345.0000"},
[]string{"12345", "012345", "000012345", "000000000000012345"},
},
{
[]string{"123E5", "12300000", "00123E5", "000000123E5", "12300000.00000000"},
[]string{"12300000", "123E5", "00123E5", "0000000000123E5"},
},
{
[]string{"123E-2", "1.23", "00000001.23", "1.2300000000000000", "000000001.23000000000000"},
[]string{"123E-2", "1.23", "000001.23", "0000000000001.23"},
},
} }
for _, ca := range binTests { for _, ca := range binTests {
keys := make([]string, 0, len(ca.hashNumbers)+len(ca.binNumbers)) keys := make([]string, 0, len(ca.hashNumbers)+len(ca.binNumbers))
...@@ -260,12 +280,12 @@ func TestShift(t *testing.T) { ...@@ -260,12 +280,12 @@ func TestShift(t *testing.T) {
output string output string
err error err error
} }
var dotest = func(t *testing.T, tests []tcase) { dotest := func(t *testing.T, tests []tcase) {
for _, ca := range tests { for _, ca := range tests {
var dec Decimal var dec Decimal
err := dec.FromBytes([]byte(ca.input)) err := dec.FromBytes([]byte(ca.input))
assert.Nil(t, err) assert.Nil(t, err)
//origin := dec // origin := dec
err = dec.Shift(ca.shift) err = dec.Shift(ca.shift)
assert.Equal(t, err, ca.err) assert.Equal(t, err, ca.err)
result := dec.ToBytes() result := dec.ToBytes()
...@@ -448,7 +468,7 @@ func TestRoundWithCeil(t *testing.T) { ...@@ -448,7 +468,7 @@ func TestRoundWithCeil(t *testing.T) {
{"15.1", 0, "16", nil}, {"15.1", 0, "16", nil},
{"15.5", 0, "16", nil}, {"15.5", 0, "16", nil},
{"15.9", 0, "16", nil}, {"15.9", 0, "16", nil},
//TODO:fix me // TODO:fix me
{"-15.1", 0, "-16", nil}, {"-15.1", 0, "-16", nil},
{"-15.5", 0, "-16", nil}, {"-15.5", 0, "-16", nil},
{"-15.9", 0, "-16", nil}, {"-15.9", 0, "-16", nil},
...@@ -580,7 +600,7 @@ func TestToBinFromBin(t *testing.T) { ...@@ -580,7 +600,7 @@ func TestToBinFromBin(t *testing.T) {
} }
for _, tt := range errTests { for _, tt := range errTests {
_, _ = dec.ToBin(tt.prec, tt.frac) _, _ = dec.ToBin(tt.prec, tt.frac)
//assert.Equal(t,ErrBadNumber.Equal(err), IsTrue) // assert.Equal(t,ErrBadNumber.Equal(err), IsTrue)
} }
} }
......
...@@ -74,7 +74,7 @@ func GetMaxFloat(flen int, decimal int) float64 { ...@@ -74,7 +74,7 @@ func GetMaxFloat(flen int, decimal int) float64 {
func TruncateFloat(f float64, flen int, decimal int) (float64, error) { func TruncateFloat(f float64, flen int, decimal int) (float64, error) {
if math.IsNaN(f) { if math.IsNaN(f) {
// nan returns 0 // nan returns 0
//todo ErrOverflow.GenWithStackByArgs("DOUBLE", "") // todo ErrOverflow.GenWithStackByArgs("DOUBLE", "")
return 0, nil return 0, nil
} }
...@@ -87,12 +87,12 @@ func TruncateFloat(f float64, flen int, decimal int) (float64, error) { ...@@ -87,12 +87,12 @@ func TruncateFloat(f float64, flen int, decimal int) (float64, error) {
var err error var err error
if f > maxF { if f > maxF {
f = maxF f = maxF
//err = ErrOverflow.GenWithStackByArgs("DOUBLE", "") // err = ErrOverflow.GenWithStackByArgs("DOUBLE", "")
} else if f < -maxF { } else if f < -maxF {
f = -maxF f = -maxF
// err = ErrOverflow.GenWithStackByArgs("DOUBLE", "") // err = ErrOverflow.GenWithStackByArgs("DOUBLE", "")
} }
//todo errors.Trace(err) // todo errors.Trace(err)
return f, err return f, err
} }
......
...@@ -28,9 +28,7 @@ import ( ...@@ -28,9 +28,7 @@ import (
perrors "github.com/pkg/errors" perrors "github.com/pkg/errors"
) )
var ( var privateBlocks []*net.IPNet
privateBlocks []*net.IPNet
)
const ( const (
// Ipv4SplitCharacter use for slipt Ipv4 // Ipv4SplitCharacter use for slipt Ipv4
......
...@@ -36,9 +36,8 @@ import ( ...@@ -36,9 +36,8 @@ import (
"github.com/dubbogo/gost/path/filepath" "github.com/dubbogo/gost/path/filepath"
) )
var ( // CurrentPID returns the process id of the caller.
CurrentPID = os.Getpid() var CurrentPID = os.Getpid()
)
const ( const (
cgroupMemLimitPath = "/sys/fs/cgroup/memory/memory.limit_in_bytes" cgroupMemLimitPath = "/sys/fs/cgroup/memory/memory.limit_in_bytes"
......
...@@ -51,7 +51,7 @@ func TestSysStat(t *testing.T) { ...@@ -51,7 +51,7 @@ func TestSysStat(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("GetProcessMemoryStat() = error %+v", err) t.Errorf("GetProcessMemoryStat() = error %+v", err)
} }
//t.Logf("process memory usage stat %v", memoryStat) // t.Logf("process memory usage stat %v", memoryStat)
if memoryStat <= uint64(size) { if memoryStat <= uint64(size) {
t.Errorf("memory usage stat %d < %d", memoryStat, size) t.Errorf("memory usage stat %d < %d", memoryStat, size)
} }
......
...@@ -80,6 +80,7 @@ func TestTaskPoolSimple(t *testing.T) { ...@@ -80,6 +80,7 @@ func TestTaskPoolSimple(t *testing.T) {
}() }()
} }
wg.Wait() wg.Wait()
tp.Close()
cntValue := atomic.LoadInt64(cnt) cntValue := atomic.LoadInt64(cnt)
if taskCnt != cntValue { if taskCnt != cntValue {
...@@ -195,7 +196,7 @@ func BenchmarkTaskPoolSimple_RandomTask(b *testing.B) { ...@@ -195,7 +196,7 @@ func BenchmarkTaskPoolSimple_RandomTask(b *testing.B) {
func TestTaskPool(t *testing.T) { func TestTaskPool(t *testing.T) {
numCPU := runtime.NumCPU() numCPU := runtime.NumCPU()
//taskCnt := int64(numCPU * numCPU * 100) // taskCnt := int64(numCPU * numCPU * 100)
tp := NewTaskPool( tp := NewTaskPool(
WithTaskPoolTaskPoolSize(1), WithTaskPoolTaskPoolSize(1),
...@@ -203,7 +204,7 @@ func TestTaskPool(t *testing.T) { ...@@ -203,7 +204,7 @@ func TestTaskPool(t *testing.T) {
WithTaskPoolTaskQueueLength(1), WithTaskPoolTaskQueueLength(1),
) )
//task, cnt := newCountTask() // task, cnt := newCountTask()
task, _ := newCountTask() task, _ := newCountTask()
var wg sync.WaitGroup var wg sync.WaitGroup
...@@ -231,7 +232,7 @@ func BenchmarkTaskPool_CountTask(b *testing.B) { ...@@ -231,7 +232,7 @@ func BenchmarkTaskPool_CountTask(b *testing.B) {
tp := NewTaskPool( tp := NewTaskPool(
WithTaskPoolTaskPoolSize(runtime.NumCPU()), WithTaskPoolTaskPoolSize(runtime.NumCPU()),
WithTaskPoolTaskQueueNumber(runtime.NumCPU()), WithTaskPoolTaskQueueNumber(runtime.NumCPU()),
//WithTaskPoolTaskQueueLength(runtime.NumCPU()), // WithTaskPoolTaskQueueLength(runtime.NumCPU()),
) )
b.Run(`AddTask`, func(b *testing.B) { b.Run(`AddTask`, func(b *testing.B) {
...@@ -260,7 +261,6 @@ func BenchmarkTaskPool_CountTask(b *testing.B) { ...@@ -260,7 +261,6 @@ func BenchmarkTaskPool_CountTask(b *testing.B) {
} }
}) })
}) })
} }
// cpu-intensive task // cpu-intensive task
...@@ -268,7 +268,7 @@ func BenchmarkTaskPool_CPUTask(b *testing.B) { ...@@ -268,7 +268,7 @@ func BenchmarkTaskPool_CPUTask(b *testing.B) {
tp := NewTaskPool( tp := NewTaskPool(
WithTaskPoolTaskPoolSize(runtime.NumCPU()), WithTaskPoolTaskPoolSize(runtime.NumCPU()),
WithTaskPoolTaskQueueNumber(runtime.NumCPU()), WithTaskPoolTaskQueueNumber(runtime.NumCPU()),
//WithTaskPoolTaskQueueLength(runtime.NumCPU()), // WithTaskPoolTaskQueueLength(runtime.NumCPU()),
) )
b.Run(`fib`, func(b *testing.B) { b.Run(`fib`, func(b *testing.B) {
...@@ -306,7 +306,6 @@ func BenchmarkTaskPool_CPUTask(b *testing.B) { ...@@ -306,7 +306,6 @@ func BenchmarkTaskPool_CPUTask(b *testing.B) {
} }
}) })
}) })
} }
// IO-intensive task // IO-intensive task
...@@ -314,7 +313,7 @@ func BenchmarkTaskPool_IOTask(b *testing.B) { ...@@ -314,7 +313,7 @@ func BenchmarkTaskPool_IOTask(b *testing.B) {
tp := NewTaskPool( tp := NewTaskPool(
WithTaskPoolTaskPoolSize(runtime.NumCPU()), WithTaskPoolTaskPoolSize(runtime.NumCPU()),
WithTaskPoolTaskQueueNumber(runtime.NumCPU()), WithTaskPoolTaskQueueNumber(runtime.NumCPU()),
//WithTaskPoolTaskQueueLength(runtime.NumCPU()), // WithTaskPoolTaskQueueLength(runtime.NumCPU()),
) )
b.Run(`AddTask`, func(b *testing.B) { b.Run(`AddTask`, func(b *testing.B) {
...@@ -349,7 +348,7 @@ func BenchmarkTaskPool_RandomTask(b *testing.B) { ...@@ -349,7 +348,7 @@ func BenchmarkTaskPool_RandomTask(b *testing.B) {
tp := NewTaskPool( tp := NewTaskPool(
WithTaskPoolTaskPoolSize(runtime.NumCPU()), WithTaskPoolTaskPoolSize(runtime.NumCPU()),
WithTaskPoolTaskQueueNumber(runtime.NumCPU()), WithTaskPoolTaskQueueNumber(runtime.NumCPU()),
//WithTaskPoolTaskQueueLength(runtime.NumCPU()), // WithTaskPoolTaskQueueLength(runtime.NumCPU()),
) )
b.Run(`AddTask`, func(b *testing.B) { b.Run(`AddTask`, func(b *testing.B) {
...@@ -455,7 +454,7 @@ func TestWithPool(t *testing.T) { ...@@ -455,7 +454,7 @@ func TestWithPool(t *testing.T) {
tp := NewTaskPool( tp := NewTaskPool(
WithTaskPoolTaskPoolSize(1000), WithTaskPoolTaskPoolSize(1000),
WithTaskPoolTaskQueueNumber(2), WithTaskPoolTaskQueueNumber(2),
//WithTaskPoolTaskQueueLength(runtime.NumCPU()), // WithTaskPoolTaskQueueLength(runtime.NumCPU()),
) )
task, _ := newIOTask() task, _ := newIOTask()
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
...@@ -473,7 +472,7 @@ func TestWithPoolUseAlways(t *testing.T) { ...@@ -473,7 +472,7 @@ func TestWithPoolUseAlways(t *testing.T) {
tp := NewTaskPool( tp := NewTaskPool(
WithTaskPoolTaskPoolSize(1000), WithTaskPoolTaskPoolSize(1000),
WithTaskPoolTaskQueueNumber(10), WithTaskPoolTaskQueueNumber(10),
//WithTaskPoolTaskQueueLength(runtime.NumCPU()), // WithTaskPoolTaskQueueLength(runtime.NumCPU()),
) )
task, _ := newIOTask() task, _ := newIOTask()
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
......
...@@ -62,7 +62,7 @@ func TestAfter(t *testing.T) { ...@@ -62,7 +62,7 @@ func TestAfter(t *testing.T) {
) )
wheel = NewTimerWheel() wheel = NewTimerWheel()
//Init() // Init()
defer wheel.Stop() defer wheel.Stop()
...@@ -174,6 +174,6 @@ func TestTimer_Stop(t *testing.T) { ...@@ -174,6 +174,6 @@ func TestTimer_Stop(t *testing.T) {
time.Sleep(1e9) time.Sleep(1e9)
time.Sleep(TimeSecondDuration(0.01)) time.Sleep(TimeSecondDuration(0.01))
//assert.Equalf(t, 0, defaultTimerWheel.TimerNumber(), "after stop") // assert.Equalf(t, 0, defaultTimerWheel.TimerNumber(), "after stop")
time.Sleep(3e9) time.Sleep(3e9)
} }
...@@ -28,11 +28,9 @@ import ( ...@@ -28,11 +28,9 @@ import (
) )
func TestTickFunc(t *testing.T) { func TestTickFunc(t *testing.T) {
var (
//num int // num int
cw CountWatch var cw CountWatch // xassert *assert.Assertions
//xassert *assert.Assertions
)
InitDefaultTimerWheel() InitDefaultTimerWheel()
...@@ -40,14 +38,14 @@ func TestTickFunc(t *testing.T) { ...@@ -40,14 +38,14 @@ func TestTickFunc(t *testing.T) {
gxlog.CInfo("timer costs:%dms", cw.Count()/1e6) gxlog.CInfo("timer costs:%dms", cw.Count()/1e6)
} }
//num = 3 // num = 3
//xassert = assert.New(t) // xassert = assert.New(t)
cw.Start() cw.Start()
TickFunc(TimeSecondDuration(0.5), f) TickFunc(TimeSecondDuration(0.5), f)
TickFunc(TimeSecondDuration(1.3), f) TickFunc(TimeSecondDuration(1.3), f)
TickFunc(TimeSecondDuration(61.5), f) TickFunc(TimeSecondDuration(61.5), f)
time.Sleep(62e9) time.Sleep(62e9)
//xassert.Equal(defaultTimerWheel.TimerNumber(), num, "") // just equal in this ut // xassert.Equal(defaultTimerWheel.TimerNumber(), num, "") // just equal in this ut
} }
func TestTicker_Reset(t *testing.T) { func TestTicker_Reset(t *testing.T) {
...@@ -80,7 +78,7 @@ func TestTicker_Stop(t *testing.T) { ...@@ -80,7 +78,7 @@ func TestTicker_Stop(t *testing.T) {
var ( var (
ticker *Ticker ticker *Ticker
cw CountWatch cw CountWatch
//xassert assert.Assertions // xassert assert.Assertions
) )
InitDefaultTimerWheel() InitDefaultTimerWheel()
...@@ -93,12 +91,12 @@ func TestTicker_Stop(t *testing.T) { ...@@ -93,12 +91,12 @@ func TestTicker_Stop(t *testing.T) {
ticker = TickFunc(TimeSecondDuration(4.5), f) ticker = TickFunc(TimeSecondDuration(4.5), f)
// 添加是异步进行的,所以sleep一段时间再去检测timer number // 添加是异步进行的,所以sleep一段时间再去检测timer number
time.Sleep(TimeSecondDuration(0.001)) time.Sleep(TimeSecondDuration(0.001))
//timerNumber := defaultTimerWheel.TimerNumber() // timerNumber := defaultTimerWheel.TimerNumber()
//xassert.Equal(timerNumber, 1, "") // xassert.Equal(timerNumber, 1, "")
time.Sleep(TimeSecondDuration(5)) time.Sleep(TimeSecondDuration(5))
ticker.Stop() ticker.Stop()
// 删除是异步进行的,所以sleep一段时间再去检测timer number // 删除是异步进行的,所以sleep一段时间再去检测timer number
//time.Sleep(TimeSecondDuration(0.001)) // time.Sleep(TimeSecondDuration(0.001))
//timerNumber = defaultTimerWheel.TimerNumber() // timerNumber = defaultTimerWheel.TimerNumber()
//xassert.Equal(timerNumber, 0, "") // xassert.Equal(timerNumber, 0, "")
} }
...@@ -246,7 +246,7 @@ func NewTimerWheel() *TimerWheel { ...@@ -246,7 +246,7 @@ func NewTimerWheel() *TimerWheel {
func (w *TimerWheel) output() { func (w *TimerWheel) output() {
for idx := range w.slot { for idx := range w.slot {
log.Printf("print slot %d\n", idx) log.Printf("print slot %d\n", idx)
//w.slot[idx].Output() // w.slot[idx].Output()
} }
} }
...@@ -319,9 +319,7 @@ func (w *TimerWheel) insertSlot(idx int, node *timerNode) { ...@@ -319,9 +319,7 @@ func (w *TimerWheel) insertSlot(idx int, node *timerNode) {
} }
func (w *TimerWheel) deleteTimerNode(node *timerNode) { func (w *TimerWheel) deleteTimerNode(node *timerNode) {
var ( var level int
level int
)
LOOP: LOOP:
for level = range w.slot[:] { for level = range w.slot[:] {
...@@ -336,9 +334,7 @@ LOOP: ...@@ -336,9 +334,7 @@ LOOP:
} }
func (w *TimerWheel) resetTimerNode(node *timerNode) { func (w *TimerWheel) resetTimerNode(node *timerNode) {
var ( var level int
level int
)
LOOP: LOOP:
for level = range w.slot[:] { for level = range w.slot[:] {
...@@ -357,9 +353,7 @@ LOOP: ...@@ -357,9 +353,7 @@ LOOP:
} }
func (w *TimerWheel) deltaDiff(clock int64) int64 { func (w *TimerWheel) deltaDiff(clock int64) int64 {
var ( var handTime int64
handTime int64
)
for idx, hand := range w.hand[:] { for idx, hand := range w.hand[:] {
handTime += hand * msLimit[idx] handTime += hand * msLimit[idx]
......
...@@ -36,9 +36,7 @@ type Wheel struct { ...@@ -36,9 +36,7 @@ type Wheel struct {
} }
func NewWheel(span time.Duration, buckets int) *Wheel { func NewWheel(span time.Duration, buckets int) *Wheel {
var ( var w *Wheel
w *Wheel
)
if span == 0 { if span == 0 {
panic("@span == 0") panic("@span == 0")
...@@ -86,7 +84,7 @@ func (w *Wheel) After(timeout time.Duration) <-chan struct{} { ...@@ -86,7 +84,7 @@ func (w *Wheel) After(timeout time.Duration) <-chan struct{} {
panic("@timeout over ring's life period") panic("@timeout over ring's life period")
} }
var pos = int(timeout / w.span) pos := int(timeout / w.span)
if 0 < pos { if 0 < pos {
pos-- pos--
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment