mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
If non-primary host fails to process a request, retry on primary node. conditions when we should not do this: - no error - we've aleady tried the primary - we're making a status request to get the primary node...this could lead to lock contention if we allow it to happen as we are making an http request within an on going http request to discover the primary node. This also deletes the RemoveHost method and the associated test b/c it is not used anywhere anymore and updates the returned error type.
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
// Copyright 2021 Molecula Corp. All rights reserved.
|
|
// package ctl contains all pilosa subcommands other than 'server'. These are
|
|
// generally administration, testing, and debugging tools.
|
|
|
|
package client
|
|
|
|
import (
|
|
"testing"
|
|
|
|
pnet "github.com/molecula/featurebase/v3/net"
|
|
)
|
|
|
|
func TestNewClusterWithHost(t *testing.T) {
|
|
c := NewClusterWithHost(pnet.DefaultURI())
|
|
hosts := c.Hosts()
|
|
if len(hosts) != 1 || !hosts[0].Equals(pnet.DefaultURI()) {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestAddHost(t *testing.T) {
|
|
const addr = "http://localhost:3000"
|
|
c := DefaultCluster()
|
|
if c.Hosts() == nil {
|
|
t.Fatalf("Hosts should not be nil")
|
|
}
|
|
uri, err := pnet.NewURIFromAddress(addr)
|
|
if err != nil {
|
|
t.Fatalf("Cannot parse address")
|
|
}
|
|
target, err := pnet.NewURIFromAddress(addr)
|
|
if err != nil {
|
|
t.Fatalf("Cannot parse address")
|
|
}
|
|
c.AddHost(uri)
|
|
hosts := c.Hosts()
|
|
if len(hosts) != 1 || !hosts[0].Equals(target) {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestHosts(t *testing.T) {
|
|
c := DefaultCluster()
|
|
if c.Host() != nil {
|
|
t.Fatalf("Hosts with empty cluster should return nil")
|
|
}
|
|
c = NewClusterWithHost(pnet.DefaultURI())
|
|
if !c.Host().Equals(pnet.DefaultURI()) {
|
|
t.Fatalf("Host should return a value if there are hosts in the cluster")
|
|
}
|
|
}
|