示例#1
0
func (self *ProtobufClientSuite) BenchmarkSingle(c *gocheck.C) {
	var HEARTBEAT_TYPE = protocol.Request_HEARTBEAT
	prs := FakeHeartbeatServer()
	client := NewProtobufClient(prs.Listener.Addr().String(), time.Second)
	client.Connect()
	c.ResetTimer()
	for i := 0; i < c.N; i++ {
		responseChan := make(chan *protocol.Response, 1)
		heartbeatRequest := &protocol.Request{
			Type:     &HEARTBEAT_TYPE,
			Database: protocol.String(""),
		}
		rcw := cluster.NewResponseChannelWrapper(responseChan)
		client.MakeRequest(heartbeatRequest, rcw)
		<-responseChan
	}
}
示例#2
0
func (self *ClientServerSuite) TestClientCanMakeRequests(c *C) {
	requestHandler := &MockRequestHandler{}
	protobufServer := NewProtobufServer(":8091", requestHandler)
	go protobufServer.ListenAndServe()
	c.Assert(protobufServer, Not(IsNil))
	protobufClient := NewProtobufClient("localhost:8091", 0)
	protobufClient.Connect()
	responseStream := make(chan *protocol.Response, 1)

	mock := `
  {
    "points": [
      { "values": [{"int64_value": 3}]}
    ],
    "name": "foo",
    "fields": ["val"]
  }`
	fmt.Println("creating series")
	series := stringToSeries(mock, c)
	t := time.Now().Unix()
	s := uint64(1)
	series.Points[0].Timestamp = &t
	series.Points[0].SequenceNumber = &s
	id := uint32(1)
	database := "pauldb"
	proxyWrite := protocol.Request_WRITE
	request := &protocol.Request{Id: &id, Type: &proxyWrite, Database: &database, MultiSeries: []*protocol.Series{series}}

	time.Sleep(time.Second * 1)
	err := protobufClient.MakeRequest(request, cluster.NewResponseChannelWrapper(responseStream))
	c.Assert(err, IsNil)
	timer := time.NewTimer(time.Second)
	select {
	case <-timer.C:
		c.Error("Timed out waiting for response")
	case response := <-responseStream:
		c.Assert(*response.Type, Equals, protocol.Response_END_STREAM)
	}
}