Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gostnops
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
gostnops
Commits
5b49df32
Commit
5b49df32
authored
Mar 28, 2021
by
georgehao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: format gost use gofumpt
parent
9f1418de
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
106 additions
and
123 deletions
+106
-123
bytes_buffer_pool.go
bytes/bytes_buffer_pool.go
+1
-3
slice_pool.go
bytes/slice_pool.go
+1
-3
slice_pool_test.go
bytes/slice_pool_test.go
+1
-1
hashset.go
container/set/hashset.go
+3
-0
context.go
context/context.go
+1
-3
client.go
database/kv/etcd/v3/client.go
+3
-4
client_test.go
database/kv/etcd/v3/client_test.go
+0
-14
options.go
database/kv/etcd/v3/options.go
+5
-5
client.go
database/kv/zk/client.go
+4
-6
client_test.go
database/kv/zk/client_test.go
+0
-1
parser.go
encoding/json/parser.go
+1
-1
pretty_test.go
log/pretty_test.go
+3
-3
decimal.go
math/big/decimal.go
+6
-6
decimal_test.go
math/big/decimal_test.go
+43
-23
helper.go
math/big/helper.go
+3
-3
net.go
net/net.go
+1
-3
sys.go
runtime/sys.go
+1
-3
sys_test.go
runtime/sys_test.go
+1
-1
task_pool_test.go
sync/task_pool_test.go
+8
-10
sleep_test.go
time/sleep_test.go
+2
-2
ticker_test.go
time/ticker_test.go
+12
-14
timer.go
time/timer.go
+4
-10
wheel.go
time/wheel.go
+2
-4
No files found.
bytes/bytes_buffer_pool.go
View file @
5b49df32
...
@@ -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
{
...
...
bytes/slice_pool.go
View file @
5b49df32
...
@@ -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
()
...
...
bytes/slice_pool_test.go
View file @
5b49df32
...
@@ -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
)
}
}
}
}
...
...
container/set/hashset.go
View file @
5b49df32
...
@@ -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
...
...
context/context.go
View file @
5b49df32
...
@@ -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
{}
...
...
database/kv/etcd/v3/client.go
View file @
5b49df32
...
@@ -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"
)
...
@@ -199,7 +198,7 @@ func (c *Client) keepSessionLoop(s *concurrency.Session) {
...
@@ -199,7 +198,7 @@ func (c *Client) keepSessionLoop(s *concurrency.Session) {
}
}
}
}
//GetRawClient return etcd raw client
//
GetRawClient return etcd raw client
func
(
c
*
Client
)
GetRawClient
()
*
clientv3
.
Client
{
func
(
c
*
Client
)
GetRawClient
()
*
clientv3
.
Client
{
c
.
lock
.
RLock
()
c
.
lock
.
RLock
()
defer
c
.
lock
.
RUnlock
()
defer
c
.
lock
.
RUnlock
()
...
@@ -207,7 +206,7 @@ func (c *Client) GetRawClient() *clientv3.Client {
...
@@ -207,7 +206,7 @@ func (c *Client) GetRawClient() *clientv3.Client {
return
c
.
rawClient
return
c
.
rawClient
}
}
//GetEndPoints return etcd endpoints
//
GetEndPoints return etcd endpoints
func
(
c
*
Client
)
GetEndPoints
()
[]
string
{
func
(
c
*
Client
)
GetEndPoints
()
[]
string
{
return
c
.
endpoints
return
c
.
endpoints
}
}
...
@@ -285,7 +284,7 @@ func (c *Client) CleanKV() error {
...
@@ -285,7 +284,7 @@ func (c *Client) CleanKV() error {
return
err
return
err
}
}
//GetChildren return node children
//
GetChildren return node children
func
(
c
*
Client
)
GetChildren
(
k
string
)
([]
string
,
[]
string
,
error
)
{
func
(
c
*
Client
)
GetChildren
(
k
string
)
([]
string
,
[]
string
,
error
)
{
rawClient
:=
c
.
GetRawClient
()
rawClient
:=
c
.
GetRawClient
()
...
...
database/kv/etcd/v3/client_test.go
View file @
5b49df32
...
@@ -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
{
...
...
database/kv/etcd/v3/options.go
View file @
5b49df32
...
@@ -34,15 +34,15 @@ const (
...
@@ -34,15 +34,15 @@ const (
// Options client configuration
// Options client configuration
type
Options
struct
{
type
Options
struct
{
//Name etcd server name
//
Name etcd server name
Name
string
Name
string
//Endpoints etcd endpoints
//
Endpoints etcd endpoints
Endpoints
[]
string
Endpoints
[]
string
//Client etcd client
//
Client etcd client
Client
*
Client
Client
*
Client
//Timeout timeout
//
Timeout timeout
Timeout
time
.
Duration
Timeout
time
.
Duration
//Heartbeat second
//
Heartbeat second
Heartbeat
int
Heartbeat
int
}
}
...
...
database/kv/zk/client.go
View file @
5b49df32
...
@@ -73,8 +73,7 @@ type ZkEventHandler interface {
...
@@ -73,8 +73,7 @@ type ZkEventHandler interface {
}
}
// DefaultHandler is default handler for zk event
// DefaultHandler is default handler for zk event
type
DefaultHandler
struct
{
type
DefaultHandler
struct
{}
}
// StateToString will transfer zk state to string
// StateToString will transfer zk state to string
func
StateToString
(
state
zk
.
State
)
string
{
func
StateToString
(
state
zk
.
State
)
string
{
...
@@ -110,7 +109,7 @@ func initZookeeperClientPool() {
...
@@ -110,7 +109,7 @@ func initZookeeperClientPool() {
zkClientPool
.
zkClient
=
make
(
map
[
string
]
*
ZookeeperClient
)
zkClientPool
.
zkClient
=
make
(
map
[
string
]
*
ZookeeperClient
)
}
}
//NewZookeeperClient will create a ZookeeperClient
//
NewZookeeperClient will create a ZookeeperClient
func
NewZookeeperClient
(
name
string
,
zkAddrs
[]
string
,
share
bool
,
opts
...
zkClientOption
)
(
*
ZookeeperClient
,
error
)
{
func
NewZookeeperClient
(
name
string
,
zkAddrs
[]
string
,
share
bool
,
opts
...
zkClientOption
)
(
*
ZookeeperClient
,
error
)
{
if
share
{
if
share
{
clientPoolOnce
.
Do
(
initZookeeperClientPool
)
clientPoolOnce
.
Do
(
initZookeeperClientPool
)
...
@@ -371,7 +370,7 @@ func (z *ZookeeperClient) CreateTempWithValue(basePath string, value []byte) err
...
@@ -371,7 +370,7 @@ func (z *ZookeeperClient) CreateTempWithValue(basePath string, value []byte) err
return
nil
return
nil
}
}
//Delete will delete basePath
//
Delete will delete basePath
func
(
z
*
ZookeeperClient
)
Delete
(
basePath
string
)
error
{
func
(
z
*
ZookeeperClient
)
Delete
(
basePath
string
)
error
{
err
:=
ErrNilZkClientConn
err
:=
ErrNilZkClientConn
conn
:=
z
.
getConn
()
conn
:=
z
.
getConn
()
...
@@ -520,7 +519,7 @@ func (z *ZookeeperClient) GetContent(zkPath string) ([]byte, *zk.Stat, error) {
...
@@ -520,7 +519,7 @@ func (z *ZookeeperClient) GetContent(zkPath string) ([]byte, *zk.Stat, error) {
return
z
.
Conn
.
Get
(
zkPath
)
return
z
.
Conn
.
Get
(
zkPath
)
}
}
//SetContent set content of zkPath
//
SetContent set content of zkPath
func
(
z
*
ZookeeperClient
)
SetContent
(
zkPath
string
,
content
[]
byte
,
version
int32
)
(
*
zk
.
Stat
,
error
)
{
func
(
z
*
ZookeeperClient
)
SetContent
(
zkPath
string
,
content
[]
byte
,
version
int32
)
(
*
zk
.
Stat
,
error
)
{
return
z
.
Conn
.
Set
(
zkPath
,
content
,
version
)
return
z
.
Conn
.
Set
(
zkPath
,
content
,
version
)
}
}
...
@@ -564,5 +563,4 @@ func (z *ZookeeperClient) Close() {
...
@@ -564,5 +563,4 @@ func (z *ZookeeperClient) Close() {
conn
.
Close
()
conn
.
Close
()
}
}
}
}
}
}
database/kv/zk/client_test.go
View file @
5b49df32
...
@@ -137,7 +137,6 @@ func Test_newMockZookeeperClient(t *testing.T) {
...
@@ -137,7 +137,6 @@ func Test_newMockZookeeperClient(t *testing.T) {
}()
}()
states
:=
[]
zk
.
State
{
zk
.
StateConnecting
,
zk
.
StateConnected
,
zk
.
StateHasSession
}
states
:=
[]
zk
.
State
{
zk
.
StateConnecting
,
zk
.
StateConnected
,
zk
.
StateHasSession
}
verifyEventStateOrder
(
t
,
event
,
states
,
"event channel"
)
verifyEventStateOrder
(
t
,
event
,
states
,
"event channel"
)
}
}
func
TestCreate
(
t
*
testing
.
T
)
{
func
TestCreate
(
t
*
testing
.
T
)
{
...
...
encoding/json/parser.go
View file @
5b49df32
...
@@ -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
)
...
...
log/pretty_test.go
View file @
5b49df32
...
@@ -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
)
}
}
math/big/decimal.go
View file @
5b49df32
...
@@ -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
}
}
math/big/decimal_test.go
View file @
5b49df32
...
@@ -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)
}
}
}
}
...
...
math/big/helper.go
View file @
5b49df32
...
@@ -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
}
}
...
...
net/net.go
View file @
5b49df32
...
@@ -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
...
...
runtime/sys.go
View file @
5b49df32
...
@@ -36,9 +36,7 @@ import (
...
@@ -36,9 +36,7 @@ import (
"github.com/dubbogo/gost/path/filepath"
"github.com/dubbogo/gost/path/filepath"
)
)
var
(
var
CurrentPID
=
os
.
Getpid
()
CurrentPID
=
os
.
Getpid
()
)
const
(
const
(
cgroupMemLimitPath
=
"/sys/fs/cgroup/memory/memory.limit_in_bytes"
cgroupMemLimitPath
=
"/sys/fs/cgroup/memory/memory.limit_in_bytes"
...
...
runtime/sys_test.go
View file @
5b49df32
...
@@ -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
)
}
}
...
...
sync/task_pool_test.go
View file @
5b49df32
...
@@ -196,7 +196,7 @@ func BenchmarkTaskPoolSimple_RandomTask(b *testing.B) {
...
@@ -196,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
),
...
@@ -204,7 +204,7 @@ func TestTaskPool(t *testing.T) {
...
@@ -204,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
...
@@ -232,7 +232,7 @@ func BenchmarkTaskPool_CountTask(b *testing.B) {
...
@@ -232,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
)
{
...
@@ -261,7 +261,6 @@ func BenchmarkTaskPool_CountTask(b *testing.B) {
...
@@ -261,7 +261,6 @@ func BenchmarkTaskPool_CountTask(b *testing.B) {
}
}
})
})
})
})
}
}
// cpu-intensive task
// cpu-intensive task
...
@@ -269,7 +268,7 @@ func BenchmarkTaskPool_CPUTask(b *testing.B) {
...
@@ -269,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
)
{
...
@@ -307,7 +306,6 @@ func BenchmarkTaskPool_CPUTask(b *testing.B) {
...
@@ -307,7 +306,6 @@ func BenchmarkTaskPool_CPUTask(b *testing.B) {
}
}
})
})
})
})
}
}
// IO-intensive task
// IO-intensive task
...
@@ -315,7 +313,7 @@ func BenchmarkTaskPool_IOTask(b *testing.B) {
...
@@ -315,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
)
{
...
@@ -350,7 +348,7 @@ func BenchmarkTaskPool_RandomTask(b *testing.B) {
...
@@ -350,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
)
{
...
@@ -456,7 +454,7 @@ func TestWithPool(t *testing.T) {
...
@@ -456,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
++
{
...
@@ -474,7 +472,7 @@ func TestWithPoolUseAlways(t *testing.T) {
...
@@ -474,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
++
{
...
...
time/sleep_test.go
View file @
5b49df32
...
@@ -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
)
}
}
time/ticker_test.go
View file @
5b49df32
...
@@ -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, "")
}
}
time/timer.go
View file @
5b49df32
...
@@ -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
]
...
...
time/wheel.go
View file @
5b49df32
...
@@ -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
--
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment