-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix sorting and add single key w/ filter test.
- Loading branch information
Showing
3 changed files
with
143 additions
and
8 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
140 changes: 140 additions & 0 deletions
140
integration/groupby_query_single_key_with_filter_no_order_test.go
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,140 @@ | ||
// +build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGroupByQuerySingleKeyWithFilterNoOrder(t *testing.T) { | ||
if testing.Short() { | ||
t.SkipNow() | ||
} | ||
|
||
cfg := loadConfig(t, testConfig1) | ||
ts := newTestServerSetup(t, cfg) | ||
defer ts.close(t) | ||
|
||
log := ts.dbOpts.InstrumentOptions().Logger() | ||
log.Info("testing groupby query w/ single-key, no filter and no order") | ||
require.NoError(t, ts.startServer()) | ||
log.Info("server is now up") | ||
|
||
testData := ` | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:25:42-08:00","st":true,"sid":{"foo":1,"bar":2},"tt":"active","tz":-6,"v":1.5} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:26:42-08:00","st":true,"sid":{"foo":1,"bar":2},"tt":"active","tz":-6,"v":1.5} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:27:42-08:00","st":true,"sid":{"foo":1,"bar":2},"tt":"active","tz":-6,"v":1.5} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:28:42-08:00","st":true,"sid":{"foo":1,"bar":2},"tt":"active","tz":-6,"v":1.5} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:29:42-08:00","st":true,"sid":{"foo":1,"bar":2},"tt":"active","tz":-6,"v":1.5} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:30:42-08:00","st":true,"sid":{"foo":2,"bar":4},"tt":"active","tz":-6,"v":1.5} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:31:42-08:00","st":true,"sid":{"foo":2,"bar":4},"tt":"active","tz":-6,"v":1.5} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:32:42-08:00","st":true,"sid":{"foo":2,"bar":4},"tt":"active","tz":-6,"v":1.5} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:33:42-08:00","st":true,"sid":{"foo":2,"bar":4},"tt":"active","tz":-6,"v":1.5} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:34:42-08:00","st":true,"sid":{"foo":2,"bar":4},"tt":"active","tz":-6,"v":1.5} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:35:42-08:00","st":false,"sid":{"foo":3,"bar":6},"tt":"inactive","tz":-6,"v":15} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:36:42-08:00","st":false,"sid":{"foo":3,"bar":6},"tt":"inactive","tz":-6,"v":15} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:37:42-08:00","st":false,"sid":{"foo":3,"bar":6},"tt":"inactive","tz":-6,"v":15} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:38:42-08:00","st":false,"sid":{"foo":3,"bar":6},"tt":"inactive","tz":-6,"v":15} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:39:42-08:00","st":false,"sid":{"foo":3,"bar":6},"tt":"inactive","tz":-6,"v":15} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:40:42-08:00","st":false,"sid":{"foo":4,"bar":8},"tt":"inactive","tz":-6,"v":15} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:41:42-08:00","st":false,"sid":{"foo":4,"bar":8},"tt":"inactive","tz":-6,"v":15} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:42:42-08:00","st":false,"sid":{"foo":4,"bar":8},"tt":"inactive","tz":-6,"v":15} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:43:42-08:00","st":false,"sid":{"foo":4,"bar":8},"tt":"inactive","tz":-6,"v":15} | ||
{"service":"testNamespace","@timestamp":"2019-01-22T13:44:42-08:00","st":false,"sid":{"foo":4,"bar":8},"tt":"inactive","tz":-6,"v":15}` | ||
|
||
tests := []struct { | ||
queryJSON string | ||
expectedResults groupByQuerySingleKeyResults | ||
}{ | ||
{ | ||
queryJSON: `{ | ||
"namespace": "testNamespace", | ||
"start_time": 1548115200, | ||
"end_time": 1548201600, | ||
"calculations": [ | ||
{ | ||
"op": "COUNT" | ||
} | ||
], | ||
"filters": [ | ||
{ | ||
"filters": [ | ||
{ | ||
"field": "st", | ||
"op": "=", | ||
"value": true | ||
} | ||
], | ||
"filter_combinator": "AND" | ||
} | ||
], | ||
"group_by": [ | ||
"tt" | ||
]}`, | ||
expectedResults: groupByQuerySingleKeyResults{ | ||
Groups: []singleKeyResultGroup{ | ||
singleKeyResultGroup{ | ||
Key: "active", | ||
Values: []interface{}{float64(10)}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
queryJSON: `{ | ||
"namespace": "testNamespace", | ||
"start_time": 1548115200, | ||
"end_time": 1548201600, | ||
"calculations": [ | ||
{ | ||
"op": "COUNT" | ||
} | ||
], | ||
"filters": [ | ||
{ | ||
"filters": [ | ||
{ | ||
"field": "st", | ||
"op": "=", | ||
"value": true | ||
} | ||
], | ||
"filter_combinator": "AND" | ||
} | ||
], | ||
"group_by": [ | ||
"sid.bar" | ||
]}`, | ||
expectedResults: groupByQuerySingleKeyResults{ | ||
Groups: []singleKeyResultGroup{ | ||
singleKeyResultGroup{ | ||
Key: float64(2), | ||
Values: []interface{}{float64(5)}, | ||
}, | ||
singleKeyResultGroup{ | ||
Key: float64(4), | ||
Values: []interface{}{float64(5)}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
client := ts.newHTTPClient() | ||
require.NoError(t, client.write([]byte(strings.TrimSpace(testData)))) | ||
|
||
for _, test := range tests { | ||
results, err := client.queryGroupBySingleKey([]byte(test.queryJSON)) | ||
assert.NoError(t, err) | ||
sort.Sort(results) | ||
assert.Equal(t, test.expectedResults, results) | ||
} | ||
|
||
require.NoError(t, ts.stopServer()) | ||
log.Info("server is now down") | ||
} |
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