Explorar o código

feat: Removing old integrations

Matthias Ladkau %!s(int64=4) %!d(string=hai) anos
pai
achega
3fe157712f

+ 0 - 152
integration/brawler/eventsource.go

@@ -1,152 +0,0 @@
-/*
- * EliasDB
- *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-/*
-Package brawler contains an eventsource for Brawler which forwards
-internal EliasDB events to Brawler engines.
-*/
-package brawler
-
-import (
-	"fmt"
-	"io"
-
-	"devt.de/krotik/common/defs/brawler"
-	"devt.de/krotik/eliasdb/graph"
-	"devt.de/krotik/eliasdb/graph/data"
-)
-
-/*
-AddEventPublisher adds an EventPublisher to a given Manager using an EventBridge.
-*/
-func AddEventPublisher(gm *graph.Manager, publisher brawler.EventPublisher, errOut io.Writer) {
-	gm.SetGraphRule(&EventBridge{publisher, errOut})
-}
-
-/*
-EventMapping is a mapping between EliasDB event types to Brawler event kinds.
-*/
-var EventMapping = map[int]string{
-
-	/*
-	   EventNodeCreated is thrown when a node gets created.
-
-	   Parameters: partition of created node, created node
-	*/
-	graph.EventNodeCreated: "db.node.created",
-
-	/*
-	   EventNodeUpdated is thrown when a node gets updated.
-
-	   Parameters: partition of updated node, updated node, old node
-	*/
-	graph.EventNodeUpdated: "db.node.updated",
-
-	/*
-	   EventNodeDeleted is thrown when a node gets deleted.
-
-	   Parameters: partition of deleted node, deleted node
-	*/
-	graph.EventNodeDeleted: "db.node.deleted",
-
-	/*
-	   EventEdgeCreated is thrown when an edge gets created.
-
-	   Parameters: partition of created edge, created edge
-	*/
-	graph.EventEdgeCreated: "db.edge.created",
-
-	/*
-	   EventEdgeUpdated is thrown when an edge gets updated.
-
-	   Parameters: partition of updated edge, updated edge, old edge
-	*/
-	graph.EventEdgeUpdated: "db.edge.updated",
-
-	/*
-	   EventEdgeDeleted is thrown when an edge gets deleted.
-
-	   Parameters: partition of deleted edge, deleted edge
-	*/
-	graph.EventEdgeDeleted: "db.edge.deleted",
-}
-
-// Event bridge between EliasDB and Brawler
-// ===========================================
-
-/*
-EventBridge is a rule for a graph manager to forward all graph events to
-Brawler.
-*/
-type EventBridge struct {
-	publisher brawler.EventPublisher
-	errOut    io.Writer
-}
-
-/*
-Name returns the name of the rule.
-*/
-func (r *EventBridge) Name() string {
-	return "brawler.eventbridge"
-}
-
-/*
-Handles returns a list of events which are handled by this rule.
-*/
-func (r *EventBridge) Handles() []int {
-	return []int{graph.EventNodeCreated, graph.EventNodeUpdated, graph.EventNodeDeleted,
-		graph.EventEdgeCreated, graph.EventEdgeUpdated, graph.EventEdgeDeleted}
-}
-
-/*
-Handle handles an event.
-*/
-func (r *EventBridge) Handle(gm *graph.Manager, trans graph.Trans, event int, ed ...interface{}) error {
-
-	if name, ok := EventMapping[event]; ok {
-
-		// Build up state
-
-		state := map[interface{}]interface{}{
-			"part": fmt.Sprint(ed[0]),
-		}
-
-		switch event {
-		case graph.EventNodeCreated:
-			state["node"] = ed[1].(data.Node)
-
-		case graph.EventNodeUpdated:
-			state["node"] = ed[1].(data.Node)
-			state["old_node"] = ed[2].(data.Node)
-
-		case graph.EventNodeDeleted:
-			state["node"] = ed[1].(data.Node)
-
-		case graph.EventEdgeCreated:
-			state["edge"] = ed[1].(data.Edge)
-
-		case graph.EventEdgeUpdated:
-			state["edge"] = ed[1].(data.Edge)
-			state["old_edge"] = ed[2].(data.Edge)
-
-		case graph.EventEdgeDeleted:
-			state["edge"] = ed[1].(data.Edge)
-		}
-
-		// Try to inject the event
-
-		err := r.publisher.AddEvent(name, []string{name}, state)
-		if err != nil && r.errOut != nil {
-			r.errOut.Write([]byte(err.Error()))
-		}
-	}
-
-	return nil
-}

+ 0 - 249
integration/brawler/eventsource_test.go

@@ -1,249 +0,0 @@
-/*
- * EliasDB
- *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-package brawler
-
-import (
-	"bytes"
-	"fmt"
-	"testing"
-
-	"devt.de/krotik/eliasdb/graph"
-	"devt.de/krotik/eliasdb/graph/data"
-	"devt.de/krotik/eliasdb/graph/graphstorage"
-)
-
-type mockEventPublisher struct {
-	buf bytes.Buffer
-	err error
-}
-
-func (p *mockEventPublisher) AddEvent(name string, kind []string, state map[interface{}]interface{}) error {
-	if p.err == nil {
-		p.buf.WriteString(fmt.Sprintf("%v-%v-%v-%v-%v-%v-%v", name, kind, state["part"], state["node"], state["edge"],
-			state["old_node"], state["old_edge"]))
-	}
-	return p.err
-}
-
-func TestEventSource(t *testing.T) {
-
-	ep := &mockEventPublisher{bytes.Buffer{}, nil}
-	log := bytes.Buffer{}
-
-	mgs := graphstorage.NewMemoryGraphStorage("iterator test")
-	gm := graph.NewGraphManager(mgs)
-
-	AddEventPublisher(gm, ep, &log)
-
-	if res := fmt.Sprint(gm.GraphRules()); res != "[brawler.eventbridge system.deletenodeedges system.updatenodestats]" {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	if res := fmt.Sprint(ep.buf.String()); res != `
-`[1:] {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	// Now generate some events
-
-	gm.StoreNode("main", data.NewGraphNodeFromMap(map[string]interface{}{
-		"key":  "foo",
-		"kind": "bar",
-	}))
-
-	if res := fmt.Sprint(ep.buf.String()); res != `
-db.node.created-[db.node.created]-main-GraphNode:
-     key : foo
-    kind : bar
--<nil>-<nil>-<nil>`[1:] {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	ep.err = fmt.Errorf("foo")
-
-	gm.StoreNode("main", data.NewGraphNodeFromMap(map[string]interface{}{
-		"key":  "foo",
-		"kind": "bar",
-	}))
-
-	if log.String() != "foo" {
-		t.Error("Expected some errors:", log.String())
-		return
-	}
-
-	ep.err = nil
-
-	node1 := data.NewGraphNode()
-	node1.SetAttr("key", "123")
-	node1.SetAttr("kind", "mykind")
-	node1.SetAttr("Name", "Node1")
-
-	gm.StoreNode("main", node1)
-
-	node2 := data.NewGraphNode()
-	node2.SetAttr("key", "456")
-	node2.SetAttr("kind", "mykind")
-	node2.SetAttr("Name", "Node2")
-
-	gm.StoreNode("main", node2)
-
-	node3 := data.NewGraphNode()
-	node3.SetAttr("key", "789")
-	node3.SetAttr("kind", "mykind")
-	node3.SetAttr("Name", "Node3")
-
-	gm.StoreNode("main", node3)
-
-	edge := data.NewGraphEdge()
-
-	edge.SetAttr("key", "abc")
-	edge.SetAttr("kind", "myedge")
-
-	edge.SetAttr(data.EdgeEnd1Key, node1.Key())
-	edge.SetAttr(data.EdgeEnd1Kind, node1.Kind())
-	edge.SetAttr(data.EdgeEnd1Role, "node1")
-	edge.SetAttr(data.EdgeEnd1Cascading, true)
-
-	edge.SetAttr(data.EdgeEnd2Key, node2.Key())
-	edge.SetAttr(data.EdgeEnd2Kind, node2.Kind())
-	edge.SetAttr(data.EdgeEnd2Role, "node2")
-	edge.SetAttr(data.EdgeEnd2Cascading, false)
-
-	gm.StoreEdge("main", edge)
-
-	if res := fmt.Sprint(ep.buf.String()); res != `
-db.node.created-[db.node.created]-main-GraphNode:
-     key : foo
-    kind : bar
--<nil>-<nil>-<nil>db.node.created-[db.node.created]-main-GraphNode:
-     key : 123
-    kind : mykind
-    Name : Node1
--<nil>-<nil>-<nil>db.node.created-[db.node.created]-main-GraphNode:
-     key : 456
-    kind : mykind
-    Name : Node2
--<nil>-<nil>-<nil>db.node.created-[db.node.created]-main-GraphNode:
-     key : 789
-    kind : mykind
-    Name : Node3
--<nil>-<nil>-<nil>db.edge.created-[db.edge.created]-main-<nil>-GraphEdge:
-              key : abc
-             kind : myedge
-    end1cascading : true
-          end1key : 123
-         end1kind : mykind
-         end1role : node1
-    end2cascading : false
-          end2key : 456
-         end2kind : mykind
-         end2role : node2
--<nil>-<nil>`[1:] {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	ep.buf.Reset()
-
-	// Do some updates
-
-	edge = data.NewGraphEdge()
-
-	edge.SetAttr("key", "abc")
-	edge.SetAttr("kind", "myedge")
-	edge.SetAttr("foo", "bar")
-	edge.SetAttr(data.EdgeEnd1Key, node1.Key())
-	edge.SetAttr(data.EdgeEnd1Kind, node1.Kind())
-	edge.SetAttr(data.EdgeEnd1Role, "node1")
-	edge.SetAttr(data.EdgeEnd1Cascading, true)
-
-	edge.SetAttr(data.EdgeEnd2Key, node2.Key())
-	edge.SetAttr(data.EdgeEnd2Kind, node2.Kind())
-	edge.SetAttr(data.EdgeEnd2Role, "node2")
-	edge.SetAttr(data.EdgeEnd2Cascading, false)
-
-	gm.StoreEdge("main", edge)
-
-	node1 = data.NewGraphNode()
-	node1.SetAttr("key", "123")
-	node1.SetAttr("kind", "mykind")
-	node1.SetAttr("Name", "Node66")
-
-	gm.StoreNode("main", node1)
-
-	if res := fmt.Sprint(ep.buf.String()); res != `
-db.edge.updated-[db.edge.updated]-main-<nil>-GraphEdge:
-              key : abc
-             kind : myedge
-    end1cascading : true
-          end1key : 123
-         end1kind : mykind
-         end1role : node1
-    end2cascading : false
-          end2key : 456
-         end2kind : mykind
-         end2role : node2
-              foo : bar
--<nil>-GraphEdge:
-              key : abc
-             kind : myedge
-    end1cascading : true
-          end1key : 123
-         end1kind : mykind
-         end1role : node1
-    end2cascading : false
-          end2key : 456
-         end2kind : mykind
-         end2role : node2
-db.node.updated-[db.node.updated]-main-GraphNode:
-     key : 123
-    kind : mykind
-    Name : Node66
--<nil>-GraphNode:
-     key : 123
-    kind : mykind
-    Name : Node1
--<nil>`[1:] {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	ep.buf.Reset()
-
-	// Do deletions
-
-	gm.RemoveNode("main", "456", "mykind") // This should also delete the edge
-
-	if res := fmt.Sprint(ep.buf.String()); res != `
-db.node.deleted-[db.node.deleted]-main-GraphNode:
-     key : 456
-    kind : mykind
-    Name : Node2
--<nil>-<nil>-<nil>db.edge.deleted-[db.edge.deleted]-main-<nil>-GraphEdge:
-              key : abc
-             kind : myedge
-    end1cascading : true
-          end1key : 123
-         end1kind : mykind
-         end1role : node1
-    end2cascading : false
-          end2key : 456
-         end2kind : mykind
-         end2role : node2
-              foo : bar
--<nil>-<nil>`[1:] {
-		t.Error("Unexpected result:", res)
-		return
-	}
-}

+ 0 - 334
integration/rumble/edge.go

@@ -1,334 +0,0 @@
-/*
- * EliasDB
- *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-/*
-Package rumble contains Rumble functions which interface with EliasDB.
-*/
-package rumble
-
-import (
-	"fmt"
-
-	"devt.de/krotik/common/defs/rumble"
-	"devt.de/krotik/eliasdb/api"
-	"devt.de/krotik/eliasdb/graph"
-	"devt.de/krotik/eliasdb/graph/data"
-)
-
-// Function: storeEdge
-// ===================
-
-/*
-StoreEdgeFunc inserts or updates an edge in EliasDB.
-*/
-type StoreEdgeFunc struct {
-}
-
-/*
-Name returns the name of the function.
-*/
-func (f *StoreEdgeFunc) Name() string {
-	return "db.storeEdge"
-}
-
-/*
-Validate is called for parameter validation and to reset the function state.
-*/
-func (f *StoreEdgeFunc) Validate(argsNum int, rt rumble.Runtime) rumble.RuntimeError {
-	var err rumble.RuntimeError
-
-	if argsNum != 2 && argsNum != 3 {
-		err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-			"Function storeEdge requires 2 or 3 parameters: partition, edge"+
-				" map and optionally a transaction")
-	}
-
-	return err
-}
-
-/*
-Execute executes the rumble function.
-*/
-func (f *StoreEdgeFunc) Execute(argsVal []interface{}, vars rumble.Variables,
-	rt rumble.Runtime) (interface{}, rumble.RuntimeError) {
-
-	var trans graph.Trans
-	var err rumble.RuntimeError
-
-	part := fmt.Sprint(argsVal[0])
-	nodeMap, ok := argsVal[1].(map[interface{}]interface{})
-
-	// Check parameters
-
-	if !ok {
-		err = rt.NewRuntimeError(rumble.ErrNotAMap,
-			"Second parameter must be a map")
-	}
-
-	if err == nil && len(argsVal) > 2 {
-		if trans, ok = argsVal[2].(graph.Trans); !ok {
-			err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-				"Third parameter must be a transaction")
-		}
-	}
-
-	// Build up node to store
-
-	edge := data.NewGraphEdgeFromNode(NewGraphNodeFromRumbleMap(nodeMap))
-
-	// Store the edge
-
-	if err == nil {
-
-		if trans != nil {
-			err = trans.StoreEdge(part, edge)
-		} else {
-			err = api.GM.StoreEdge(part, edge)
-		}
-
-		if err != nil {
-
-			// Wrap error message in RuntimeError
-
-			err = rt.NewRuntimeError(rumble.ErrInvalidState,
-				fmt.Sprintf("Cannot store edge: %v", err.Error()))
-		}
-	}
-
-	return nil, err
-}
-
-// Function: removeEdge
-// ====================
-
-/*
-RemoveEdgeFunc removes an edge in EliasDB.
-*/
-type RemoveEdgeFunc struct {
-}
-
-/*
-Name returns the name of the function.
-*/
-func (f *RemoveEdgeFunc) Name() string {
-	return "db.removeEdge"
-}
-
-/*
-Validate is called for parameter validation and to reset the function state.
-*/
-func (f *RemoveEdgeFunc) Validate(argsNum int, rt rumble.Runtime) rumble.RuntimeError {
-	var err rumble.RuntimeError
-
-	if argsNum != 3 && argsNum != 4 {
-		err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-			"Function removeEdge requires 3 or 4 parameters: partition, edge key,"+
-				" edge kind and optionally a transaction")
-	}
-
-	return err
-}
-
-/*
-Execute executes the rumble function.
-*/
-func (f *RemoveEdgeFunc) Execute(argsVal []interface{}, vars rumble.Variables,
-	rt rumble.Runtime) (interface{}, rumble.RuntimeError) {
-
-	var trans graph.Trans
-	var err rumble.RuntimeError
-
-	part := fmt.Sprint(argsVal[0])
-	key := fmt.Sprint(argsVal[1])
-	kind := fmt.Sprint(argsVal[2])
-
-	// Check parameters
-
-	if len(argsVal) > 3 {
-		var ok bool
-
-		if trans, ok = argsVal[3].(graph.Trans); !ok {
-			err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-				"Fourth parameter must be a transaction")
-		}
-	}
-
-	// Remove the edge
-
-	if err == nil {
-
-		if trans != nil {
-			err = trans.RemoveEdge(part, key, kind)
-		} else {
-			_, err = api.GM.RemoveEdge(part, key, kind)
-		}
-
-		if err != nil {
-
-			// Wrap error message in RuntimeError
-
-			err = rt.NewRuntimeError(rumble.ErrInvalidState,
-				fmt.Sprintf("Cannot remove edge: %v", err.Error()))
-		}
-	}
-
-	return nil, err
-}
-
-// Function: fetchEdge
-// ===================
-
-/*
-FetchEdgeFunc fetches an edge in EliasDB.
-*/
-type FetchEdgeFunc struct {
-}
-
-/*
-Name returns the name of the function.
-*/
-func (f *FetchEdgeFunc) Name() string {
-	return "db.fetchEdge"
-}
-
-/*
-Validate is called for parameter validation and to reset the function state.
-*/
-func (f *FetchEdgeFunc) Validate(argsNum int, rt rumble.Runtime) rumble.RuntimeError {
-	var err rumble.RuntimeError
-
-	if argsNum != 3 {
-		err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-			"Function fetchEdge requires 3 parameters: partition, edge key and"+
-				" edge kind")
-	}
-
-	return err
-}
-
-/*
-Execute executes the rumble function.
-*/
-func (f *FetchEdgeFunc) Execute(argsVal []interface{}, vars rumble.Variables,
-	rt rumble.Runtime) (interface{}, rumble.RuntimeError) {
-
-	var node data.Node
-	var res interface{}
-	var err rumble.RuntimeError
-
-	part := fmt.Sprint(argsVal[0])
-	key := fmt.Sprint(argsVal[1])
-	kind := fmt.Sprint(argsVal[2])
-
-	conv := func(m map[string]interface{}) map[interface{}]interface{} {
-		c := make(map[interface{}]interface{})
-		for k, v := range m {
-			c[k] = v
-		}
-		return c
-	}
-
-	// Fetch the node
-
-	if node, err = api.GM.FetchEdge(part, key, kind); node != nil {
-		res = conv(node.Data())
-	}
-
-	if err != nil {
-
-		// Wrap error message in RuntimeError
-
-		err = rt.NewRuntimeError(rumble.ErrInvalidState,
-			fmt.Sprintf("Cannot fetch edge: %v", err.Error()))
-	}
-
-	return res, err
-}
-
-// Function: traverse
-// ==================
-
-/*
-TraverseFunc traverses an edge in EliasDB.
-*/
-type TraverseFunc struct {
-}
-
-/*
-Name returns the name of the function.
-*/
-func (f *TraverseFunc) Name() string {
-	return "db.traverse"
-}
-
-/*
-Validate is called for parameter validation and to reset the function state.
-*/
-func (f *TraverseFunc) Validate(argsNum int, rt rumble.Runtime) rumble.RuntimeError {
-	var err rumble.RuntimeError
-
-	if argsNum != 4 {
-		err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-			"Function traverse requires 4 parameters: partition, node key,"+
-				" node kind and a traversal spec")
-	}
-
-	return err
-}
-
-/*
-Execute executes the rumble function.
-*/
-func (f *TraverseFunc) Execute(argsVal []interface{}, vars rumble.Variables,
-	rt rumble.Runtime) (interface{}, rumble.RuntimeError) {
-
-	var nodes []data.Node
-	var edges []data.Edge
-	var res interface{}
-	var err rumble.RuntimeError
-
-	part := fmt.Sprint(argsVal[0])
-	key := fmt.Sprint(argsVal[1])
-	kind := fmt.Sprint(argsVal[2])
-	spec := fmt.Sprint(argsVal[3])
-
-	conv := func(m map[string]interface{}) map[interface{}]interface{} {
-		c := make(map[interface{}]interface{})
-		for k, v := range m {
-			c[k] = v
-		}
-		return c
-	}
-
-	// Do the traversal
-
-	if nodes, edges, err = api.GM.TraverseMulti(part, key, kind, spec, true); err == nil {
-
-		resNodes := make([]interface{}, len(nodes))
-		for i, n := range nodes {
-			resNodes[i] = conv(n.Data())
-		}
-		resEdges := make([]interface{}, len(edges))
-		for i, e := range edges {
-			resEdges[i] = conv(e.Data())
-		}
-		res = []interface{}{resNodes, resEdges}
-	}
-
-	if err != nil {
-
-		// Wrap error message in RuntimeError
-
-		err = rt.NewRuntimeError(rumble.ErrInvalidState,
-			fmt.Sprintf("Cannot traverse: %v", err.Error()))
-	}
-
-	return res, err
-}

+ 0 - 369
integration/rumble/edge_test.go

@@ -1,369 +0,0 @@
-/*
- * EliasDB
- *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-package rumble
-
-import (
-	"fmt"
-	"testing"
-
-	"devt.de/krotik/eliasdb/api"
-	"devt.de/krotik/eliasdb/graph"
-	"devt.de/krotik/eliasdb/graph/data"
-	"devt.de/krotik/eliasdb/graph/graphstorage"
-)
-
-func TestStoreAndRemoveEdge(t *testing.T) {
-
-	mr := &mockRuntime{}
-	mgs := graphstorage.NewMemoryGraphStorage("mystorage")
-	gm := graph.NewGraphManager(mgs)
-
-	api.GM = gm
-
-	se := &StoreEdgeFunc{}
-
-	if se.Name() != "db.storeEdge" {
-		t.Error("Unexpected result:", se.Name())
-		return
-	}
-
-	if err := se.Validate(2, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if err := se.Validate(3, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if err := se.Validate(1, mr); err == nil || err.Error() != "Invalid construct Function storeEdge requires 2 or 3 parameters: partition, edge map and optionally a transaction" {
-		t.Error(err)
-		return
-	}
-
-	if _, err := se.Execute([]interface{}{"main", map[interface{}]interface{}{
-		"key": "foo",
-	}}, nil, mr); err == nil || err.Error() != "Invalid state Cannot store edge: GraphError: Invalid data (Edge is missing a kind value)" {
-		t.Error(err)
-		return
-	}
-
-	if _, err := se.Execute([]interface{}{"main", "x"}, nil, mr); err == nil || err.Error() != "Operand is not a map Second parameter must be a map" {
-		t.Error(err)
-		return
-	}
-
-	if _, err := se.Execute([]interface{}{"main", map[interface{}]interface{}{
-		"key": "foo",
-	}, "x"}, nil, mr); err == nil || err.Error() != "Invalid construct Third parameter must be a transaction" {
-		t.Error(err)
-		return
-	}
-
-	gm.StoreNode("main", data.NewGraphNodeFromMap(map[string]interface{}{
-		"key":  "a",
-		"kind": "b",
-	}))
-	gm.StoreNode("main", data.NewGraphNodeFromMap(map[string]interface{}{
-		"key":  "c",
-		"kind": "d",
-	}))
-
-	_, err := se.Execute([]interface{}{"main", map[interface{}]interface{}{
-		"key":           "123",
-		"kind":          "e",
-		"end1cascading": true,
-		"end1key":       "a",
-		"end1kind":      "b",
-		"end1role":      "role1",
-		"end2cascading": false,
-		"end2key":       "c",
-		"end2kind":      "d",
-		"end2role":      "role2",
-	}}, nil, mr)
-
-	if err != nil {
-		t.Error(err)
-		return
-	}
-
-	_, err = se.Execute([]interface{}{"main", map[interface{}]interface{}{
-		"key":           "123",
-		"kind":          "e",
-		"end1cascading": true,
-		"end1key":       "a",
-		"end1kind":      "b1",
-		"end1role":      "role1",
-		"end2cascading": false,
-		"end2key":       "c",
-		"end2kind":      "d",
-		"end2role":      "role2",
-	}}, nil, mr)
-
-	if err == nil || err.Error() != "Invalid state Cannot store edge: GraphError: Invalid data (Can't store edge to non-existing node kind: b1)" {
-		t.Error(err)
-		return
-	}
-
-	fe := &FetchEdgeFunc{}
-
-	if fe.Name() != "db.fetchEdge" {
-		t.Error("Unexpected result:", fe.Name())
-		return
-	}
-
-	if err := fe.Validate(3, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if err := fe.Validate(1, mr); err == nil || err.Error() != "Invalid construct Function fetchEdge requires 3 parameters: partition, edge key and edge kind" {
-		t.Error(err)
-		return
-	}
-
-	if _, err := fe.Execute([]interface{}{"mai n", "123", "e"}, nil, mr); err == nil || err.Error() !=
-		"Invalid state Cannot fetch edge: GraphError: Invalid data (Partition name mai n is not alphanumeric - can only contain [a-zA-Z0-9_])" {
-		t.Error(err)
-		return
-	}
-
-	res, err := fe.Execute([]interface{}{"main", "123", "e"}, nil, mr)
-	if fmt.Sprint(data.NewGraphEdgeFromNode(NewGraphNodeFromRumbleMap(res.(map[interface{}]interface{})))) != `
-GraphEdge:
-              key : 123
-             kind : e
-    end1cascading : true
-          end1key : a
-         end1kind : b
-         end1role : role1
-    end2cascading : false
-          end2key : c
-         end2kind : d
-         end2role : role2
-`[1:] || err != nil {
-		t.Error("Unexpected result:", fmt.Sprint(data.NewGraphEdgeFromNode(NewGraphNodeFromRumbleMap(res.(map[interface{}]interface{})))), err)
-		return
-	}
-
-	tr := &TraverseFunc{}
-
-	if tr.Name() != "db.traverse" {
-		t.Error("Unexpected result:", tr.Name())
-		return
-	}
-
-	if err := tr.Validate(4, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if err := tr.Validate(1, mr); err == nil || err.Error() != "Invalid construct Function traverse requires 4 parameters: partition, node key, node kind and a traversal spec" {
-		t.Error(err)
-		return
-	}
-
-	_, err = tr.Execute([]interface{}{"main", "c", "d", "::"}, nil, mr)
-	if err == nil || err.Error() != "Invalid state Cannot traverse: GraphError: Invalid data (Invalid spec: ::)" {
-		t.Error(err)
-		return
-	}
-
-	res, err = tr.Execute([]interface{}{"main", "c", "d", ":::"}, nil, mr)
-	if err != nil {
-		t.Error(err)
-		return
-	}
-
-	if fmt.Sprint(data.NewGraphEdgeFromNode(NewGraphNodeFromRumbleMap(res.([]interface{})[1].([]interface{})[0].(map[interface{}]interface{})))) != `
-GraphEdge:
-              key : 123
-             kind : e
-    end1cascading : false
-          end1key : c
-         end1kind : d
-         end1role : role2
-    end2cascading : true
-          end2key : a
-         end2kind : b
-         end2role : role1
-`[1:] || err != nil {
-		t.Error("Unexpected result:", fmt.Sprint(data.NewGraphEdgeFromNode(NewGraphNodeFromRumbleMap(res.([]interface{})[1].([]interface{})[0].(map[interface{}]interface{})))), err)
-		return
-	}
-
-	if fmt.Sprint(NewGraphNodeFromRumbleMap(res.([]interface{})[0].([]interface{})[0].(map[interface{}]interface{}))) != `
-GraphNode:
-     key : a
-    kind : b
-`[1:] || err != nil {
-		t.Error("Unexpected result:", fmt.Sprint(NewGraphNodeFromRumbleMap(res.([]interface{})[0].([]interface{})[0].(map[interface{}]interface{}))), err)
-		return
-	}
-
-	re := &RemoveEdgeFunc{}
-
-	if re.Name() != "db.removeEdge" {
-		t.Error("Unexpected result:", re.Name())
-		return
-	}
-
-	if err := re.Validate(3, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if err := re.Validate(1, mr); err == nil || err.Error() !=
-		"Invalid construct Function removeEdge requires 3 or 4 parameters: partition, edge key, edge kind and optionally a transaction" {
-		t.Error(err)
-		return
-	}
-
-	if _, err := re.Execute([]interface{}{"mai n", "123", "e"}, nil, mr); err == nil || err.Error() !=
-		"Invalid state Cannot remove edge: GraphError: Invalid data (Partition name mai n is not alphanumeric - can only contain [a-zA-Z0-9_])" {
-		t.Error(err)
-		return
-	}
-
-	if _, err := re.Execute([]interface{}{"mai n", "123", "e", "bla"}, nil, mr); err == nil || err.Error() !=
-		"Invalid construct Fourth parameter must be a transaction" {
-		t.Error(err)
-		return
-	}
-
-	if _, err := re.Execute([]interface{}{"main", "123", "e"}, nil, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	res, err = fe.Execute([]interface{}{"main", "123", "e"}, nil, mr)
-	if res != nil || err != nil {
-		t.Error("Unexpected result:", res, err)
-		return
-	}
-}
-
-func TestStoreEdgeTrans(t *testing.T) {
-
-	mr := &mockRuntime{}
-	mgs := graphstorage.NewMemoryGraphStorage("mystorage")
-	gm := graph.NewGraphManager(mgs)
-
-	api.GM = gm
-
-	sn := &StoreNodeFunc{}
-	se := &StoreEdgeFunc{}
-	tc := &CommitTransFunc{}
-
-	trans := graph.NewGraphTrans(gm)
-
-	if _, err := sn.Execute([]interface{}{"main", map[interface{}]interface{}{
-		"key":  "a",
-		"kind": "b",
-	}, trans}, nil, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if _, err := sn.Execute([]interface{}{"main", map[interface{}]interface{}{
-		"key":  "c",
-		"kind": "d",
-	}, trans}, nil, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	_, err := se.Execute([]interface{}{"main", map[interface{}]interface{}{
-		"key":           "123",
-		"kind":          "e",
-		"end1cascading": true,
-		"end1key":       "a",
-		"end1kind":      "b",
-		"end1role":      "role1",
-		"end2cascading": false,
-		"end2key":       "c",
-		"end2kind":      "d",
-		"end2role":      "role2",
-	}, trans}, nil, mr)
-
-	if err != nil {
-		t.Error(err)
-		return
-	}
-
-	if res := fmt.Sprint(trans.Counts()); res != "2 1 0 0" {
-		t.Error("Unexpected result:", res)
-		return
-	}
-	if _, err := tc.Execute([]interface{}{trans}, nil, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	// Check that the nodes have been committed
-
-	if res := fmt.Sprint(trans.Counts()); res != "0 0 0 0" {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	if res := gm.EdgeCount("e"); res != 1 {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	se.Execute([]interface{}{"main", map[interface{}]interface{}{
-		"key":           "123",
-		"kind":          "e",
-		"end1cascading": true,
-		"end1key":       "a",
-		"end1kind":      "b",
-		"end1role":      "role1",
-		"end2cascading": false,
-		"end2key":       "c1",
-		"end2kind":      "d",
-		"end2role":      "role2",
-	}, trans}, nil, mr)
-
-	if _, err := tc.Execute([]interface{}{trans}, nil, mr); err == nil || err.Error() !=
-		"Invalid construct Cannot store node: GraphError: Invalid data (Can't find edge endpoint: c1 (d))" {
-		t.Error(err)
-		return
-	}
-
-	re := &RemoveEdgeFunc{}
-
-	if _, err := re.Execute([]interface{}{"main", "123", "e", trans}, nil, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if res := fmt.Sprint(trans.Counts()); res != "0 0 0 1" {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	if _, err := tc.Execute([]interface{}{trans}, nil, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if res := fmt.Sprint(trans.Counts()); res != "0 0 0 0" {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	if res := gm.EdgeCount("e"); res != 0 {
-		t.Error("Unexpected result:", res)
-		return
-	}
-}

+ 0 - 88
integration/rumble/eql.go

@@ -1,88 +0,0 @@
-/*
- * EliasDB
- *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-package rumble
-
-import (
-	"fmt"
-
-	"devt.de/krotik/common/defs/rumble"
-	"devt.de/krotik/eliasdb/api"
-	"devt.de/krotik/eliasdb/eql"
-)
-
-// Function: query
-// ===============
-
-/*
-QueryFunc runs an EQL query.
-*/
-type QueryFunc struct {
-}
-
-/*
-Name returns the name of the function.
-*/
-func (f *QueryFunc) Name() string {
-	return "db.query"
-}
-
-/*
-Validate is called for parameter validation and to reset the function state.
-*/
-func (f *QueryFunc) Validate(argsNum int, rt rumble.Runtime) rumble.RuntimeError {
-	var err rumble.RuntimeError
-
-	if argsNum != 2 {
-		err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-			"Function query requires 2 parameters: partition and a query string")
-	}
-
-	return err
-}
-
-/*
-Execute executes the rumble function.
-*/
-func (f *QueryFunc) Execute(argsVal []interface{}, vars rumble.Variables,
-	rt rumble.Runtime) (interface{}, rumble.RuntimeError) {
-
-	part := fmt.Sprint(argsVal[0])
-	query := fmt.Sprint(argsVal[1])
-
-	res, err := eql.RunQuery("db.query", part, query, api.GM)
-
-	if err != nil {
-
-		// Wrap error message in RuntimeError
-
-		return nil, rt.NewRuntimeError(rumble.ErrInvalidState,
-			fmt.Sprintf(err.Error()))
-	}
-
-	// Convert result to rumble data structure
-
-	labels := res.Header().Labels()
-	cols := make([]interface{}, len(labels))
-	for i, v := range labels {
-		cols[i] = v
-	}
-
-	rrows := res.Rows()
-	rows := make([]interface{}, len(rrows))
-	for i, v := range rrows {
-		rows[i] = v
-	}
-
-	return map[interface{}]interface{}{
-		"cols": cols,
-		"rows": rows,
-	}, err
-}

+ 0 - 81
integration/rumble/eql_test.go

@@ -1,81 +0,0 @@
-/*
- * EliasDB
- *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-package rumble
-
-import (
-	"fmt"
-	"testing"
-
-	"devt.de/krotik/eliasdb/api"
-	"devt.de/krotik/eliasdb/graph"
-	"devt.de/krotik/eliasdb/graph/data"
-	"devt.de/krotik/eliasdb/graph/graphstorage"
-)
-
-func TestQuery(t *testing.T) {
-
-	mr := &mockRuntime{}
-	mgs := graphstorage.NewMemoryGraphStorage("mystorage")
-	gm := graph.NewGraphManager(mgs)
-
-	api.GM = gm
-
-	gm.StoreNode("main", data.NewGraphNodeFromMap(map[string]interface{}{
-		"key":  "a",
-		"kind": "b",
-	}))
-	gm.StoreNode("main", data.NewGraphNodeFromMap(map[string]interface{}{
-		"key":  "c",
-		"kind": "d",
-	}))
-
-	q := &QueryFunc{}
-
-	if q.Name() != "db.query" {
-		t.Error("Unexpected result:", q.Name())
-		return
-	}
-
-	if err := q.Validate(2, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if err := q.Validate(1, mr); err == nil || err.Error() != "Invalid construct Function query requires 2 parameters: partition and a query string" {
-		t.Error(err)
-		return
-	}
-
-	res, err := q.Execute([]interface{}{"main", "get b"}, nil, mr)
-
-	if err != nil {
-		t.Error(err)
-		return
-	}
-
-	if res := res.(map[interface{}]interface{})["rows"]; fmt.Sprint(res) != "[[a]]" {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	if res := res.(map[interface{}]interface{})["cols"]; fmt.Sprint(res) != "[B Key]" {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	_, err = q.Execute([]interface{}{"main", "got b"}, nil, mr)
-
-	if err == nil || err.Error() != "Invalid state EQL error in db.query: Invalid construct (Unknown query type: got) (Line:1 Pos:1)" {
-		t.Error(err)
-		return
-	}
-
-}

+ 0 - 269
integration/rumble/node.go

@@ -1,269 +0,0 @@
-/*
- * EliasDB
- *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-/*
-Package rumble contains Rumble functions which interface with EliasDB.
-*/
-package rumble
-
-import (
-	"fmt"
-
-	"devt.de/krotik/common/defs/rumble"
-	"devt.de/krotik/eliasdb/api"
-	"devt.de/krotik/eliasdb/graph"
-	"devt.de/krotik/eliasdb/graph/data"
-)
-
-// Function: storeNode
-// ===================
-
-/*
-StoreNodeFunc inserts or updates a node in EliasDB.
-*/
-type StoreNodeFunc struct {
-}
-
-/*
-Name returns the name of the function.
-*/
-func (f *StoreNodeFunc) Name() string {
-	return "db.storeNode"
-}
-
-/*
-Validate is called for parameter validation and to reset the function state.
-*/
-func (f *StoreNodeFunc) Validate(argsNum int, rt rumble.Runtime) rumble.RuntimeError {
-	var err rumble.RuntimeError
-
-	if argsNum != 2 && argsNum != 3 {
-		err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-			"Function storeNode requires 2 or 3 parameters: partition, node"+
-				" map and optionally a transaction")
-	}
-
-	return err
-}
-
-/*
-Execute executes the rumble function.
-*/
-func (f *StoreNodeFunc) Execute(argsVal []interface{}, vars rumble.Variables,
-	rt rumble.Runtime) (interface{}, rumble.RuntimeError) {
-
-	var trans graph.Trans
-	var err rumble.RuntimeError
-
-	part := fmt.Sprint(argsVal[0])
-	nodeMap, ok := argsVal[1].(map[interface{}]interface{})
-
-	// Check parameters
-
-	if !ok {
-		err = rt.NewRuntimeError(rumble.ErrNotAMap,
-			"Second parameter must be a map")
-	}
-
-	if err == nil && len(argsVal) > 2 {
-		if trans, ok = argsVal[2].(graph.Trans); !ok {
-			err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-				"Third parameter must be a transaction")
-		}
-	}
-
-	// Build up node to store
-
-	node := NewGraphNodeFromRumbleMap(nodeMap)
-
-	// Store the node
-
-	if err == nil {
-
-		if trans != nil {
-			err = trans.StoreNode(part, node)
-		} else {
-			err = api.GM.StoreNode(part, node)
-		}
-
-		if err != nil {
-
-			// Wrap error message in RuntimeError
-
-			err = rt.NewRuntimeError(rumble.ErrInvalidState,
-				fmt.Sprintf("Cannot store node: %v", err.Error()))
-		}
-	}
-
-	return nil, err
-}
-
-// Function: removeNode
-// ====================
-
-/*
-RemoveNodeFunc removes a node in EliasDB.
-*/
-type RemoveNodeFunc struct {
-}
-
-/*
-Name returns the name of the function.
-*/
-func (f *RemoveNodeFunc) Name() string {
-	return "db.removeNode"
-}
-
-/*
-Validate is called for parameter validation and to reset the function state.
-*/
-func (f *RemoveNodeFunc) Validate(argsNum int, rt rumble.Runtime) rumble.RuntimeError {
-	var err rumble.RuntimeError
-
-	if argsNum != 3 && argsNum != 4 {
-		err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-			"Function removeNode requires 3 or 4 parameters: partition, node key"+
-				" node kind and optionally a transaction")
-	}
-
-	return err
-}
-
-/*
-Execute executes the rumble function.
-*/
-func (f *RemoveNodeFunc) Execute(argsVal []interface{}, vars rumble.Variables,
-	rt rumble.Runtime) (interface{}, rumble.RuntimeError) {
-
-	var trans graph.Trans
-	var err rumble.RuntimeError
-
-	part := fmt.Sprint(argsVal[0])
-	key := fmt.Sprint(argsVal[1])
-	kind := fmt.Sprint(argsVal[2])
-
-	// Check parameters
-
-	if len(argsVal) > 3 {
-		var ok bool
-
-		if trans, ok = argsVal[3].(graph.Trans); !ok {
-			err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-				"Fourth parameter must be a transaction")
-		}
-	}
-
-	// Remove the node
-
-	if err == nil {
-
-		if trans != nil {
-			err = trans.RemoveNode(part, key, kind)
-		} else {
-			_, err = api.GM.RemoveNode(part, key, kind)
-		}
-
-		if err != nil {
-
-			// Wrap error message in RuntimeError
-
-			err = rt.NewRuntimeError(rumble.ErrInvalidState,
-				fmt.Sprintf("Cannot remove node: %v", err.Error()))
-		}
-	}
-
-	return nil, err
-}
-
-// Function: fetchNode
-// ===================
-
-/*
-FetchNodeFunc fetches a node in EliasDB.
-*/
-type FetchNodeFunc struct {
-}
-
-/*
-Name returns the name of the function.
-*/
-func (f *FetchNodeFunc) Name() string {
-	return "db.fetchNode"
-}
-
-/*
-Validate is called for parameter validation and to reset the function state.
-*/
-func (f *FetchNodeFunc) Validate(argsNum int, rt rumble.Runtime) rumble.RuntimeError {
-	var err rumble.RuntimeError
-
-	if argsNum != 3 {
-		err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-			"Function fetchNode requires 3 parameters: partition, node key"+
-				" node kind")
-	}
-
-	return err
-}
-
-/*
-Execute executes the rumble function.
-*/
-func (f *FetchNodeFunc) Execute(argsVal []interface{}, vars rumble.Variables,
-	rt rumble.Runtime) (interface{}, rumble.RuntimeError) {
-
-	var node data.Node
-	var res interface{}
-	var err rumble.RuntimeError
-
-	part := fmt.Sprint(argsVal[0])
-	key := fmt.Sprint(argsVal[1])
-	kind := fmt.Sprint(argsVal[2])
-
-	conv := func(m map[string]interface{}) map[interface{}]interface{} {
-		c := make(map[interface{}]interface{})
-		for k, v := range m {
-			c[k] = v
-		}
-		return c
-	}
-
-	// Fetch the node
-
-	if node, err = api.GM.FetchNode(part, key, kind); node != nil {
-		res = conv(node.Data())
-	}
-
-	if err != nil {
-
-		// Wrap error message in RuntimeError
-
-		err = rt.NewRuntimeError(rumble.ErrInvalidState,
-			fmt.Sprintf("Cannot fetch node: %v", err.Error()))
-	}
-
-	return res, err
-}
-
-// Helper functions
-// ================
-
-/*
-NewGraphNodeFromRumbleMap creates a new Node instance.
-*/
-func NewGraphNodeFromRumbleMap(d map[interface{}]interface{}) data.Node {
-	node := data.NewGraphNode()
-
-	for k, v := range d {
-		node.SetAttr(fmt.Sprint(k), v)
-	}
-
-	return node
-}

+ 0 - 359
integration/rumble/node_test.go

@@ -1,359 +0,0 @@
-/*
- * EliasDB
- *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-package rumble
-
-import (
-	"fmt"
-	"testing"
-
-	"devt.de/krotik/common/defs/rumble"
-	"devt.de/krotik/eliasdb/api"
-	"devt.de/krotik/eliasdb/graph"
-	"devt.de/krotik/eliasdb/graph/graphstorage"
-)
-
-type mockRuntime struct {
-}
-
-func (mr *mockRuntime) NewRuntimeError(t error, d string) rumble.RuntimeError {
-	return fmt.Errorf("%v %v", t, d)
-}
-
-func TestStoreAndRemoveNode(t *testing.T) {
-
-	mr := &mockRuntime{}
-	mgs := graphstorage.NewMemoryGraphStorage("mystorage")
-	gm := graph.NewGraphManager(mgs)
-
-	api.GM = gm
-
-	sn := &StoreNodeFunc{}
-
-	if sn.Name() != "db.storeNode" {
-		t.Error("Unexpected result:", sn.Name())
-		return
-	}
-
-	if err := sn.Validate(2, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if err := sn.Validate(3, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if err := sn.Validate(1, mr); err == nil || err.Error() != "Invalid construct Function storeNode requires 2 or 3 parameters: partition, node map and optionally a transaction" {
-		t.Error(err)
-		return
-	}
-
-	if _, err := sn.Execute([]interface{}{"main", "bla"}, nil, mr); err == nil || err.Error() != "Operand is not a map Second parameter must be a map" {
-		t.Error(err)
-		return
-	}
-
-	if _, err := sn.Execute([]interface{}{"main", map[interface{}]interface{}{}, "bla"}, nil, mr); err == nil || err.Error() != "Invalid construct Third parameter must be a transaction" {
-		t.Error(err)
-		return
-	}
-
-	if _, err := sn.Execute([]interface{}{"main", "bla"}, nil, mr); err == nil || err.Error() != "Operand is not a map Second parameter must be a map" {
-		t.Error(err)
-		return
-	}
-
-	if _, err := sn.Execute([]interface{}{"main", map[interface{}]interface{}{
-		"key": "foo",
-	}}, nil, mr); err == nil || err.Error() != "Invalid state Cannot store node: GraphError: Invalid data (Node is missing a kind value)" {
-		t.Error(err)
-		return
-	}
-
-	if _, err := sn.Execute([]interface{}{"main", map[interface{}]interface{}{
-		"key":  "foo",
-		"kind": "bar",
-	}}, nil, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if res := gm.NodeCount("bar"); res != 1 {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	fn := &FetchNodeFunc{}
-
-	if fn.Name() != "db.fetchNode" {
-		t.Error("Unexpected result:", fn.Name())
-		return
-	}
-
-	if err := fn.Validate(3, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if err := fn.Validate(1, mr); err == nil || err.Error() != "Invalid construct Function fetchNode requires 3 parameters: partition, node key node kind" {
-		t.Error(err)
-		return
-	}
-
-	_, err := fn.Execute([]interface{}{"main", "foo", "ba r"}, nil, mr)
-	if err == nil || err.Error() !=
-		"Invalid state Cannot fetch node: GraphError: Invalid data (Node kind ba r is not alphanumeric - can only contain [a-zA-Z0-9_])" {
-		t.Error(err)
-		return
-	}
-
-	res, err := fn.Execute([]interface{}{"main", "foo", "bar"}, nil, mr)
-	if fmt.Sprint(NewGraphNodeFromRumbleMap(res.(map[interface{}]interface{}))) != `
-GraphNode:
-     key : foo
-    kind : bar
-`[1:] || err != nil {
-		t.Error("Unexpected result:", res, err)
-		return
-	}
-
-	rn := &RemoveNodeFunc{}
-
-	if err := rn.Validate(1, mr); err == nil || err.Error() !=
-		"Invalid construct Function removeNode requires 3 or 4 parameters: partition, node key node kind and optionally a transaction" {
-		t.Error(err)
-		return
-	}
-
-	_, err = rn.Execute([]interface{}{"mai n", "foo", "bar"}, nil, mr)
-	if err == nil || err.Error() != "Invalid state Cannot remove node: GraphError: Invalid data (Partition name mai n is not alphanumeric - can only contain [a-zA-Z0-9_])" {
-		t.Error(err)
-		return
-	}
-
-	_, err = rn.Execute([]interface{}{"main", "foo", "bar"}, nil, mr)
-	if err != nil {
-		t.Error(err)
-		return
-	}
-
-	res, err = fn.Execute([]interface{}{"main", "foo", "bar"}, nil, mr)
-
-	if res != nil || err != nil {
-		t.Error("Unexpected result:", res, err)
-		return
-	}
-}
-
-func TestStoreNodeTrans(t *testing.T) {
-
-	mr := &mockRuntime{}
-	mgs := graphstorage.NewMemoryGraphStorage("mystorage")
-	gm := graph.NewGraphManager(mgs)
-
-	api.GM = gm
-
-	sn := &StoreNodeFunc{}
-	tn := &NewTransFunc{}
-	tn2 := &NewRollingTransFunc{}
-	tc := &CommitTransFunc{}
-
-	if tn.Name() != "db.newTrans" {
-		t.Error("Unexpected result:", tn.Name())
-		return
-	}
-
-	if tn2.Name() != "db.newRollingTrans" {
-		t.Error("Unexpected result:", tn2.Name())
-		return
-	}
-
-	if tc.Name() != "db.commitTrans" {
-		t.Error("Unexpected result:", tc.Name())
-		return
-	}
-
-	if err := tn.Validate(0, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if err := tn2.Validate(1, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if err := tn.Validate(1, mr); err == nil || err.Error() != "Invalid construct Function newTrans does not require any parameters" {
-		t.Error(err)
-		return
-	}
-
-	if err := tn2.Validate(0, mr); err == nil || err.Error() != "Invalid construct Function newRollingTrans requires the rolling threshold (number of operations before rolling)" {
-		t.Error(err)
-		return
-	}
-
-	if err := tc.Validate(1, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if err := tc.Validate(0, mr); err == nil || err.Error() != "Invalid construct Function commitTrans	 requires the transaction to commit as parameter" {
-		t.Error(err)
-		return
-	}
-
-	trans, err := tn.Execute(nil, nil, mr)
-	if err != nil {
-		t.Error(err)
-		return
-	}
-
-	_, err = tn2.Execute([]interface{}{"foo"}, nil, mr)
-	if err == nil || err.Error() != "Operand is not a number Rolling threshold must be a number not: foo" {
-		t.Error(err)
-		return
-	}
-
-	_, err = tn2.Execute([]interface{}{1}, nil, mr)
-	if err != nil {
-		t.Error(err)
-		return
-	}
-
-	if _, err := sn.Execute([]interface{}{"main", map[interface{}]interface{}{
-		"key":  "foo1",
-		"kind": "bar",
-	}, trans}, nil, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if _, err := sn.Execute([]interface{}{"main", map[interface{}]interface{}{
-		"key":  "foo2",
-		"kind": "bar",
-	}, trans}, nil, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	if _, err := sn.Execute([]interface{}{"main", map[interface{}]interface{}{
-		"key":  "foo3",
-		"kind": "bar",
-	}, trans}, nil, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	// Check that the nodes are in the transaction
-
-	if res := fmt.Sprint(trans.(graph.Trans).Counts()); res != "3 0 0 0" {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	if res := gm.NodeCount("bar"); res != 0 {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	// Commit the nodes
-
-	if _, err := tc.Execute([]interface{}{"main", map[interface{}]interface{}{
-		"key":  "foo3",
-		"kind": "bar",
-	}, trans}, nil, mr); err == nil || err.Error() != "Invalid construct Parameter must be a transaction" {
-		t.Error(err)
-		return
-	}
-
-	if _, err := tc.Execute([]interface{}{trans}, nil, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	// Check that the nodes have been committed
-
-	if res := fmt.Sprint(trans.(graph.Trans).Counts()); res != "0 0 0 0" {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	if res := gm.NodeCount("bar"); res != 3 {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	// Remove the nodes
-
-	rn := &RemoveNodeFunc{}
-
-	if rn.Name() != "db.removeNode" {
-		t.Error("Unexpected result:", rn.Name())
-		return
-	}
-
-	_, err = rn.Execute([]interface{}{"main", "foo1", "bar", nil}, nil, mr)
-	if err == nil || err.Error() != "Invalid construct Fourth parameter must be a transaction" {
-		t.Error(err)
-		return
-	}
-
-	_, err = rn.Execute([]interface{}{"main", "foo1", "bar", trans}, nil, mr)
-	if err != nil {
-		t.Error(err)
-		return
-	}
-
-	_, err = rn.Execute([]interface{}{"main", "foo2", "bar", trans}, nil, mr)
-	if err != nil {
-		t.Error(err)
-		return
-	}
-
-	_, err = rn.Execute([]interface{}{"main", "foo3", "bar", trans}, nil, mr)
-	if err != nil {
-		t.Error(err)
-		return
-	}
-
-	// Check that the nodes are in the transaction
-
-	if res := fmt.Sprint(trans.(graph.Trans).Counts()); res != "0 0 3 0" {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	if res := gm.NodeCount("bar"); res != 3 {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	// Commit the nodes
-
-	if _, err := tc.Execute([]interface{}{trans}, nil, mr); err != nil {
-		t.Error(err)
-		return
-	}
-
-	// Check that the nodes have been committed
-
-	if res := fmt.Sprint(trans.(graph.Trans).Counts()); res != "0 0 0 0" {
-		t.Error("Unexpected result:", res)
-		return
-	}
-
-	if res := gm.NodeCount("bar"); res != 0 {
-		t.Error("Unexpected result:", res)
-		return
-	}
-}

+ 0 - 166
integration/rumble/trans.go

@@ -1,166 +0,0 @@
-/*
- * EliasDB
- *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-package rumble
-
-import (
-	"fmt"
-	"strconv"
-
-	"devt.de/krotik/common/defs/rumble"
-	"devt.de/krotik/eliasdb/api"
-	"devt.de/krotik/eliasdb/graph"
-)
-
-// Function: newTrans
-// ==================
-
-/*
-NewTransFunc creates a new transaction for EliasDB.
-*/
-type NewTransFunc struct {
-}
-
-/*
-Name returns the name of the function.
-*/
-func (f *NewTransFunc) Name() string {
-	return "db.newTrans"
-}
-
-/*
-Validate is called for parameter validation and to reset the function state.
-*/
-func (f *NewTransFunc) Validate(argsNum int, rt rumble.Runtime) rumble.RuntimeError {
-	var err rumble.RuntimeError
-
-	if argsNum != 0 {
-		err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-			"Function newTrans does not require any parameters")
-	}
-
-	return err
-}
-
-/*
-Execute executes the rumble function.
-*/
-func (f *NewTransFunc) Execute(argsVal []interface{}, vars rumble.Variables,
-	rt rumble.Runtime) (interface{}, rumble.RuntimeError) {
-
-	return graph.NewConcurrentGraphTrans(api.GM), nil
-}
-
-// Function: newRollingTrans
-// =========================
-
-/*
-NewRollingTransFunc creates a new rolling transaction for EliasDB.
-A rolling transaction commits after n entries.
-*/
-type NewRollingTransFunc struct {
-}
-
-/*
-Name returns the name of the function.
-*/
-func (f *NewRollingTransFunc) Name() string {
-	return "db.newRollingTrans"
-}
-
-/*
-Validate is called for parameter validation and to reset the function state.
-*/
-func (f *NewRollingTransFunc) Validate(argsNum int, rt rumble.Runtime) rumble.RuntimeError {
-	var err rumble.RuntimeError
-
-	if argsNum != 1 {
-		err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-			"Function newRollingTrans requires the rolling threshold (number of operations before rolling)")
-	}
-
-	return err
-}
-
-/*
-Execute executes the rumble function.
-*/
-func (f *NewRollingTransFunc) Execute(argsVal []interface{}, vars rumble.Variables,
-	rt rumble.Runtime) (interface{}, rumble.RuntimeError) {
-
-	i, err := strconv.Atoi(fmt.Sprint(argsVal[0]))
-
-	if err != nil {
-		return nil, rt.NewRuntimeError(rumble.ErrNotANumber,
-			fmt.Sprintf("Rolling threshold must be a number not: %v", argsVal[0]))
-	}
-
-	trans := graph.NewRollingTrans(graph.NewConcurrentGraphTrans(api.GM),
-		i, api.GM, graph.NewConcurrentGraphTrans)
-
-	return trans, nil
-}
-
-// Function: commitTrans
-// =====================
-
-/*
-CommitTransFunc commits an existing transaction for EliasDB.
-*/
-type CommitTransFunc struct {
-}
-
-/*
-Name returns the name of the function.
-*/
-func (f *CommitTransFunc) Name() string {
-	return "db.commitTrans"
-}
-
-/*
-Validate is called for parameter validation and to reset the function state.
-*/
-func (f *CommitTransFunc) Validate(argsNum int, rt rumble.Runtime) rumble.RuntimeError {
-	var err rumble.RuntimeError
-
-	if argsNum != 1 {
-		err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-			"Function commitTrans	 requires the transaction to commit as parameter")
-	}
-
-	return err
-}
-
-/*
-Execute executes the rumble function.
-*/
-func (f *CommitTransFunc) Execute(argsVal []interface{}, vars rumble.Variables,
-	rt rumble.Runtime) (interface{}, rumble.RuntimeError) {
-
-	var err rumble.RuntimeError
-
-	trans, ok := argsVal[0].(graph.Trans)
-
-	// Check parameters
-
-	if !ok {
-		err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-			"Parameter must be a transaction")
-	}
-
-	if err == nil {
-		if err = trans.Commit(); err != nil {
-			err = rt.NewRuntimeError(rumble.ErrInvalidConstruct,
-				fmt.Sprintf("Cannot store node: %v", err.Error()))
-		}
-	}
-
-	return nil, err
-}