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

WIP: integration: add v2v3 emulation #9634

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 16 additions & 2 deletions etcdserver/api/v2v3/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package v2v3

import (
"context"
"time"

"github.com/coreos/etcd/etcdserver/membership"
"github.com/coreos/etcd/pkg/types"

Expand All @@ -25,7 +28,18 @@ func (s *v2v3Server) ID() types.ID {
// TODO: use an actual member ID
return types.ID(0xe7cd2f00d)
}
func (s *v2v3Server) ClientURLs() []string { panic("STUB") }
func (s *v2v3Server) Members() []*membership.Member { panic("STUB") }
func (s *v2v3Server) ClientURLs() []string { panic("STUB") }

func (s *v2v3Server) Members() []*membership.Member {
ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
defer cancel()
resp, err := s.c.MemberList(ctx)
if err != nil {
// TODO: how can we upport errors here?
panic("STUB")
}
return v3MembersToMembership(resp.Members)
}

func (s *v2v3Server) Member(id types.ID) *membership.Member { panic("STUB") }
func (s *v2v3Server) Version() *semver.Version { panic("STUB") }
6 changes: 5 additions & 1 deletion integration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/coreos/etcd/etcdserver"
"github.com/coreos/etcd/etcdserver/api/etcdhttp"
"github.com/coreos/etcd/etcdserver/api/v2http"
"github.com/coreos/etcd/etcdserver/api/v2v3"
"github.com/coreos/etcd/etcdserver/api/v3client"
"github.com/coreos/etcd/etcdserver/api/v3election"
epb "github.com/coreos/etcd/etcdserver/api/v3election/v3electionpb"
Expand Down Expand Up @@ -517,6 +518,7 @@ type member struct {
raftHandler *testutil.PauseableHandler
s *etcdserver.EtcdServer
serverClosers []func()
v2v3Server etcdserver.ServerPeer

grpcServerOpts []grpc.ServerOption
grpcServer *grpc.Server
Expand Down Expand Up @@ -766,6 +768,8 @@ func (m *member) Launch() error {
})
}

m.v2v3Server = v2v3.NewServer(nil, v3client.New(m.s), "/v2v3")

for _, ln := range m.PeerListeners {
cm := cmux.New(ln)
// don't hang on matcher after closing listener
Expand Down Expand Up @@ -806,7 +810,7 @@ func (m *member) Launch() error {
for _, ln := range m.ClientListeners {
hs := &httptest.Server{
Listener: ln,
Config: &http.Server{Handler: v2http.NewClientHandler(m.s, m.ServerConfig.ReqTimeout())},
Config: &http.Server{Handler: v2http.NewClientHandler(m.v2API(), m.ServerConfig.ReqTimeout())},
}
if m.ClientTLSInfo == nil {
hs.Start()
Expand Down
25 changes: 25 additions & 0 deletions integration/v2_api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2018 The etcd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !v2v3

package integration

import "github.com/coreos/etcd/etcdserver"

const v2IndexOffset = 3

func (m *member) v2API() etcdserver.ServerPeer {
return m.s
}
6 changes: 3 additions & 3 deletions integration/v2_http_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ func TestV2Set(t *testing.T) {
"/v2/keys/foo/bar",
v,
http.StatusCreated,
`{"action":"set","node":{"key":"/foo/bar","value":"bar","modifiedIndex":4,"createdIndex":4}}`,
fmt.Sprintf(`{"action":"set","node":{"key":"/foo/bar","value":"bar","modifiedIndex":%d,"createdIndex":%d}}`, v2IndexOffset+1, v2IndexOffset+1),
},
{
"/v2/keys/foodir?dir=true",
url.Values{},
http.StatusCreated,
`{"action":"set","node":{"key":"/foodir","dir":true,"modifiedIndex":5,"createdIndex":5}}`,
fmt.Sprintf(`{"action":"set","node":{"key":"/foodir","dir":true,"modifiedIndex":%d,"createdIndex":%d}}`, v2IndexOffset+2, v2IndexOffset+2),
},
{
"/v2/keys/fooempty",
url.Values(map[string][]string{"value": {""}}),
http.StatusCreated,
`{"action":"set","node":{"key":"/fooempty","value":"","modifiedIndex":6,"createdIndex":6}}`,
fmt.Sprintf(`{"action":"set","node":{"key":"/fooempty","value":"","modifiedIndex":%d,"createdIndex":%d}}`, v2IndexOffset+3, v2IndexOffset+3),
},
{
"/v2/keys/foo/novalue",
Expand Down
25 changes: 25 additions & 0 deletions integration/v2v3_api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2018 The etcd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build v2v3

package integration

import "github.com/coreos/etcd/etcdserver"

const v2IndexOffset = 0

func (m *member) v2API() etcdserver.ServerPeer {
return m.v2v3Server
}