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.
Set tmax if the batch is empty or not grouping by time (influxdata#927)
* set tmax if the batch is empty or not grouping by time * CHANGELOG.md * add tests for query IsGroupedByTime
- Loading branch information
Nathaniel Cook
authored
Sep 20, 2016
1 parent
3a2fd51
commit 9ea0f90
Showing
6 changed files
with
174 additions
and
17 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
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,139 @@ | ||
package kapacitor_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/influxdata/kapacitor" | ||
) | ||
|
||
func TestQuery_Clone(t *testing.T) { | ||
testCases := []string{ | ||
"SELECT usage FROM telegraf.autogen.cpu", | ||
"SELECT mean(usage) FROM telegraf.autogen.cpu WHERE host = 'serverA'", | ||
"SELECT mean(usage) FROM telegraf.autogen.cpu WHERE host = 'serverA' AND dc = 'slc'", | ||
"SELECT mean(usage) FROM telegraf.autogen.cpu WHERE host = 'serverA' AND dc = 'slc' OR product = 'login'", | ||
"SELECT mean(usage) FROM telegraf.autogen.cpu WHERE host = 'serverA' AND (dc = 'slc' OR product = 'login')", | ||
} | ||
|
||
equal := func(q0, q1 *kapacitor.Query) error { | ||
if got, exp := q0.String(), q1.String(); got != exp { | ||
return fmt.Errorf("unequal query string: got %s exp %s", got, exp) | ||
} | ||
if got, exp := q0.StartTime(), q1.StartTime(); got != exp { | ||
return fmt.Errorf("unequal query start time: got %v exp %v", got, exp) | ||
} | ||
if got, exp := q0.StopTime(), q1.StopTime(); got != exp { | ||
return fmt.Errorf("unequal query stop time: got %v exp %v", got, exp) | ||
} | ||
if got, exp := q0.IsGroupedByTime(), q1.IsGroupedByTime(); got != exp { | ||
return fmt.Errorf("unequal query IsGroupedByTime: got %v exp %v", got, exp) | ||
} | ||
return nil | ||
} | ||
for _, query := range testCases { | ||
q, err := kapacitor.NewQuery(query) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
clone, err := q.Clone() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := equal(clone, q); err != nil { | ||
t.Error(err) | ||
} | ||
|
||
// Modify original start time | ||
start := time.Date(1975, 1, 1, 0, 0, 0, 0, time.UTC) | ||
q.SetStartTime(start) | ||
|
||
if err := equal(clone, q); err == nil { | ||
t.Errorf("equal after modification: got %v", clone) | ||
} | ||
|
||
// Modify clone in the same way | ||
clone.SetStartTime(start) | ||
if err := equal(clone, q); err != nil { | ||
t.Error(err) | ||
} | ||
|
||
// Re-clone | ||
clone, err = q.Clone() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := equal(clone, q); err != nil { | ||
t.Error(err) | ||
} | ||
|
||
// Modify original stop time | ||
stop := time.Date(1975, 1, 2, 0, 0, 0, 0, time.UTC) | ||
q.SetStopTime(stop) | ||
|
||
if err := equal(clone, q); err == nil { | ||
t.Errorf("equal after modification: got %v", clone) | ||
} | ||
|
||
// Modify clone in the same way | ||
clone.SetStopTime(stop) | ||
if err := equal(clone, q); err != nil { | ||
t.Error(err) | ||
} | ||
|
||
// Re-clone | ||
clone, err = q.Clone() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := equal(clone, q); err != nil { | ||
t.Error(err) | ||
} | ||
|
||
// Set dimensions | ||
q.Dimensions([]interface{}{time.Hour}) | ||
if err := equal(clone, q); err == nil { | ||
t.Errorf("equal after modification: got %v", clone) | ||
} | ||
// Set dimesions on the clone in the same way | ||
clone.Dimensions([]interface{}{time.Hour}) | ||
if err := equal(clone, q); err != nil { | ||
t.Error(err) | ||
} | ||
// Re-clone | ||
clone, err = q.Clone() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := equal(clone, q); err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
} | ||
func TestQuery_IsGroupedByTime(t *testing.T) { | ||
q, err := kapacitor.NewQuery("SELECT usage FROM telegraf.autogen.cpu") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
q.Dimensions([]interface{}{time.Hour}) | ||
if !q.IsGroupedByTime() { | ||
t.Error("expected query to be grouped by time") | ||
} | ||
|
||
q, err = kapacitor.NewQuery("SELECT usage FROM telegraf.autogen.cpu") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
q.Dimensions([]interface{}{kapacitor.TimeDimension{Length: time.Hour, Offset: time.Minute}}) | ||
if !q.IsGroupedByTime() { | ||
t.Error("expected query to be grouped by time") | ||
} | ||
|
||
q.Dimensions([]interface{}{"host"}) | ||
if q.IsGroupedByTime() { | ||
t.Error("expected query to not be grouped by time") | ||
} | ||
} |
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