func New(clientPool ClientPool, sharedSecret []byte, bufferSize uint, logger *gosteno.Logger) *DopplerForwarder { inputChan := make(chan *events.Envelope) stopChan := make(chan struct{}) // We set the sink identifier to be "Doppler" since the truncating buffer is between // Metron and Doppler. So in case of lost messages the dropped message event // will say "Lost messages ... to Doppler" bufferContext := truncatingbuffer.NewSystemContext("MetronAgent", "Doppler") truncatingBuffer := truncatingbuffer.NewTruncatingBuffer(inputChan, bufferSize, bufferContext, logger, stopChan) return &DopplerForwarder{ clientPool: clientPool, sharedSecret: sharedSecret, truncatingBuffer: truncatingBuffer, inputChan: inputChan, logger: logger, stopChan: stopChan, } }
func RunTruncatingBuffer(inputChan <-chan *events.Envelope, bufferSize uint, context truncatingbuffer.BufferContext, logger *gosteno.Logger, stopChannel chan struct{}) *truncatingbuffer.TruncatingBuffer { b := truncatingbuffer.NewTruncatingBuffer(inputChan, bufferSize, context, logger, stopChannel) go b.Run() return b }
var _ = Describe("Truncating Buffer", func() { var inMessageChan chan *events.Envelope var stopChannel chan struct{} var bufferSize uint var buffer *truncatingbuffer.TruncatingBuffer var context truncatingbuffer.BufferContext BeforeEach(func() { inMessageChan = make(chan *events.Envelope) stopChannel = make(chan struct{}) context = &FakeContext{} bufferSize = 3 }) JustBeforeEach(func() { buffer = truncatingbuffer.NewTruncatingBuffer(inMessageChan, bufferSize, context, loggertesthelper.Logger(), stopChannel) }) AfterEach(func() { if inMessageChan != nil { close(inMessageChan) } }) It("panics if buffer size is less than 3", func() { Expect(func() { truncatingbuffer.NewTruncatingBuffer(inMessageChan, 2, context, loggertesthelper.Logger(), nil) }).To(Panic()) }) It("panics if context is nil", func() {