func Test_Reception_Of_One_ToWork_Message(t *testing.T) { // given the listener c := messaging.NewListenerConfig() c.LookupAddr = []string{"127.0.0.1:24161"} l := messaging.NewListener(c) defer l.Stop() // broker initialization b := broker.NewBroker() b.BrokerPort = "24150" b.BrokerHttpPort = "24151" b.LookUpTcpPort = "24160" b.LookUpHttpPort = "24161" b.Start() defer b.Stop() // test message creation mess := message.ToWork{int64(1), message.TEST, "myPkg", "go1.6", "https://github.com/vil-coyote-acme/toto-example.git"} body, _ := json.Marshal(mess) // message sending config := nsq.NewConfig() p, _ := nsq.NewProducer("127.0.0.1:24150", config) p.Publish(c.Topic, body) // when incomingChan := l.Start() // then assert.Equal(t, message.ToWork{int64(1), message.TEST, "myPkg", "go1.6", "https://github.com/vil-coyote-acme/toto-example.git"}, <-incomingChan) }
// start listening for toWork // will start an embeded broker, a report producer and a toWork listener func startListening() { // first start the broker logger.Info("Starting listening for jobs") embeddedBroker = broker.NewBroker() embeddedBroker.BrokerAddr = brokerAddr embeddedBroker.BrokerPort = brokerPort embeddedBroker.StartBroker() // start the report producer logger.Info("Starting the report producer") reportChan = make(chan message.Report, 20) producerConf := messaging.NewProducerConfig() producerConf.NsqAddr = brokerAddr + ":" + brokerPort producer := messaging.NewProducer(producerConf) producer.Start(reportChan) // start the work listener logger.Info("Starting the work listener") listenerConf := messaging.NewListenerConfig() listenerConf.LookupAddr = []string{nsqLookUpHost + ":" + nsqLookUpPort} listener = messaging.NewListener(listenerConf) // must create the topic BEFORE listing on it sayHello(listenerConf.Topic) toWorkChan = listener.Start() // and then start executing incoming job logger.Info("Starting execution incoming Jobs") build.ExecuteJob(toWorkChan, reportChan) logger.Info("Agent setup done") }
func Test_Producer_Start(t *testing.T) { // given c := NewProducerConfig() c.NsqAddr = "127.0.0.1:14150" p := NewProducer(c) // and broker initialization b := broker.NewBroker() b.BrokerPort = "14150" b.BrokerHttpPort = "14151" b.LookUpTcpPort = "14160" b.LookUpHttpPort = "14161" b.Start() defer b.Stop() // when ch := make(chan message.Report, 20) p.Start(ch) mes := message.Report{int64(1), message.PENDING, []string{"test"}} ch <- mes // and test listener receip, consumer := testtools.SetupListener(c.Topic, b.LookUpHttpAddrr+":"+b.LookUpHttpPort) // then assert.Equal(t, mes, <-receip) consumer.Stop() }
func startLookUp() *broker.Broker { b := broker.NewBroker() b.StartLookUp() return b }