예제 #1
0
func TestSegment(t *testing.T) {
	engine, err := origins.Init("mem", nil)

	segment := NewSegment(engine, "test", 1)

	gen := testutil.NewRandGenerator("test", 1, 0)

	var (
		f *origins.Fact
		n = 10000
	)

	// Write facts to segment.
	for i := 0; i < n; i++ {
		f = gen.Next()

		if err = segment.Write(f); err != nil {
			t.Fatal(err)
		}
	}

	// Compare counts.
	if segment.Count != n {
		t.Errorf("segment: expected %d count, got %d", n, segment.Count)
	}

	// Compare expected number of blocks.
	if segment.Blocks != n/blockSize {
		t.Errorf("segment: expected %d blocks, got %d", n/blockSize, segment.Blocks)
	}

	// Validate the blocks have been written to storage (even though the
	// data has been committed).
	id := segment.UUID

	for i := 0; i < segment.Blocks; i++ {
		bl, _ := dal.GetBlock(engine, "test", id, i)

		if bl == nil {
			t.Errorf("segment: block %s.%d is nil", id, i)
		}
	}

	// Abort the segment.
	if err = segment.Abort(engine); err != nil {
		t.Error("segment: abort failed %s", err)
	}

	for i := 0; i < segment.Blocks; i++ {
		bl, _ := dal.GetBlock(engine, "test", id, i)

		if bl != nil {
			t.Fatalf("segment: %s.%d should be nil", id, i)
		}
	}
}
예제 #2
0
파일: log_test.go 프로젝트: l-k-/origins
// Initializes an in-memory store and generates n transactions each with m
// randomly generated facts.
func randStorage(domain string, n, m int) storage.Engine {
	engine, _ := origins.Init("memory", nil)

	for i := 0; i < m; i++ {
		tx, _ := transactor.New(engine, transactor.Options{
			AllowDuplicates: true,
		})

		gen := testutil.NewRandGenerator(domain, tx.ID, n)

		origins.Copy(gen, tx)
		tx.Commit()
	}

	return engine
}
예제 #3
0
func benchSegmentSize(b *testing.B, n int) {
	engine, _ := origins.Init("mem", nil)

	var f *origins.Fact

	for i := 0; i < b.N; i++ {
		gen := testutil.NewRandGenerator("test", 1, n)
		segment := NewSegment(engine, "test", 1)

		for j := 0; j < n; j++ {
			f = gen.Next()
			segment.Write(f)
		}

		engine.Multi(func(tx storage.Tx) error {
			return segment.Commit(tx)
		})
	}
}
예제 #4
0
func benchSegmentBlockSize(b *testing.B, bs int) {
	engine, _ := origins.Init("mem", nil)

	blockSize = bs

	var f *origins.Fact

	gen := testutil.NewRandGenerator("test", 1, 0)

	segment := NewSegment(engine, "test", 1)

	for i := 0; i < b.N; i++ {
		f = gen.Next()
		segment.Write(f)
	}

	engine.Multi(func(tx storage.Tx) error {
		return segment.Commit(tx)
	})

	blockSize = 1000
}