本文整理匯總了Golang中github.com/mozilla-services/heka/client.NewProtobufEncoder函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewProtobufEncoder函數的具體用法?Golang NewProtobufEncoder怎麽用?Golang NewProtobufEncoder使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewProtobufEncoder函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewHekaLogger
// Create a new Heka logging interface.
func NewHekaLogger(conf *MzConfig) *HekaLogger {
//Preflight
var encoder client.Encoder = nil
var sender client.Sender = nil
var logname string = ""
var err error
var tracer bool = false
var filter int64
pid := int32(os.Getpid())
dhost, _ := os.Hostname()
conf.SetDefaultFlag("heka.show_caller", false)
conf.SetDefault("logger.filter", "10")
filter, _ = strconv.ParseInt(conf.Get("logger.filter", "10"), 0, 0)
if conf.GetFlag("heka.use") {
encoder = client.NewProtobufEncoder(nil)
sender, err = client.NewNetworkSender(conf.Get("heka.sender", "tcp"),
conf.Get("heka.server_addr", "127.0.0.1:5565"))
if err != nil {
log.Panic("Could not create sender ", err)
}
logname = conf.Get("heka.logger_name", "package")
}
return &HekaLogger{encoder: encoder,
sender: sender,
logname: logname,
pid: pid,
hostname: conf.Get("heka.current_host", dhost),
conf: conf,
tracer: tracer,
filter: filter}
}
示例2: Init
func (s *SandboxEncoder) Init(config interface{}) (err error) {
conf := config.(*SandboxEncoderConfig)
s.sbc = &sandbox.SandboxConfig{
ScriptType: conf.ScriptType,
ScriptFilename: conf.ScriptFilename,
ModuleDirectory: conf.ModuleDirectory,
PreserveData: conf.PreserveData,
MemoryLimit: conf.MemoryLimit,
InstructionLimit: conf.InstructionLimit,
OutputLimit: conf.OutputLimit,
Profile: conf.Profile,
Config: conf.Config,
}
s.sbc.ScriptFilename = pipeline.PrependShareDir(s.sbc.ScriptFilename)
s.sampleDenominator = pipeline.Globals().SampleDenominator
s.tz = time.UTC
if tz, ok := s.sbc.Config["tz"]; ok {
if s.tz, err = time.LoadLocation(tz.(string)); err != nil {
return
}
}
dataDir := pipeline.PrependBaseDir(sandbox.DATA_DIR)
if !fileExists(dataDir) {
if err = os.MkdirAll(dataDir, 0700); err != nil {
return
}
}
switch s.sbc.ScriptType {
case "lua":
s.sb, err = lua.CreateLuaSandbox(s.sbc)
default:
return fmt.Errorf("Unsupported script type: %s", s.sbc.ScriptType)
}
if err != nil {
return fmt.Errorf("Sandbox creation failed: '%s'", err)
}
s.preservationFile = filepath.Join(dataDir, s.name+sandbox.DATA_EXT)
if s.sbc.PreserveData && fileExists(s.preservationFile) {
err = s.sb.Init(s.preservationFile, "encoder")
} else {
err = s.sb.Init("", "encoder")
}
if err != nil {
return fmt.Errorf("Sandbox initialization failed: %s", err)
}
s.sb.InjectMessage(func(payload, payload_type, payload_name string) int {
s.injected = true
s.output = []byte(payload)
return 0
})
s.sample = true
s.cEncoder = client.NewProtobufEncoder(nil)
return
}
示例3: NewHekaClient
// NewHekaClient returns a new HekaClient with pre-defined encoder and sender.
func NewHekaClient(hi string) (hc *HekaClient, err error) {
hc = &HekaClient{}
hc.encoder = client.NewProtobufEncoder(nil)
hc.sender, err = client.NewNetworkSender("tcp", hi)
if err == nil {
return hc, nil
}
return
}
示例4: main
func main() {
configFile := flag.String("config", "sbmgr.toml", "Sandbox manager configuration file")
scriptFile := flag.String("script", "xyz.lua", "Sandbox script file")
scriptConfig := flag.String("scriptconfig", "xyz.toml", "Sandbox script configuration file")
filterName := flag.String("filtername", "filter", "Sandbox filter name (used on unload)")
action := flag.String("action", "load", "Sandbox manager action")
flag.Parse()
var config SbmgrConfig
if _, err := toml.DecodeFile(*configFile, &config); err != nil {
log.Printf("Error decoding config file: %s", err)
return
}
sender, err := client.NewNetworkSender("tcp", config.IpAddress)
if err != nil {
log.Fatalf("Error creating sender: %s\n", err.Error())
}
encoder := client.NewProtobufEncoder(&config.Signer)
manager := client.NewClient(sender, encoder)
hostname, _ := os.Hostname()
msg := &message.Message{}
msg.SetType("heka.control.sandbox")
msg.SetTimestamp(time.Now().UnixNano())
msg.SetUuid(uuid.NewRandom())
msg.SetHostname(hostname)
switch *action {
case "load":
code, err := ioutil.ReadFile(*scriptFile)
if err != nil {
log.Printf("Error reading scriptFile: %s\n", err.Error())
return
}
msg.SetPayload(string(code))
conf, err := ioutil.ReadFile(*scriptConfig)
if err != nil {
log.Printf("Error reading scriptConfig: %s\n", err.Error())
return
}
f, _ := message.NewField("config", string(conf), "toml")
msg.AddField(f)
case "unload":
f, _ := message.NewField("name", *filterName, "")
msg.AddField(f)
default:
log.Printf("Invalid action: %s", *action)
}
f1, _ := message.NewField("action", *action, "")
msg.AddField(f1)
err = manager.SendMessage(msg)
if err != nil {
log.Printf("Error sending message: %s\n", err.Error())
}
}
示例5: NewProtobufEmitter
// NewProtobufEmitter creates a Protobuf-encoded Heka log message emitter.
// Protobuf encoding should be preferred over JSON for efficiency.
func NewProtobufEmitter(sender client.Sender, envVersion,
hostname, loggerName string) *HekaEmitter {
return &HekaEmitter{
Sender: sender,
StreamEncoder: client.NewProtobufEncoder(nil),
LogName: fmt.Sprintf("%s-%s", loggerName, VERSION),
Pid: int32(os.Getpid()),
EnvVersion: envVersion,
Hostname: hostname,
}
}
示例6: NewHekaClient
// NewHekaClient returns a new HekaClient with process ID, hostname, encoder and sender.
func NewHekaClient(h, hn string) (self *HekaClient, err error) {
self = &HekaClient{}
self.pid = int32(os.Getpid())
if hn == "" {
self.hostname, _ = os.Hostname()
} else {
self.hostname = hn
}
self.encoder = client.NewProtobufEncoder(nil)
self.sender, err = client.NewNetworkSender("tcp", h)
if err == nil {
return self, nil
}
return
}
示例7: sendToHeka
// sendToHeka sends array of snap metrics to Heka
func (shc *SnapHekaClient) sendToHeka(metrics []plugin.MetricType) error {
pid := int32(os.Getpid())
hostname, _ := os.Hostname()
// Initializes Heka message encoder
encoder := client.NewProtobufEncoder(nil)
// Creates Heka message sender
sender, err := client.NewNetworkSender(shc.hekaScheme, shc.hekaHost)
if err != nil {
logger.WithField("_block", "sendToHeka").Error("create NewNetworkSender error: ", err)
return err
}
var buf []byte
for _, m := range metrics {
b, _, e := plugin.MarshalMetricTypes(plugin.SnapJSONContentType, []plugin.MetricType{m})
if e != nil {
logger.WithField("_block", "sendToHeka").Error("marshal metric error: ", m)
continue
}
// Converts snap metric to Heka message
msg, err := createHekaMessage(string(b), m, pid, hostname)
if err != nil {
logger.WithField("_block", "sendToHeka").Error("create message error: ", err)
continue
}
err = encoder.EncodeMessageStream(msg, &buf)
if err != nil {
logger.WithField("_block", "sendToHeka").Error("encoding error: ", err)
continue
}
err = sender.SendMessage(buf)
if err != nil {
logger.WithField("_block", "sendToHeka").Error("sending message error: ", err)
}
}
sender.Close()
return nil
}
示例8: Run
func (no *NsqOutput) Run(or pipeline.OutputRunner, h pipeline.PluginHelper) (err error) {
var (
encoder client.Encoder
msg *message.Message
msgBody []byte = make([]byte, 0, 1024)
pack *pipeline.PipelinePack
)
conf := no.conf
encoder = client.NewProtobufEncoder(nil)
for pack = range or.InChan() {
if conf.Serialize {
msg = pack.Message
if err = encoder.EncodeMessageStream(msg, &msgBody); err != nil {
or.LogError(err)
err = nil
pack.Recycle()
continue
}
//err := no.nsqwriter.PublishAsync(conf.Topic, []byte(pack.Message.GetPayload()), nil)
//err = no.nsqwriter.PublishAsync(conf.Topic, msgBody, nil)
_, _, err = no.nsqwriter.Publish(conf.Topic, msgBody)
if err != nil {
or.LogError(fmt.Errorf("error in writer.PublishAsync"))
}
msgBody = msgBody[:0]
} else {
err = no.nsqwriter.PublishAsync(conf.Topic, []byte(pack.Message.GetPayload()), nil)
if err != nil {
or.LogError(fmt.Errorf("error in writer.PublishAsync"))
}
}
pack.Recycle()
}
return
}
示例9: AMQPPluginSpec
func AMQPPluginSpec(c gs.Context) {
t := &ts.SimpleT{}
ctrl := gomock.NewController(t)
defer ctrl.Finish()
config := NewPipelineConfig(nil)
// Our two user/conn waitgroups
ug := new(sync.WaitGroup)
cg := new(sync.WaitGroup)
// Setup the mock channel
mch := NewMockAMQPChannel(ctrl)
// Setup the mock amqpHub with the mock chan return
aqh := NewMockAMQPConnectionHub(ctrl)
aqh.EXPECT().GetChannel("").Return(mch, ug, cg, nil)
var oldHub AMQPConnectionHub
oldHub = amqpHub
amqpHub = aqh
defer func() {
amqpHub = oldHub
}()
c.Specify("An amqp input", func() {
// Setup all the mock calls for Init
mch.EXPECT().ExchangeDeclare("", "", false, true, false, false,
gomock.Any()).Return(nil)
mch.EXPECT().QueueDeclare("", false, true, false, false,
gomock.Any()).Return(amqp.Queue{}, nil)
mch.EXPECT().QueueBind("", "test", "", false, gomock.Any()).Return(nil)
mch.EXPECT().Qos(2, 0, false).Return(nil)
ith := new(InputTestHelper)
ith.Msg = getTestMessage()
ith.Pack = NewPipelinePack(config.inputRecycleChan)
// set up mock helper, decoder set, and packSupply channel
ith.MockHelper = NewMockPluginHelper(ctrl)
ith.MockInputRunner = NewMockInputRunner(ctrl)
ith.Decoders = make([]DecoderRunner, int(message.Header_JSON+1))
ith.Decoders[message.Header_PROTOCOL_BUFFER] = NewMockDecoderRunner(ctrl)
ith.Decoders[message.Header_JSON] = NewMockDecoderRunner(ctrl)
ith.PackSupply = make(chan *PipelinePack, 1)
ith.DecodeChan = make(chan *PipelinePack)
ith.MockDecoderSet = NewMockDecoderSet(ctrl)
ith.MockInputRunner.EXPECT().InChan().Return(ith.PackSupply)
ith.MockHelper.EXPECT().DecoderSet().Times(2).Return(ith.MockDecoderSet)
encCall := ith.MockDecoderSet.EXPECT().ByEncodings()
encCall.Return(ith.Decoders, nil)
c.Specify("with a valid setup and no decoders", func() {
amqpInput := new(AMQPInput)
defaultConfig := amqpInput.ConfigStruct().(*AMQPInputConfig)
defaultConfig.URL = ""
defaultConfig.Exchange = ""
defaultConfig.ExchangeType = ""
defaultConfig.RoutingKey = "test"
err := amqpInput.Init(defaultConfig)
c.Assume(err, gs.IsNil)
c.Expect(amqpInput.ch, gs.Equals, mch)
c.Specify("consumes a message", func() {
// Create a channel to send data to the input
// Drop a message on there and close the channel
streamChan := make(chan amqp.Delivery, 1)
ack := ts.NewMockAcknowledger(ctrl)
ack.EXPECT().Ack(gomock.Any(), false)
streamChan <- amqp.Delivery{
ContentType: "text/plain",
Body: []byte("This is a message"),
Timestamp: time.Now(),
Acknowledger: ack,
}
mch.EXPECT().Consume("", "", false, false, false, false,
gomock.Any()).Return(streamChan, nil)
// Expect the injected packet
ith.MockInputRunner.EXPECT().Inject(gomock.Any())
// Increase the usage since Run decrements it on close
ug.Add(1)
ith.PackSupply <- ith.Pack
go func() {
amqpInput.Run(ith.MockInputRunner, ith.MockHelper)
}()
ith.PackSupply <- ith.Pack
c.Expect(ith.Pack.Message.GetType(), gs.Equals, "amqp")
c.Expect(ith.Pack.Message.GetPayload(), gs.Equals, "This is a message")
close(streamChan)
})
c.Specify("consumes a serialized message", func() {
encoder := client.NewProtobufEncoder(nil)
streamChan := make(chan amqp.Delivery, 1)
//.........這裏部分代碼省略.........
示例10: createProtobufStream
// Create a protocol buffers stream for the given message, put it in the given
// byte slice.
func createProtobufStream(pack *PipelinePack, outBytes *[]byte) (err error) {
enc := client.NewProtobufEncoder(nil)
err = enc.EncodeMessageStream(pack.Message, outBytes)
return
}
示例11: main
func main() {
configFile := flag.String("config", "flood.toml", "Heka Flood configuration file")
configTest := flag.String("test", "default", "Test section to load")
flag.Parse()
if flag.NFlag() == 0 {
flag.PrintDefaults()
os.Exit(0)
}
var config FloodConfig
if _, err := toml.DecodeFile(*configFile, &config); err != nil {
client.LogError.Printf("Error decoding config file: %s", err)
return
}
var test FloodTest
var ok bool
if test, ok = config[*configTest]; !ok {
client.LogError.Printf("Configuration test: '%s' was not found", *configTest)
return
}
if test.MsgInterval != "" {
var err error
if test.msgInterval, err = time.ParseDuration(test.MsgInterval); err != nil {
client.LogError.Printf("Invalid message_interval duration %s: %s", test.MsgInterval,
err.Error())
return
}
}
if test.PprofFile != "" {
profFile, err := os.Create(test.PprofFile)
if err != nil {
client.LogError.Fatalln(err)
}
pprof.StartCPUProfile(profFile)
defer pprof.StopCPUProfile()
}
if test.MaxMessageSize > 0 {
message.SetMaxMessageSize(test.MaxMessageSize)
}
var sender *client.NetworkSender
var err error
if test.UseTls {
var goTlsConfig *tls.Config
goTlsConfig, err = tcp.CreateGoTlsConfig(&test.Tls)
if err != nil {
client.LogError.Fatalf("Error creating TLS config: %s\n", err)
}
sender, err = client.NewTlsSender(test.Sender, test.IpAddress, goTlsConfig)
} else {
sender, err = client.NewNetworkSender(test.Sender, test.IpAddress)
}
if err != nil {
client.LogError.Fatalf("Error creating sender: %s\n", err)
}
unsignedEncoder := client.NewProtobufEncoder(nil)
signedEncoder := client.NewProtobufEncoder(&test.Signer)
oversizedEncoder := &OversizedEncoder{}
var numTestMessages = 1
var unsignedMessages [][]byte
var signedMessages [][]byte
var oversizedMessages [][]byte
rdm := &randomDataMaker{
src: rand.NewSource(time.Now().UnixNano()),
asciiOnly: test.AsciiOnly,
}
if test.VariableSizeMessages {
numTestMessages = 64
unsignedMessages = makeVariableMessage(unsignedEncoder, numTestMessages, rdm, false)
signedMessages = makeVariableMessage(signedEncoder, numTestMessages, rdm, false)
oversizedMessages = makeVariableMessage(oversizedEncoder, 1, rdm, true)
} else {
if test.StaticMessageSize == 0 {
test.StaticMessageSize = 1000
}
unsignedMessages = makeFixedMessage(unsignedEncoder, test.StaticMessageSize,
rdm)
signedMessages = makeFixedMessage(signedEncoder, test.StaticMessageSize,
rdm)
}
// wait for sigint
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT)
var msgsSent, bytesSent, msgsDelivered uint64
var corruptPercentage, lastCorruptPercentage, signedPercentage, lastSignedPercentage, oversizedPercentage, lastOversizedPercentage float64
var corrupt bool
// set up counter loop
ticker := time.NewTicker(time.Duration(time.Second))
go timerLoop(&msgsSent, &bytesSent, ticker)
//.........這裏部分代碼省略.........
示例12: AMQPPluginSpec
func AMQPPluginSpec(c gs.Context) {
t := &pipeline_ts.SimpleT{}
ctrl := gomock.NewController(t)
defer ctrl.Finish()
config := NewPipelineConfig(nil)
// Our two user/conn waitgroups.
ug := new(sync.WaitGroup)
cg := new(sync.WaitGroup)
// Setup the mock channel.
mch := NewMockAMQPChannel(ctrl)
// Setup the mock amqpHub with the mock chan return.
aqh := NewMockAMQPConnectionHub(ctrl)
aqh.EXPECT().GetChannel("", AMQPDialer{}).Return(mch, ug, cg, nil)
errChan := make(chan error, 1)
bytesChan := make(chan []byte, 1)
c.Specify("An amqp input", func() {
// Setup all the mock calls for Init.
mch.EXPECT().ExchangeDeclare("", "", false, true, false, false,
gomock.Any()).Return(nil)
mch.EXPECT().QueueDeclare("", false, true, false, false,
gomock.Any()).Return(amqp.Queue{}, nil)
mch.EXPECT().QueueBind("", "test", "", false, gomock.Any()).Return(nil)
mch.EXPECT().Qos(2, 0, false).Return(nil)
ith := new(plugins_ts.InputTestHelper)
ith.Msg = pipeline_ts.GetTestMessage()
ith.Pack = NewPipelinePack(config.InputRecycleChan())
// Set up relevant mocks.
ith.MockHelper = NewMockPluginHelper(ctrl)
ith.MockInputRunner = NewMockInputRunner(ctrl)
ith.MockSplitterRunner = NewMockSplitterRunner(ctrl)
ith.PackSupply = make(chan *PipelinePack, 1)
ith.MockInputRunner.EXPECT().NewSplitterRunner("").Return(ith.MockSplitterRunner)
amqpInput := new(AMQPInput)
amqpInput.amqpHub = aqh
config := amqpInput.ConfigStruct().(*AMQPInputConfig)
config.URL = ""
config.Exchange = ""
config.ExchangeType = ""
config.RoutingKey = "test"
config.QueueTTL = 300000
err := amqpInput.Init(config)
c.Assume(err, gs.IsNil)
c.Expect(amqpInput.ch, gs.Equals, mch)
c.Specify("consumes a text message", func() {
// Create a channel to send data to the input. Drop a message on
// there and close the channel.
streamChan := make(chan amqp.Delivery, 1)
ack := plugins_ts.NewMockAcknowledger(ctrl)
ack.EXPECT().Ack(gomock.Any(), false)
streamChan <- amqp.Delivery{
ContentType: "text/plain",
Body: []byte("This is a message"),
Timestamp: time.Now(),
Acknowledger: ack,
}
mch.EXPECT().Consume("", "", false, false, false, false,
gomock.Any()).Return(streamChan, nil)
// Increase the usage since Run decrements it on close.
ug.Add(1)
splitCall := ith.MockSplitterRunner.EXPECT().SplitBytes(gomock.Any(),
nil)
splitCall.Do(func(recd []byte, del Deliverer) {
bytesChan <- recd
})
ith.MockSplitterRunner.EXPECT().UseMsgBytes().Return(false)
ith.MockSplitterRunner.EXPECT().SetPackDecorator(gomock.Any())
go func() {
err := amqpInput.Run(ith.MockInputRunner, ith.MockHelper)
errChan <- err
}()
msgBytes := <-bytesChan
c.Expect(string(msgBytes), gs.Equals, "This is a message")
close(streamChan)
err = <-errChan
})
c.Specify("consumes a protobuf encoded message", func() {
encoder := client.NewProtobufEncoder(nil)
streamChan := make(chan amqp.Delivery, 1)
msg := new(message.Message)
msg.SetUuid(uuid.NewRandom())
msg.SetTimestamp(time.Now().UnixNano())
msg.SetType("logfile")
msg.SetLogger("/a/nice/path")
//.........這裏部分代碼省略.........
示例13: Init
func (p *ProtobufEncoder) Init(config interface{}) error {
p.cEncoder = client.NewProtobufEncoder(nil)
p.sample = true
p.sampleDenominator = Globals().SampleDenominator
return nil
}
示例14: main
func main() {
configFile := flag.String("config", "sbmgr.toml", "Sandbox manager configuration file")
scriptFile := flag.String("script", "xyz.lua", "Sandbox script file")
scriptConfig := flag.String("scriptconfig", "xyz.toml", "Sandbox script configuration file")
filterName := flag.String("filtername", "filter", "Sandbox filter name (used on unload)")
action := flag.String("action", "load", "Sandbox manager action")
flag.Parse()
var config SbmgrConfig
if _, err := toml.DecodeFile(*configFile, &config); err != nil {
client.LogError.Printf("Error decoding config file: %s", err)
return
}
var sender *client.NetworkSender
var err error
if config.UseTls {
var goTlsConfig *tls.Config
goTlsConfig, err = tcp.CreateGoTlsConfig(&config.Tls)
if err != nil {
client.LogError.Fatalf("Error creating TLS config: %s\n", err)
}
sender, err = client.NewTlsSender("tcp", config.IpAddress, goTlsConfig)
} else {
sender, err = client.NewNetworkSender("tcp", config.IpAddress)
}
if err != nil {
client.LogError.Fatalf("Error creating sender: %s\n", err.Error())
}
encoder := client.NewProtobufEncoder(&config.Signer)
manager := client.NewClient(sender, encoder)
hostname, _ := os.Hostname()
msg := &message.Message{}
msg.SetLogger(pipeline.HEKA_DAEMON) // identify the message as 'internal' for filtering purposes
msg.SetType("heka.control.sandbox")
msg.SetTimestamp(time.Now().UnixNano())
msg.SetUuid(uuid.NewRandom())
msg.SetHostname(hostname)
switch *action {
case "load":
code, err := ioutil.ReadFile(*scriptFile)
if err != nil {
client.LogError.Printf("Error reading scriptFile: %s\n", err.Error())
return
}
msg.SetPayload(string(code))
conf, err := ioutil.ReadFile(*scriptConfig)
if err != nil {
client.LogError.Printf("Error reading scriptConfig: %s\n", err.Error())
return
}
f, _ := message.NewField("config", string(conf), "toml")
msg.AddField(f)
case "unload":
f, _ := message.NewField("name", *filterName, "")
msg.AddField(f)
default:
client.LogError.Printf("Invalid action: %s", *action)
}
f1, _ := message.NewField("action", *action, "")
msg.AddField(f1)
err = manager.SendMessage(msg)
if err != nil {
client.LogError.Printf("Error sending message: %s\n", err.Error())
}
}
示例15: QueueBufferSpec
//.........這裏部分代碼省略.........
c.Expect(offset, gs.Equals, int64(22))
})
c.Specify("RollQueue", func() {
feeder.queue = tmpDir
err := feeder.RollQueue()
c.Expect(err, gs.IsNil)
c.Expect(fileExists(getQueueFilename(feeder.queue,
feeder.writeId)), gs.IsTrue)
feeder.writeFile.WriteString("this is a test item")
feeder.writeFile.Close()
reader.checkpointFilename = filepath.Join(tmpDir, "cp.txt")
reader.queue = tmpDir
reader.writeCheckpoint(fmt.Sprintf("%d 10", feeder.writeId))
reader.checkpointFile.Close()
err = reader.initReadFile()
c.Assume(err, gs.IsNil)
buf := make([]byte, 4)
n, err := reader.readFile.Read(buf)
c.Expect(n, gs.Equals, 4)
c.Expect(string(buf), gs.Equals, "test")
feeder.writeFile.Close()
reader.readFile.Close()
})
c.Specify("QueueRecord", func() {
reader.checkpointFilename = filepath.Join(tmpDir, "cp.txt")
reader.queue = tmpDir
newpack := NewPipelinePack(nil)
newpack.Message = msg
payload := "Write me out to the network"
newpack.Message.SetPayload(payload)
encoder := client.NewProtobufEncoder(nil)
protoBytes, err := encoder.EncodeMessage(newpack.Message)
newpack.MsgBytes = protoBytes
expectedLen := 115
c.Specify("adds framing", func() {
err = feeder.RollQueue()
c.Expect(err, gs.IsNil)
err = feeder.QueueRecord(newpack)
fName := getQueueFilename(feeder.queue, feeder.writeId)
c.Expect(fileExists(fName), gs.IsTrue)
c.Expect(err, gs.IsNil)
feeder.writeFile.Close()
f, err := os.Open(fName)
c.Expect(err, gs.IsNil)
n, record, err := reader.sRunner.GetRecordFromStream(f)
f.Close()
c.Expect(n, gs.Equals, expectedLen)
c.Expect(err, gs.IsNil)
headerLen := int(record[1]) + message.HEADER_FRAMING_SIZE
record = record[headerLen:]
outMsg := new(message.Message)
proto.Unmarshal(record, outMsg)
c.Expect(outMsg.GetPayload(), gs.Equals, payload)
})
c.Specify("when queue has limit", func() {
feeder.Config.MaxBufferSize = uint64(200)
c.Expect(feeder.queueSize.Get(), gs.Equals, uint64(0))
err = feeder.RollQueue()