当前位置: 首页>>代码示例>>Golang>>正文


Golang assert.MustNoError函数代码示例

本文整理汇总了Golang中github.com/wandoulabs/codis/pkg/utils/assert.MustNoError函数的典型用法代码示例。如果您正苦于以下问题:Golang MustNoError函数的具体用法?Golang MustNoError怎么用?Golang MustNoError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了MustNoError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: init

func init() {
	conn = zkhelper.NewConn()
	conf = &Config{
		proxyId:     "proxy_test",
		productName: "test",
		zkAddr:      "localhost:2181",
		fact:        func(string, int) (zkhelper.Conn, error) { return conn, nil },
		proto:       "tcp4",
	}

	//init action path
	prefix := models.GetWatchActionPath(conf.productName)
	err := models.CreateActionRootPath(conn, prefix)
	assert.MustNoError(err)

	//init slot
	err = models.InitSlotSet(conn, conf.productName, 1024)
	assert.MustNoError(err)

	//init  server group
	g1 := models.NewServerGroup(conf.productName, 1)
	g1.Create(conn)
	g2 := models.NewServerGroup(conf.productName, 2)
	g2.Create(conn)

	redis1, _ = miniredis.Run()
	redis2, _ = miniredis.Run()

	s1 := models.NewServer(models.SERVER_TYPE_MASTER, redis1.Addr())
	s2 := models.NewServer(models.SERVER_TYPE_MASTER, redis2.Addr())

	g1.AddServer(conn, s1, "")
	g2.AddServer(conn, s2, "")

	//set slot range
	err = models.SetSlotRange(conn, conf.productName, 0, 511, 1, models.SLOT_STATUS_ONLINE)
	assert.MustNoError(err)

	err = models.SetSlotRange(conn, conf.productName, 512, 1023, 2, models.SLOT_STATUS_ONLINE)
	assert.MustNoError(err)

	s = New(":19000", ":11000", conf)

	err = models.SetProxyStatus(conn, conf.productName, conf.proxyId, models.PROXY_STATE_ONLINE)
	assert.MustNoError(err)
}
开发者ID:cougar731,项目名称:codis,代码行数:46,代码来源:proxy_test.go

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: runFakeRedisSrv

func runFakeRedisSrv(addr string) {
	l, err := net.Listen("tcp", addr)
	assert.MustNoError(err)
	for {
		c, err := l.Accept()
		if err != nil {
			continue
		}

		go func(c net.Conn) {
			w := bufio.NewWriter(c)
			w.WriteString("+OK\r\n")
			w.Flush()
		}(c)
	}
}
开发者ID:cookiebus,项目名称:codis,代码行数:16,代码来源:server_group_test.go

示例13: TestMarkOffline

//this should be the last test
func TestMarkOffline(t *testing.T) {
	suicide := int64(0)
	go func() {
		s.Join()
		atomic.StoreInt64(&suicide, 1)
	}()

	err := models.SetProxyStatus(conn, conf.productName, conf.proxyId, models.PROXY_STATE_MARK_OFFLINE)
	assert.MustNoError(err)

	time.Sleep(3 * time.Second)

	if atomic.LoadInt64(&suicide) == 0 {
		t.Error("shoud be suicided")
	}
}
开发者ID:cougar731,项目名称:codis,代码行数:17,代码来源:proxy_test.go

示例14: 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

示例15: 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


注:本文中的github.com/wandoulabs/codis/pkg/utils/assert.MustNoError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。