| 1 |
package statement |
| 2 |
|
| 3 |
import ( |
| 4 |
"strings" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/influxdata/influxdb/stress/v2/stress_client" |
| 8 |
) |
| 9 |
|
| 10 |
func TestInsertSetID(t *testing.T) { |
| 11 |
e := newTestInsert() |
| 12 |
newID := "oaijnifo" |
| 13 |
e.SetID(newID) |
| 14 |
if e.StatementID != newID { |
| 15 |
t.Errorf("Expected: %v\nGot: %v\n", newID, e.StatementID) |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
func TestInsertRun(t *testing.T) { |
| 20 |
i := newTestInsert() |
| 21 |
s, packageCh, _ := stressClient.NewTestStressTest() |
| 22 |
|
| 23 |
go func() { |
| 24 |
for pkg := range packageCh { |
| 25 |
countPoints := i.Timestamp.Count |
| 26 |
batchSize := s.BatchSize |
| 27 |
got := len(strings.Split(string(pkg.Body), "\n")) |
| 28 |
switch got { |
| 29 |
case countPoints % batchSize: |
| 30 |
case batchSize: |
| 31 |
default: |
| 32 |
t.Errorf("countPoints: %v\nbatchSize: %v\ngot: %v\n", countPoints, batchSize, got) |
| 33 |
} |
| 34 |
pkg.Tracer.Done() |
| 35 |
} |
| 36 |
}() |
| 37 |
i.Run(s) |
| 38 |
} |
| 39 |
|
| 40 |
func newTestInsert() *InsertStatement { |
| 41 |
return &InsertStatement{ |
| 42 |
TestID: "foo_test", |
| 43 |
StatementID: "foo_ID", |
| 44 |
Name: "foo_name", |
| 45 |
TemplateString: "cpu,%v %v %v", |
| 46 |
Timestamp: newTestTimestamp(), |
| 47 |
Templates: newTestTemplates(), |
| 48 |
TagCount: 1, |
| 49 |
} |
| 50 |
} |