當前位置: 首頁>>代碼示例>>Golang>>正文


Golang sender.NewSender函數代碼示例

本文整理匯總了Golang中github.com/juju/juju/worker/metrics/sender.NewSender函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewSender函數的具體用法?Golang NewSender怎麽用?Golang NewSender使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewSender函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestHandler

func (s *senderSuite) TestHandler(c *gc.C) {
	apiSender := newTestAPIMetricSender()
	tmpDir := c.MkDir()
	metricFactory := &stubMetricFactory{
		&testing.Stub{},
		tmpDir,
	}

	declaredMetrics := map[string]corecharm.Metric{
		"pings": corecharm.Metric{Description: "test pings", Type: corecharm.MetricTypeAbsolute},
	}
	recorder, err := metricFactory.Recorder(declaredMetrics, "local:trusty/testcharm", "testcharm/0")
	c.Assert(err, jc.ErrorIsNil)

	err = recorder.AddMetric("pings", "50", time.Now())
	c.Assert(err, jc.ErrorIsNil)

	err = recorder.Close()
	c.Assert(err, jc.ErrorIsNil)

	metricSender, err := sender.NewSender(apiSender, s.metricfactory, s.socketDir, "")
	c.Assert(err, jc.ErrorIsNil)

	conn := &mockConnection{data: []byte(fmt.Sprintf("%v\n", tmpDir))}
	err = metricSender.Handle(conn)
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(apiSender.batches, gc.HasLen, 1)
	c.Assert(apiSender.batches[0].Tag, gc.Equals, "testcharm/0")
	c.Assert(apiSender.batches[0].Batch.CharmURL, gc.Equals, "local:trusty/testcharm")
	c.Assert(apiSender.batches[0].Batch.Metrics, gc.HasLen, 1)
	c.Assert(apiSender.batches[0].Batch.Metrics[0].Key, gc.Equals, "pings")
	c.Assert(apiSender.batches[0].Batch.Metrics[0].Value, gc.Equals, "50")
}
開發者ID:exekias,項目名稱:juju,代碼行數:34,代碼來源:sender_test.go

示例2: TestNoSpoolDirectory

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

	metricfactory := &stubMetricFactory{
		&testing.Stub{},
		"/some/random/spool/dir",
	}

	metricSender := sender.NewSender(apiSender, metricfactory)
	stopCh := make(chan struct{})
	err := metricSender.Do(stopCh)
	c.Assert(err, gc.ErrorMatches, `failed to open spool directory "/some/random/spool/dir": .*`)

	c.Assert(apiSender.batches, gc.HasLen, 0)
}
開發者ID:imoapps,項目名稱:juju,代碼行數:15,代碼來源:sender_test.go

示例3: 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

示例4: TestNoMetricsToSend

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

	newTmpSpoolDir := c.MkDir()
	metricfactory := &stubMetricFactory{
		&testing.Stub{},
		newTmpSpoolDir,
	}

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

	c.Assert(apiSender.batches, gc.HasLen, 0)
}
開發者ID:imoapps,項目名稱:juju,代碼行數:16,代碼來源:sender_test.go

示例5: 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

示例6: 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


注:本文中的github.com/juju/juju/worker/metrics/sender.NewSender函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。