Debian Codegraph @

stress/v2/stress_client/commune.go

raw symbols SCIP
1 package stressClient
2
3 import (
4 "log"
5 "time"
6
7 "github.com/influxdata/influxdb/models"
8 )
9
10 // Communes are a method for passing points between InsertStatements and QueryStatements.
11
12 type commune struct {
13 ch chan string
14 storedPoint models.Point
15 }
16
17 // NewCommune creates a new commune with a buffered chan of length n
18 func newCommune(n int) *commune {
19 return &commune{ch: make(chan string, n)}
20 }
21
22 func (c *commune) point(precision string) models.Point {
23
24 pt := []byte(<-c.ch)
25
26 p, err := models.ParsePointsWithPrecision(pt, time.Now().UTC(), precision)
27
28 if err != nil {
29 log.Fatalf("Error parsing point for commune\n point: %v\n error: %v\n", pt, err)
30 }
31
32 if len(p) == 0 {
33 return c.storedPoint
34 }
35
36 c.storedPoint = p[0]
37 return p[0]
38 }
39
40 // SetCommune creates a new commune on the StressTest
41 func (st *StressTest) SetCommune(name string) chan<- string {
42 com := newCommune(10)
43 st.communes[name] = com
44
45 return com.ch
46 }
47
48 // GetPoint is called by a QueryStatement and retrieves a point sent by the associated InsertStatement
49 func (st *StressTest) GetPoint(name, precision string) models.Point {
50 p := st.communes[name].point(precision)
51
52 // Function needs to return a point. Panic if it doesn't
53 if p == nil {
54 log.Fatal("Commune not returning point")
55 }
56
57 return p
58 }