本文整理匯總了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)
}
}