Ejemplo n.º 1
0
func TestBufferedMaxSize(t *testing.T) {
	s := NewTestServer()
	// 5 ms is hopefully enough time to be processed. Kind of a fragile test, but simple.
	c, err := NewBufferedClient(s.Addr, 100, 12, 5*time.Millisecond)
	if err != nil {
		t.Fatal(err)
	}
	for i := byte(0); i < 4; i++ {
		c.Set("a", []byte{'a' + i})
	}
	c.Close()
	asrt.Equal(t, s.NextMessage(), "a:a|s\na:b|s")
	asrt.Equal(t, s.NextMessage(), "a:c|s\na:d|s")
}
Ejemplo n.º 2
0
func TestTime(t *testing.T) {
	server, client := MakeServerAndClient()
	defer server.Close()

	client.Time("foo", 3*time.Second)
	asrt.Equal(t, server.NextMessage(), "foo:3000|ms")
}
Ejemplo n.º 3
0
func TestBufferedMinFlush(t *testing.T) {
	s := NewTestServer()
	c, err := NewBufferedClient(s.Addr, 100, 100, 5*time.Millisecond)
	if err != nil {
		t.Fatal(err)
	}
	for i := byte(0); i < 4; i++ {
		c.Set("a", []byte{'a' + i})
		if i == 1 {
			time.Sleep(10 * time.Millisecond)
		}
	}
	c.Close()
	asrt.Equal(t, s.NextMessage(), "a:a|s\na:b|s")
	asrt.Equal(t, s.NextMessage(), "a:c|s\na:d|s")
}
Ejemplo n.º 4
0
func TestSet(t *testing.T) {
	server, client := MakeServerAndClient()
	defer server.Close()

	client.Set("foo", []byte("hello"))
	asrt.Equal(t, server.NextMessage(), "foo:hello|s")
}
Ejemplo n.º 5
0
func TestGauge(t *testing.T) {
	server, client := MakeServerAndClient()
	defer server.Close()

	client.Gauge("foo", 123.456)
	asrt.Equal(t, server.NextMessage(), "foo:123.456|g")
}
Ejemplo n.º 6
0
func TestCount(t *testing.T) {
	server, client := MakeServerAndClient()
	defer server.Close()

	client.Count("foo", 3, 1)
	asrt.Equal(t, server.NextMessage(), "foo:3|c")

	client.Count("foo", 3, 0.5)
	asrt.Equal(t, server.NextMessage(), "foo:3|[email protected]")

	client.Count("blah", -123.456, 1)
	asrt.Equal(t, server.NextMessage(), "blah:-123.456|c")

	client.Inc("incme")
	asrt.Equal(t, server.NextMessage(), "incme:1|c")

	randFloat = MakeNonRandom([]float64{0.6, 0.4})
	client.CountProb("foo", 3, 0.5) // nothin
	client.CountProb("bar", 3, 0.5)
	asrt.Equal(t, server.NextMessage(), "bar:3|[email protected]")

	client.IncProb("foo", 0.5)
	client.IncProb("bar", 0.5)
	asrt.Equal(t, server.NextMessage(), "bar:1|[email protected]")
}