mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #2629 from crawford/ports
*: update to use IANA-assigned ports
This commit is contained in:
commit
374a18130a
@ -44,13 +44,13 @@ First start a single-member cluster of etcd:
|
||||
./bin/etcd
|
||||
```
|
||||
|
||||
This will bring up etcd listening on port 4001 for client communication and on port 7001 for server-to-server communication.
|
||||
This will bring up etcd listening on port 2379 for client communication and on port 2380 for server-to-server communication.
|
||||
|
||||
Next, let's set a single key, and then retrieve it:
|
||||
|
||||
```
|
||||
curl -L http://127.0.0.1:4001/v2/keys/mykey -XPUT -d value="this is awesome"
|
||||
curl -L http://127.0.0.1:4001/v2/keys/mykey
|
||||
curl -L http://127.0.0.1:2379/v2/keys/mykey -XPUT -d value="this is awesome"
|
||||
curl -L http://127.0.0.1:2379/v2/keys/mykey
|
||||
```
|
||||
|
||||
You have successfully started an etcd and written a key to the store.
|
||||
@ -112,7 +112,7 @@ New minor versions may add additional features to the API.
|
||||
You can get the version of etcd by issuing a request to /version:
|
||||
|
||||
```sh
|
||||
curl -L http://127.0.0.1:4001/version
|
||||
curl -L http://127.0.0.1:2379/version
|
||||
```
|
||||
|
||||
#### API Versioning
|
||||
|
@ -50,9 +50,9 @@ type Config struct {
|
||||
// example, a three-node cluster could be provided like so:
|
||||
//
|
||||
// Endpoints: []string{
|
||||
// "http://node1.example.com:4001",
|
||||
// "http://node1.example.com:2379",
|
||||
// "http://node2.example.com:2379",
|
||||
// "http://node3.example.com:4001",
|
||||
// "http://node3.example.com:2379",
|
||||
// }
|
||||
//
|
||||
// If multiple endpoints are provided, the Client will attempt to
|
||||
|
@ -626,12 +626,12 @@ func TestHTTPClusterClientSync(t *testing.T) {
|
||||
})
|
||||
|
||||
hc := &httpClusterClient{clientFactory: cf}
|
||||
err := hc.reset([]string{"http://127.0.0.1:4001"})
|
||||
err := hc.reset([]string{"http://127.0.0.1:2379"})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error during setup: %#v", err)
|
||||
}
|
||||
|
||||
want := []string{"http://127.0.0.1:4001"}
|
||||
want := []string{"http://127.0.0.1:2379"}
|
||||
got := hc.Endpoints()
|
||||
if !reflect.DeepEqual(want, got) {
|
||||
t.Fatalf("incorrect endpoints: want=%#v got=%#v", want, got)
|
||||
@ -666,12 +666,12 @@ func TestHTTPClusterClientSyncFail(t *testing.T) {
|
||||
})
|
||||
|
||||
hc := &httpClusterClient{clientFactory: cf}
|
||||
err := hc.reset([]string{"http://127.0.0.1:4001"})
|
||||
err := hc.reset([]string{"http://127.0.0.1:2379"})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error during setup: %#v", err)
|
||||
}
|
||||
|
||||
want := []string{"http://127.0.0.1:4001"}
|
||||
want := []string{"http://127.0.0.1:2379"}
|
||||
got := hc.Endpoints()
|
||||
if !reflect.DeepEqual(want, got) {
|
||||
t.Fatalf("incorrect endpoints: want=%#v got=%#v", want, got)
|
||||
|
@ -25,7 +25,7 @@ Create a Config and exchange it for a Client:
|
||||
)
|
||||
|
||||
cfg := client.Config{
|
||||
Endpoints: []string{"http://127.0.0.1:4001"},
|
||||
Endpoints: []string{"http://127.0.0.1:2379"},
|
||||
Transport: DefaultTransport,
|
||||
}
|
||||
|
||||
|
@ -128,23 +128,23 @@ func TestMemberUnmarshal(t *testing.T) {
|
||||
|
||||
// both client and peer URLs
|
||||
{
|
||||
body: []byte(`{"peerURLs": ["http://127.0.0.1:4001"], "clientURLs": ["http://127.0.0.1:4001"]}`),
|
||||
body: []byte(`{"peerURLs": ["http://127.0.0.1:2379"], "clientURLs": ["http://127.0.0.1:2379"]}`),
|
||||
wantMember: Member{
|
||||
PeerURLs: []string{
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.1:2379",
|
||||
},
|
||||
ClientURLs: []string{
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.1:2379",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// multiple peer URLs
|
||||
{
|
||||
body: []byte(`{"peerURLs": ["http://127.0.0.1:4001", "https://example.com"]}`),
|
||||
body: []byte(`{"peerURLs": ["http://127.0.0.1:2379", "https://example.com"]}`),
|
||||
wantMember: Member{
|
||||
PeerURLs: []string{
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.1:2379",
|
||||
"https://example.com",
|
||||
},
|
||||
ClientURLs: nil,
|
||||
@ -153,11 +153,11 @@ func TestMemberUnmarshal(t *testing.T) {
|
||||
|
||||
// multiple client URLs
|
||||
{
|
||||
body: []byte(`{"clientURLs": ["http://127.0.0.1:4001", "https://example.com"]}`),
|
||||
body: []byte(`{"clientURLs": ["http://127.0.0.1:2379", "https://example.com"]}`),
|
||||
wantMember: Member{
|
||||
PeerURLs: nil,
|
||||
ClientURLs: []string{
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.1:2379",
|
||||
"https://example.com",
|
||||
},
|
||||
},
|
||||
@ -311,7 +311,7 @@ func TestHTTPMembersAPIAddSuccess(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHTTPMembersAPIAddError(t *testing.T) {
|
||||
okPeer := "http://example.com:4001"
|
||||
okPeer := "http://example.com:2379"
|
||||
tests := []struct {
|
||||
peerURL string
|
||||
client httpClient
|
||||
|
@ -55,10 +55,10 @@ func TestSRVGetCluster(t *testing.T) {
|
||||
&net.SRV{Target: "10.0.0.3", Port: 2480},
|
||||
},
|
||||
[]*net.SRV{
|
||||
&net.SRV{Target: "10.0.0.1", Port: 7001},
|
||||
&net.SRV{Target: "10.0.0.1", Port: 2380},
|
||||
},
|
||||
nil,
|
||||
"0=https://10.0.0.1:2480,1=https://10.0.0.2:2480,2=https://10.0.0.3:2480,3=http://10.0.0.1:7001",
|
||||
"0=https://10.0.0.1:2480,1=https://10.0.0.2:2480,2=https://10.0.0.3:2480,3=http://10.0.0.1:2380",
|
||||
},
|
||||
{
|
||||
[]*net.SRV{
|
||||
@ -67,10 +67,10 @@ func TestSRVGetCluster(t *testing.T) {
|
||||
&net.SRV{Target: "10.0.0.3", Port: 2480},
|
||||
},
|
||||
[]*net.SRV{
|
||||
&net.SRV{Target: "10.0.0.1", Port: 7001},
|
||||
&net.SRV{Target: "10.0.0.1", Port: 2380},
|
||||
},
|
||||
[]string{"https://10.0.0.1:2480"},
|
||||
"dnsClusterTest=https://10.0.0.1:2480,0=https://10.0.0.2:2480,1=https://10.0.0.3:2480,2=http://10.0.0.1:7001",
|
||||
"dnsClusterTest=https://10.0.0.1:2480,0=https://10.0.0.2:2480,1=https://10.0.0.3:2480,2=http://10.0.0.1:2380",
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -233,7 +233,7 @@ The following exit codes can be returned from etcdctl:
|
||||
|
||||
## Peers
|
||||
|
||||
If your etcd cluster isn't available on `http://127.0.0.1:4001` you can specify
|
||||
If your etcd cluster isn't available on `http://127.0.0.1:2379` you can specify
|
||||
a `--peers` flag or `ETCDCTL_PEERS` environment variable. You can list one peer,
|
||||
or a comma-separated list of peers.
|
||||
|
||||
|
@ -31,7 +31,7 @@ func main() {
|
||||
cli.BoolFlag{Name: "debug", Usage: "output cURL commands which can be used to reproduce the request"},
|
||||
cli.BoolFlag{Name: "no-sync", Usage: "don't synchronize cluster information before sending request"},
|
||||
cli.StringFlag{Name: "output, o", Value: "simple", Usage: "output response in the given format (`simple` or `json`)"},
|
||||
cli.StringFlag{Name: "peers, C", Value: "", Usage: "a comma-delimited list of machine addresses in the cluster (default: \"127.0.0.1:4001\")"},
|
||||
cli.StringFlag{Name: "peers, C", Value: "", Usage: "a comma-delimited list of machine addresses in the cluster (default: \"127.0.0.1:4001,127.0.0.1:2379\")"},
|
||||
cli.StringFlag{Name: "cert-file", Value: "", Usage: "identify HTTPS client using this SSL certificate file"},
|
||||
cli.StringFlag{Name: "key-file", Value: "", Usage: "identify HTTPS client using this SSL key file"},
|
||||
cli.StringFlag{Name: "ca-file", Value: "", Usage: "verify certificates of HTTPS-enabled servers using this CA bundle"},
|
||||
|
@ -153,14 +153,14 @@ func TestConfigParsingOtherFlags(t *testing.T) {
|
||||
|
||||
func TestConfigParsingV1Flags(t *testing.T) {
|
||||
args := []string{
|
||||
"-peer-addr=127.0.0.1:7001",
|
||||
"-addr=127.0.0.1:4001",
|
||||
"-peer-addr=127.0.0.1:2380",
|
||||
"-addr=127.0.0.1:2379",
|
||||
}
|
||||
wcfg := NewConfig()
|
||||
wcfg.lpurls = []url.URL{{Scheme: "http", Host: "[::]:7001"}}
|
||||
wcfg.apurls = []url.URL{{Scheme: "http", Host: "127.0.0.1:7001"}}
|
||||
wcfg.lcurls = []url.URL{{Scheme: "http", Host: "[::]:4001"}}
|
||||
wcfg.acurls = []url.URL{{Scheme: "http", Host: "127.0.0.1:4001"}}
|
||||
wcfg.lpurls = []url.URL{{Scheme: "http", Host: "[::]:2380"}}
|
||||
wcfg.apurls = []url.URL{{Scheme: "http", Host: "127.0.0.1:2380"}}
|
||||
wcfg.lcurls = []url.URL{{Scheme: "http", Host: "[::]:2379"}}
|
||||
wcfg.acurls = []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}}
|
||||
|
||||
cfg := NewConfig()
|
||||
if err := cfg.Parse(args); err != nil {
|
||||
|
@ -27,8 +27,8 @@ func TestGenClusterString(t *testing.T) {
|
||||
wstr string
|
||||
}{
|
||||
{
|
||||
"default", []string{"http://127.0.0.1:4001"},
|
||||
"default=http://127.0.0.1:4001",
|
||||
"default", []string{"http://127.0.0.1:2379"},
|
||||
"default=http://127.0.0.1:2379",
|
||||
},
|
||||
{
|
||||
"node1", []string{"http://0.0.0.0:2379", "http://1.1.1.1:2379"},
|
||||
|
@ -594,7 +594,7 @@ func TestClusterString(t *testing.T) {
|
||||
),
|
||||
3: newTestMember(
|
||||
3,
|
||||
[]string{"http://3.3.3.3:1234", "http://127.0.0.1:7001"},
|
||||
[]string{"http://3.3.3.3:1234", "http://127.0.0.1:2380"},
|
||||
"ghi",
|
||||
nil,
|
||||
),
|
||||
@ -613,7 +613,7 @@ func TestClusterString(t *testing.T) {
|
||||
),
|
||||
},
|
||||
}
|
||||
w := "abc=http://0.0.0.0:0000,abc=http://1.1.1.1:1111,def=http://2.2.2.2:2222,ghi=http://127.0.0.1:7001,ghi=http://3.3.3.3:1234"
|
||||
w := "abc=http://0.0.0.0:0000,abc=http://1.1.1.1:1111,def=http://2.2.2.2:2222,ghi=http://127.0.0.1:2380,ghi=http://3.3.3.3:1234"
|
||||
if g := cls.String(); g != w {
|
||||
t.Fatalf("Cluster.String():\ngot %#v\nwant %#v", g, w)
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func TestConfigVerifyExistingWithDiscoveryURLFail(t *testing.T) {
|
||||
}
|
||||
c := &ServerConfig{
|
||||
Name: "node1",
|
||||
DiscoveryURL: "http://127.0.0.1:4001/abcdefg",
|
||||
DiscoveryURL: "http://127.0.0.1:2379/abcdefg",
|
||||
PeerURLs: mustNewURLs(t, []string{"http://127.0.0.1:2380"}),
|
||||
Cluster: cluster,
|
||||
NewCluster: false,
|
||||
@ -105,7 +105,7 @@ func TestConfigVerifyLocalMember(t *testing.T) {
|
||||
},
|
||||
{
|
||||
// Advertised peer URLs must match those in cluster-state
|
||||
"node1=http://localhost:7001,node1=http://localhost:12345",
|
||||
"node1=http://localhost:2380,node1=http://localhost:12345",
|
||||
[]string{"http://localhost:12345"},
|
||||
true,
|
||||
|
||||
@ -113,7 +113,7 @@ func TestConfigVerifyLocalMember(t *testing.T) {
|
||||
},
|
||||
{
|
||||
// Advertised peer URLs must match those in cluster-state
|
||||
"node1=http://localhost:7001",
|
||||
"node1=http://localhost:2380",
|
||||
[]string{},
|
||||
true,
|
||||
|
||||
@ -121,7 +121,7 @@ func TestConfigVerifyLocalMember(t *testing.T) {
|
||||
},
|
||||
{
|
||||
// do not care about the urls if strict is not set
|
||||
"node1=http://localhost:7001",
|
||||
"node1=http://localhost:2380",
|
||||
[]string{},
|
||||
false,
|
||||
|
||||
|
@ -37,23 +37,23 @@ func TestMemberUnmarshal(t *testing.T) {
|
||||
|
||||
// both client and peer URLs
|
||||
{
|
||||
body: []byte(`{"peerURLs": ["http://127.0.0.1:4001"], "clientURLs": ["http://127.0.0.1:4001"]}`),
|
||||
body: []byte(`{"peerURLs": ["http://127.0.0.1:2379"], "clientURLs": ["http://127.0.0.1:2379"]}`),
|
||||
wantMember: Member{
|
||||
PeerURLs: []string{
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.1:2379",
|
||||
},
|
||||
ClientURLs: []string{
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.1:2379",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// multiple peer URLs
|
||||
{
|
||||
body: []byte(`{"peerURLs": ["http://127.0.0.1:4001", "https://example.com"]}`),
|
||||
body: []byte(`{"peerURLs": ["http://127.0.0.1:2379", "https://example.com"]}`),
|
||||
wantMember: Member{
|
||||
PeerURLs: []string{
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.1:2379",
|
||||
"https://example.com",
|
||||
},
|
||||
ClientURLs: nil,
|
||||
@ -62,11 +62,11 @@ func TestMemberUnmarshal(t *testing.T) {
|
||||
|
||||
// multiple client URLs
|
||||
{
|
||||
body: []byte(`{"clientURLs": ["http://127.0.0.1:4001", "https://example.com"]}`),
|
||||
body: []byte(`{"clientURLs": ["http://127.0.0.1:2379", "https://example.com"]}`),
|
||||
wantMember: Member{
|
||||
PeerURLs: nil,
|
||||
ClientURLs: []string{
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.1:2379",
|
||||
"https://example.com",
|
||||
},
|
||||
},
|
||||
@ -122,7 +122,7 @@ func TestMemberCreateRequestUnmarshalFail(t *testing.T) {
|
||||
[]byte(`{"peerURLs": "foo"}`),
|
||||
[]byte(`{"peerURLs": ["."]}`),
|
||||
[]byte(`{"peerURLs": []}`),
|
||||
[]byte(`{"peerURLs": ["http://127.0.0.1:4001/foo"]}`),
|
||||
[]byte(`{"peerURLs": ["http://127.0.0.1:2379/foo"]}`),
|
||||
[]byte(`{"peerURLs": ["http://127.0.0.1"]}`),
|
||||
}
|
||||
|
||||
|
@ -401,10 +401,10 @@ func TestApplyRequestOnAdminMemberAttributes(t *testing.T) {
|
||||
Method: "PUT",
|
||||
ID: 1,
|
||||
Path: path.Join(storeMembersPrefix, strconv.FormatUint(1, 16), attributesSuffix),
|
||||
Val: `{"Name":"abc","ClientURLs":["http://127.0.0.1:4001"]}`,
|
||||
Val: `{"Name":"abc","ClientURLs":["http://127.0.0.1:2379"]}`,
|
||||
}
|
||||
srv.applyRequest(req)
|
||||
w := Attributes{Name: "abc", ClientURLs: []string{"http://127.0.0.1:4001"}}
|
||||
w := Attributes{Name: "abc", ClientURLs: []string{"http://127.0.0.1:2379"}}
|
||||
if g := cl.Member(1).Attributes; !reflect.DeepEqual(g, w) {
|
||||
t.Errorf("attributes = %v, want %v", g, w)
|
||||
}
|
||||
|
@ -93,23 +93,23 @@ func TestSetBindAddrFromAddr(t *testing.T) {
|
||||
},
|
||||
// addr flag set
|
||||
{
|
||||
args: []string{"-addr=192.0.3.17:4001"},
|
||||
waddr: &IPAddressPort{IP: "::", Port: 4001},
|
||||
args: []string{"-addr=192.0.3.17:2379"},
|
||||
waddr: &IPAddressPort{IP: "::", Port: 2379},
|
||||
},
|
||||
// bindAddr flag set
|
||||
{
|
||||
args: []string{"-bind-addr=127.0.0.1:4001"},
|
||||
waddr: &IPAddressPort{IP: "127.0.0.1", Port: 4001},
|
||||
args: []string{"-bind-addr=127.0.0.1:2379"},
|
||||
waddr: &IPAddressPort{IP: "127.0.0.1", Port: 2379},
|
||||
},
|
||||
// both addr flags set
|
||||
{
|
||||
args: []string{"-bind-addr=127.0.0.1:4001", "-addr=192.0.3.17:4001"},
|
||||
waddr: &IPAddressPort{IP: "127.0.0.1", Port: 4001},
|
||||
args: []string{"-bind-addr=127.0.0.1:2379", "-addr=192.0.3.17:2379"},
|
||||
waddr: &IPAddressPort{IP: "127.0.0.1", Port: 2379},
|
||||
},
|
||||
// both addr flags set, IPv6
|
||||
{
|
||||
args: []string{"-bind-addr=[2001:db8::4:9]:4001", "-addr=[2001:db8::4:f0]:4001"},
|
||||
waddr: &IPAddressPort{IP: "2001:db8::4:9", Port: 4001},
|
||||
args: []string{"-bind-addr=[2001:db8::4:9]:2379", "-addr=[2001:db8::4:f0]:2379"},
|
||||
waddr: &IPAddressPort{IP: "2001:db8::4:9", Port: 2379},
|
||||
},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
|
@ -27,7 +27,7 @@ func TestIPAddressPortSet(t *testing.T) {
|
||||
|
||||
fail := []string{
|
||||
// bad IP specification
|
||||
":4001",
|
||||
":2379",
|
||||
"127.0:8080",
|
||||
"123:456",
|
||||
// bad port specification
|
||||
@ -62,8 +62,8 @@ func TestIPAddressPortSet(t *testing.T) {
|
||||
|
||||
func TestIPAddressPortString(t *testing.T) {
|
||||
addresses := []string{
|
||||
"[2001:db8::1:1234]:4001",
|
||||
"127.0.0.1:4001",
|
||||
"[2001:db8::1:1234]:2379",
|
||||
"127.0.0.1:2379",
|
||||
}
|
||||
for i, tt := range addresses {
|
||||
f := &IPAddressPort{}
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
type URLsValue types.URLs
|
||||
|
||||
// Set parses a command line set of URLs formatted like:
|
||||
// http://127.0.0.1:7001,http://10.1.1.2:80
|
||||
// http://127.0.0.1:2380,http://10.1.1.2:80
|
||||
func (us *URLsValue) Set(s string) error {
|
||||
strs := strings.Split(s, ",")
|
||||
nus, err := types.NewURLs(strs)
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
func TestValidateURLsValueBad(t *testing.T) {
|
||||
tests := []string{
|
||||
// bad IP specification
|
||||
":4001",
|
||||
":2379",
|
||||
"127.0:8080",
|
||||
"123:456",
|
||||
// bad port specification
|
||||
|
@ -157,73 +157,73 @@ func TestURLsEqual(t *testing.T) {
|
||||
expect bool
|
||||
}{
|
||||
{
|
||||
a: []url.URL{{Scheme: "http", Host: "127.0.0.1:4001"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "127.0.0.1:4001"}},
|
||||
a: []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
a: []url.URL{{Scheme: "http", Host: "example.com:4001"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "10.0.10.1:4001"}},
|
||||
a: []url.URL{{Scheme: "http", Host: "example.com:2379"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "10.0.10.1:2379"}},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
a: []url.URL{{Scheme: "http", Host: "127.0.0.1:4001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "127.0.0.1:4001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
a: []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
a: []url.URL{{Scheme: "http", Host: "example.com:4001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "example.com:4001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
a: []url.URL{{Scheme: "http", Host: "example.com:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "example.com:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
a: []url.URL{{Scheme: "http", Host: "10.0.10.1:4001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "example.com:4001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
a: []url.URL{{Scheme: "http", Host: "10.0.10.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "example.com:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
expect: true,
|
||||
},
|
||||
{
|
||||
a: []url.URL{{Scheme: "http", Host: "127.0.0.1:4001"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
a: []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
a: []url.URL{{Scheme: "http", Host: "example.com:7001"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "10.0.10.1:4001"}},
|
||||
a: []url.URL{{Scheme: "http", Host: "example.com:2380"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "10.0.10.1:2379"}},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
a: []url.URL{{Scheme: "http", Host: "127.0.0.1:4001"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "10.0.0.1:4001"}},
|
||||
a: []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "10.0.0.1:2379"}},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
a: []url.URL{{Scheme: "http", Host: "example.com:4001"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "10.0.0.1:4001"}},
|
||||
a: []url.URL{{Scheme: "http", Host: "example.com:2379"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "10.0.0.1:2379"}},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
a: []url.URL{{Scheme: "http", Host: "127.0.0.1:4001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "127.0.0.1:7001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
a: []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "127.0.0.1:2380"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
a: []url.URL{{Scheme: "http", Host: "example.com:4001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "127.0.0.1:7001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
a: []url.URL{{Scheme: "http", Host: "example.com:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "127.0.0.1:2380"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
a: []url.URL{{Scheme: "http", Host: "127.0.0.1:4001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "10.0.0.1:4001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
a: []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "10.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
a: []url.URL{{Scheme: "http", Host: "example.com:4001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "10.0.0.1:4001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
a: []url.URL{{Scheme: "http", Host: "example.com:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "10.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
a: []url.URL{{Scheme: "http", Host: "10.0.0.1:4001"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "10.0.0.1:4001"}, {Scheme: "http", Host: "127.0.0.1:7001"}},
|
||||
a: []url.URL{{Scheme: "http", Host: "10.0.0.1:2379"}},
|
||||
b: []url.URL{{Scheme: "http", Host: "10.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
|
||||
expect: false,
|
||||
},
|
||||
}
|
||||
|
@ -27,23 +27,23 @@ func TestNewURLs(t *testing.T) {
|
||||
wurls URLs
|
||||
}{
|
||||
{
|
||||
[]string{"http://127.0.0.1:4001"},
|
||||
testutil.MustNewURLs(t, []string{"http://127.0.0.1:4001"}),
|
||||
[]string{"http://127.0.0.1:2379"},
|
||||
testutil.MustNewURLs(t, []string{"http://127.0.0.1:2379"}),
|
||||
},
|
||||
// it can trim space
|
||||
{
|
||||
[]string{" http://127.0.0.1:4001 "},
|
||||
testutil.MustNewURLs(t, []string{"http://127.0.0.1:4001"}),
|
||||
[]string{" http://127.0.0.1:2379 "},
|
||||
testutil.MustNewURLs(t, []string{"http://127.0.0.1:2379"}),
|
||||
},
|
||||
// it does sort
|
||||
{
|
||||
[]string{
|
||||
"http://127.0.0.2:4001",
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.2:2379",
|
||||
"http://127.0.0.1:2379",
|
||||
},
|
||||
testutil.MustNewURLs(t, []string{
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.2:4001",
|
||||
"http://127.0.0.1:2379",
|
||||
"http://127.0.0.2:2379",
|
||||
}),
|
||||
},
|
||||
}
|
||||
@ -65,22 +65,22 @@ func TestURLsString(t *testing.T) {
|
||||
"",
|
||||
},
|
||||
{
|
||||
testutil.MustNewURLs(t, []string{"http://127.0.0.1:4001"}),
|
||||
"http://127.0.0.1:4001",
|
||||
testutil.MustNewURLs(t, []string{"http://127.0.0.1:2379"}),
|
||||
"http://127.0.0.1:2379",
|
||||
},
|
||||
{
|
||||
testutil.MustNewURLs(t, []string{
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.2:4001",
|
||||
"http://127.0.0.1:2379",
|
||||
"http://127.0.0.2:2379",
|
||||
}),
|
||||
"http://127.0.0.1:4001,http://127.0.0.2:4001",
|
||||
"http://127.0.0.1:2379,http://127.0.0.2:2379",
|
||||
},
|
||||
{
|
||||
testutil.MustNewURLs(t, []string{
|
||||
"http://127.0.0.2:4001",
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.2:2379",
|
||||
"http://127.0.0.1:2379",
|
||||
}),
|
||||
"http://127.0.0.2:4001,http://127.0.0.1:4001",
|
||||
"http://127.0.0.2:2379,http://127.0.0.1:2379",
|
||||
},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
@ -93,16 +93,16 @@ func TestURLsString(t *testing.T) {
|
||||
|
||||
func TestURLsSort(t *testing.T) {
|
||||
g := testutil.MustNewURLs(t, []string{
|
||||
"http://127.0.0.4:4001",
|
||||
"http://127.0.0.2:4001",
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.3:4001",
|
||||
"http://127.0.0.4:2379",
|
||||
"http://127.0.0.2:2379",
|
||||
"http://127.0.0.1:2379",
|
||||
"http://127.0.0.3:2379",
|
||||
})
|
||||
w := testutil.MustNewURLs(t, []string{
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.2:4001",
|
||||
"http://127.0.0.3:4001",
|
||||
"http://127.0.0.4:4001",
|
||||
"http://127.0.0.1:2379",
|
||||
"http://127.0.0.2:2379",
|
||||
"http://127.0.0.3:2379",
|
||||
"http://127.0.0.4:2379",
|
||||
})
|
||||
gurls := URLs(g)
|
||||
gurls.Sort()
|
||||
@ -121,22 +121,22 @@ func TestURLsStringSlice(t *testing.T) {
|
||||
[]string{},
|
||||
},
|
||||
{
|
||||
testutil.MustNewURLs(t, []string{"http://127.0.0.1:4001"}),
|
||||
[]string{"http://127.0.0.1:4001"},
|
||||
testutil.MustNewURLs(t, []string{"http://127.0.0.1:2379"}),
|
||||
[]string{"http://127.0.0.1:2379"},
|
||||
},
|
||||
{
|
||||
testutil.MustNewURLs(t, []string{
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.2:4001",
|
||||
"http://127.0.0.1:2379",
|
||||
"http://127.0.0.2:2379",
|
||||
}),
|
||||
[]string{"http://127.0.0.1:4001", "http://127.0.0.2:4001"},
|
||||
[]string{"http://127.0.0.1:2379", "http://127.0.0.2:2379"},
|
||||
},
|
||||
{
|
||||
testutil.MustNewURLs(t, []string{
|
||||
"http://127.0.0.2:4001",
|
||||
"http://127.0.0.1:4001",
|
||||
"http://127.0.0.2:2379",
|
||||
"http://127.0.0.1:2379",
|
||||
}),
|
||||
[]string{"http://127.0.0.2:4001", "http://127.0.0.1:4001"},
|
||||
[]string{"http://127.0.0.2:2379", "http://127.0.0.1:2379"},
|
||||
},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
@ -152,13 +152,13 @@ func TestNewURLsFail(t *testing.T) {
|
||||
// no urls given
|
||||
{},
|
||||
// missing protocol scheme
|
||||
{"://127.0.0.1:4001"},
|
||||
{"://127.0.0.1:2379"},
|
||||
// unsupported scheme
|
||||
{"mailto://127.0.0.1:4001"},
|
||||
{"mailto://127.0.0.1:2379"},
|
||||
// not conform to host:port
|
||||
{"http://127.0.0.1"},
|
||||
// contain a path
|
||||
{"http://127.0.0.1:4001/path"},
|
||||
{"http://127.0.0.1:2379/path"},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
_, err := NewURLs(tt)
|
||||
|
@ -81,7 +81,7 @@ func TestReverseProxyServe(t *testing.T) {
|
||||
transport: tt.rt,
|
||||
}
|
||||
|
||||
req, _ := http.NewRequest("GET", "http://192.0.2.2:4001", nil)
|
||||
req, _ := http.NewRequest("GET", "http://192.0.2.2:2379", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
rp.ServeHTTP(rr, req)
|
||||
|
||||
|
@ -174,7 +174,7 @@ func TestServeRaftStreamPrefix(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
req, err := http.NewRequest("GET", "http://localhost:7001"+tt.path, nil)
|
||||
req, err := http.NewRequest("GET", "http://localhost:2380"+tt.path, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("#%d: could not create request: %#v", i, err)
|
||||
}
|
||||
@ -281,7 +281,7 @@ func TestServeRaftStreamPrefixBad(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
req, err := http.NewRequest(tt.method, "http://localhost:7001"+tt.path, nil)
|
||||
req, err := http.NewRequest(tt.method, "http://localhost:2380"+tt.path, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("#%d: could not create request: %#v", i, err)
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ import (
|
||||
// and increase success count in stats.
|
||||
func TestPipelineSend(t *testing.T) {
|
||||
tr := &roundTripperRecorder{}
|
||||
picker := mustNewURLPicker(t, []string{"http://localhost:7001"})
|
||||
picker := mustNewURLPicker(t, []string{"http://localhost:2380"})
|
||||
fs := &stats.FollowerStats{}
|
||||
p := newPipeline(tr, picker, types.ID(1), types.ID(1), fs, &fakeRaft{}, nil)
|
||||
|
||||
@ -50,7 +50,7 @@ func TestPipelineSend(t *testing.T) {
|
||||
|
||||
func TestPipelineExceedMaximalServing(t *testing.T) {
|
||||
tr := newRoundTripperBlocker()
|
||||
picker := mustNewURLPicker(t, []string{"http://localhost:7001"})
|
||||
picker := mustNewURLPicker(t, []string{"http://localhost:2380"})
|
||||
fs := &stats.FollowerStats{}
|
||||
p := newPipeline(tr, picker, types.ID(1), types.ID(1), fs, &fakeRaft{}, nil)
|
||||
|
||||
@ -90,7 +90,7 @@ func TestPipelineExceedMaximalServing(t *testing.T) {
|
||||
// TestPipelineSendFailed tests that when send func meets the post error,
|
||||
// it increases fail count in stats.
|
||||
func TestPipelineSendFailed(t *testing.T) {
|
||||
picker := mustNewURLPicker(t, []string{"http://localhost:7001"})
|
||||
picker := mustNewURLPicker(t, []string{"http://localhost:2380"})
|
||||
fs := &stats.FollowerStats{}
|
||||
p := newPipeline(newRespRoundTripper(0, errors.New("blah")), picker, types.ID(1), types.ID(1), fs, &fakeRaft{}, nil)
|
||||
|
||||
@ -106,7 +106,7 @@ func TestPipelineSendFailed(t *testing.T) {
|
||||
|
||||
func TestPipelinePost(t *testing.T) {
|
||||
tr := &roundTripperRecorder{}
|
||||
picker := mustNewURLPicker(t, []string{"http://localhost:7001"})
|
||||
picker := mustNewURLPicker(t, []string{"http://localhost:2380"})
|
||||
p := newPipeline(tr, picker, types.ID(1), types.ID(1), nil, &fakeRaft{}, nil)
|
||||
if err := p.post([]byte("some data")); err != nil {
|
||||
t.Fatalf("unexpect post error: %v", err)
|
||||
@ -116,8 +116,8 @@ func TestPipelinePost(t *testing.T) {
|
||||
if g := tr.Request().Method; g != "POST" {
|
||||
t.Errorf("method = %s, want %s", g, "POST")
|
||||
}
|
||||
if g := tr.Request().URL.String(); g != "http://localhost:7001/raft" {
|
||||
t.Errorf("url = %s, want %s", g, "http://localhost:7001/raft")
|
||||
if g := tr.Request().URL.String(); g != "http://localhost:2380/raft" {
|
||||
t.Errorf("url = %s, want %s", g, "http://localhost:2380/raft")
|
||||
}
|
||||
if g := tr.Request().Header.Get("Content-Type"); g != "application/protobuf" {
|
||||
t.Errorf("content type = %s, want %s", g, "application/protobuf")
|
||||
@ -141,10 +141,10 @@ func TestPipelinePostBad(t *testing.T) {
|
||||
err error
|
||||
}{
|
||||
// RoundTrip returns error
|
||||
{"http://localhost:7001", 0, errors.New("blah")},
|
||||
{"http://localhost:2380", 0, errors.New("blah")},
|
||||
// unexpected response status code
|
||||
{"http://localhost:7001", http.StatusOK, nil},
|
||||
{"http://localhost:7001", http.StatusCreated, nil},
|
||||
{"http://localhost:2380", http.StatusOK, nil},
|
||||
{"http://localhost:2380", http.StatusCreated, nil},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
picker := mustNewURLPicker(t, []string{tt.u})
|
||||
@ -164,8 +164,8 @@ func TestPipelinePostErrorc(t *testing.T) {
|
||||
code int
|
||||
err error
|
||||
}{
|
||||
{"http://localhost:7001", http.StatusForbidden, nil},
|
||||
{"http://localhost:7001", http.StatusPreconditionFailed, nil},
|
||||
{"http://localhost:2380", http.StatusForbidden, nil},
|
||||
{"http://localhost:2380", http.StatusPreconditionFailed, nil},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
picker := mustNewURLPicker(t, []string{tt.u})
|
||||
|
@ -86,7 +86,7 @@ func TestStreamReaderDialRequest(t *testing.T) {
|
||||
tr := &roundTripperRecorder{}
|
||||
sr := &streamReader{
|
||||
tr: tr,
|
||||
picker: mustNewURLPicker(t, []string{"http://localhost:7001"}),
|
||||
picker: mustNewURLPicker(t, []string{"http://localhost:2380"}),
|
||||
t: tt,
|
||||
from: types.ID(1),
|
||||
to: types.ID(2),
|
||||
@ -96,7 +96,7 @@ func TestStreamReaderDialRequest(t *testing.T) {
|
||||
sr.dial()
|
||||
|
||||
req := tr.Request()
|
||||
wurl := fmt.Sprintf("http://localhost:7001" + tt.endpoint() + "/1")
|
||||
wurl := fmt.Sprintf("http://localhost:2380" + tt.endpoint() + "/1")
|
||||
if req.URL.String() != wurl {
|
||||
t.Errorf("#%d: url = %s, want %s", i, req.URL.String(), wurl)
|
||||
}
|
||||
@ -133,7 +133,7 @@ func TestStreamReaderDialResult(t *testing.T) {
|
||||
tr := newRespRoundTripper(tt.code, tt.err)
|
||||
sr := &streamReader{
|
||||
tr: tr,
|
||||
picker: mustNewURLPicker(t, []string{"http://localhost:7001"}),
|
||||
picker: mustNewURLPicker(t, []string{"http://localhost:2380"}),
|
||||
t: streamTypeMessage,
|
||||
from: types.ID(1),
|
||||
to: types.ID(2),
|
||||
|
@ -72,7 +72,7 @@ func TestTransportAdd(t *testing.T) {
|
||||
leaderStats: ls,
|
||||
peers: make(map[types.ID]Peer),
|
||||
}
|
||||
tr.AddPeer(1, []string{"http://localhost:7001"})
|
||||
tr.AddPeer(1, []string{"http://localhost:2380"})
|
||||
defer tr.Stop()
|
||||
|
||||
if _, ok := ls.Followers["1"]; !ok {
|
||||
@ -84,7 +84,7 @@ func TestTransportAdd(t *testing.T) {
|
||||
}
|
||||
|
||||
// duplicate AddPeer is ignored
|
||||
tr.AddPeer(1, []string{"http://localhost:7001"})
|
||||
tr.AddPeer(1, []string{"http://localhost:2380"})
|
||||
ns := tr.peers[types.ID(1)]
|
||||
if s != ns {
|
||||
t.Errorf("sender = %v, want %v", ns, s)
|
||||
@ -97,7 +97,7 @@ func TestTransportRemove(t *testing.T) {
|
||||
leaderStats: stats.NewLeaderStats(""),
|
||||
peers: make(map[types.ID]Peer),
|
||||
}
|
||||
tr.AddPeer(1, []string{"http://localhost:7001"})
|
||||
tr.AddPeer(1, []string{"http://localhost:2380"})
|
||||
tr.RemovePeer(types.ID(1))
|
||||
defer tr.Stop()
|
||||
|
||||
@ -111,9 +111,9 @@ func TestTransportUpdate(t *testing.T) {
|
||||
tr := &transport{
|
||||
peers: map[types.ID]Peer{types.ID(1): peer},
|
||||
}
|
||||
u := "http://localhost:7001"
|
||||
u := "http://localhost:2380"
|
||||
tr.UpdatePeer(types.ID(1), []string{u})
|
||||
wurls := types.URLs(testutil.MustNewURLs(t, []string{"http://localhost:7001"}))
|
||||
wurls := types.URLs(testutil.MustNewURLs(t, []string{"http://localhost:2380"}))
|
||||
if !reflect.DeepEqual(peer.urls, wurls) {
|
||||
t.Errorf("urls = %+v, want %+v", peer.urls, wurls)
|
||||
}
|
||||
@ -127,7 +127,7 @@ func TestTransportErrorc(t *testing.T) {
|
||||
peers: make(map[types.ID]Peer),
|
||||
errorc: errorc,
|
||||
}
|
||||
tr.AddPeer(1, []string{"http://localhost:7001"})
|
||||
tr.AddPeer(1, []string{"http://localhost:2380"})
|
||||
defer tr.Stop()
|
||||
|
||||
select {
|
||||
|
Loading…
x
Reference in New Issue
Block a user