Exemplo n.º 1
0
func TestKafkaErrors(t *testing.T) {
	p := newStubProducer(true)
	errs := make(chan []interface{}, len(spans))
	lg := log.Logger(log.LoggerFunc(func(keyvals ...interface{}) error {
		for i := 0; i < len(keyvals); i += 2 {
			if keyvals[i] == "result" && keyvals[i+1] == "failed to produce msg" {
				errs <- keyvals
			}
		}
		return nil
	}))
	c, err := zipkin.NewKafkaCollector(
		[]string{"192.0.2.10:9092"},
		zipkin.KafkaProducer(p),
		zipkin.KafkaLogger(lg),
	)
	if err != nil {
		t.Fatal(err)
	}
	for _, want := range spans {
		_ = collectSpan(t, c, p, want)
	}

	for i := 0; i < len(spans); i++ {
		select {
		case <-errs:
		case <-time.After(100 * time.Millisecond):
			t.Fatalf("errors not logged. got %d, wanted %d", i, len(spans))
		}
	}
}
Exemplo n.º 2
0
func TestKafkaCloseError(t *testing.T) {
	p := newStubProducer(true)
	c, err := zipkin.NewKafkaCollector(
		[]string{"192.0.2.10:9092"}, zipkin.KafkaProducer(p),
	)
	if err != nil {
		t.Fatal(err)
	}
	if err = c.Close(); err == nil {
		t.Error("no error on close")
	}
}
Exemplo n.º 3
0
func TestKafkaClose(t *testing.T) {
	p := newStubProducer(false)
	c, err := zipkin.NewKafkaCollector(
		[]string{"192.0.2.10:9092"}, zipkin.KafkaProducer(p),
	)
	if err != nil {
		t.Fatal(err)
	}
	if err = c.Close(); err != nil {
		t.Fatal(err)
	}
	if !p.closed {
		t.Fatal("producer not closed")
	}
}
Exemplo n.º 4
0
func TestKafkaProduce(t *testing.T) {
	p := newStubProducer(false)
	c, err := zipkin.NewKafkaCollector(
		[]string{"192.0.2.10:9092"}, zipkin.KafkaProducer(p),
	)
	if err != nil {
		t.Fatal(err)
	}

	for _, want := range spans {
		m := collectSpan(t, c, p, want)
		testMetadata(t, m)
		got := deserializeSpan(t, m.Value)
		testEqual(t, want, got)
	}
}