Exemple #1
0
func TestSendSingle(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping because of short test")
	}
	p, port := newTestTCP()

	tp := &testPasser{
		in: make(chan *event.Event),
	}

	p.Start(tp)

	c, err := net.Dial("tcp", fmt.Sprintf("localhost:%d", port))
	if err != nil {
		t.Fatal(err)
	}

	e := newTestEvent()

	conn := newman.NewConn(c)
	conn.Write(e)

	ne := <-tp.in

	ne.Tags.ForEach(func(k, v string) {
		if e.Get(k) != v {
			t.Fatalf("Wanted %s got %s for %s", e.Get(k), v, k)
		}
	})

	if ne.Metric != e.Metric {
		t.Fatal()
	}
}
Exemple #2
0
func TestMany(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping because of short test")
	}
	p, port := newTestTCP()
	tp := &testPasser{
		in: make(chan *event.Event),
	}

	p.Start(tp)

	c, err := net.Dial("tcp", fmt.Sprintf("localhost:%d", port))
	if err != nil {
		t.Fatal(err)
	}

	conn := newman.NewConn(c)

	go func() {
		// send 10000 events
		for i := 0; i < 10000; i++ {
			e := newTestEvent()
			conn.Write(e)
		}

	}()

	for i := 0; i < 10000; i++ {
		<-tp.in
	}
}
Exemple #3
0
func main() {
	n := make(chan *event.Event)
	genEvents([]string{"host1", "host2", "host3"}, []string{"1", "2", "3", "4"}, n)
	slp := time.Second

	for {
		c, err := net.Dial("tcp4", "localhost:5555")
		if err != nil {
			log.Println(err)
			time.Sleep(slp)
			slp *= 2
		} else {
			slp = time.Second

			conn := newman.NewConn(c)
			for {
				e := <-n
				err = conn.Write(e)
				if err != nil {
					log.Println(err)
					break
				}
			}
		}
	}
}
Exemple #4
0
func (t *TCPProvider) consume(c *net.TCPConn, p event.EventPasser) {

	// create a newman connection
	conn := newman.NewConn(c)
	conn.SetWaiter(&newman.Backoff{})

	// drain the connection for ever
	in, _ := conn.Generate(func() newman.Message {
		return event.NewEvent()
	})
	for raw := range in {
		// convert it to an event because we know that is what we are getting
		e := raw.(*event.Event)

		// pass it on to the next step
		p.PassEvent(e)
	}

	// when it is done, close the connection
	c.Close()
}