-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcolumnaragent_test.go
92 lines (69 loc) · 2.3 KB
/
columnaragent_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package gocbcore
import (
"context"
"time"
)
func (suite *ColumnarTestSuite) TestBasicQuery() {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
res, err := suite.agent.Query(ctx, ColumnarQueryOptions{
Payload: map[string]interface{}{
"statement": "FROM RANGE(0, 99) AS i SELECT *",
},
})
suite.Require().NoError(err)
var rows [][]byte
for row := res.NextRow(); row != nil; row = res.NextRow() {
rows = append(rows, row)
}
suite.Assert().Len(rows, 100)
err = res.Err()
suite.Require().NoError(err)
_, err = res.MetaData()
suite.Require().NoError(err)
err = res.Close()
suite.Require().NoError(err)
}
func (suite *ColumnarTestSuite) TestDispatchTimeout() {
// This test purposefully triggers error cases.
globalTestLogger.SuppressWarnings(true)
defer globalTestLogger.SuppressWarnings(false)
cfg := suite.makeAgentConfig(suite.ColumnarTestConfig)
cfg.SeedConfig.SRVRecord = nil
cfg.SeedConfig.MemdAddrs = []string{"couchbases://utternonsense"}
agent, err := CreateColumnarAgent(&cfg)
suite.Require().NoError(err)
defer agent.Close()
_, err = agent.Query(context.Background(), ColumnarQueryOptions{
Payload: map[string]interface{}{
"statement": "FROM RANGE(0, 99) AS i SELECT *",
"timeout": "1s",
},
})
suite.Require().ErrorIs(err, ErrTimeout)
var columnarError *ColumnarError
suite.Require().ErrorAs(err, &columnarError)
suite.Assert().NotEmpty(columnarError.Statement)
}
func (suite *ColumnarTestSuite) TestDispatchContextTimeout() {
// This test purposefully triggers error cases.
globalTestLogger.SuppressWarnings(true)
defer globalTestLogger.SuppressWarnings(false)
cfg := suite.makeAgentConfig(suite.ColumnarTestConfig)
cfg.SeedConfig.SRVRecord = nil
cfg.SeedConfig.MemdAddrs = []string{"couchbases://utternonsense"}
agent, err := CreateColumnarAgent(&cfg)
suite.Require().NoError(err)
defer agent.Close()
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
_, err = agent.Query(ctx, ColumnarQueryOptions{
Payload: map[string]interface{}{
"statement": "FROM RANGE(0, 99) AS i SELECT *",
},
})
suite.Require().ErrorIs(err, context.DeadlineExceeded)
var columnarError *ColumnarError
suite.Require().ErrorAs(err, &columnarError)
suite.Assert().NotEmpty(columnarError.Statement)
}