Example #1
0
func TestBuildSubscribers(t *testing.T) {
	c := bytes.NewBufferString(testConfig)
	cfg, err := ReadConfig(c)
	if err != nil {
		t.Error(err)
	}

	subscribers := cfg.BuildSubscribers()
	if subscribers == nil {
		t.Error("failed to parse subscribers")
	}

	expectedSubscribers := map[string]proxy.Subscriber{
		"tcp_subscriber": proxy.NewTCPMetricsSubscriber("localhost:9777", 1),
	}

	for _, subscriber := range subscribers {
		if reflect.TypeOf(subscriber) != reflect.TypeOf(expectedSubscribers[subscriber.Name()]) {
			t.Fatal("invalid subscriber type")
		}

		if !subscriber.Equals(expectedSubscribers[subscriber.Name()]) {
			t.Fatal("inconsistent subscriber configuration")
		}
		t.Log(subscriber)
	}
}
Example #2
0
func (c Config) BuildSubscribers() []proxy.Subscriber {
	subscribers := []proxy.Subscriber{}

	for name, config := range c.Subscribers {
		switch name {
		case "tcp_subscriber":
			destAddr := config["destaddr"].(string)
			concurrencyLevel := config["concurrency_level"].(int)
			subscribers = append(subscribers, proxy.NewTCPMetricsSubscriber(destAddr, concurrencyLevel))

		}

	}
	return subscribers
}