Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unit test of influxd in the windows #5489

Merged
merged 3 commits into from
Feb 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/influxd/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ Options:
// retentionAndShardFromPath will take the shard relative path and split it into the
// retention policy name and shard ID. The first part of the path should be the database name.
func retentionAndShardFromPath(path string) (retention, shard string, err error) {
a := strings.Split(path, "/")
a := strings.Split(path, string(filepath.Separator))
if len(a) != 3 {
return "", "", fmt.Errorf("expected database, retention policy, and shard id in path: %s", path)
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/influxd/run/backup_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

"github.com/influxdb/influxdb/cmd/influxd/backup"
"github.com/influxdb/influxdb/cmd/influxd/restore"
"github.com/influxdb/influxdb/cmd/influxd/run"
"github.com/influxdb/influxdb/services/meta"
)

func TestServer_BackupAndRestore(t *testing.T) {
Expand Down Expand Up @@ -56,7 +58,8 @@ func TestServer_BackupAndRestore(t *testing.T) {

// now backup
cmd := backup.NewCommand()
if err := cmd.Run("-host", config.Meta.BindAddress, "-database", "mydb", backupDir); err != nil {
hostAddress, _ := meta.DefaultHost(run.DefaultHostname, config.Meta.BindAddress)
if err := cmd.Run("-host", hostAddress, "-database", "mydb", backupDir); err != nil {
t.Fatalf("error backing up: %s", err.Error())
}
}()
Expand Down
25 changes: 9 additions & 16 deletions cmd/influxd/run/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/influxdb/influxdb/services/udp"
"github.com/influxdb/influxdb/tcp"
"github.com/influxdb/influxdb/tsdb"
"github.com/influxdb/usage-client/v1"
client "github.com/influxdb/usage-client/v1"
// Initialize the engine packages
_ "github.com/influxdb/influxdb/tsdb/engine"
)
Expand Down Expand Up @@ -123,8 +123,13 @@ func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) {
}
}

nodeAddr, err := meta.DefaultHost(DefaultHostname, c.Meta.HTTPBindAddress)
if err != nil {
return nil, err
}

// load the node information
metaAddresses := []string{c.Meta.HTTPBindAddress}
metaAddresses := []string{nodeAddr}
if !c.Meta.Enabled {
metaAddresses = c.Meta.JoinPeers
}
Expand All @@ -149,11 +154,11 @@ func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) {
return nil, fmt.Errorf("must run as either meta node or data node or both")
}

httpBindAddress, err := defaultHost(DefaultHostname, c.HTTPD.BindAddress)
httpBindAddress, err := meta.DefaultHost(DefaultHostname, c.HTTPD.BindAddress)
if err != nil {
return nil, err
}
tcpBindAddress, err := defaultHost(DefaultHostname, bind)
tcpBindAddress, err := meta.DefaultHost(DefaultHostname, bind)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -748,18 +753,6 @@ func stopProfile() {
}
}

func defaultHost(hostname, addr string) (string, error) {
host, port, err := net.SplitHostPort(addr)
if err != nil {
return "", err
}

if host == "" {
return net.JoinHostPort(hostname, port), nil
}
return addr, nil
}

type tcpaddr struct{ host string }

func (a *tcpaddr) Network() string { return "tcp" }
Expand Down
12 changes: 9 additions & 3 deletions cmd/influxd/run/server_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,15 @@ func (s *Server) Close() {
if err := s.Server.Close(); err != nil {
panic(err.Error())
}
os.RemoveAll(s.Config.Meta.Dir)
os.RemoveAll(s.Config.Data.Dir)
os.RemoveAll(s.Config.HintedHandoff.Dir)
if err := os.RemoveAll(s.Config.Meta.Dir); err != nil {
panic(err.Error())
}
if err := os.RemoveAll(s.Config.Data.Dir); err != nil {
panic(err.Error())
}
if err := os.RemoveAll(s.Config.HintedHandoff.Dir); err != nil {
panic(err.Error())
}
}

// URL returns the base URL for the httpd endpoint.
Expand Down
8 changes: 6 additions & 2 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ func (n *Node) Save() error {
if err != nil {
return err
}
defer f.Close()

if err := json.NewEncoder(f).Encode(n); err != nil {
if err = json.NewEncoder(f).Encode(n); err != nil {
f.Close()
return err
}

if err = f.Close(); nil != err {
return err
}

Expand Down
22 changes: 15 additions & 7 deletions services/meta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,11 @@ func (c *Config) Validate() error {
}

func (c *Config) defaultHost(addr string) string {
host, port, err := net.SplitHostPort(addr)
if err != nil {
address, err := DefaultHost(DefaultHostname, addr)
if nil != err {
return addr
}

if host == "" {
return net.JoinHostPort(DefaultHostname, port)
}
return addr
return address
}

// DefaultedBindAddress returns the BindAddress normalized with the
Expand All @@ -120,3 +116,15 @@ func (c *Config) DefaultedBindAddress() string {
func (c *Config) DefaultedHTTPBindAddress() string {
return c.defaultHost(c.HTTPBindAddress)
}

func DefaultHost(hostname, addr string) (string, error) {
host, port, err := net.SplitHostPort(addr)
if err != nil {
return "", err
}

if host == "" || host == "0.0.0.0" || host == "::" {
return net.JoinHostPort(hostname, port), nil
}
return addr, nil
}