influxdb/stress/v2/stress_client/commune.go

59 lines
1.3 KiB
Go
Raw Normal View History

package stressClient
2016-04-21 18:03:43 +00:00
import (
2016-04-25 18:13:10 +00:00
"log"
2016-04-21 18:03:43 +00:00
"time"
"github.com/influxdata/influxdb/models"
)
// Communes are a method for passing points between InsertStatements and QueryStatements.
type commune struct {
2016-04-28 21:22:39 +00:00
ch chan string
2016-04-21 18:03:43 +00:00
storedPoint models.Point
}
// NewCommune creates a new commune with a buffered chan of length n
2016-04-28 21:22:39 +00:00
func newCommune(n int) *commune {
return &commune{ch: make(chan string, n)}
2016-04-21 18:03:43 +00:00
}
func (c *commune) point(precision string) models.Point {
pt := []byte(<-c.ch)
p, err := models.ParsePointsWithPrecision(pt, time.Now().UTC(), precision)
if err != nil {
2016-04-25 18:13:10 +00:00
log.Fatalf("Error parsing point for commune\n point: %v\n error: %v\n", pt, err)
2016-04-21 18:03:43 +00:00
}
if len(p) == 0 {
return c.storedPoint
}
2016-04-28 21:22:39 +00:00
c.storedPoint = p[0]
2016-04-21 18:03:43 +00:00
return p[0]
}
// SetCommune creates a new commune on the StressTest
func (st *StressTest) SetCommune(name string) chan<- string {
2016-04-28 21:22:39 +00:00
com := newCommune(10)
st.communes[name] = com
2016-04-21 18:03:43 +00:00
2016-04-28 21:22:39 +00:00
return com.ch
2016-04-21 18:03:43 +00:00
}
// GetPoint is called by a QueryStatement and retrieves a point sent by the associated InsertStatement
func (st *StressTest) GetPoint(name, precision string) models.Point {
p := st.communes[name].point(precision)
2016-04-21 18:03:43 +00:00
// Function needs to return a point. Panic if it doesn't
if p == nil {
2016-04-25 18:13:10 +00:00
log.Fatal("Commune not returning point")
2016-04-21 18:03:43 +00:00
}
return p
}