• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang spool.NewJSONMetricReader函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/juju/juju/worker/metrics/spool.NewJSONMetricReader函数的典型用法代码示例。如果您正苦于以下问题:Golang NewJSONMetricReader函数的具体用法?Golang NewJSONMetricReader怎么用?Golang NewJSONMetricReader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewJSONMetricReader函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestUnblockedReaders

func (s *metricsReaderSuite) TestUnblockedReaders(c *gc.C) {
	r, err := spool.NewJSONMetricReader(s.paths.GetMetricsSpoolDir())
	c.Assert(err, jc.ErrorIsNil)
	err = r.Close()
	c.Assert(err, jc.ErrorIsNil)

	r2, err := spool.NewJSONMetricReader(s.paths.GetMetricsSpoolDir())
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(r2, gc.NotNil)
	err = r2.Close()
	c.Assert(err, jc.ErrorIsNil)
}
开发者ID:bac,项目名称:juju,代码行数:12,代码来源:metrics_test.go


示例2: TestInit

func (s *metricsRecorderSuite) TestInit(c *gc.C) {
	w, err := spool.NewJSONMetricRecorder(
		spool.MetricRecorderConfig{
			SpoolDir: s.paths.GetMetricsSpoolDir(),
			Metrics:  map[string]corecharm.Metric{"pings": corecharm.Metric{}},
			CharmURL: "local:precise/wordpress",
			UnitTag:  s.unitTag,
		})
	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 := spool.NewJSONMetricReader(s.paths.GetMetricsSpoolDir())
	c.Assert(err, jc.ErrorIsNil)
	batches, err := r.Read()
	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")
	c.Assert(batch.UnitTag, gc.Equals, s.unitTag)

	err = r.Close()
	c.Assert(err, jc.ErrorIsNil)
}
开发者ID:bac,项目名称:juju,代码行数:31,代码来源:metrics_test.go


示例3: TestBuiltinMetricNotGeneratedIfNotDefined

func (s *FlushContextSuite) TestBuiltinMetricNotGeneratedIfNotDefined(c *gc.C) {
	uuid := utils.MustNewUUID()
	paths := runnertesting.NewRealPaths(c)
	ctx := s.getMeteredHookContext(c, uuid.String(), -1, "", noProxies, true, s.metricsDefinition("pings"), paths)
	reader, err := spool.NewJSONMetricReader(
		paths.GetMetricsSpoolDir(),
	)

	err = ctx.Flush("some badge", nil)
	c.Assert(err, jc.ErrorIsNil)
	batches, err := reader.Read()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(batches, gc.HasLen, 0)
}
开发者ID:howbazaar,项目名称:juju,代码行数:14,代码来源:flush_test.go


示例4: TestMetricSendingSuccess

func (s *senderSuite) TestMetricSendingSuccess(c *gc.C) {
	apiSender := newTestAPIMetricSender()

	metricSender := sender.NewSender(apiSender, s.metricfactory)
	stopCh := make(chan struct{})
	err := metricSender.Do(stopCh)
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(apiSender.batches, gc.HasLen, 1)

	reader, err := spool.NewJSONMetricReader(s.spoolDir)
	c.Assert(err, jc.ErrorIsNil)
	batches, err := reader.Read()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(batches, gc.HasLen, 0)
}
开发者ID:imoapps,项目名称:juju,代码行数:16,代码来源:sender_test.go


示例5: TestRemoval

func (s *metricsReaderSuite) TestRemoval(c *gc.C) {
	r, err := spool.NewJSONMetricReader(s.paths.GetMetricsSpoolDir())
	c.Assert(err, jc.ErrorIsNil)

	batches, err := r.Read()
	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.Read()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(batches, gc.HasLen, 0)
	err = r.Close()
	c.Assert(err, jc.ErrorIsNil)
}
开发者ID:bac,项目名称:juju,代码行数:19,代码来源:metrics_test.go


示例6: TestUnknownMetricKey

func (s *metricsRecorderSuite) TestUnknownMetricKey(c *gc.C) {
	w, err := spool.NewJSONMetricRecorder(
		spool.MetricRecorderConfig{
			SpoolDir: s.paths.GetMetricsSpoolDir(),
			Metrics:  map[string]corecharm.Metric{},
			CharmURL: "local:precise/wordpress",
			UnitTag:  s.unitTag,
		})
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(w, gc.NotNil)
	err = w.AddMetric("pings", "5", time.Now())
	c.Assert(err, gc.ErrorMatches, `metric key "pings" not declared by the charm`)
	err = w.Close()
	c.Assert(err, jc.ErrorIsNil)

	r, err := spool.NewJSONMetricReader(s.paths.GetMetricsSpoolDir())
	c.Assert(err, jc.ErrorIsNil)
	batches, err := r.Read()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(batches, gc.HasLen, 0)
}
开发者ID:kakamessi99,项目名称:juju,代码行数:21,代码来源:metrics_test.go


示例7: TestSendingFails

func (s *senderSuite) TestSendingFails(c *gc.C) {
	apiSender := newTestAPIMetricSender()

	select {
	case apiSender.sendError <- errors.New("something went wrong"):
	default:
		c.Fatalf("blocked error channel")
	}

	metricSender := sender.NewSender(apiSender, s.metricfactory)
	stopCh := make(chan struct{})
	err := metricSender.Do(stopCh)
	c.Assert(err, gc.ErrorMatches, "something went wrong")

	c.Assert(apiSender.batches, gc.HasLen, 1)

	reader, err := spool.NewJSONMetricReader(s.spoolDir)
	c.Assert(err, jc.ErrorIsNil)
	batches, err := reader.Read()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(batches, gc.HasLen, 1)
}
开发者ID:imoapps,项目名称:juju,代码行数:22,代码来源:sender_test.go


示例8: TestSendingGetDuplicate

func (s *senderSuite) TestSendingGetDuplicate(c *gc.C) {
	apiSender := newTestAPIMetricSender()

	apiErr := &params.Error{Message: "already exists", Code: params.CodeAlreadyExists}
	select {
	case apiSender.errors <- apiErr:
	default:
		c.Fatalf("blocked error channel")
	}

	metricSender := sender.NewSender(apiSender, s.metricfactory)
	stopCh := make(chan struct{})
	err := metricSender.Do(stopCh)
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(apiSender.batches, gc.HasLen, 1)

	reader, err := spool.NewJSONMetricReader(s.spoolDir)
	c.Assert(err, jc.ErrorIsNil)
	batches, err := reader.Read()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(batches, gc.HasLen, 0)
}
开发者ID:imoapps,项目名称:juju,代码行数:23,代码来源:sender_test.go


示例9: Reader

func (s *stubMetricFactory) Reader() (spool.MetricReader, error) {
	s.MethodCall(s, "Reader")
	return spool.NewJSONMetricReader(s.spoolDir)

}
开发者ID:exekias,项目名称:juju,代码行数:5,代码来源:sender_test.go


示例10: TestMetricValidation

func (s *metricsRecorderSuite) TestMetricValidation(c *gc.C) {
	tests := []struct {
		about         string
		key           string
		value         string
		expectedError string
	}{{
		about:         "metric not declared",
		key:           "pings",
		value:         "5",
		expectedError: `metric key "pings" not declared by the charm`,
	}, {
		about:         "non float metrics",
		key:           "pongs",
		value:         "abcd",
		expectedError: `invalid value type: expected float, got "abcd"`,
	}, {
		about:         "negative value",
		key:           "pongs",
		value:         "-5.0",
		expectedError: `invalid value: value must be greater or equal to zero, got -5.0`,
	}, {
		about:         "large value",
		key:           "pongs",
		value:         "1234567890123456789012345678901234567890",
		expectedError: `metric value is too large`,
	},
	}

	for _, test := range tests {
		w, err := spool.NewJSONMetricRecorder(
			spool.MetricRecorderConfig{
				SpoolDir: s.paths.GetMetricsSpoolDir(),
				Metrics: map[string]corecharm.Metric{
					"juju-units": corecharm.Metric{},
					"pongs": corecharm.Metric{
						Type: corecharm.MetricTypeAbsolute,
					},
				},
				CharmURL: "local:precise/wordpress",
				UnitTag:  s.unitTag,
			})
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(w, gc.NotNil)

		c.Logf("running test: %s", test.about)
		err = w.AddMetric(test.key, test.value, time.Now())
		if test.expectedError != "" {
			c.Assert(err, gc.ErrorMatches, test.expectedError)
			err = w.Close()
			c.Assert(err, jc.ErrorIsNil)

			r, err := spool.NewJSONMetricReader(s.paths.GetMetricsSpoolDir())
			c.Assert(err, jc.ErrorIsNil)
			batches, err := r.Read()
			c.Assert(err, jc.ErrorIsNil)
			c.Assert(batches, gc.HasLen, 0)
		} else {
			c.Assert(err, jc.ErrorIsNil)
			err = w.Close()
			c.Assert(err, jc.ErrorIsNil)
		}
	}
}
开发者ID:bac,项目名称:juju,代码行数:64,代码来源:metrics_test.go



注:本文中的github.com/juju/juju/worker/metrics/spool.NewJSONMetricReader函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang migrationflag.Manifold函数代码示例发布时间:2022-05-23
下一篇:
Golang sender.NewSender函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap