func (s *MetricsReaderSuite) TestUnblockedReaders(c *gc.C) { r, err := runner.NewJSONMetricsReader(s.paths.GetMetricsSpoolDir()) c.Assert(err, jc.ErrorIsNil) err = r.Close() c.Assert(err, jc.ErrorIsNil) r2, err := runner.NewJSONMetricsReader(s.paths.GetMetricsSpoolDir()) c.Assert(err, jc.ErrorIsNil) c.Assert(r2, gc.NotNil) err = r2.Close() c.Assert(err, jc.ErrorIsNil) }
func (s *MetricsReaderSuite) TestBlockedReaders(c *gc.C) { r, err := runner.NewJSONMetricsReader(s.paths.GetMetricsSpoolDir()) c.Assert(err, jc.ErrorIsNil) _, err = r.Open() c.Assert(err, jc.ErrorIsNil) r2, err := runner.NewJSONMetricsReader(s.paths.GetMetricsSpoolDir()) c.Assert(err, jc.ErrorIsNil) _, err = r2.Open() c.Assert(err, gc.ErrorMatches, `lock timeout exceeded`) err = r.Close() c.Assert(err, jc.ErrorIsNil) }
func (s *MetricsReaderSuite) TestRemoval(c *gc.C) { r, err := runner.NewJSONMetricsReader(s.paths.GetMetricsSpoolDir()) c.Assert(err, jc.ErrorIsNil) batches, err := r.Open() c.Assert(err, jc.ErrorIsNil) for _, batch := range batches { err := r.Remove(batch.UUID) c.Assert(err, jc.ErrorIsNil) } err = r.Close() c.Assert(err, jc.ErrorIsNil) batches, err = r.Open() c.Assert(err, jc.ErrorIsNil) c.Assert(batches, gc.HasLen, 0) err = r.Close() c.Assert(err, jc.ErrorIsNil) }
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) }