Пример #1
0
func BenchmarkEngineGet(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.Set(p, k, v)

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		e.Get(p, k)
	}
}
Пример #2
0
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)
	}
}
Пример #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))
	}
}