本文整理匯總了Golang中github.com/mozilla-services/heka/plugins.PayloadEncoder.SetPipelineConfig方法的典型用法代碼示例。如果您正苦於以下問題:Golang PayloadEncoder.SetPipelineConfig方法的具體用法?Golang PayloadEncoder.SetPipelineConfig怎麽用?Golang PayloadEncoder.SetPipelineConfig使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mozilla-services/heka/plugins.PayloadEncoder
的用法示例。
在下文中一共展示了PayloadEncoder.SetPipelineConfig方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FileOutputSpec
func FileOutputSpec(c gs.Context) {
t := new(pipeline_ts.SimpleT)
ctrl := gomock.NewController(t)
tmpFileName := fmt.Sprintf("fileoutput-test-%d", time.Now().UnixNano())
tmpFilePath := filepath.Join(os.TempDir(), tmpFileName)
defer func() {
ctrl.Finish()
os.Remove(tmpFilePath)
}()
oth := plugins_ts.NewOutputTestHelper(ctrl)
var wg sync.WaitGroup
inChan := make(chan *PipelinePack, 1)
pConfig := NewPipelineConfig(nil)
c.Specify("A FileOutput", func() {
fileOutput := new(FileOutput)
encoder := new(plugins.PayloadEncoder)
encoder.Init(encoder.ConfigStruct())
config := fileOutput.ConfigStruct().(*FileOutputConfig)
config.Path = tmpFilePath
msg := pipeline_ts.GetTestMessage()
pack := NewPipelinePack(pConfig.InputRecycleChan())
pack.Message = msg
pack.Decoded = true
c.Specify("w/ ProtobufEncoder", func() {
encoder := new(ProtobufEncoder)
encoder.SetPipelineConfig(pConfig)
encoder.Init(nil)
oth.MockOutputRunner.EXPECT().Encoder().Return(encoder)
c.Specify("uses framing", func() {
oth.MockOutputRunner.EXPECT().SetUseFraming(true)
err := fileOutput.Init(config)
defer os.Remove(tmpFilePath)
c.Assume(err, gs.IsNil)
oth.MockOutputRunner.EXPECT().InChan().Return(inChan)
wg.Add(1)
go func() {
err = fileOutput.Run(oth.MockOutputRunner, oth.MockHelper)
c.Expect(err, gs.IsNil)
wg.Done()
}()
close(inChan)
wg.Wait()
})
c.Specify("but not if config says not to", func() {
useFraming := false
config.UseFraming = &useFraming
err := fileOutput.Init(config)
defer os.Remove(tmpFilePath)
c.Assume(err, gs.IsNil)
oth.MockOutputRunner.EXPECT().InChan().Return(inChan)
wg.Add(1)
go func() {
err = fileOutput.Run(oth.MockOutputRunner, oth.MockHelper)
c.Expect(err, gs.IsNil)
wg.Done()
}()
close(inChan)
wg.Wait()
// We should fail if SetUseFraming is called since we didn't
// EXPECT it.
})
})
c.Specify("processes incoming messages", func() {
err := fileOutput.Init(config)
c.Assume(err, gs.IsNil)
fileOutput.file.Close()
// Save for comparison.
payload := fmt.Sprintf("%s\n", pack.Message.GetPayload())
oth.MockOutputRunner.EXPECT().InChan().Return(inChan)
oth.MockOutputRunner.EXPECT().Encode(pack).Return(encoder.Encode(pack))
wg.Add(1)
go fileOutput.receiver(oth.MockOutputRunner, &wg)
inChan <- pack
close(inChan)
outBatch := <-fileOutput.batchChan
wg.Wait()
c.Expect(string(outBatch), gs.Equals, payload)
})
c.Specify("commits to a file", func() {
outStr := "Write me out to the log file"
outBytes := []byte(outStr)
c.Specify("with default settings", func() {
err := fileOutput.Init(config)
c.Assume(err, gs.IsNil)
// Start committer loop
wg.Add(1)
//.........這裏部分代碼省略.........