本文整理汇总了Golang中github.com/wandoulabs/codis/pkg/utils/assert.Must函数的典型用法代码示例。如果您正苦于以下问题:Golang Must函数的具体用法?Golang Must怎么用?Golang Must使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Must函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestProxyOfflineInWaitActionReceiver
func TestProxyOfflineInWaitActionReceiver(t *testing.T) {
log.Infof("test proxy offline when waiting action response")
fakeZkConn := zkhelper.NewConn()
for i := 1; i <= 4; i++ {
CreateProxyInfo(fakeZkConn, productName, &ProxyInfo{
Id: strconv.Itoa(i),
State: PROXY_STATE_ONLINE,
})
go waitForProxyMarkOffline(fakeZkConn, strconv.Itoa(i))
}
lst, _ := ProxyList(fakeZkConn, productName, nil)
assert.Must(len(lst) == 4)
go func() {
time.Sleep(500 * time.Millisecond)
actionPath := path.Join(GetActionResponsePath(productName), fakeZkConn.Seq2Str(1))
//create test response for proxy 4, means proxy 1,2,3 are timeout
fakeZkConn.Create(path.Join(actionPath, "4"), nil,
0, zkhelper.DefaultFileACLs())
}()
err := NewActionWithTimeout(fakeZkConn, productName, ACTION_TYPE_SLOT_CHANGED, nil, "desc", true, 3*1000)
if err != nil {
assert.Must(err.Error() == ErrReceiverTimeout.Error())
}
for i := 1; i <= 3; i++ {
info, _ := GetProxyInfo(fakeZkConn, productName, strconv.Itoa(i))
assert.Must(info.State == PROXY_STATE_OFFLINE)
}
}
开发者ID:cougar731,项目名称:codis,代码行数:33,代码来源:action_test.go
示例2: TestBytesizeError
func TestBytesizeError(t *testing.T) {
var err error
_, err = Parse("--1")
assert.Must(errors.Equal(err, ErrBadBytesize))
_, err = Parse("hello world")
assert.Must(errors.Equal(err, ErrBadBytesize))
_, err = Parse("123.132.32")
assert.Must(errors.Equal(err, ErrBadBytesize))
}
开发者ID:cougar731,项目名称:codis,代码行数:9,代码来源:bytesize_test.go
示例3: TestDecodeBulkBytes
func TestDecodeBulkBytes(t *testing.T) {
test := "*2\r\n$4\r\nLLEN\r\n$6\r\nmylist\r\n"
resp, err := DecodeFromBytes([]byte(test))
assert.MustNoError(err)
assert.Must(len(resp.Array) == 2)
s1 := resp.Array[0]
assert.Must(bytes.Equal(s1.Value, []byte("LLEN")))
s2 := resp.Array[1]
assert.Must(bytes.Equal(s2.Value, []byte("mylist")))
}
开发者ID:cougar731,项目名称:codis,代码行数:10,代码来源:decoder_test.go
示例4: TestDecodeInvalidRequests
func TestDecodeInvalidRequests(t *testing.T) {
test := []string{
"*hello\r\n",
"*-100\r\n",
"*3\r\nhi",
"*3\r\nhi\r\n",
"*4\r\n$1",
"*4\r\n$1\r",
"*4\r\n$1\n",
"*2\r\n$3\r\nget\r\n$what?\r\nx\r\n",
"*4\r\n$3\r\nget\r\n$1\r\nx\r\n",
"*2\r\n$3\r\nget\r\n$1\r\nx",
"*2\r\n$3\r\nget\r\n$1\r\nx\r",
"*2\r\n$3\r\nget\r\n$100\r\nx\r\n",
"$6\r\nfoobar\r",
"$0\rn\r\n",
"$-1\n",
"*0",
"*2n$3\r\nfoo\r\n$3\r\nbar\r\n",
"*-\r\n",
"+OK\n",
"-Error message\r",
}
for _, s := range test {
_, err := DecodeFromBytes([]byte(s))
assert.Must(err != nil)
}
}
开发者ID:cougar731,项目名称:codis,代码行数:28,代码来源:decoder_test.go
示例5: TestForceRemoveLock
func TestForceRemoveLock(t *testing.T) {
fakeZkConn := zkhelper.NewConn()
zkLock := utils.GetZkLock(fakeZkConn, productName)
assert.Must(zkLock != nil)
zkLock.Lock("force remove lock")
zkPath := fmt.Sprintf("/zk/codis/db_%s/LOCK", productName)
children, _, err := fakeZkConn.Children(zkPath)
assert.MustNoError(err)
assert.Must(len(children) != 0)
ForceRemoveLock(fakeZkConn, productName)
children, _, err = fakeZkConn.Children(zkPath)
assert.MustNoError(err)
assert.Must(len(children) == 0)
}
开发者ID:cougar731,项目名称:codis,代码行数:16,代码来源:action_test.go
示例6: newConnPair
func newConnPair() (*Conn, *Conn) {
l, err := net.Listen("tcp", "127.0.0.1:0")
assert.MustNoError(err)
defer l.Close()
const bufsize = 128 * 1024
cc := make(chan *Conn, 1)
go func() {
defer close(cc)
for {
c, err := l.Accept()
if err != nil {
return
}
cc <- NewConnSize(c, bufsize)
}
}()
conn1, err := DialTimeout(l.Addr().String(), bufsize, time.Millisecond*50)
assert.MustNoError(err)
conn2, ok := <-cc
assert.Must(ok)
return conn1, conn2
}
开发者ID:cougar731,项目名称:codis,代码行数:26,代码来源:conn_test.go
示例7: TestBtoi
func TestBtoi(t *testing.T) {
for i, b := range tmap {
v, err := btoi(b)
assert.MustNoError(err)
assert.Must(v == i)
}
}
开发者ID:cougar731,项目名称:codis,代码行数:7,代码来源:decoder_test.go
示例8: TestDecodeSimpleRequest3
func TestDecodeSimpleRequest3(t *testing.T) {
test := []string{"\r", "\n", " \n"}
for _, s := range test {
_, err := DecodeFromBytes([]byte(s))
assert.Must(err != nil)
}
}
开发者ID:cougar731,项目名称:codis,代码行数:7,代码来源:decoder_test.go
示例9: TestConnReaderTimeout
func TestConnReaderTimeout(t *testing.T) {
resp := NewString([]byte("hello world"))
conn1, conn2 := newConnPair()
defer func() {
connPool.Put(conn2)
}()
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
var err error
conn1.ReaderTimeout = time.Millisecond * 10
_, err = conn1.Reader.Decode()
assert.Must(err != nil && IsTimeout(err))
conn1.Reader.Err = nil
conn1.ReaderTimeout = 0
_, err = conn1.Reader.Decode()
assert.MustNoError(err)
_, err = conn1.Reader.Decode()
assert.Must(err != nil && errors.Equal(err, io.EOF))
}()
wg.Add(1)
go func() {
defer wg.Done()
var err error
time.Sleep(time.Millisecond * 100)
err = conn2.Writer.Encode(resp, true)
assert.MustNoError(err)
conn2.Close()
}()
wg.Wait()
conn1.Close()
conn2.Close()
}
开发者ID:leoYY,项目名称:codis,代码行数:46,代码来源:conn_test.go
示例10: TestBackend
func TestBackend(t *testing.T) {
l, err := net.Listen("tcp", "127.0.0.1:0")
assert.MustNoError(err)
defer l.Close()
addr := l.Addr().String()
reqc := make(chan *Request, 16384)
go func() {
bc := NewBackendConn(addr)
defer bc.Close()
defer close(reqc)
var resp = redis.NewBulkBytes(make([]byte, 4096))
for i := 0; i < cap(reqc); i++ {
r := &Request{
Resp: resp,
Wait: &sync.WaitGroup{},
}
r.Wait.Add(1)
bc.PushBack(r)
reqc <- r
}
}()
go func() {
c, err := l.Accept()
assert.MustNoError(err)
defer c.Close()
conn := redis.NewConn(c)
time.Sleep(time.Millisecond * 300)
for i := 0; i < cap(reqc); i++ {
_, err := conn.Reader.Decode()
assert.MustNoError(err)
resp := redis.NewString([]byte(strconv.Itoa(i)))
assert.MustNoError(conn.Writer.Encode(resp, true))
}
}()
var n int
for r := range reqc {
r.Wait.Wait()
assert.Must(string(r.Response.Resp.Value) == strconv.Itoa(n))
n++
}
assert.Must(n == cap(reqc))
}
开发者ID:cookiebus,项目名称:codis,代码行数:45,代码来源:backend_test.go
示例11: TestAddSlaveToEmptyGroup
func TestAddSlaveToEmptyGroup(t *testing.T) {
resetEnv()
g := NewServerGroup(productName, 1)
g.Create(conn)
s1 := NewServer(SERVER_TYPE_SLAVE, "127.0.0.1:1111")
err := g.AddServer(conn, s1)
assert.MustNoError(err)
assert.Must(g.Servers[0].Type == SERVER_TYPE_MASTER)
}
开发者ID:cookiebus,项目名称:codis,代码行数:10,代码来源:server_group_test.go
示例12: TestGetOpStr
func TestGetOpStr(t *testing.T) {
var m = map[string]string{
"get": "GET",
"aBc": "ABC",
"おはよ": "おはよ",
"ni hao!": "NI HAO!",
"": "",
}
for k, v := range m {
resp := redis.NewArray([]*redis.Resp{redis.NewBulkBytes([]byte(k))})
s, err := getOpStr(resp)
if v != "" {
assert.MustNoError(err)
assert.Must(s == v)
} else {
assert.Must(err != nil)
}
}
}
开发者ID:cougar731,项目名称:codis,代码行数:19,代码来源:mapper_test.go
示例13: TestDecodeSimpleRequest2
func TestDecodeSimpleRequest2(t *testing.T) {
test := []string{
"hello world\r\n",
"hello world \r\n",
" hello world \r\n",
" hello world\r\n",
" hello world \r\n",
}
for _, s := range test {
resp, err := DecodeFromBytes([]byte(s))
assert.MustNoError(err)
assert.Must(resp.IsArray())
assert.Must(len(resp.Array) == 2)
s1 := resp.Array[0]
assert.Must(bytes.Equal(s1.Value, []byte("hello")))
s2 := resp.Array[1]
assert.Must(bytes.Equal(s2.Value, []byte("world")))
}
}
开发者ID:cougar731,项目名称:codis,代码行数:19,代码来源:decoder_test.go
示例14: TestProxy
func TestProxy(t *testing.T) {
fakeZkConn := zkhelper.NewConn()
path := GetSlotBasePath(productName)
children, _, _ := fakeZkConn.Children(path)
assert.Must(len(children) == 0)
g := NewServerGroup(productName, 1)
g.Create(fakeZkConn)
// test create new group
_, err := ServerGroups(fakeZkConn, productName)
assert.MustNoError(err)
ok, err := g.Exists(fakeZkConn)
assert.MustNoError(err)
assert.Must(ok)
s1 := NewServer(SERVER_TYPE_MASTER, "localhost:1111")
g.AddServer(fakeZkConn, s1, "")
err = InitSlotSet(fakeZkConn, productName, 1024)
assert.MustNoError(err)
children, _, _ = fakeZkConn.Children(path)
assert.Must(len(children) == 1024)
s, err := GetSlot(fakeZkConn, productName, 1)
assert.MustNoError(err)
assert.Must(s.GroupId == -1)
err = SetSlotRange(fakeZkConn, productName, 0, 1023, 1, SLOT_STATUS_ONLINE)
assert.MustNoError(err)
pi := &ProxyInfo{
Id: "proxy_1",
Addr: "localhost:1234",
State: PROXY_STATE_OFFLINE,
}
_, err = CreateProxyInfo(fakeZkConn, productName, pi)
assert.MustNoError(err)
ps, err := ProxyList(fakeZkConn, productName, nil)
assert.MustNoError(err)
assert.Must(len(ps) == 1)
assert.Must(ps[0].Id == "proxy_1")
err = SetProxyStatus(fakeZkConn, productName, pi.Id, PROXY_STATE_ONLINE)
assert.MustNoError(err)
p, err := GetProxyInfo(fakeZkConn, productName, pi.Id)
assert.MustNoError(err)
assert.Must(p.State == PROXY_STATE_ONLINE)
}
开发者ID:cougar731,项目名称:codis,代码行数:56,代码来源:proxy_test.go
示例15: TestConnWriterTimeout
func TestConnWriterTimeout(t *testing.T) {
resp := NewString([]byte("hello world"))
conn1, conn2 := newConnPair()
defer func() {
connPool.Put(conn2)
}()
var wg sync.WaitGroup
var count atomic2.Int64
wg.Add(1)
go func() {
defer wg.Done()
defer conn2.Close()
conn2.WriterTimeout = time.Millisecond * 50
for {
if err := conn2.Writer.Encode(resp, true); err != nil {
assert.Must(IsTimeout(err))
return
}
count.Incr()
}
}()
wg.Wait()
for i := count.Get(); i != 0; i-- {
_, err := conn1.Reader.Decode()
assert.MustNoError(err)
}
_, err := conn1.Reader.Decode()
assert.Must(err != nil && errors.Equal(err, io.EOF))
conn1.Close()
conn2.Close()
}
开发者ID:leoYY,项目名称:codis,代码行数:39,代码来源:conn_test.go
示例16: TestSessions
func TestSessions(t *testing.T) {
cleanupSessions(time.Now().Unix() + 100000)
assert.Must(sessions.Len() == 0)
l, err := net.Listen("tcp", "127.0.0.1:0")
assert.MustNoError(err)
defer l.Close()
const cnt = 8
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < cnt; i++ {
c, err := l.Accept()
assert.MustNoError(err)
NewSession(c)
}
}()
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < cnt; i++ {
c, err := net.Dial("tcp", l.Addr().String())
assert.MustNoError(err)
NewSession(c)
}
}()
wg.Wait()
assert.Must(sessions.Len() == cnt*2)
cleanupSessions(time.Now().Unix() + 10)
assert.Must(sessions.Len() == 0)
}
开发者ID:cookiebus,项目名称:codis,代码行数:36,代码来源:session_test.go
示例17: TestNewAction
func TestNewAction(t *testing.T) {
fakeZkConn := zkhelper.NewConn()
err := NewAction(fakeZkConn, productName, ACTION_TYPE_SLOT_CHANGED, nil, "desc", false)
assert.MustNoError(err)
prefix := GetWatchActionPath(productName)
exist, _, err := fakeZkConn.Exists(prefix)
assert.MustNoError(err)
assert.Must(exist)
//test if response node exists
d, _, err := fakeZkConn.Get(prefix + "/0000000001")
assert.MustNoError(err)
//test get action data
d, _, err = fakeZkConn.Get(GetActionResponsePath(productName) + "/0000000001")
assert.MustNoError(err)
var action Action
err = json.Unmarshal(d, &action)
assert.MustNoError(err)
assert.Must(action.Desc == "desc")
assert.Must(action.Type == ACTION_TYPE_SLOT_CHANGED)
}
开发者ID:cougar731,项目名称:codis,代码行数:24,代码来源:action_test.go
示例18: TestHashSlot
func TestHashSlot(t *testing.T) {
var m = map[string]string{
"{abc}": "abc",
"{{{abc1}abc2}": "{{abc1",
"abc1{abc2{abc3}": "abc2{abc3",
"{{{{abc": "{{{{abc",
"{{{{abc}": "{{{abc",
"{{}{{abc": "{",
"abc}{abc": "abc}{abc",
"abc}{123}456": "123",
"123{abc}456": "abc",
"{}abc": "",
"abc{}123": "",
"123{456}": "456",
}
for k, v := range m {
i := hashSlot([]byte(k))
j := hashSlot([]byte(v))
assert.Must(i == j)
}
}
开发者ID:cougar731,项目名称:codis,代码行数:21,代码来源:mapper_test.go
示例19: TestServerGroup
func TestServerGroup(t *testing.T) {
resetEnv()
g := NewServerGroup(productName, 1)
g.Create(conn)
// test create new group
groups, err := ServerGroups(conn, productName)
assert.MustNoError(err)
assert.Must(len(groups) != 0)
ok, err := g.Exists(conn)
assert.MustNoError(err)
assert.Must(ok)
gg, err := GetGroup(conn, productName, 1)
assert.MustNoError(err)
assert.Must(gg != nil && gg.Id == g.Id)
s1 := NewServer(SERVER_TYPE_MASTER, "127.0.0.1:1111")
s2 := NewServer(SERVER_TYPE_MASTER, "127.0.0.1:2222")
err = g.AddServer(conn, s1)
servers, err := g.GetServers(conn)
assert.MustNoError(err)
assert.Must(len(servers) == 1)
g.AddServer(conn, s2)
assert.Must(len(g.Servers) == 1)
s2.Type = SERVER_TYPE_SLAVE
g.AddServer(conn, s2)
assert.Must(len(g.Servers) == 2)
err = g.Promote(conn, s2.Addr)
assert.MustNoError(err)
s, err := g.Master(conn)
assert.MustNoError(err)
assert.Must(s.Addr == s2.Addr)
}
开发者ID:cookiebus,项目名称:codis,代码行数:42,代码来源:server_group_test.go
示例20: TestItox
func TestItox(t *testing.T) {
for i := 0; i < len(itoamap)*2; i++ {
n, p := -i, i
assert.Must(strconv.Itoa(n) == itoa(int64(n)))
assert.Must(strconv.Itoa(p) == itoa(int64(p)))
assert.Must(strconv.Itoa(n) == string(itob(int64(n))))
assert.Must(strconv.Itoa(p) == string(itob(int64(p))))
}
tests := []int64{
math.MaxInt32, math.MinInt32,
math.MaxInt64, math.MinInt64,
}
for _, v := range tests {
assert.Must(strconv.FormatInt(v, 10) == itoa(int64(v)))
assert.Must(strconv.FormatInt(v, 10) == string(itob(int64(v))))
}
}
开发者ID:cookiebus,项目名称:codis,代码行数:17,代码来源:encoder_test.go
注:本文中的github.com/wandoulabs/codis/pkg/utils/assert.Must函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论