Esempio n. 1
0
func (s *MetricsReaderSuite) SetUpTest(c *gc.C) {
	s.paths = NewRealPaths(c)

	var err error
	s.w, err = runner.NewJSONMetricsRecorder(s.paths.GetMetricsSpoolDir(), "local:precise/wordpress")
	c.Assert(err, jc.ErrorIsNil)
	err = s.w.AddMetric("pings", "5", time.Now())
	c.Assert(err, jc.ErrorIsNil)
	err = s.w.Close()
	c.Assert(err, jc.ErrorIsNil)
}
Esempio n. 2
0
func (s *MetricsRecorderSuite) TestMetricRecorderInit(c *gc.C) {
	w, err := runner.NewJSONMetricsRecorder(s.paths.GetMetricsSpoolDir(), "local:precise/wordpress")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(w, gc.NotNil)
	err = w.AddMetric("pings", "5", time.Now())
	c.Assert(err, jc.ErrorIsNil)
	err = w.Close()
	c.Assert(err, jc.ErrorIsNil)

	r, err := runner.NewJSONMetricsReader(s.paths.GetMetricsSpoolDir())
	c.Assert(err, jc.ErrorIsNil)
	batches, err := r.Open()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(batches, gc.HasLen, 1)
	batch := batches[0]
	c.Assert(batch.CharmURL, gc.Equals, "local:precise/wordpress")
	c.Assert(batch.UUID, gc.Not(gc.Equals), "")
	c.Assert(batch.Metrics, gc.HasLen, 1)
	c.Assert(batch.Metrics[0].Key, gc.Equals, "pings")
	c.Assert(batch.Metrics[0].Value, gc.Equals, "5")

	err = r.Close()
	c.Assert(err, jc.ErrorIsNil)
}