本文整理汇总了Golang中github.com/signalfx/metricproxy/dp/dptest.NewBasicSink函数的典型用法代码示例。如果您正苦于以下问题:Golang NewBasicSink函数的具体用法?Golang NewBasicSink怎么用?Golang NewBasicSink使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewBasicSink函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestNew
func TestNew(t *testing.T) {
ctx := context.Background()
sendTo1 := dptest.NewBasicSink()
sendTo2 := dptest.NewBasicSink()
demux := New([]dpsink.Sink{sendTo1, sendTo2})
pts := []*datapoint.Datapoint{dptest.DP(), dptest.DP()}
es := []*event.Event{dptest.E(), dptest.E()}
ctx2, _ := context.WithTimeout(ctx, time.Millisecond)
assert.Error(t, demux.AddDatapoints(ctx2, pts))
assert.Error(t, demux.AddEvents(ctx2, es))
assert.NoError(t, demux.AddDatapoints(context.Background(), []*datapoint.Datapoint{}))
assert.NoError(t, demux.AddEvents(context.Background(), []*event.Event{}))
}
开发者ID:baris,项目名称:metricproxy,代码行数:14,代码来源:demultiplexer_test.go
示例2: TestListenerLoader
func TestListenerLoader(t *testing.T) {
listenFrom := &config.ListenFrom{
ListenAddr: workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0"),
ServerAcceptDeadline: workarounds.GolangDoesnotAllowPointerToTimeLiteral(time.Millisecond),
}
ctx := context.Background()
forwardTo := dptest.NewBasicSink()
listener, err := ListenerLoader(ctx, forwardTo, listenFrom)
defer listener.Close()
assert.Equal(t, nil, err, "Should be ok to make")
defer listener.Close()
listeningDialAddress := fmt.Sprintf("127.0.0.1:%d", nettest.TCPPort(listener.psocket))
assert.Equal(t, numStats, len(listener.Stats()), "Should have no stats")
assert.NoError(t, err, "Should be ok to make")
conn, err := net.Dial("tcp", listeningDialAddress)
assert.NoError(t, err, "Should be ok to make")
assert.Equal(t, int64(0), listener.stats.invalidDatapoints)
var buf bytes.Buffer
fmt.Fprintf(&buf, "%s %d %d\n\nINVALIDLINE", "ametric", 2, 2)
_, err = buf.WriteTo(conn)
conn.Close()
assert.Equal(t, nil, err, "Should be ok to write")
dp := forwardTo.Next()
assert.Equal(t, "ametric", dp.Metric, "Should be metric")
i := dp.Value.(datapoint.IntValue).Int()
assert.Equal(t, int64(2), i, "Should get 2")
for atomic.LoadInt64(&listener.stats.retriedListenErrors) == 0 {
time.Sleep(time.Millisecond)
}
assert.Equal(t, int64(1), atomic.LoadInt64(&listener.stats.invalidDatapoints))
}
开发者ID:baris,项目名称:metricproxy,代码行数:33,代码来源:carbonlistener_test.go
示例3: TestCounterSinkEvent
func TestCounterSinkEvent(t *testing.T) {
es := []*event.Event{
{},
{},
}
ctx := context.Background()
bs := dptest.NewBasicSink()
count := &Counter{}
middleSink := NextWrap(count)(bs)
go func() {
// Allow time for us to get in the middle of a call
time.Sleep(time.Millisecond)
assert.Equal(t, int64(1), atomic.LoadInt64(&count.CallsInFlight), "After a sleep, should be in flight")
datas := <-bs.EventsChan
assert.Equal(t, 2, len(datas), "Original datas should be sent")
}()
middleSink.AddEvents(ctx, es)
assert.Equal(t, int64(0), atomic.LoadInt64(&count.CallsInFlight), "Call is finished")
assert.Equal(t, int64(0), atomic.LoadInt64(&count.TotalProcessErrors), "No errors so far (see above)")
assert.Equal(t, numTests, len(count.Stats(map[string]string{})), "Just checking stats len()")
bs.RetError(errors.New("nope"))
middleSink.AddEvents(ctx, es)
assert.Equal(t, int64(1), atomic.LoadInt64(&count.TotalProcessErrors), "Error should be sent through")
}
开发者ID:tomzhang,项目名称:metricproxy,代码行数:25,代码来源:counter_test.go
示例4: TestBufferedForwarderBasicEvent
// TODO figure out why this test is flaky, should be > 2, but change to >= 2 so it passes
func TestBufferedForwarderBasicEvent(t *testing.T) {
ctx := context.Background()
config := Config{
BufferSize: 210,
MaxTotalDatapoints: 1000,
MaxTotalEvents: 1000,
NumDrainingThreads: 1,
MaxDrainSize: 1000,
}
sendTo := dptest.NewBasicSink()
bf := NewBufferedForwarder(ctx, config, sendTo)
defer bf.Close()
assert.NoError(t, bf.AddEvents(ctx, []*event.Event{}))
time.Sleep(time.Millisecond)
for i := 0; i < 100; i++ {
datas := []*event.Event{
dptest.E(),
dptest.E(),
}
assert.NoError(t, bf.AddEvents(ctx, datas))
if i == 0 {
seen := <-sendTo.EventsChan
assert.Equal(t, 2, len(seen), "The first send should eventually come back with the first two events")
}
}
// Wait for more events
seen := <-sendTo.EventsChan
assert.True(t, len(seen) >= 2, fmt.Sprintf("Events should buffer: %d", len(seen)))
assert.Equal(t, numStats, len(bf.Stats(map[string]string{})), "Checking returned stats size")
}
开发者ID:baris,项目名称:metricproxy,代码行数:31,代码来源:bufferedforwarder_test.go
示例5: TestCollectDListenerWithQueryParams
func TestCollectDListenerWithQueryParams(t *testing.T) {
jsonBody := testCollectdBody
sendTo := dptest.NewBasicSink()
ctx := context.Background()
c := JSONDecoder{
SendTo: sendTo,
}
req, _ := http.NewRequest("POST", "http://127.0.0.1:8081/post-collectd?sfxdim_foo=bar&sfxdim_zam=narf&sfxdim_empty=&pleaseignore=true", bytes.NewBuffer([]byte(jsonBody)))
req.Header.Set("Content-Type", "application/json")
loadExpectedDims := map[string]string{"foo": "bar", "zam": "narf", "plugin": "load", "host": "i-b13d1e5f"}
memoryExpectedDims := map[string]string{"host": "i-b13d1e5f", "plugin": "memory", "dsname": "value", "foo": "bar", "zam": "narf"}
dfComplexExpectedDims := map[string]string{"plugin": "df", "plugin_instance": "dev", "dsname": "value", "foo": "bar", "zam": "narf", "host": "i-b13d1e5f"}
parsedInstanceExpectedDims := map[string]string{"foo": "bar", "zam": "narf", "host": "mwp-signalbox", "f": "x", "plugin_instance": "analytics", "k1": "v1", "k2": "v2", "dsname": "value", "plugin": "tail"}
eventExpectedDims := map[string]string{"foo": "bar", "host": "mwp-signalbox", "plugin": "my_plugin", "f": "x", "plugin_instance": "my_plugin_instance", "k": "v", "zam": "narf"}
go func() {
dps := <-sendTo.PointsChan
assert.Equal(t, "load.shortterm", dps[0].Metric, "Metric not named correctly")
assert.Equal(t, loadExpectedDims, dps[0].Dimensions, "Dimensions not set correctly")
assert.Equal(t, "load.midterm", dps[1].Metric, "Metric not named correctly")
assert.Equal(t, loadExpectedDims, dps[1].Dimensions, "Dimensions not set correctly")
assert.Equal(t, "load.longterm", dps[2].Metric, "Metric not named correctly")
assert.Equal(t, loadExpectedDims, dps[2].Dimensions, "Dimensions not set correctly")
assert.Equal(t, "memory.used", dps[3].Metric, "Metric not named correctly")
assert.Equal(t, memoryExpectedDims, dps[3].Dimensions, "Dimensions not set correctly")
assert.Equal(t, "df_complex.free", dps[4].Metric, "Metric not named correctly")
assert.Equal(t, dfComplexExpectedDims, dps[4].Dimensions, "Dimensions not set correctly")
assert.Equal(t, "memory.old_gen_end", dps[5].Metric, "Metric not named correctly")
assert.Equal(t, parsedInstanceExpectedDims, dps[5].Dimensions, "Dimensions not set correctly")
assert.Equal(t, "memory.total_heap_space", dps[6].Metric, "Metric not named correctly")
assert.Equal(t, parsedInstanceExpectedDims, dps[6].Dimensions, "Dimensions not set correctly")
events := <-sendTo.EventsChan
assert.Equal(t, "imanotify.notify_instance", events[0].EventType, "Metric not named correctly")
assert.Equal(t, eventExpectedDims, events[0].Dimensions, "Dimensions not set correctly")
}()
resp := httptest.NewRecorder()
c.ServeHTTPC(ctx, resp, req)
assert.Equal(t, resp.Code, http.StatusOK, "Request should work")
req, _ = http.NewRequest("POST", "http://127.0.0.1:8081/post-collectd", bytes.NewBuffer([]byte(`invalidjson`)))
req.Header.Set("Content-Type", "application/json")
resp = httptest.NewRecorder()
c.ServeHTTPC(ctx, resp, req)
assert.Equal(t, c.TotalBlankDims, int64(1))
assert.Equal(t, http.StatusBadRequest, resp.Code, "Request should work")
}
开发者ID:baris,项目名称:metricproxy,代码行数:60,代码来源:collectdlistener_test.go
示例6: TestStatDrainingThreadCancel
func TestStatDrainingThreadCancel(t *testing.T) {
testSink := dptest.NewBasicSink()
ctx, cancel := context.WithCancel(context.Background())
drainer := NewDrainingThread(time.Hour, []dpsink.Sink{testSink}, []Keeper{&statKeeper{}}, ctx)
cancel()
assert.Equal(t, ctx.Err(), drainer.start())
}
开发者ID:baris,项目名称:metricproxy,代码行数:7,代码来源:keeper_test.go
示例7: TestCarbonHandleConnection
func TestCarbonHandleConnection(t *testing.T) {
log.Info("START TestCarbonHandleConnection")
defer log.Info("END TestCarbonHandleConnection")
listenFrom := &config.ListenFrom{
ListenAddr: workarounds.GolangDoesnotAllowPointerToStringLiteral("localhost:0"),
}
ctx := context.Background()
forwardTo := dptest.NewBasicSink()
listener, err := ListenerLoader(ctx, forwardTo, listenFrom)
defer listener.Close()
listeningDialAddress := fmt.Sprintf("localhost:%d", nettest.TCPPort(listener.psocket))
conn, err := net.Dial("tcp", listeningDialAddress)
assert.NoError(t, err)
conn.Close()
assert.Error(t, listener.handleConnection(conn))
conn, err = net.Dial("tcp", listeningDialAddress)
assert.NoError(t, err)
waitChan := make(chan struct{})
go func() {
time.Sleep(time.Millisecond * 10)
assert.NoError(t, conn.Close())
close(waitChan)
}()
<-waitChan
for atomic.LoadInt64(&listener.stats.totalEOFCloses) == 0 {
time.Sleep(time.Millisecond)
}
}
开发者ID:baris,项目名称:metricproxy,代码行数:33,代码来源:carbonlistener_test.go
示例8: TestStatDrainingThreadSend
func TestStatDrainingThreadSend(t *testing.T) {
testSink := dptest.NewBasicSink()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
drainer := NewDrainingThread(time.Millisecond, []dpsink.Sink{testSink}, []Keeper{&statKeeper{}}, ctx)
assert.Equal(t, 1, len(drainer.Stats()))
<-testSink.PointsChan
}
开发者ID:baris,项目名称:metricproxy,代码行数:8,代码来源:keeper_test.go
示例9: TestInvalidListen
func TestInvalidListen(t *testing.T) {
listenFrom := &config.ListenFrom{
ListenAddr: workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:999999"),
}
sendTo := dptest.NewBasicSink()
ctx := context.Background()
_, err := ListenerLoader(ctx, sendTo, listenFrom)
assert.Error(t, err)
}
开发者ID:baris,项目名称:metricproxy,代码行数:9,代码来源:collectdlistener_test.go
示例10: TestCarbonInvalidListenerLoader
func TestCarbonInvalidListenerLoader(t *testing.T) {
ctx := context.Background()
listenFrom := &config.ListenFrom{
ListenAddr: workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:999999"),
}
sendTo := dptest.NewBasicSink()
_, err := ListenerLoader(ctx, sendTo, listenFrom)
assert.NotEqual(t, nil, err, "Should get an error making")
}
开发者ID:baris,项目名称:metricproxy,代码行数:9,代码来源:carbonlistener_test.go
示例11: TestCollectDListener
func TestCollectDListener(t *testing.T) {
jsonBody := testCollectdBody
sendTo := dptest.NewBasicSink()
ctx := context.Background()
listenFrom := &config.ListenFrom{
Dimensions: map[string]string{"hello": "world"},
}
collectdListener, err := ListenerLoader(ctx, sendTo, listenFrom)
defer collectdListener.Close()
assert.Nil(t, err)
assert.NotNil(t, collectdListener)
req, _ := http.NewRequest("POST", "http://127.0.0.1:8081/post-collectd", bytes.NewBuffer([]byte(jsonBody)))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
go func() {
dps := <-sendTo.PointsChan
assert.Equal(t, len(dps), 8)
assert.Equal(t, "load.shortterm", dps[0].Metric, "Metric not named correctly")
assert.Equal(t, "load.midterm", dps[1].Metric, "Metric not named correctly")
assert.Equal(t, "load.longterm", dps[2].Metric, "Metric not named correctly")
assert.Equal(t, "memory.used", dps[3].Metric, "Metric not named correctly")
assert.Equal(t, "df_complex.free", dps[4].Metric, "Metric not named correctly")
assert.Equal(t, "memory.old_gen_end", dps[5].Metric, "Metric not named correctly")
assert.Equal(t, "memory.total_heap_space", dps[6].Metric, "Metric not named correctly")
assert.Equal(t, "gauge.page.loadtime", dps[7].Metric, "Metric not named correctly")
assert.Equal(t, map[string]string{"hello": "world", "dsname": "value", "plugin": "dogstatsd", "env": "dev", "k1": "v1", "host": "some-host"}, dps[7].Dimensions, "Dimensions not parsed correctly")
events := <-sendTo.EventsChan
assert.Equal(t, len(events), 2)
assert.Equal(t, "imanotify.notify_instance", events[0].EventType, "Event not named correctly")
assert.Equal(t, "counter.exception", events[1].EventType, "Event not named correctly")
}()
resp, err := client.Do(req)
if err != nil {
fmt.Println(err.Error())
assert.Fail(t, "Err should be nil")
}
assert.Equal(t, http.StatusOK, resp.StatusCode, "Request should work")
assert.Equal(t, 12, len(collectdListener.Stats()), "Request should work")
req, _ = http.NewRequest("POST", "http://127.0.0.1:8081/post-collectd", bytes.NewBuffer([]byte(`invalidjson`)))
req.Header.Set("Content-Type", "application/json")
resp, err = client.Do(req)
assert.Nil(t, err)
assert.Equal(t, http.StatusBadRequest, resp.StatusCode, "Request should work")
req, _ = http.NewRequest("POST", "http://127.0.0.1:8081/post-collectd", bytes.NewBuffer([]byte(jsonBody)))
req.Header.Set("Content-Type", "application/plaintext")
resp, err = client.Do(req)
assert.Nil(t, err)
assert.Equal(t, http.StatusNotFound, resp.StatusCode, "Request should work (Plaintext not supported)")
}
开发者ID:tomzhang,项目名称:metricproxy,代码行数:56,代码来源:collectdlistener_test.go
示例12: TestCarbonInvalidCarbonDeconstructorListenerLoader
func TestCarbonInvalidCarbonDeconstructorListenerLoader(t *testing.T) {
listenFrom := &config.ListenFrom{
ListenAddr: workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:12247"),
MetricDeconstructor: workarounds.GolangDoesnotAllowPointerToStringLiteral("UNKNOWN"),
}
ctx := context.Background()
forwardTo := dptest.NewBasicSink()
_, err := ListenerLoader(ctx, forwardTo, listenFrom)
assert.NotEqual(t, nil, err, "Should get an error making")
}
开发者ID:baris,项目名称:metricproxy,代码行数:10,代码来源:carbonlistener_test.go
示例13: TestCreation
func TestCreation(t *testing.T) {
listenFrom := config.ListenFrom{}
listenFrom.ListenAddr = workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0")
forwardTo := dptest.NewBasicSink()
ctx := context.Background()
l, err := ListenerLoader(ctx, forwardTo, &listenFrom)
defer l.Close()
assert.Equal(t, nil, err, "Expect no error")
assert.Equal(t, numStats, len(l.Stats()), "Expect no stats")
forwarder, err := NewForwarder("127.0.0.1", nettest.TCPPort(l.psocket), time.Second, []string{"zzfirst"}, 10)
defer forwarder.Close()
assert.Equal(t, nil, err, "Expect no error")
assert.Equal(t, 1, len(forwarder.pool.conns))
timeToSend := time.Now().Round(time.Second)
dpSent := dptest.DP()
dpSent.Timestamp = timeToSend
log.Info("Sending a dp")
forwarder.AddDatapoints(ctx, []*datapoint.Datapoint{dpSent})
log.Info("Looking for DP back")
dpSeen := forwardTo.Next()
assert.Equal(t, "randtest."+dpSent.Metric, dpSeen.Metric, "Expect metric back")
assert.Equal(t, dpSent.Timestamp, dpSeen.Timestamp, "Expect metric back")
// Test creating a new connection if pool is empty
for forwarder.pool.Get() != nil {
}
forwarder.AddDatapoints(ctx, []*datapoint.Datapoint{dpSent})
dpSeen = forwardTo.Next()
assert.Equal(t, "randtest."+dpSent.Metric, dpSeen.Metric, "Expect metric back")
assert.Equal(t, dpSent.Timestamp, dpSeen.Timestamp, "Expect metric back")
//
// Test creation error if pool is empty
for forwarder.pool.Get() != nil {
}
forwarder.dialer = func(network, address string, timeout time.Duration) (net.Conn, error) {
return nil, errors.New("nope")
}
assert.Error(t, forwarder.AddDatapoints(ctx, []*datapoint.Datapoint{dpSeen}))
forwarder.dialer = net.DialTimeout
assert.NoError(t, forwarder.AddDatapoints(ctx, []*datapoint.Datapoint{dpSeen}), "Should get the conn back")
}
开发者ID:baris,项目名称:metricproxy,代码行数:46,代码来源:carbonforwarder_test.go
示例14: BenchmarkCollectdListener
func BenchmarkCollectdListener(b *testing.B) {
bytes := int64(0)
smallCollectdBody := `[
{
"dsnames": [
"shortterm"
],
"dstypes": [
"gauge"
],
"host": "i-b13d1e5f",
"interval": 10.0,
"plugin": "load",
"plugin_instance": "",
"time": 1415062577.4960001,
"type": "load",
"type_instance": "",
"values": [
0.76000000000000001
]
}]`
sendTo := dptest.NewBasicSink()
sendTo.PointsChan = make(chan []*datapoint.Datapoint, 2)
ctx := context.Background()
c := JSONDecoder{
SendTo: sendTo,
}
b.ReportAllocs()
b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
writter := httptest.NewRecorder()
body := strings.NewReader(smallCollectdBody)
req, _ := http.NewRequest("GET", "http://example.com/collectd", body)
req.Header.Add("Content-type", "application/json")
b.StartTimer()
c.ServeHTTPC(ctx, writter, req)
b.StopTimer()
bytes += int64(len(testCollectdBody))
item := <-sendTo.PointsChan
assert.Equal(b, 1, len(item))
}
b.SetBytes(bytes)
}
开发者ID:baris,项目名称:metricproxy,代码行数:46,代码来源:collectdlistener_test.go
示例15: TestFailureInRead
func TestFailureInRead(t *testing.T) {
jsonBody := testCollectdBody
sendTo := dptest.NewBasicSink()
sendTo.RetError(errors.New("error"))
ctx := context.Background()
listenFrom := &config.ListenFrom{}
collectdListener, err := ListenerLoader(ctx, sendTo, listenFrom)
defer collectdListener.Close()
assert.Nil(t, err)
assert.NotNil(t, collectdListener)
req, _ := http.NewRequest("POST", "http://127.0.0.1:8081/post-collectd", bytes.NewBuffer([]byte(jsonBody)))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
assert.Equal(t, http.StatusBadRequest, resp.StatusCode, "Request should work")
}
开发者ID:baris,项目名称:metricproxy,代码行数:18,代码来源:collectdlistener_test.go
示例16: TestEmptyMetricFilter
func TestEmptyMetricFilter(t *testing.T) {
end := dptest.NewBasicSink()
end.Resize(1)
ctx := context.Background()
filt := EmptyMetricFilter{}
p1 := dptest.DP()
p2 := dptest.DP()
p1.Metric = ""
assert.NoError(t, filt.AddDatapoints(ctx, []*datapoint.Datapoint{p1, p2}, end))
out := <-end.PointsChan
assert.Equal(t, 1, len(out))
assert.Equal(t, int64(1), filt.EmptyMetricFiltered)
assert.NoError(t, filt.AddDatapoints(ctx, []*datapoint.Datapoint{p1}, end))
runtime.Gosched()
assert.Equal(t, 0, len(end.PointsChan))
}
开发者ID:baris,项目名称:metricproxy,代码行数:19,代码来源:filter_test.go
示例17: TestBufferedForwarderContexts
func TestBufferedForwarderContexts(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
config := Config{
BufferSize: 0,
MaxTotalDatapoints: 10,
NumDrainingThreads: 2,
MaxDrainSize: 1000,
}
datas := []*datapoint.Datapoint{
{},
}
sendTo := dptest.NewBasicSink()
bf := NewBufferedForwarder(ctx, config, sendTo)
bf.AddDatapoints(ctx, datas)
canceledContext, cancelFunc := context.WithCancel(ctx)
waiter := make(chan struct{})
go func() {
cancelFunc()
<-canceledContext.Done()
bf.Close()
close(waiter)
sendTo.Next()
}()
// Wait for this to get drained out
<-waiter
outer:
for {
select {
case bf.dpChan <- datas:
default:
break outer
}
}
assert.Equal(t, context.Canceled, bf.AddDatapoints(canceledContext, datas), "Should escape when passed context canceled")
cancel()
assert.Equal(t, context.Canceled, bf.AddDatapoints(context.Background(), datas), "Should err when parent context canceled")
bf.stopContext = context.Background()
assert.Equal(t, context.Canceled, bf.AddDatapoints(canceledContext, datas), "Should escape when passed context canceled")
}
开发者ID:baris,项目名称:metricproxy,代码行数:42,代码来源:bufferedforwarder_test.go
示例18: TestCarbonNoWriteEvents
func TestCarbonNoWriteEvents(t *testing.T) {
listenFrom := config.ListenFrom{}
listenFrom.ListenAddr = workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0")
forwardTo := dptest.NewBasicSink()
ctx := context.Background()
l, err := ListenerLoader(ctx, forwardTo, &listenFrom)
defer l.Close()
assert.Equal(t, nil, err, "Expect no error")
assert.Equal(t, numStats, len(l.Stats()), "Expect no stats")
forwarder, err := NewForwarder("127.0.0.1", nettest.TCPPort(l.psocket), time.Second, []string{"zzfirst"}, 10)
assert.Equal(t, nil, err, "Expect no error")
assert.Equal(t, 1, len(forwarder.pool.conns))
timeToSend := time.Now().Round(time.Second)
eSent := dptest.E()
eSent.Timestamp = timeToSend
eSent.Meta["blarg"] = "abcd 123 123"
log.Info("Sending a e")
forwarder.AddEvents(ctx, []*event.Event{eSent})
assert.Equal(t, 0, len(forwardTo.EventsChan))
}
开发者ID:baris,项目名称:metricproxy,代码行数:21,代码来源:carbonforwarder_test.go
示例19: TestLoader
func TestLoader(t *testing.T) {
listenFrom := config.ListenFrom{}
listenFrom.ListenAddr = workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0")
ctx := context.Background()
forwardTo := dptest.NewBasicSink()
l, err := ListenerLoader(ctx, forwardTo, &listenFrom)
port := nettest.TCPPort(l.psocket)
ft := config.ForwardTo{
Host: workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1"),
Port: workarounds.GolangDoesnotAllowPointerToUint16Literal(port),
}
f, err := ForwarderLoader(context.Background(), &ft)
assert.NoError(t, err)
dpSent := dptest.DP()
dpSent.Dimensions = map[string]string{}
assert.NoError(t, f.AddDatapoints(ctx, []*datapoint.Datapoint{dpSent}))
dpSeen := forwardTo.Next()
assert.Equal(t, dpSent.Metric, dpSeen.Metric)
assert.Equal(t, numStats+1, len(f.Stats()))
}
开发者ID:baris,项目名称:metricproxy,代码行数:21,代码来源:carbonforwarder_test.go
示例20: TestBufferedForwarderMaxTotalEvents
func TestBufferedForwarderMaxTotalEvents(t *testing.T) {
config := Config{
BufferSize: 15,
MaxTotalEvents: 7,
NumDrainingThreads: 1,
MaxDrainSize: 1000,
}
ctx := context.Background()
sendTo := dptest.NewBasicSink()
bf := NewBufferedForwarder(ctx, config, sendTo)
defer bf.Close()
events := []*event.Event{
{},
{},
}
for i := 0; i < 100; i++ {
bf.AddEvents(ctx, events)
}
assert.Equal(t, ErrEBufferFull, bf.AddEvents(ctx, events), "With small buffer size, I should error out with a full buffer")
}
开发者ID:baris,项目名称:metricproxy,代码行数:21,代码来源:bufferedforwarder_test.go
注:本文中的github.com/signalfx/metricproxy/dp/dptest.NewBasicSink函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论