本文整理匯總了Golang中github.com/fcavani/e.Trace函數的典型用法代碼示例。如果您正苦於以下問題:Golang Trace函數的具體用法?Golang Trace怎麽用?Golang Trace使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Trace函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestFoo
func TestFoo(t *testing.T) {
err := instances.New("1", "5", reflect.ValueOf(&FooFactory{}), owners)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
ff := &FooFactoryClient{
Net: "tcp",
Addrs: server.Address().String(),
Auth: id,
Session: "1",
Instance: "5",
PointerRecv: true,
}
err = ff.Init(true)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
defer ff.CloseClient()
foo := ff.Make("test")
if err = ff.Error(); err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
if foo.String() != "foo:test" {
t.Fatal("foo returned the wrong string")
}
}
示例2: BenchmarkBoltDbBuffer
func BenchmarkBoltDbBuffer(b *testing.B) {
name, err := rand.FileName("boltdb", ".db", 10)
if err != nil {
b.Error(e.Trace(e.Forward(err)))
}
name = os.TempDir() + "/" + name
gob := &Gob{
TypeName: types.Name(&log{}),
}
bolt, err := NewBoltDb("test", name, 0600, nil, gob, gob)
if err != nil {
b.Error(e.Trace(e.Forward(err)))
}
logger := New(
NewOutBuffer(
NewGeneric(bolt).F(DefFormatter),
b.N/2,
),
false,
).Domain("test")
b.ResetTimer()
for i := 0; i < b.N; i++ {
logger.Print(msg)
b.SetBytes(l)
}
}
示例3: TestStruct1
func TestStruct1(t *testing.T) {
err := instances.New("1", "2", reflect.ValueOf(&Struct1{}), owners)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
s1 := &Struct1Client{
Net: "tcp",
Addrs: server.Address().String(),
Auth: id,
Session: "1",
Instance: "2",
PointerRecv: true,
}
str, err := s1.Func1()
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
if str == nil {
t.Fatal("nil str")
}
if *str != "string" {
t.Fatal("wrong string", *str)
}
err = s1.CloseClient()
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
}
示例4: TestEditPlainTextCredentials
func TestEditPlainTextCredentials(t *testing.T) {
ptc := NewPlainTextCredentials()
pt1 := &PlainText{"id", "pass1234"}
err := ptc.Add(pt1)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
pt1b := &PlainText{"id", "pass2345"}
err = ptc.Edit(pt1b)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
auth, err := ptc.Get("id")
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
if !auth.Auth(pt1b) {
t.Fatal("auth not equal")
}
pt2 := &PlainText{"id2", "pass2345"}
err = ptc.Edit(pt2)
if err != nil && !e.Equal(err, ErrCredNotExist) {
t.Fatal(e.Trace(e.Forward(err)))
}
}
示例5: TestGet
func TestGet(t *testing.T) {
inst, err := instances.Get("1", "1")
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
if inst.Instance().Type() != reflect.TypeOf(&teststruct{}) {
t.Fatal("get fail")
}
inst, err = instances.Get("1", "3")
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
if inst.Instance().Type() != reflect.TypeOf(&teststruct{}) {
t.Fatal("get fail")
}
_, err = instances.Get("1", "1")
if err != nil && !e.Equal(err, ErrAuthUserNotAuthorized) {
t.Fatal(e.Trace(e.Forward(err)))
}
_, err = instances.Get("2", "2")
if err != nil && !e.Equal(err, ErrSessionNotFound) {
t.Fatal(e.Trace(e.Forward(err)))
}
_, err = instances.Get("1", "2")
if err != nil && !e.Equal(err, ErrInstanceNotFound) {
t.Fatal(e.Trace(e.Forward(err)))
}
}
示例6: TestInitClones
func TestInitClones(t *testing.T) {
connPool = &clones{
Num: 1,
MaxNum: 5,
}
err := connPool.Init()
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
connPoolErr := &clones{
Num: 0,
MaxNum: 5,
}
err = connPoolErr.Init()
if err != nil && !e.Equal(err, "number of clones invalid") {
t.Fatal(e.Trace(e.Forward(err)))
} else if err == nil {
t.Fatal("nil error")
}
connPoolErr = &clones{
Num: 10,
MaxNum: 5,
}
err = connPoolErr.Init()
if err != nil && !e.Equal(err, "number of streams is greater than max") {
t.Fatal(e.Trace(e.Forward(err)))
} else if err == nil {
t.Fatal("nil error")
}
}
示例7: TestAuthSession
func TestAuthSession(t *testing.T) {
a := &auth.PlainText{"id3", "pass6969"}
err := instances.AuthSession("sess", a)
if err != nil && !e.Equal(err, ErrSessionNotFound) {
t.Fatal(e.Trace(e.Forward(err)))
} else if err == nil {
t.Fatal("error is nil")
}
err = instances.AuthSession("1", a)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
err = instances.AuthSession("1", &auth.PlainText{"id3", "pass69222269"})
if err != nil && !e.Equal(err, ErrAuthUserNotAuthorized) {
t.Fatal(e.Trace(e.Forward(err)))
} else if err == nil {
t.Fatal("error is nil")
}
err = instances.AuthSession("1", &auth.PlainText{"id4", "pass69222269"})
if err != nil && !e.Equal(err, ErrAuthUserNotAuthorized) {
t.Fatal(e.Trace(e.Forward(err)))
} else if err == nil {
t.Fatal("error is nil")
}
}
示例8: TestBigPriority
func TestBigPriority(t *testing.T) {
var numQueues uint64 = 1<<64 - 1
q := NewPriority(numQueues, func() (Queue, error) {
q := NewSimple(10, 1)
return q, nil
})
defer q.Stop()
q.Process()
job := job.NewSimple("name", numQueues-1, func() error {
delta, err := rand.Int63n(1000, "go")
if err != nil {
return e.Forward(err)
}
delta++
time.Sleep(time.Duration(delta) * time.Millisecond)
return nil
})
err := q.Add(job)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
job.Returns(&err)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
}
示例9: TestBarrierWriterReaderPartial
func TestBarrierWriterReaderPartial(t *testing.T) {
buf := NewBuffer()
defer buf.Close()
b, err := rand.Bytes(1e6, "go")
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
n, err := buf.Write(b)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
if n != len(b) {
t.Fatal("length invalid")
}
b2 := make([]byte, len(b))
count := 0
l := 100
for count < len(b) {
n, err = buf.Read(b2[count : count+l])
if err == io.EOF {
break
} else if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
count += n
}
if count != len(b) {
t.Fatal("length invalid", count, len(b))
}
if !bytes.Equal(b, b2) {
t.Fatal("not equal")
}
}
示例10: TestAddPlainTextCredentials
func TestAddPlainTextCredentials(t *testing.T) {
ptc := NewPlainTextCredentials()
pt1 := &PlainText{"id", "pass1234"}
pt1b := &PlainText{"id", "pass1234"}
pt2 := &PlainText{"id2", "pass2345"}
hash := &Hashed{"a", "b"}
err := ptc.Add(pt1)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
err = ptc.Add(pt2)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
err = ptc.Add(pt1b)
if err != nil && !e.Equal(err, ErrCredExist) {
t.Fatal(e.Trace(e.Forward(err)))
}
err = ptc.Add(hash)
if err != nil && !e.Equal(err, ErrNotComp) {
t.Fatal(e.Trace(e.Forward(err)))
}
}
示例11: TestValidate
func TestValidate(t *testing.T) {
ptc := NewPlainTextCredentials()
pt1 := &PlainText{"id", "passpass"}
pt2 := &PlainText{"id2", "passpass2"}
pt3 := &PlainText{"id3", "passpass2"}
pt1b := &PlainText{"id", "passpass2"}
err := ptc.Add(pt1)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
err = ptc.Add(pt2)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
err = ptc.Add(pt3)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
if err := Validate(ptc, pt1); err != nil {
t.Fatal("invalid")
}
if err := Validate(ptc, pt2); err != nil {
t.Fatal("invalid")
}
if err := Validate(ptc, pt3); err != nil {
t.Fatal("invalid")
}
if err := Validate(ptc, pt1b); err == nil {
t.Fatal("invalid")
}
}
示例12: TestProtoReqInst
func TestProtoReqInst(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
enc := msgpack.NewEncoder(buf)
dec := msgpack.NewDecoder(buf)
req := &ReqInst{
Inst: "inst",
Obj: "obj",
Args: []interface{}{"string", int(42)},
}
err := enc.Encode(req)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
recv := ReqInst{}
err = dec.Decode(&recv)
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
if recv.Inst != "inst" || recv.Obj != "obj" || len(recv.Args) != 2 || recv.Args[0].(string) != "string" || recv.Args[1].(int) != 42 {
t.Fatal("don't decode")
}
}
示例13: BenchmarkMongoDbBuffer
func BenchmarkMongoDbBuffer(b *testing.B) {
mongodb, err := NewMongoDb("mongodb://localhost/test", "test", nil, Log, 30*time.Second)
if err != nil {
b.Error(e.Trace(e.Forward(err)))
}
err = mongodb.Drop()
if err != nil {
b.Error(e.Trace(e.Forward(err)))
}
logger := New(
NewOutBuffer(
NewGeneric(mongodb).F(DefFormatter),
b.N/2,
),
false,
).Domain("test")
b.ResetTimer()
for i := 0; i < b.N; i++ {
logger.Print(msg)
b.SetBytes(l)
}
b.StopTimer()
err = mongodb.Drop()
if err != nil {
b.Error(e.Trace(e.Forward(err)))
}
}
示例14: put
func put(t *testing.T, s Storer, num int) {
err := s.Tx(true, func(tx Transaction) error {
var err error
for i := 0; i < num; i++ {
key := strconv.Itoa(i)
err = tx.Put(key, &TestStruct{I: i, Key: key})
if err != nil {
return err
}
}
err = tx.Put("3a", &TestStruct{I: 3, Key: "3a"})
if err != nil {
return err
}
err = tx.Put("3a", &TestStruct{I: 3, Key: "3a"})
if err != nil {
return err
}
return nil
})
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
l, err := s.Len()
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
if l != uint(num+1) {
t.Fatalf("wrong len %v %v", l, num)
}
}
示例15: del
func del(t *testing.T, s Storer, num int) {
err := s.Tx(true, func(tx Transaction) error {
var err error
for i := 0; i < num; i++ {
key := strconv.Itoa(i)
err = tx.Del(key)
if err != nil {
return err
}
}
err = tx.Del("3a")
if err != nil {
return err
}
return nil
})
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
l, err := s.Len()
if err != nil {
t.Fatal(e.Trace(e.Forward(err)))
}
if l != 0 {
t.Fatalf("something remining %v", l)
}
}