forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package tick | ||
|
||
import ( | ||
"github.com/influxdata/kapacitor/pipeline" | ||
"github.com/influxdata/kapacitor/tick/ast" | ||
) | ||
|
||
// BarrierNode converts the window pipeline node into the TICKScript AST | ||
type BarrierNode struct { | ||
Function | ||
} | ||
|
||
// NewBarrierNode creates a Barrier function builder | ||
func NewBarrierNode(parents []ast.Node) *BarrierNode { | ||
return &BarrierNode{ | ||
Function{ | ||
Parents: parents, | ||
}, | ||
} | ||
} | ||
|
||
// Build creates a window ast.Node | ||
func (n *BarrierNode) Build(b *pipeline.BarrierNode) (ast.Node, error) { | ||
n.Pipe("barrier"). | ||
Dot("idle", b.Idle). | ||
Dot("period", b.Period) | ||
return n.prev, n.err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package tick_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/influxdata/kapacitor/pipeline" | ||
) | ||
|
||
func TestBarrierNode(t *testing.T) { | ||
type args struct { | ||
idle time.Duration | ||
period time.Duration | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "barrier with idle", | ||
args: args{ | ||
idle: time.Second, | ||
}, | ||
want: `stream | ||
|from() | ||
|barrier() | ||
.idle(1s) | ||
`, | ||
}, | ||
{ | ||
name: "barrier with period", | ||
args: args{ | ||
period: time.Second, | ||
}, | ||
want: `stream | ||
|from() | ||
|barrier() | ||
.period(1s) | ||
`, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
stream := &pipeline.StreamNode{} | ||
pipe := pipeline.CreatePipelineSources(stream) | ||
|
||
b := stream.From().Barrier() | ||
b.Idle = tt.args.idle | ||
b.Period = tt.args.period | ||
|
||
got, err := PipelineTick(pipe) | ||
if err != nil { | ||
t.Fatalf("Unexpected error building pipeline %v", err) | ||
} | ||
if got != tt.want { | ||
t.Errorf("%q. TestBarrier() =\n%v\n want\n%v\n", tt.name, got, tt.want) | ||
} | ||
}) | ||
} | ||
} |