Exemple #1
0
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
	})
}
Exemple #2
0
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
	})
}
Exemple #3
0
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))
	}
}