Esempio n. 1
0
func (w *WriteShardRequest) AddMessage(name string, value interface{}, timestamp time.Time, tags map[string]string) {
	// w.AddMessages([]db.Message{db.NewMessage(
	// 	name, tags, map[string]interface{}{"value": value}, timestamp,
	// )})
	//TODO: fix this
	w.AddMessages([]db.Message{db.NewMessage(timestamp)})
}
Esempio n. 2
0
func (w *WriteShardRequest) unmarshalMessages() []db.Message {
	messages := make([]db.Message, len(w.pb.GetMessages()))
	for i, m := range w.pb.GetMessages() {
		// msg := db.NewMessage(
		// 	m.GetName(), map[string]string{},
		// 	map[string]interface{}{}, time.Unix(0, m.GetTime()))

		msg := db.NewMessage(time.Unix(0, m.GetTime()))

		// for _, f := range m.GetFields() {
		// 	n := f.GetName()
		// 	if f.Int32 != nil {
		// 		msg.AddField(n, f.GetInt32())
		// 	} else if f.Int64 != nil {
		// 		msg.AddField(n, f.GetInt64())
		// 	} else if f.Float64 != nil {
		// 		msg.AddField(n, f.GetFloat64())
		// 	} else if f.Bool != nil {
		// 		msg.AddField(n, f.GetBool())
		// 	} else if f.String_ != nil {
		// 		msg.AddField(n, f.GetString_())
		// 	} else {
		// 		msg.AddField(n, f.GetBytes())
		// 	}
		// }

		// tags := db.Tags{}
		// for _, t := range m.GetTags() {
		// 	tags[t.GetKey()] = t.GetValue()
		// }
		// msg.SetTags(tags)
		messages[i] = msg
	}
	return messages
}
Esempio n. 3
0
// Ensure the shard writer returns an error when reading times out.
func TestShardWriter_Write_ErrReadTimeout(t *testing.T) {
	ln, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		t.Fatal(err)
	}

	w := cluster.NewShardWriter(time.Millisecond)
	w.MetaStore = &metaStore{host: ln.Addr().String()}
	now := time.Now()

	shardID := uint64(1)
	ownerID := uint64(2)
	var messages []db.Message
	messages = append(messages, db.NewMessage(now))

	if err := w.WriteShard(shardID, ownerID, messages); err == nil || !strings.Contains(err.Error(), "i/o timeout") {
		t.Fatalf("unexpected error: %s", err)
	}
}
Esempio n. 4
0
// Ensure the shard writer can successful write a multiple requests.
func TestShardWriter_WriteShard_Multiple(t *testing.T) {
	ts := newTestWriteService(writeShardSuccess)
	s := cluster.NewService(cluster.Config{})
	s.Listener = ts.muxln
	s.DataStore = ts
	if err := s.Open(); err != nil {
		t.Fatal(err)
	}
	defer s.Close()
	defer ts.Close()

	w := cluster.NewShardWriter(time.Minute)
	w.MetaStore = &metaStore{host: ts.ln.Addr().String()}

	// Build a single point.
	now := time.Now()
	var messages []db.Message
	messages = append(messages, db.NewMessage(now))

	// Write to shard twice and close.
	if err := w.WriteShard(1, 2, messages); err != nil {
		t.Fatal(err)
	} else if err := w.WriteShard(1, 2, messages); err != nil {
		t.Fatal(err)
	} else if err := w.Close(); err != nil {
		t.Fatal(err)
	}

	// Validate response.
	responses, err := ts.ResponseN(1)
	if err != nil {
		t.Fatal(err)
	} else if responses[0].shardID != 1 {
		t.Fatalf("unexpected shard id: %d", responses[0].shardID)
	}

	// Validate message.
	m := responses[0].messages[0]
	if m.Time().UnixNano() != now.UnixNano() {
		t.Fatalf("unexpected time: %s", m.Time())
	}
}
Esempio n. 5
0
// Ensure the shard writer returns an error when the server fails to accept the write.
func TestShardWriter_WriteShard_Error(t *testing.T) {
	ts := newTestWriteService(writeShardFail)
	s := cluster.NewService(cluster.Config{})
	s.Listener = ts.muxln
	s.DataStore = ts
	if err := s.Open(); err != nil {
		t.Fatal(err)
	}
	defer s.Close()
	defer ts.Close()

	w := cluster.NewShardWriter(time.Minute)
	w.MetaStore = &metaStore{host: ts.ln.Addr().String()}
	now := time.Now()

	shardID := uint64(1)
	ownerID := uint64(2)
	var messages []db.Message
	messages = append(messages, db.NewMessage(now))

	if err := w.WriteShard(shardID, ownerID, messages); err == nil || err.Error() != "error code 1: write shard 1: failed to write" {
		t.Fatalf("unexpected error: %v", err)
	}
}
Esempio n. 6
0
// Ensure the shard writer returns an error when dialing times out.
func TestShardWriter_Write_ErrDialTimeout(t *testing.T) {
	ts := newTestWriteService(writeShardSuccess)
	s := cluster.NewService(cluster.Config{})
	s.Listener = ts.muxln
	s.DataStore = ts
	if err := s.Open(); err != nil {
		t.Fatal(err)
	}
	defer s.Close()
	defer ts.Close()

	w := cluster.NewShardWriter(time.Nanosecond)
	w.MetaStore = &metaStore{host: ts.ln.Addr().String()}
	now := time.Now()

	shardID := uint64(1)
	ownerID := uint64(2)
	var messages []db.Message
	messages = append(messages, db.NewMessage(now))

	if err, exp := w.WriteShard(shardID, ownerID, messages), "i/o timeout"; err == nil || !strings.Contains(err.Error(), exp) {
		t.Fatalf("expected error %v, to contain %s", err, exp)
	}
}
Esempio n. 7
0
// AddMessage adds a message to the WriteMessagesRequest with field name 'value'
func (w *WriteMessagesRequest) AddMessage(name string, value interface{}, timestamp time.Time, tags map[string]string) {
	w.Messages = append(w.Messages, db.NewMessage(timestamp))
}
Esempio n. 8
0
func (p *Point) MarshalString() string {
	// return db.NewPoint(p.Measurement, p.Tags, p.Fields, p.Time).String()
	//TODO: fix this
	return db.NewMessage(p.Time).String()
}