Exemplo n.º 1
0
// Ensure the service can return shard data.
func TestService_handleConn(t *testing.T) {
	t.Skip("not implemented for tsm1 engine")
	s := MustOpenService()
	defer s.Close()

	// Mock shard.
	sh := MustOpenShard(123)
	defer sh.Close()
	s.TSDBStore.ShardFn = func(id uint64) *tsdb.Shard {
		if id != 123 {
			t.Fatalf("unexpected id: %d", id)
		}
		return sh.Shard
	}

	// Create client and request shard from service.
	c := copier.NewClient(s.Addr().String())
	r, err := c.ShardReader(123)
	if err != nil {
		t.Fatal(err)
	} else if r == nil {
		t.Fatal("expected reader")
	}
	defer r.Close()

	// Slurp from reader.
	var n uint64
	if err := binary.Read(r, binary.BigEndian, &n); err != nil {
		t.Fatal(err)
	}
	buf := make([]byte, n)
	if _, err := io.ReadFull(r, buf); err != nil {
		t.Fatal(err)
	}

	// Read database from disk.
	exp, err := ioutil.ReadFile(sh.Path())
	if err != nil {
		t.Fatal(err)
	}

	// Trim expected bytes since bolt won't read beyond the HWM.
	exp = exp[0:len(buf)]

	// Compare disk and reader contents.
	if !bytes.Equal(exp, buf) {
		t.Fatalf("data mismatch: exp=len(%d), got=len(%d)", len(exp), len(buf))
	}
}
Exemplo n.º 2
0
// Ensure the service can return an error to the client.
func TestService_handleConn_Error(t *testing.T) {
	s := MustOpenService()
	defer s.Close()

	// Mock missing shard.
	s.TSDBStore.ShardFn = func(id uint64) *tsdb.Shard { return nil }

	// Create client and request shard from service.
	c := copier.NewClient(s.Addr().String())
	r, err := c.ShardReader(123)
	if err == nil || err.Error() != `shard not found: id=123` {
		t.Fatalf("unexpected error: %s", err)
	} else if r != nil {
		t.Fatal("expected nil reader")
	}
}