本文整理汇总了Golang中github.com/chop-dbhi/origins/storage.Engine类的典型用法代码示例。如果您正苦于以下问题:Golang Engine类的具体用法?Golang Engine怎么用?Golang Engine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Engine类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BenchmarkEngineIncr
func BenchmarkEngineIncr(b *testing.B, n string, e storage.Engine) {
p := "test"
k := "counter"
b.ResetTimer()
for i := 0; i < b.N; i++ {
e.Incr(p, k)
}
}
示例2: BenchmarkEngineSet
func BenchmarkEngineSet(b *testing.B, n string, e storage.Engine) {
p := "test"
k := "data"
// Mimicking a 1000 facts at 150 bytes each
v := randSeq(150 * 1000)
b.ResetTimer()
for i := 0; i < b.N; i++ {
e.Set(p, k, v)
}
}
示例3: BenchmarkTxIncr
func BenchmarkTxIncr(b *testing.B, n string, e storage.Engine) {
p := "test"
k := "counter"
e.Multi(func(tx storage.Tx) error {
b.ResetTimer()
for i := 0; i < b.N; i++ {
tx.Incr(p, k)
}
return nil
})
}
示例4: BenchmarkTxSet
func BenchmarkTxSet(b *testing.B, n string, e storage.Engine) {
p := "test"
k := "data"
// Mimicking a 1000 facts at 150 bytes each
v := randSeq(150 * 1000)
e.Multi(func(tx storage.Tx) error {
b.ResetTimer()
for i := 0; i < b.N; i++ {
tx.Set(p, k, v)
}
return nil
})
}
示例5: TestTx
func TestTx(t *testing.T, n string, e storage.Engine) {
p := "test"
k := "hello"
v := "world"
e.Multi(func(tx storage.Tx) error {
v = "bill"
if err := tx.Set(p, k, []byte(v)); err != nil {
t.Errorf("%s: set failed in tx", n)
}
return nil
})
// Ensure the value is visible outside of the transaction.
b, _ := e.Get(p, k)
if string(b) != v {
t.Errorf("%s: expected %s, got %s", n, v, string(b))
}
}
示例6: TestEngine
func TestEngine(t *testing.T, n string, e storage.Engine) {
p := "test"
k := "hello"
v := "world"
if err := e.Set(p, k, []byte(v)); err != nil {
t.Fatal(err)
}
b, err := e.Get(p, k)
if err != nil {
t.Fatal(err)
}
if string(b) != v {
t.Errorf("%s: expected %s, got %s", n, v, string(b))
}
id, err := e.Incr(p, "counter")
if err != nil {
t.Fatalf("%s: incr error %s", n, err)
}
if id != 1 {
t.Errorf("%s: expected 1, got %v", n, id)
}
id, err = e.Incr(p, "counter")
if err != nil {
t.Fatalf("%s: incr error %s", n, err)
}
if id != 2 {
t.Errorf("%s: expected 2, got %v", n, id)
}
if err = e.Delete(p, "counter"); err != nil {
t.Errorf("%s: %s", n, err)
}
if v, err := e.Get(p, "counter"); v != nil {
t.Errorf("%s: expected delete", n)
} else if err != nil {
t.Errorf("%s: %s", n, err)
}
}