示例#1
0
func BenchmarkBlockEncoder(b *testing.B) {
	f := origins.Fact{
		Domain: "testing",

		Operation: origins.Assertion,

		Transaction: 5,

		Time: chrono.Norm(time.Now()),

		Entity: &origins.Ident{
			Domain: "testing",
			Name:   "field",
		},

		Attribute: &origins.Ident{
			Domain: "testing",
			Name:   "dataType",
		},

		Value: &origins.Ident{
			Name: "string",
		},
	}

	encoder := NewBlockEncoder()

	for i := 0; i < b.N; i++ {
		encoder.Write(&f)
	}
}
示例#2
0
文件: dal_test.go 项目: l-k-/origins
func TestSegmentMethods(t *testing.T) {
	engine, _ := origins.Init("memory", nil)

	id := uuid.NewV4()
	next := uuid.NewV4()

	now := chrono.Norm(time.Now().UTC())

	s := Segment{
		UUID:        &id,
		Transaction: 10,
		Domain:      "testing",
		Time:        now,
		Blocks:      5,
		Count:       4800,
		Bytes:       460800,
		Next:        &next,
		Base:        &next,
	}

	_, err := SetSegment(engine, "testing", &s)

	if err != nil {
		t.Error(err)
	}

	s2, err := GetSegment(engine, "testing", &id)

	if err != nil {
		t.Error(err)
	}

	assert.Equal(t, s.Transaction, s2.Transaction)
	assert.Equal(t, *s.Next, *s2.Next)
}
示例#3
0
文件: dal_test.go 项目: l-k-/origins
func BenchmarkGetSegment(b *testing.B) {
	engine, _ := origins.Init("memory", nil)

	id := uuid.NewV4()
	next := uuid.NewV4()

	now := chrono.Norm(time.Now().UTC())

	s := &Segment{
		UUID:        &id,
		Transaction: 10,
		Domain:      "testing",
		Time:        now,
		Blocks:      5,
		Count:       4800,
		Bytes:       460800,
		Next:        &next,
		Base:        &next,
	}

	SetSegment(engine, "testing", s)

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		GetSegment(engine, "testing", &id)
	}
}
示例#4
0
func BenchmarkUnmarshalFact(b *testing.B) {
	f := &origins.Fact{
		Domain: "testing",

		Operation: origins.Assertion,

		Transaction: 5,

		Time: chrono.Norm(time.Now()),

		Entity: &origins.Ident{
			Domain: "testing",
			Name:   "field",
		},

		Attribute: &origins.Ident{
			Domain: "testing",
			Name:   "dataType",
		},

		Value: &origins.Ident{
			Name: "string",
		},
	}

	f2 := &origins.Fact{}

	m := &ProtoFact{}

	bf, _ := marshalFact(m, f)

	for i := 0; i < b.N; i++ {
		unmarshalFact(m, bf, "testing", 5, f2)
	}
}
示例#5
0
func TestBlockDecoder(t *testing.T) {
	f := origins.Fact{
		Domain: "testing",

		Operation: origins.Assertion,

		Transaction: 5,

		Time: chrono.Norm(time.Now()),

		Entity: &origins.Ident{
			Domain: "testing",
			Name:   "field",
		},

		Attribute: &origins.Ident{
			Domain: "testing",
			Name:   "dataType",
		},

		Value: &origins.Ident{
			Name: "string",
		},
	}

	encoder := NewBlockEncoder()

	for i := 0; i < 5; i++ {
		encoder.Write(&f)
	}

	// Initialize decoder with encoded bytes.
	decoder := NewBlockDecoder(encoder.Bytes(), "testing", 5)

	var n int

	for {
		fact := decoder.Next()

		if fact == nil {
			break
		}

		n++
	}

	if err := decoder.Err(); err != nil {
		t.Error(err)
	}

	if n != encoder.Count {
		t.Error("expected 5, got %d", n)
	}
}
示例#6
0
文件: dal_test.go 项目: l-k-/origins
func TestBlockMethods(t *testing.T) {
	engine, _ := origins.Init("memory", nil)

	id := uuid.NewV4()
	idx := 0

	f := &origins.Fact{
		Domain: "testing",

		Operation: origins.Assertion,

		Transaction: 5,

		Time: chrono.Norm(time.Now()),

		Entity: &origins.Ident{
			Domain: "testing",
			Name:   "field",
		},

		Attribute: &origins.Ident{
			Domain: "testing",
			Name:   "dataType",
		},

		Value: &origins.Ident{
			Name: "string",
		},
	}

	encoder := NewBlockEncoder()

	for i := 0; i < 1000; i++ {
		encoder.Write(f)
	}

	_, err := SetBlock(engine, "testing", &id, idx, encoder.Bytes())

	if err != nil {
		t.Error(err)
	}

	_, err = GetBlock(engine, "testing", &id, idx)

	if err != nil {
		t.Error(err)
	}
}
示例#7
0
func BenchmarkBlockDecoder(b *testing.B) {
	// Stop to do large initialization.
	b.StopTimer()

	f := &origins.Fact{
		Domain: "testing",

		Operation: origins.Assertion,

		Transaction: 5,

		Time: chrono.Norm(time.Now()),

		Entity: &origins.Ident{
			Domain: "testing",
			Name:   "field",
		},

		Attribute: &origins.Ident{
			Domain: "testing",
			Name:   "dataType",
		},

		Value: &origins.Ident{
			Name: "string",
		},
	}

	encoder := NewBlockEncoder()

	for i := 0; i < 2000000; i++ {
		encoder.Write(f)
	}

	// Initialize decoder with encoded bytes.
	decoder := NewBlockDecoder(encoder.Bytes(), "testing", 5)

	b.StartTimer()

	for i := 0; i < b.N; i++ {
		if f = decoder.Next(); f == nil {
			b.Error("decoder: ran out of facts")
			break
		}
	}
}
示例#8
0
文件: dal_test.go 项目: l-k-/origins
func BenchmarkGetBlock(b *testing.B) {
	engine, _ := origins.Init("memory", nil)

	id := uuid.NewV4()
	idx := 0

	f := &origins.Fact{
		Domain: "testing",

		Operation: origins.Assertion,

		Transaction: 5,

		Time: chrono.Norm(time.Now()),

		Entity: &origins.Ident{
			Domain: "testing",
			Name:   "field",
		},

		Attribute: &origins.Ident{
			Domain: "testing",
			Name:   "dataType",
		},

		Value: &origins.Ident{
			Name: "string",
		},
	}

	encoder := NewBlockEncoder()

	for i := 0; i < 1000; i++ {
		encoder.Write(f)
	}

	SetBlock(engine, "testing", &id, idx, encoder.Bytes())

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		GetBlock(engine, "testing", &id, idx)
	}
}
示例#9
0
func TestMarshalFact(t *testing.T) {
	f := origins.Fact{
		Domain: "testing",

		Operation: origins.Assertion,

		Transaction: 5,

		Time: chrono.Norm(time.Now()),

		Entity: &origins.Ident{
			Domain: "testing",
			Name:   "field",
		},

		Attribute: &origins.Ident{
			Domain: "testing",
			Name:   "dataType",
		},

		Value: &origins.Ident{
			Name: "string",
		},
	}

	m := ProtoFact{}

	b, err := marshalFact(&m, &f)

	if err != nil {
		t.Error(err)
	}

	f2 := origins.Fact{}

	if err = unmarshalFact(&m, b, "testing", 5, &f2); err != nil {
		t.Error(err)
	}

	assert.Equal(t, f.Operation, f2.Operation)
	assert.Equal(t, f.Time, f2.Time)
	assert.True(t, f.Entity.Is(f2.Entity))
	assert.True(t, f.Value.Is(f2.Value))
}
示例#10
0
func TestBlockEncoder(t *testing.T) {
	f := origins.Fact{
		Domain: "testing",

		Operation: origins.Assertion,

		Transaction: 5,

		Time: chrono.Norm(time.Now()),

		Entity: &origins.Ident{
			Domain: "testing",
			Name:   "field",
		},

		Attribute: &origins.Ident{
			Domain: "testing",
			Name:   "dataType",
		},

		Value: &origins.Ident{
			Name: "string",
		},
	}

	encoder := NewBlockEncoder()

	for i := 0; i < 5; i++ {
		if err := encoder.Write(&f); err != nil {
			t.Error(err)
		}
	}

	if encoder.Count != 5 {
		t.Error("expected 5, got %d", encoder.Count)
	}
}