//Simple pusher for testing func PusherProto(count int, finished chan int, msg *messaging.Food, port int) { log.Info("Starting pusher") socket, err := nano.NewPushSocket() if nil != err { log.Error(err) } defer socket.Close() socket.SetSendTimeout(500 * time.Millisecond) sport := strconv.Itoa(port) _, err = socket.Connect("tcp://localhost:" + sport) if nil != err { log.Error(err) return } log.Info("Connected and ready to send data") tot := 0 for { bytes, _ := msg.Marshal() _, err := socket.Send(bytes, 0) //blocking if nil != err { log.Error(err) continue } else { tot++ } if tot >= count { break } } log.Info("Finished sending data exiting") finished <- tot }
gi.Describe("NewSwallowers", func() { gi.It("Test swallower new method, with close", func() { foodChan := make(chan *messaging.Food) sw := NewSwallow("test", foodChan, 2) close(foodChan) sw.Close() }) }) gi.Describe("Positive tests", func() { var ( timestamp int64 hostname string tag string content string priority int32 facility int32 severity int32 food *messaging.Food swallowChan chan *messaging.Food wg sync.WaitGroup ) gi.BeforeEach(func() { timestamp = int64(time.Now().Unix()) hostname = "hostname" tag = "tag" content = "content" priority = 1 facility = 7 severity = 2 fType := messaging.RFC3164 food = new(messaging.Food)
//Injest data from queue and ship the data off to be swallowed func OpenWide(chewChan chan *messaging.Food, done chan interface{}, wg *sync.WaitGroup, port int) { var ( msg []byte err error ) defer close(chewChan) socket, err := nano.NewPullSocket() if nil != err { log.Error(err) } defer socket.Close() r := rep.NewReporter() //repeat stats with 0 if nothing is reported r.RegisterStatWIndex("lips", "timeout") r.RegisterStatWIndex("lips", "good") r.RegisterStatWIndex("lips", "bad") socket.SetRecvTimeout(1000 * time.Millisecond) sport := strconv.Itoa(port) _, err = socket.Bind("tcp://*:" + sport) if nil != err { log.Error(err) } log.Info("Connected and ready to receive data") main: for { select { case <-done: { log.Info("Got done signal") break main } default: { msg, err = socket.Recv(0) if nil != err { r.AddStatWIndex("lips", 1, "timeout") //we hit timeout } if nil != msg { food := new(messaging.Food) err = food.Unmarshal(msg) if nil != err { log.Error("Invalid message: ", err) r.AddStatWIndex("lips", 1, "bad") continue } r.AddStatWIndex("lips", 1, "good") chewChan <- food } } } } log.Info("Closing lips") log.Flush() wg.Done() }