Beispiel #1
0
func TestMultipleConstraintParse(t *testing.T) {
	qs, _ := graph.NewQuadStore("memstore", "", nil)
	w, _ := graph.NewQuadWriter("single", qs, nil)
	for _, tv := range []quad.Quad{
		{"i", "like", "food", ""},
		{"i", "like", "beer", ""},
		{"you", "like", "beer", ""},
	} {
		w.AddQuad(tv)
	}
	query := `(
		$a
		(:like :beer)
		(:like "food")
	)`
	it := BuildIteratorTreeForQuery(qs, query)
	if it.Type() != graph.And {
		t.Errorf("Odd iterator tree. Got: %#v", it.Describe())
	}
	if !graph.Next(it) {
		t.Error("Got no results")
	}
	out := it.Result()
	if out != qs.ValueOf("i") {
		t.Errorf("Got %d, expected %d", out, qs.ValueOf("i"))
	}
	if graph.Next(it) {
		t.Error("Too many results")
	}
}
Beispiel #2
0
func makeTestSession(data []quad.Quad) *Session {
	qs, _ := graph.NewQuadStore("memstore", "", nil)
	w, _ := graph.NewQuadWriter("single", qs, nil)
	for _, t := range data {
		w.AddQuad(t)
	}
	return NewSession(qs)
}
Beispiel #3
0
func makeTestStore(data []quad.Quad) graph.QuadStore {
	qs, _ := graph.NewQuadStore("memstore", "", nil)
	w, _ := graph.NewQuadWriter("single", qs, nil)
	for _, t := range data {
		w.AddQuad(t)
	}
	return qs
}
Beispiel #4
0
func OpenQuadWriter(qs graph.QuadStore, cfg *config.Config) (graph.QuadWriter, error) {
	glog.Infof("Opening replication method %q", cfg.ReplicationType)
	w, err := graph.NewQuadWriter(cfg.ReplicationType, qs, cfg.ReplicationOptions)
	if err != nil {
		return nil, err
	}

	return w, nil
}
Beispiel #5
0
func NewGraph(name, dbpath string, opts graph.Options) (*Handle, error) {
	qs, err := graph.NewQuadStore(name, dbpath, opts)
	if err != nil {
		return nil, err
	}
	qw, err := graph.NewQuadWriter("single", qs, nil)
	if err != nil {
		return nil, err
	}
	return &Handle{qs, qw}, nil
}
Beispiel #6
0
func TestTreeConstraintTagParse(t *testing.T) {
	qs, _ := graph.NewQuadStore("memstore", "", nil)
	w, _ := graph.NewQuadWriter("single", qs, nil)
	w.AddQuad(quad.Quad{"i", "like", "food", ""})
	w.AddQuad(quad.Quad{"food", "is", "good", ""})
	query := "(\"i\"\n" +
		"(:like\n" +
		"($a (:is :good))))"
	it := BuildIteratorTreeForQuery(qs, query)
	if !graph.Next(it) {
		t.Error("Got no results")
	}
	tags := make(map[string]graph.Value)
	it.TagResults(tags)
	if qs.NameOf(tags["$a"]) != "food" {
		t.Errorf("Got %s, expected food", qs.NameOf(tags["$a"]))
	}

}
Beispiel #7
0
func TestTreeConstraintParse(t *testing.T) {
	qs, _ := graph.NewQuadStore("memstore", "", nil)
	w, _ := graph.NewQuadWriter("single", qs, nil)
	w.AddQuad(quad.Quad{"i", "like", "food", ""})
	w.AddQuad(quad.Quad{"food", "is", "good", ""})
	query := "(\"i\"\n" +
		"(:like\n" +
		"($a (:is :good))))"
	it := BuildIteratorTreeForQuery(qs, query)
	if it.Type() != graph.And {
		t.Errorf("Odd iterator tree. Got: %#v", it.Describe())
	}
	if !graph.Next(it) {
		t.Error("Got no results")
	}
	out := it.Result()
	if out != qs.ValueOf("i") {
		t.Errorf("Got %d, expected %d", out, qs.ValueOf("i"))
	}
}
Beispiel #8
0
func TestMemstoreBackedSexp(t *testing.T) {
	qs, _ := graph.NewQuadStore("memstore", "", nil)
	w, _ := graph.NewQuadWriter("single", qs, nil)
	emptyIt := BuildIteratorTreeForQuery(qs, "()")
	if emptyIt.Type() != graph.Null {
		t.Errorf(`Incorrect type for empty query, got:%q expect: "null"`, emptyIt.Type())
	}
	for _, test := range testQueries {
		if test.add.IsValid() {
			w.AddQuad(test.add)
		}
		it := BuildIteratorTreeForQuery(qs, test.query)
		if it.Type() != test.typ {
			t.Errorf("Incorrect type for %s, got:%q expect %q", test.message, it.Type(), test.expect)
		}
		if !graph.Next(it) {
			t.Errorf("Failed to %s", test.message)
		}
		got := it.Result()
		if expect := qs.ValueOf(test.expect); got != expect {
			t.Errorf("Incorrect result for %s, got:%v expect %v", test.message, got, expect)
		}
	}
}