/
glumelogger_test.go
56 lines (46 loc) · 1.51 KB
/
glumelogger_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package glumelogger
import (
"fmt"
"git.apache.org/thrift.git/lib/go/thrift"
"github.com/ceocoder/glumelogger/flume"
"testing"
"time"
)
const (
testHostAndPort = "localhost:51515"
)
type thriftSourceProtocolHandler struct {
t *testing.T
//TODO: start the handler with expected event values - fail if writes are different from expected
}
func (ts thriftSourceProtocolHandler) AppendBatch(events []*flume.ThriftFlumeEvent) (flume.Status, error) {
for _, event := range events {
fmt.Println(string(event.GetBody()))
ts.Append(event)
}
return flume.Status_OK, nil
}
func (ts thriftSourceProtocolHandler) Append(event *flume.ThriftFlumeEvent) (flume.Status, error) {
ts.t.Log(string(event.GetBody()))
return flume.Status_OK, nil
}
// run a test flume agent
func runDummyFlumeAgent(t *testing.T) {
transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
protocolFactory := thrift.NewTCompactProtocolFactory()
transport, _ := thrift.NewTServerSocket("localhost:51515")
handler := thriftSourceProtocolHandler{t}
processor := flume.NewThriftSourceProtocolProcessor(handler)
server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)
server.Serve()
}
func TestLogToFlumeViaThrift(t *testing.T) {
go runDummyFlumeAgent(t)
time.Sleep(1 * time.Millisecond)
logger := NewGlumeLogger("localhost", 51515, &map[string]string{})
status, err := logger.Log([]byte("foo"))
if err != nil {
t.Errorf("Write failed with %s, %s", status.String(), err)
t.Fail()
}
}