本文整理汇总了Golang中github.com/reborndb/go/errors2.ErrorEqual函数的典型用法代码示例。如果您正苦于以下问题:Golang ErrorEqual函数的具体用法?Golang ErrorEqual怎么用?Golang ErrorEqual使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ErrorEqual函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestWriteAfterWriterClose
func (s *testIoPipeSuite) TestWriteAfterWriterClose(c *C) {
r, w := Pipe()
ss := "hello"
errs := make(chan error)
go func() {
_, err := ioutils.WriteFull(w, []byte(ss))
c.Assert(err, IsNil)
c.Assert(w.Close(), IsNil)
_, err = w.Write([]byte("world"))
errs <- err
}()
buf := make([]byte, 4096)
n, err := ioutils.ReadFull(r, buf)
c.Assert(errors2.ErrorEqual(err, io.EOF), Equals, true)
c.Assert(string(buf[:n]), Equals, ss)
err = <-errs
c.Assert(errors2.ErrorEqual(err, io.ErrClosedPipe), Equals, true)
c.Assert(r.Close(), IsNil)
}
开发者ID:CowLeo,项目名称:qdb,代码行数:25,代码来源:pipe_test.go
示例2: TestBytesizeError
func (s *testBytesizeSuite) TestBytesizeError(c *C) {
var err error
_, err = Parse("--1")
c.Assert(errors2.ErrorEqual(err, ErrBadBytesize), Equals, true)
_, err = Parse("hello world")
c.Assert(errors2.ErrorEqual(err, ErrBadBytesize), Equals, true)
_, err = Parse("123.132.32")
c.Assert(errors2.ErrorEqual(err, ErrBadBytesize), Equals, true)
}
开发者ID:CowLeo,项目名称:qdb,代码行数:9,代码来源:bytesize_test.go
示例3: Get
func (db *GoLevelDB) Get(key []byte) ([]byte, error) {
value, err := db.lvdb.Get(key, db.ropt)
if errors2.ErrorEqual(err, leveldb.ErrNotFound) {
return nil, nil
}
return value, errors.Trace(err)
}
开发者ID:CowLeo,项目名称:qdb,代码行数:7,代码来源:database.go
示例4: run
func (h *Handler) run() error {
log.Infof("open listen address '%s' and start service", h.l.Addr())
for {
if nc, err := h.l.Accept(); err != nil {
return errors.Trace(err)
} else {
h.counters.clientsAccepted.Add(1)
go func() {
h.counters.clients.Add(1)
defer h.counters.clients.Sub(1)
c := newConn(nc, h, h.config.ConnTimeout)
log.Infof("new connection: %s", c)
if err := c.serve(h); err != nil {
if errors2.ErrorEqual(err, io.EOF) {
log.Infof("connection lost: %s [io.EOF]", c)
} else {
log.Warningf("connection lost: %s, err = %s", c, err)
}
} else {
log.Infof("connection exit: %s", c)
}
}()
}
}
return nil
}
开发者ID:CowLeo,项目名称:qdb,代码行数:29,代码来源:main.go
示例5: TestPipeReadClose
func (s *testIoPipeSuite) TestPipeReadClose(c *C) {
for _, u := range pipeTests {
r, w := Pipe()
ch := make(chan int, 1)
if u.async {
go s.delayClose(c, w, ch, u)
} else {
s.delayClose(c, w, ch, u)
}
buf := make([]byte, 64)
n, err := r.Read(buf)
<-ch
expect := u.err
if expect == nil {
expect = io.EOF
}
c.Assert(errors2.ErrorEqual(err, expect), Equals, true)
c.Assert(n, Equals, 0)
c.Assert(r.Close(), IsNil)
}
}
开发者ID:CowLeo,项目名称:qdb,代码行数:25,代码来源:pipe_test.go
示例6: testPipe2
func (s *testIoPipeSuite) testPipe2(c *C, fileName string) {
r, w := s.openPipe(c, fileName)
cc := 1024 * 128
ss := "Hello world!!"
go func() {
for i := 0; i < cc; i++ {
m := fmt.Sprintf("[%d]%s ", i, ss)
_, err := ioutils.WriteFull(w, []byte(m))
c.Assert(err, IsNil)
}
c.Assert(w.Close(), IsNil)
}()
time.Sleep(time.Millisecond * 100)
buf := make([]byte, len(ss)*cc*2)
n, err := ioutils.ReadFull(r, buf)
c.Assert(errors2.ErrorEqual(err, io.EOF), Equals, true)
buf = buf[:n]
for i := 0; i < cc; i++ {
m := fmt.Sprintf("[%d]%s ", i, ss)
c.Assert(len(buf) >= len(m), Equals, true)
c.Assert(string(buf[:len(m)]), Equals, m)
buf = buf[len(m):]
}
c.Assert(len(buf), Equals, 0)
c.Assert(r.Close(), IsNil)
}
开发者ID:CowLeo,项目名称:qdb,代码行数:32,代码来源:pipe_test.go
示例7: Get
func (sp *Snapshot) Get(key []byte) ([]byte, error) {
value, err := sp.snap.Get(key, sp.ropt)
if errors2.ErrorEqual(err, leveldb.ErrNotFound) {
return nil, nil
}
return value, errors.Trace(err)
}
开发者ID:CowLeo,项目名称:qdb,代码行数:8,代码来源:snapshot.go
示例8: SetCmd
// SET key value [EX seconds] [PX milliseconds] [NX|XX]
func SetCmd(s Session, args [][]byte) (redis.Resp, error) {
if err := s.Store().Set(s.DB(), args); err != nil && errors2.ErrorNotEqual(err, store.ErrSetAborted) {
return toRespError(err)
} else if errors2.ErrorEqual(err, store.ErrSetAborted) {
return redis.NewBulkBytes(nil), nil
} else {
return redis.NewString("OK"), nil
}
}
开发者ID:CowLeo,项目名称:qdb,代码行数:10,代码来源:string.go
示例9: TestPipeReadClose2
func (s *testIoPipeSuite) TestPipeReadClose2(c *C) {
r, w := Pipe()
ch := make(chan int, 1)
go s.delayClose(c, r, ch, pipeTest{})
n, err := r.Read(make([]byte, 64))
<-ch
c.Assert(errors2.ErrorEqual(err, io.ErrClosedPipe), Equals, true)
c.Assert(n, Equals, 0)
c.Assert(w.Close(), IsNil)
}
开发者ID:CowLeo,项目名称:qdb,代码行数:14,代码来源:pipe_test.go
示例10: TestWriteNil
func (s *testIoPipeSuite) TestWriteNil(c *C) {
r, w := Pipe()
go func() {
_, err := w.Write(nil)
c.Assert(err, IsNil)
c.Assert(w.Close(), IsNil)
}()
buf := make([]byte, 4096)
n, err := ioutils.ReadFull(r, buf)
c.Assert(errors2.ErrorEqual(err, io.EOF), Equals, true)
c.Assert(n, Equals, 0)
c.Assert(r.Close(), IsNil)
}
开发者ID:CowLeo,项目名称:qdb,代码行数:15,代码来源:pipe_test.go
示例11: testPipe3
func (s *testIoPipeSuite) testPipe3(c *C, fileName string) {
r, w := s.openPipe(c, fileName)
ch := make(chan int)
size := 4096
go func() {
buf := make([]byte, size)
for {
n, err := r.Read(buf)
if errors2.ErrorEqual(err, io.EOF) {
break
}
c.Assert(err, IsNil)
ch <- n
}
c.Assert(r.Close(), IsNil)
ch <- 0
}()
go func() {
buf := make([]byte, size)
for i := 1; i < size; i++ {
n, err := ioutils.WriteFull(w, buf[:i])
c.Assert(err, IsNil)
c.Assert(n, Equals, i)
}
c.Assert(w.Close(), IsNil)
}()
sum := 0
for i := 1; i < size; i++ {
sum += i
}
for {
n := <-ch
if n == 0 {
break
}
sum -= n
}
c.Assert(sum, Equals, 0)
}
开发者ID:CowLeo,项目名称:qdb,代码行数:48,代码来源:pipe_test.go
示例12: testPipe4
func (s *testIoPipeSuite) testPipe4(c *C, fileName string) {
r, w := s.openPipe(c, fileName)
key := []byte("spinlock aes-128")
block := aes.BlockSize
count := 1024 * 1024 * 128 / block
go func() {
buf := make([]byte, count*block)
m, err := aes.NewCipher(key)
c.Assert(err, IsNil)
for i := 0; i < len(buf); i++ {
buf[i] = byte(i)
}
e := cipher.NewCBCEncrypter(m, make([]byte, block))
e.CryptBlocks(buf, buf)
n, err := ioutils.WriteFull(w, buf)
c.Assert(err, IsNil)
c.Assert(w.Close(), IsNil)
c.Assert(n, Equals, len(buf))
}()
buf := make([]byte, count*block)
m, err := aes.NewCipher(key)
c.Assert(err, IsNil)
_, err = ioutils.ReadFull(r, buf)
c.Assert(err, IsNil)
e := cipher.NewCBCDecrypter(m, make([]byte, block))
e.CryptBlocks(buf, buf)
for i := 0; i < len(buf); i++ {
// make gocheck faster
if buf[i] != byte(i) {
c.Assert(buf[i], Equals, byte(i))
}
}
_, err = ioutils.ReadFull(r, buf)
c.Assert(errors2.ErrorEqual(err, io.EOF), Equals, true)
c.Assert(r.Close(), IsNil)
}
开发者ID:CowLeo,项目名称:qdb,代码行数:47,代码来源:pipe_test.go
示例13: testPipe1
func (s *testIoPipeSuite) testPipe1(c *C, fileName string) {
r, w := s.openPipe(c, fileName)
ss := "Hello world!!"
go func(data []byte) {
_, err := ioutils.WriteFull(w, data)
c.Assert(err, IsNil)
c.Assert(w.Close(), IsNil)
}([]byte(ss))
buf := make([]byte, 64)
n, err := ioutils.ReadFull(r, buf)
c.Assert(errors2.ErrorEqual(err, io.EOF), Equals, true)
c.Assert(n, Equals, len(ss))
c.Assert(string(buf[:n]), Equals, ss)
c.Assert(r.Close(), IsNil)
}
开发者ID:CowLeo,项目名称:qdb,代码行数:18,代码来源:pipe_test.go
示例14: SetNX
// SETNX key value
func (s *Store) SetNX(db uint32, args [][]byte) (int64, error) {
if len(args) != 2 {
return 0, errArguments("len(args) = %d, expect = 2", len(args))
}
key := args[0]
value := args[1]
err := s.Set(db, [][]byte{key, value, []byte("NX")})
if err != nil {
// key exists
if errors2.ErrorEqual(err, ErrSetAborted) {
return 0, nil
} else {
return 0, err
}
}
return 1, nil
}
开发者ID:ksmaheshkumar,项目名称:qdb,代码行数:22,代码来源:string.go
示例15: travelInLexRange
// travel zset in lex range, call f in every iteration.
func (o *zsetRow) travelInLexRange(s *Store, r *lexRangeSpec, f func(o *zsetRow) error) error {
it := s.getIterator()
defer s.putIterator(it)
o.Score = math.Inf(-1)
o.Member = r.Min
it.SeekTo(o.IndexKey())
prefixKey := o.IndexKeyPrefix()
for ; it.Valid(); it.Next() {
key := it.Key()
if !bytes.HasPrefix(key, prefixKey) {
return nil
}
key = key[len(prefixKey):]
if err := o.ParseIndexKeySuffix(key); err != nil {
return errors.Trace(err)
}
if r.InRange(o.Member) {
if err := f(o); errors2.ErrorEqual(err, errTravelBreak) {
return nil
} else if err != nil {
return errors.Trace(err)
}
} else if !r.LteMax(o.Member) {
return nil
}
}
if err := it.Error(); err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:ksmaheshkumar,项目名称:qdb,代码行数:38,代码来源:zset.go
示例16: reverseTravelInLexRange
// reverse travel zset in lex range, call f in every iteration.
func (o *zsetRow) reverseTravelInLexRange(s *Store, r *lexRangeSpec, f func(o *zsetRow) error) error {
it := s.getIterator()
defer s.putIterator(it)
prefixKey := o.IndexKeyPrefix()
o.seekToLastInLexRange(it, r)
for ; it.Valid(); it.Prev() {
key := it.Key()
if !bytes.HasPrefix(key, prefixKey) {
return nil
}
key = key[len(prefixKey):]
if err := o.ParseIndexKeySuffix(key); err != nil {
return errors.Trace(err)
}
if r.InRange(o.Member) {
if err := f(o); errors2.ErrorEqual(err, errTravelBreak) {
return nil
} else if err != nil {
return errors.Trace(err)
}
} else if !r.GteMin(o.Member) {
return nil
}
}
if err := it.Error(); err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:ksmaheshkumar,项目名称:qdb,代码行数:37,代码来源:zset.go
示例17: run
// migrate multi slots
func (t *MigrateTask) run() error {
// create zk conn on demand
t.coordConn = CreateCoordConn()
defer t.coordConn.Close()
to := t.NewGroupId
t.Status = MIGRATE_TASK_MIGRATING
for slotId := t.FromSlot; slotId <= t.ToSlot; slotId++ {
err := t.migrateSingleSlot(slotId, to)
if errors2.ErrorEqual(err, ErrStopMigrateByUser) {
log.Info("stop migration job by user")
break
} else if err != nil {
log.Error(err)
t.Status = MIGRATE_TASK_ERR
return err
}
t.Percent = (slotId - t.FromSlot + 1) * 100 / (t.ToSlot - t.FromSlot + 1)
log.Info("total percent:", t.Percent)
}
t.Status = MIGRATE_TASK_FINISHED
log.Info("migration finished")
return nil
}
开发者ID:GavinHwa,项目名称:reborn,代码行数:25,代码来源:migrate_task.go
示例18: TestPipeWriteClose
func (s *testIoPipeSuite) TestPipeWriteClose(c *C) {
for _, u := range pipeTests {
r, w := Pipe()
ch := make(chan int, 1)
if u.async {
go s.delayClose(c, r, ch, u)
} else {
s.delayClose(c, r, ch, u)
}
<-ch
n, err := ioutils.WriteFull(w, []byte("hello, world"))
expect := u.err
if expect == nil {
expect = io.ErrClosedPipe
}
c.Assert(errors2.ErrorEqual(err, expect), Equals, true)
c.Assert(n, Equals, 0)
c.Assert(w.Close(), IsNil)
}
}
开发者ID:CowLeo,项目名称:qdb,代码行数:24,代码来源:pipe_test.go
注:本文中的github.com/reborndb/go/errors2.ErrorEqual函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论