Rename annotation methods

Change AnnotateVertex and AnnotateEdge to VertexDebugInfo EdgeDebugInfo
to avoid confusion between debug output and future graph annotations.
This commit is contained in:
James Bardin 2016-11-14 08:46:53 -05:00
parent f37b2fafed
commit 7e66df3290
4 changed files with 29 additions and 24 deletions

View File

@ -343,13 +343,17 @@ func (g *Graph) SetDebugWriter(w io.Writer) {
g.debug.Encode(newMarshalGraph("root", g)) g.debug.Encode(newMarshalGraph("root", g))
} }
func (g *Graph) AnnotateVertex(v Vertex, info string) { // DebugVertexInfo encodes arbitrary information about a vertex in the graph
va := newVertexAnnotation(v, info) // debug logs.
func (g *Graph) DebugVertexInfo(v Vertex, info string) {
va := newVertexDebugInfo(v, info)
g.debug.Encode(va) g.debug.Encode(va)
} }
func (g *Graph) AnnotateEdge(e Edge, info string) { // DebugEdgeInfo encodes arbitrary information about an edge in the graph debug
ea := newEdgeAnnotation(e, info) // logs.
func (g *Graph) DebugEdgeInfo(e Edge, info string) {
ea := newEdgeDebugInfo(e, info)
g.debug.Encode(ea) g.debug.Encode(ea)
} }

View File

@ -426,6 +426,7 @@ type marshalOperation struct {
Type string Type string
Begin *string `json:",omitempty"` Begin *string `json:",omitempty"`
End *string `json:",omitempty"` End *string `json:",omitempty"`
Info *string `json:".omitempty"`
} }
func newBool(b bool) *bool { return &b } func newBool(b bool) *bool { return &b }
@ -468,31 +469,31 @@ func decodeGraph(r io.Reader) (*marshalGraph, error) {
return g, nil return g, nil
} }
// *Annotation structs allow encoding arbitrary information about the graph in // *DebugInfo structs allow encoding arbitrary information about the graph in
// the logs. // the logs.
type vertexAnnotation struct { type vertexDebugInfo struct {
Type string Type string
Vertex *marshalVertex Vertex *marshalVertex
Info string Info string
} }
func newVertexAnnotation(v Vertex, info string) *vertexAnnotation { func newVertexDebugInfo(v Vertex, info string) *vertexDebugInfo {
return &vertexAnnotation{ return &vertexDebugInfo{
Type: "VertexAnnotation", Type: "VertexDebugInfo",
Vertex: newMarshalVertex(v), Vertex: newMarshalVertex(v),
Info: info, Info: info,
} }
} }
type edgeAnnotation struct { type edgeDebugInfo struct {
Type string Type string
Edge *marshalEdge Edge *marshalEdge
Info string Info string
} }
func newEdgeAnnotation(e Edge, info string) *edgeAnnotation { func newEdgeDebugInfo(e Edge, info string) *edgeDebugInfo {
return &edgeAnnotation{ return &edgeDebugInfo{
Type: "EdgeAnnotation", Type: "EdgeDebugInfo",
Edge: newMarshalEdge(e), Edge: newMarshalEdge(e),
Info: info, Info: info,
} }

View File

@ -130,7 +130,7 @@ func TestGraphJSON_basicRecord(t *testing.T) {
} }
// Verify that Vertex and Edge annotations appear in the debug output // Verify that Vertex and Edge annotations appear in the debug output
func TestGraphJSON_annotations(t *testing.T) { func TestGraphJSON_debugInfo(t *testing.T) {
var g Graph var g Graph
var buf bytes.Buffer var buf bytes.Buffer
g.SetDebugWriter(&buf) g.SetDebugWriter(&buf)
@ -140,9 +140,9 @@ func TestGraphJSON_annotations(t *testing.T) {
g.Add(3) g.Add(3)
g.Connect(BasicEdge(1, 2)) g.Connect(BasicEdge(1, 2))
g.AnnotateVertex(2, "2") g.DebugVertexInfo(2, "2")
g.AnnotateVertex(3, "3") g.DebugVertexInfo(3, "3")
g.AnnotateEdge(BasicEdge(1, 2), "1|2") g.DebugEdgeInfo(BasicEdge(1, 2), "1|2")
dec := json.NewDecoder(bytes.NewReader(buf.Bytes())) dec := json.NewDecoder(bytes.NewReader(buf.Bytes()))
@ -156,8 +156,8 @@ func TestGraphJSON_annotations(t *testing.T) {
} }
switch d.Type { switch d.Type {
case "VertexAnnotation": case "VertexDebugInfo":
va := &vertexAnnotation{} va := &vertexDebugInfo{}
err := json.Unmarshal(d.JSON, va) err := json.Unmarshal(d.JSON, va)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -177,8 +177,8 @@ func TestGraphJSON_annotations(t *testing.T) {
default: default:
t.Fatalf("unexpected annotation: %#v", va) t.Fatalf("unexpected annotation: %#v", va)
} }
case "EdgeAnnotation": case "EdgeDebugInfo":
ea := &edgeAnnotation{} ea := &edgeDebugInfo{}
err := json.Unmarshal(d.JSON, ea) err := json.Unmarshal(d.JSON, ea)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -294,7 +294,7 @@ func (g *Graph) walk(walker GraphWalker) error {
// then callback with the output. // then callback with the output.
log.Printf("[DEBUG] vertex '%s.%s': evaluating", path, dag.VertexName(v)) log.Printf("[DEBUG] vertex '%s.%s': evaluating", path, dag.VertexName(v))
g.AnnotateVertex(v, fmt.Sprintf("evaluating %T(%s)", v, path)) g.DebugVertexInfo(v, fmt.Sprintf("evaluating %T(%s)", v, path))
tree = walker.EnterEvalTree(v, tree) tree = walker.EnterEvalTree(v, tree)
output, err := Eval(tree, vertexCtx) output, err := Eval(tree, vertexCtx)
@ -310,7 +310,7 @@ func (g *Graph) walk(walker GraphWalker) error {
path, path,
dag.VertexName(v)) dag.VertexName(v))
g.AnnotateVertex(v, fmt.Sprintf("expanding %T(%s)", v, path)) g.DebugVertexInfo(v, fmt.Sprintf("expanding %T(%s)", v, path))
g, err := ev.DynamicExpand(vertexCtx) g, err := ev.DynamicExpand(vertexCtx)
if err != nil { if err != nil {
@ -332,7 +332,7 @@ func (g *Graph) walk(walker GraphWalker) error {
path, path,
dag.VertexName(v)) dag.VertexName(v))
g.AnnotateVertex(v, fmt.Sprintf("subgraph: %T(%s)", v, path)) g.DebugVertexInfo(v, fmt.Sprintf("subgraph: %T(%s)", v, path))
if rerr = sn.Subgraph().(*Graph).walk(walker); rerr != nil { if rerr = sn.Subgraph().(*Graph).walk(walker); rerr != nil {
return return