| 1 | package stressClient |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | ) |
| 7 | |
| 8 | func TestNewStressClientTags(t *testing.T) { |
| 9 | pe, _, _ := newTestStressClient("localhost:8086") |
| 10 | tags := pe.tags("foo_id") |
| 11 | expected := fmtInt(len(pe.addresses)) |
| 12 | got := tags["number_targets"] |
| 13 | if expected != got { |
| 14 | t.Errorf("expected: %v\ngot: %v\n", expected, got) |
| 15 | } |
| 16 | expected = pe.precision |
| 17 | got = tags["precision"] |
| 18 | if expected != got { |
| 19 | t.Errorf("expected: %v\ngot: %v\n", expected, got) |
| 20 | } |
| 21 | expected = pe.wdelay |
| 22 | got = tags["write_interval"] |
| 23 | if expected != got { |
| 24 | t.Errorf("expected: %v\ngot: %v\n", expected, got) |
| 25 | } |
| 26 | expected = "foo_id" |
| 27 | got = tags["statement_id"] |
| 28 | if expected != got { |
| 29 | t.Errorf("expected: %v\ngot: %v\n", expected, got) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | func TestNewStressTestTags(t *testing.T) { |
| 34 | sf, _, _ := NewTestStressTest() |
| 35 | tags := sf.tags() |
| 36 | expected := sf.Precision |
| 37 | got := tags["precision"] |
| 38 | if expected != got { |
| 39 | t.Errorf("expected: %v\ngot: %v\n", expected, got) |
| 40 | } |
| 41 | expected = fmtInt(sf.BatchSize) |
| 42 | got = tags["batch_size"] |
| 43 | if expected != got { |
| 44 | t.Errorf("expected: %v\ngot: %v\n", expected, got) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func TestWritePoint(t *testing.T) { |
| 49 | pe, _, _ := newTestStressClient("localhost:8086") |
| 50 | statementID := "foo_id" |
| 51 | responseCode := 200 |
| 52 | responseTime := time.Duration(10 * time.Millisecond) |
| 53 | addedTags := map[string]string{"foo_tag": "foo_tag_value"} |
| 54 | writeBytes := 28051 |
| 55 | pt := pe.writePoint(1, statementID, responseCode, responseTime, addedTags, writeBytes) |
| 56 | got := pt.Tags()["statement_id"] |
| 57 | if statementID != got { |
| 58 | t.Errorf("expected: %v\ngot: %v\n", statementID, got) |
| 59 | } |
| 60 | fields, err := pt.Fields() |
| 61 | if err != nil { |
| 62 | t.Fatal(err) |
| 63 | } |
| 64 | got2 := int(fields["status_code"].(int64)) |
| 65 | if responseCode != got2 { |
| 66 | t.Errorf("expected: %v\ngot: %v\n", responseCode, got2) |
| 67 | } |
| 68 | expected := "write" |
| 69 | got = pt.Name() |
| 70 | if expected != got { |
| 71 | t.Errorf("expected: %v\ngot: %v\n", expected, got) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | func TestQueryPoint(t *testing.T) { |
| 76 | pe, _, _ := newTestStressClient("localhost:8086") |
| 77 | statementID := "foo_id" |
| 78 | responseCode := 200 |
| 79 | body := []byte{12} |
| 80 | responseTime := time.Duration(10 * time.Millisecond) |
| 81 | addedTags := map[string]string{"foo_tag": "foo_tag_value"} |
| 82 | pt := pe.queryPoint(statementID, body, responseCode, responseTime, addedTags) |
| 83 | got := pt.Tags()["statement_id"] |
| 84 | if statementID != got { |
| 85 | t.Errorf("expected: %v\ngot: %v\n", statementID, got) |
| 86 | } |
| 87 | fields, err := pt.Fields() |
| 88 | if err != nil { |
| 89 | t.Fatal(err) |
| 90 | } |
| 91 | got2 := int(fields["status_code"].(int64)) |
| 92 | if responseCode != got2 { |
| 93 | t.Errorf("expected: %v\ngot: %v\n", responseCode, got2) |
| 94 | } |
| 95 | expected := "query" |
| 96 | got = pt.Name() |
| 97 | if expected != got { |
| 98 | t.Errorf("expected: %v\ngot: %v\n", expected, got) |
| 99 | } |
| 100 | } |