63 Star 183 Fork 3

Gitee 极速下载/hyperledger-fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/hyperledger/fabric
克隆/下载
metrics.go 4.64 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package mocks
import (
"github.com/hyperledger/fabric/common/metrics"
"github.com/hyperledger/fabric/common/metrics/metricsfakes"
gmetrics "github.com/hyperledger/fabric/gossip/metrics"
)
type TestMetricProvider struct {
FakeProvider *metricsfakes.Provider
FakeHeightGauge *metricsfakes.Gauge
FakeCommitDurationHist *metricsfakes.Histogram
FakePayloadBufferSizeGauge *metricsfakes.Gauge
FakeDeclarationGauge *metricsfakes.Gauge
FakeSentMessages *metricsfakes.Counter
FakeBufferOverflow *metricsfakes.Counter
FakeReceivedMessages *metricsfakes.Counter
FakeTotalGauge *metricsfakes.Gauge
FakeValidationDuration *metricsfakes.Histogram
FakeListMissingPrivateDataDuration *metricsfakes.Histogram
FakeFetchDuration *metricsfakes.Histogram
FakeCommitPrivateDataDuration *metricsfakes.Histogram
FakePurgeDuration *metricsfakes.Histogram
FakeSendDuration *metricsfakes.Histogram
FakeReconciliationDuration *metricsfakes.Histogram
FakePullDuration *metricsfakes.Histogram
FakeRetrieveDuration *metricsfakes.Histogram
}
func TestUtilConstructMetricProvider() *TestMetricProvider {
fakeProvider := &metricsfakes.Provider{}
fakeHeightGauge := testUtilConstructGauge()
fakeCommitDurationHist := testUtilConstructHist()
fakePayloadBufferSizeGauge := testUtilConstructGauge()
fakeDeclarationGauge := testUtilConstructGauge()
fakeSentMessages := testUtilConstructCounter()
fakeBufferOverflow := testUtilConstructCounter()
fakeReceivedMessages := testUtilConstructCounter()
fakeTotalGauge := testUtilConstructGauge()
fakeValidationDuration := testUtilConstructHist()
fakeListMissingPrivateDataDuration := testUtilConstructHist()
fakeFetchDuration := testUtilConstructHist()
fakeCommitPrivateDataDuration := testUtilConstructHist()
fakePurgeDuration := testUtilConstructHist()
fakeSendDuration := testUtilConstructHist()
fakeReconciliationDuration := testUtilConstructHist()
fakePullDuration := testUtilConstructHist()
fakeRetrieveDuration := testUtilConstructHist()
fakeProvider.NewCounterStub = func(opts metrics.CounterOpts) metrics.Counter {
switch opts.Name {
case gmetrics.BufferOverflowOpts.Name:
return fakeBufferOverflow
case gmetrics.SentMessagesOpts.Name:
return fakeSentMessages
case gmetrics.ReceivedMessagesOpts.Name:
return fakeReceivedMessages
}
return nil
}
fakeProvider.NewHistogramStub = func(opts metrics.HistogramOpts) metrics.Histogram {
switch opts.Name {
case gmetrics.CommitDurationOpts.Name:
return fakeCommitDurationHist
case gmetrics.ValidationDurationOpts.Name:
return fakeValidationDuration
case gmetrics.ListMissingPrivateDataDurationOpts.Name:
return fakeListMissingPrivateDataDuration
case gmetrics.FetchDurationOpts.Name:
return fakeFetchDuration
case gmetrics.CommitPrivateDataDurationOpts.Name:
return fakeCommitPrivateDataDuration
case gmetrics.PurgeDurationOpts.Name:
return fakePurgeDuration
case gmetrics.SendDurationOpts.Name:
return fakeSendDuration
case gmetrics.ReconciliationDurationOpts.Name:
return fakeReconciliationDuration
case gmetrics.PullDurationOpts.Name:
return fakePullDuration
case gmetrics.RetrieveDurationOpts.Name:
return fakeRetrieveDuration
}
return nil
}
fakeProvider.NewGaugeStub = func(opts metrics.GaugeOpts) metrics.Gauge {
switch opts.Name {
case gmetrics.PayloadBufferSizeOpts.Name:
return fakePayloadBufferSizeGauge
case gmetrics.HeightOpts.Name:
return fakeHeightGauge
case gmetrics.LeaderDeclerationOpts.Name:
return fakeDeclarationGauge
case gmetrics.TotalOpts.Name:
return fakeTotalGauge
}
return nil
}
return &TestMetricProvider{
fakeProvider,
fakeHeightGauge,
fakeCommitDurationHist,
fakePayloadBufferSizeGauge,
fakeDeclarationGauge,
fakeSentMessages,
fakeBufferOverflow,
fakeReceivedMessages,
fakeTotalGauge,
fakeValidationDuration,
fakeListMissingPrivateDataDuration,
fakeFetchDuration,
fakeCommitPrivateDataDuration,
fakePurgeDuration,
fakeSendDuration,
fakeReconciliationDuration,
fakePullDuration,
fakeRetrieveDuration,
}
}
func testUtilConstructGauge() *metricsfakes.Gauge {
fakeGauge := &metricsfakes.Gauge{}
fakeGauge.WithReturns(fakeGauge)
return fakeGauge
}
func testUtilConstructHist() *metricsfakes.Histogram {
fakeHist := &metricsfakes.Histogram{}
fakeHist.WithReturns(fakeHist)
return fakeHist
}
func testUtilConstructCounter() *metricsfakes.Counter {
fakeCounter := &metricsfakes.Counter{}
fakeCounter.WithReturns(fakeCounter)
return fakeCounter
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/hyperledger-fabric.git
git@gitee.com:mirrors/hyperledger-fabric.git
mirrors
hyperledger-fabric
hyperledger-fabric
v2.1.1

搜索帮助