-
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.
Update integration tests and minor fix.
- Loading branch information
Showing
4 changed files
with
166 additions
and
6 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
142 changes: 142 additions & 0 deletions
142
integration/groupby_query_multi_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,142 @@ | ||
// +build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGroupByQueryMultiKeyWithFilterNoOrder(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/ multi-keys, 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 groupByQueryMultiKeyResults | ||
}{ | ||
{ | ||
queryJSON: `{ | ||
"namespace": "testNamespace", | ||
"start_time": 1548115200, | ||
"end_time": 1548201600, | ||
"calculations": [ | ||
{ | ||
"op": "COUNT" | ||
} | ||
], | ||
"filters": [ | ||
{ | ||
"filters": [ | ||
{ | ||
"field": "st", | ||
"op": "=", | ||
"value": true | ||
} | ||
], | ||
"filter_combinator": "AND" | ||
} | ||
], | ||
"group_by": [ | ||
"st", | ||
"tt" | ||
]}`, | ||
expectedResults: groupByQueryMultiKeyResults{ | ||
Groups: []multiKeyResultGroup{ | ||
multiKeyResultGroup{ | ||
Key: []interface{}{true, "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.foo", | ||
"tt" | ||
]}`, | ||
expectedResults: groupByQueryMultiKeyResults{ | ||
Groups: []multiKeyResultGroup{ | ||
multiKeyResultGroup{ | ||
Key: []interface{}{float64(1), "active"}, | ||
Values: []interface{}{float64(5)}, | ||
}, | ||
multiKeyResultGroup{ | ||
Key: []interface{}{float64(2), "active"}, | ||
Values: []interface{}{float64(5)}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
client := ts.newHTTPClient() | ||
require.NoError(t, client.write([]byte(strings.TrimSpace(testData)))) | ||
|
||
for _, test := range tests { | ||
results, err := client.queryGroupByMultiKey([]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
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