本文整理汇总了Golang中org/apache/htrace/conf.Builder.Build方法的典型用法代码示例。如果您正苦于以下问题:Golang Builder.Build方法的具体用法?Golang Builder.Build怎么用?Golang Builder.Build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org/apache/htrace/conf.Builder
的用法示例。
在下文中一共展示了Builder.Build方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newLogger
func newLogger(faculty string, args ...string) *Logger {
cnfBld := conf.Builder{Defaults: conf.DEFAULTS}
cnf, err := cnfBld.Build()
if err != nil {
panic(fmt.Sprintf("failed to create conf: %s", err.Error()))
}
cnf2 := cnf.Clone(args...)
lg := NewLogger(faculty, cnf2)
return lg
}
示例2: TestHeartbeaterStartupShutdown
func TestHeartbeaterStartupShutdown(t *testing.T) {
cnfBld := conf.Builder{
Values: conf.TEST_VALUES(),
Defaults: conf.DEFAULTS,
}
cnf, err := cnfBld.Build()
if err != nil {
t.Fatalf("failed to create conf: %s", err.Error())
}
lg := common.NewLogger("heartbeater", cnf)
hb := NewHeartbeater("ExampleHeartbeater", 1, lg)
if hb.String() != "ExampleHeartbeater" {
t.Fatalf("hb.String() returned %s instead of %s\n", hb.String(), "ExampleHeartbeater")
}
hb.Shutdown()
}
示例3: runHelperProcess
// Run the helper process which TestSignals spawns.
func runHelperProcess() {
cnfMap := map[string]string{
conf.HTRACE_LOG_LEVEL: "TRACE",
conf.HTRACE_LOG_PATH: "", // log to stdout
}
cnfBld := conf.Builder{Values: cnfMap, Defaults: conf.DEFAULTS}
cnf, err := cnfBld.Build()
if err != nil {
fmt.Printf("Error building configuration: %s\n", err.Error())
os.Exit(1)
}
InstallSignalHandlers(cnf)
fmt.Fprintf(os.Stderr, "Signal handler installed.\n")
// Wait for a signal to be delivered
for {
time.Sleep(time.Hour * 100)
}
}
示例4: TestHeartbeaterSendsHeartbeats
func TestHeartbeaterSendsHeartbeats(t *testing.T) {
cnfBld := conf.Builder{
Values: conf.TEST_VALUES(),
Defaults: conf.DEFAULTS,
}
cnf, err := cnfBld.Build()
if err != nil {
t.Fatalf("failed to create conf: %s", err.Error())
}
lg := common.NewLogger("heartbeater", cnf)
// The minimum amount of time which the heartbeater test should take
MINIMUM_TEST_DURATION := time.Millisecond * (NUM_TEST_HEARTBEATS * HEARTBEATER_PERIOD)
duration := MINIMUM_TEST_DURATION
for duration <= MINIMUM_TEST_DURATION {
start := time.Now()
testHeartbeaterSendsHeartbeatsImpl(t, lg)
end := time.Now()
duration = end.Sub(start)
lg.Debugf("Measured duration: %v; minimum expected duration: %v\n",
duration, MINIMUM_TEST_DURATION)
}
}
示例5: TestMetricsSinkPerHostEviction
func TestMetricsSinkPerHostEviction(t *testing.T) {
cnfBld := conf.Builder{
Values: conf.TEST_VALUES(),
Defaults: conf.DEFAULTS,
}
cnfBld.Values[conf.HTRACE_METRICS_MAX_ADDR_ENTRIES] = "2"
cnf, err := cnfBld.Build()
if err != nil {
t.Fatalf("failed to create conf: %s", err.Error())
}
msink := NewMetricsSink(cnf)
msink.UpdatePersisted("192.168.0.100", 20, 10)
msink.UpdatePersisted("192.168.0.101", 20, 10)
msink.UpdatePersisted("192.168.0.102", 20, 10)
msink.lock.Lock()
defer msink.lock.Unlock()
if len(msink.HostSpanMetrics) != 2 {
for k, v := range msink.HostSpanMetrics {
fmt.Printf("WATERMELON: [%s] = [%s]\n", k, v)
}
t.Fatalf("Expected len(msink.HostSpanMetrics) to be 2, but got %d\n",
len(msink.HostSpanMetrics))
}
}
示例6: Build
func (bld *MiniHTracedBuilder) Build() (*MiniHTraced, error) {
var err error
var store *dataStore
var rsv *RestServer
var hsv *HrpcServer
if bld.Name == "" {
bld.Name = "HTraceTest"
}
if bld.Cnf == nil {
bld.Cnf = make(map[string]string)
}
if bld.DataDirs == nil {
bld.DataDirs = make([]string, 2)
}
for idx := range bld.DataDirs {
if bld.DataDirs[idx] == "" {
bld.DataDirs[idx], err = ioutil.TempDir(os.TempDir(),
fmt.Sprintf("%s%d", bld.Name, idx+1))
if err != nil {
return nil, err
}
}
}
// Copy the default test configuration values.
for k, v := range conf.TEST_VALUES() {
_, hasVal := bld.Cnf[k]
if !hasVal {
bld.Cnf[k] = v
}
}
bld.Cnf[conf.HTRACE_DATA_STORE_DIRECTORIES] =
strings.Join(bld.DataDirs, conf.PATH_LIST_SEP)
cnfBld := conf.Builder{Values: bld.Cnf, Defaults: conf.DEFAULTS}
cnf, err := cnfBld.Build()
if err != nil {
return nil, err
}
lg := common.NewLogger("mini.htraced", cnf)
defer func() {
if err != nil {
if store != nil {
store.Close()
}
for idx := range bld.DataDirs {
if !bld.KeepDataDirsOnClose {
if bld.DataDirs[idx] != "" {
os.RemoveAll(bld.DataDirs[idx])
}
}
}
if rsv != nil {
rsv.Close()
}
lg.Infof("Failed to create MiniHTraced %s: %s\n", bld.Name, err.Error())
lg.Close()
}
}()
store, err = CreateDataStore(cnf, bld.WrittenSpans)
if err != nil {
return nil, err
}
rstListener, listenErr := net.Listen("tcp", cnf.Get(conf.HTRACE_WEB_ADDRESS))
if listenErr != nil {
return nil, listenErr
}
defer func() {
if rstListener != nil {
rstListener.Close()
}
}()
rsv, err = CreateRestServer(cnf, store, rstListener)
if err != nil {
return nil, err
}
rstListener = nil
hsv, err = CreateHrpcServer(cnf, store, bld.HrpcTestHooks)
if err != nil {
return nil, err
}
lg.Infof("Created MiniHTraced %s\n", bld.Name)
return &MiniHTraced{
Name: bld.Name,
Cnf: cnf,
DataDirs: bld.DataDirs,
Store: store,
Rsv: rsv,
Hsv: hsv,
Lg: lg,
KeepDataDirsOnClose: bld.KeepDataDirsOnClose,
}, nil
}
示例7: Build
func (bld *MiniHTracedBuilder) Build() (*MiniHTraced, error) {
var err error
var store *dataStore
var rsv *RestServer
var hsv *HrpcServer
if bld.Name == "" {
bld.Name = "HTraceTest"
}
if bld.Cnf == nil {
bld.Cnf = make(map[string]string)
}
if bld.DataDirs == nil {
bld.DataDirs = make([]string, 2)
}
for idx := range bld.DataDirs {
if bld.DataDirs[idx] == "" {
bld.DataDirs[idx], err = ioutil.TempDir(os.TempDir(),
fmt.Sprintf("%s%d", bld.Name, idx+1))
if err != nil {
return nil, err
}
}
}
bld.Cnf[conf.HTRACE_DATA_STORE_DIRECTORIES] =
strings.Join(bld.DataDirs, conf.PATH_LIST_SEP)
bld.Cnf[conf.HTRACE_WEB_ADDRESS] = ":0" // use a random port for the REST server
bld.Cnf[conf.HTRACE_HRPC_ADDRESS] = ":0" // use a random port for the HRPC server
bld.Cnf[conf.HTRACE_LOG_LEVEL] = "TRACE"
cnfBld := conf.Builder{Values: bld.Cnf, Defaults: conf.DEFAULTS}
cnf, err := cnfBld.Build()
if err != nil {
return nil, err
}
lg := common.NewLogger("mini.htraced", cnf)
defer func() {
if err != nil {
if store != nil {
store.Close()
}
for idx := range bld.DataDirs {
if bld.DataDirs[idx] != "" {
os.RemoveAll(bld.DataDirs[idx])
}
}
if rsv != nil {
rsv.Close()
}
lg.Infof("Failed to create MiniHTraced %s: %s\n", bld.Name, err.Error())
lg.Close()
}
}()
store, err = CreateDataStore(cnf, bld.WrittenSpans)
if err != nil {
return nil, err
}
rsv, err = CreateRestServer(cnf, store)
if err != nil {
return nil, err
}
hsv, err = CreateHrpcServer(cnf, store)
if err != nil {
return nil, err
}
lg.Infof("Created MiniHTraced %s\n", bld.Name)
return &MiniHTraced{
Name: bld.Name,
Cnf: cnf,
DataDirs: bld.DataDirs,
Store: store,
Rsv: rsv,
Hsv: hsv,
Lg: lg,
KeepDataDirsOnClose: bld.KeepDataDirsOnClose,
}, nil
}