Beispiel #1
0
func TestParseSexpWithMemstore(t *testing.T) {
	Convey("With a Memstore", t, func() {
		ts := graph_memstore.NewMemTripleStore()

		Convey("It should parse an empty query", func() {
			it := BuildIteratorTreeForQuery(ts, "()")
			So(it.Type(), ShouldEqual, "null")
		})

		Convey("It should get a single triple linkage", func() {
			ts.AddTriple(graph.MakeTriple("i", "can", "win", ""))
			query := "($a (:can \"win\"))"
			So(len(query), ShouldEqual, 17)
			it := BuildIteratorTreeForQuery(ts, query)
			So(it.Type(), ShouldEqual, "and")
			out, ok := it.Next()
			So(ok, ShouldBeTrue)
			So(out, ShouldEqual, ts.GetIdFor("i"))
		})

		Convey("It can get an internal linkage", func() {
			ts.AddTriple(graph.MakeTriple("i", "can", "win", ""))
			query := "(\"i\" (:can $a))"
			it := BuildIteratorTreeForQuery(ts, query)
			So(it.Type(), ShouldEqual, "and")
			out, ok := it.Next()
			So(ok, ShouldBeTrue)
			So(out, ShouldEqual, ts.GetIdFor("i"))
		})

	})
}
Beispiel #2
0
func init() {
	glog.SetToStderr(true)
	config := cayley_config.ParseConfigFromFile("cayley_appengine.cfg")
	ts := graph_memstore.NewMemTripleStore()
	glog.Errorln(config)
	LoadTriplesFromFileInto(ts, config.DatabasePath, config.LoadSize)
	cayley_http.SetupRoutes(ts, config)
}
Beispiel #3
0
func OpenTSFromConfig(config *cfg.CayleyConfig) graph.TripleStore {
	glog.Infof("Opening database \"%s\" at %s", config.DatabaseType, config.DatabasePath)
	switch config.DatabaseType {
	case "mongo", "mongodb":
		return graph_mongo.NewMongoTripleStore(config.DatabasePath, config.DatabaseOptions)
	case "leveldb":
		return graph_leveldb.NewDefaultLevelDBTripleStore(config.DatabasePath, config.DatabaseOptions)
	case "mem":
		ts := graph_memstore.NewMemTripleStore()
		CayleyLoad(ts, config, config.DatabasePath, true)
		return ts
	}
	panic("Unsupported database backend " + config.DatabaseType)
}
Beispiel #4
0
func TestTreeConstraintTagParse(t *testing.T) {
	ts := graph_memstore.NewMemTripleStore()
	ts.AddTriple(graph.MakeTriple("i", "like", "food", ""))
	ts.AddTriple(graph.MakeTriple("food", "is", "good", ""))
	query := "(\"i\"\n" +
		"(:like\n" +
		"($a (:is :good))))"
	it := BuildIteratorTreeForQuery(ts, query)
	_, ok := it.Next()
	if !ok {
		t.Error("Got no results")
	}
	tags := make(map[string]graph.TSVal)
	it.TagResults(&tags)
	if ts.GetNameFor(tags["$a"]) != "food" {
		t.Errorf("Got %s, expected food", ts.GetNameFor(tags["$a"]))
	}

}
Beispiel #5
0
func TestTreeConstraintParse(t *testing.T) {
	ts := graph_memstore.NewMemTripleStore()
	ts.AddTriple(graph.MakeTriple("i", "like", "food", ""))
	ts.AddTriple(graph.MakeTriple("food", "is", "good", ""))
	query := "(\"i\"\n" +
		"(:like\n" +
		"($a (:is :good))))"
	it := BuildIteratorTreeForQuery(ts, query)
	if it.Type() != "and" {
		t.Error("Odd iterator tree. Got: %s", it.DebugString(0))
	}
	out, ok := it.Next()
	if !ok {
		t.Error("Got no results")
	}
	if out != ts.GetIdFor("i") {
		t.Errorf("Got %d, expected %d", out, ts.GetIdFor("i"))
	}
}