mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
chore(*): make everything use goven
for i in github.com/BurntSushi/toml github.com/coreos/go-etcd/etcd github.com/coreos/go-log/log github.com/gorilla/context github.com/rcrowley/go-metrics bitbucket.org/kardianos/osext github.com/coreos/go-systemd/journal github.com/coreos/raft code.google.com/p/goprotobuf/proto ; do goven -copy -rewrite $i; done
This commit is contained in:
parent
ea8a353545
commit
13b6c1e684
@ -5,7 +5,7 @@ import (
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
func write(endpoint string, requests int, end chan int) {
|
||||
|
2
etcd.go
2
etcd.go
@ -24,7 +24,7 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
|
||||
ehttp "github.com/coreos/etcd/http"
|
||||
"github.com/coreos/etcd/log"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
golog "github.com/coreos/go-log/log"
|
||||
golog "github.com/coreos/etcd/third_party/github.com/coreos/go-log/log"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
@ -7,7 +7,7 @@ package metrics
|
||||
import (
|
||||
"io"
|
||||
|
||||
gometrics "github.com/rcrowley/go-metrics"
|
||||
gometrics "github.com/coreos/etcd/third_party/github.com/rcrowley/go-metrics"
|
||||
)
|
||||
|
||||
type Timer gometrics.Timer
|
||||
|
@ -3,7 +3,7 @@ package metrics
|
||||
import (
|
||||
"io"
|
||||
|
||||
gometrics "github.com/rcrowley/go-metrics"
|
||||
gometrics "github.com/coreos/etcd/third_party/github.com/rcrowley/go-metrics"
|
||||
)
|
||||
|
||||
type nilBucket struct{}
|
||||
|
@ -6,25 +6,25 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
gometrics "github.com/rcrowley/go-metrics"
|
||||
gometrics "github.com/coreos/etcd/third_party/github.com/rcrowley/go-metrics"
|
||||
)
|
||||
|
||||
const (
|
||||
// RuntimeMemStatsSampleInterval is the interval in seconds at which the
|
||||
// Go runtime's memory statistics will be gathered.
|
||||
RuntimeMemStatsSampleInterval = time.Duration(2) * time.Second
|
||||
RuntimeMemStatsSampleInterval = time.Duration(2) * time.Second
|
||||
|
||||
// GraphitePublishInterval is the interval in seconds at which all
|
||||
// gathered statistics will be published to a Graphite endpoint.
|
||||
GraphitePublishInterval = time.Duration(2) * time.Second
|
||||
GraphitePublishInterval = time.Duration(2) * time.Second
|
||||
)
|
||||
|
||||
type standardBucket struct {
|
||||
sync.Mutex
|
||||
name string
|
||||
registry gometrics.Registry
|
||||
timers map[string]Timer
|
||||
gauges map[string]Gauge
|
||||
name string
|
||||
registry gometrics.Registry
|
||||
timers map[string]Timer
|
||||
gauges map[string]Gauge
|
||||
}
|
||||
|
||||
func newStandardBucket(name string) standardBucket {
|
||||
@ -34,10 +34,10 @@ func newStandardBucket(name string) standardBucket {
|
||||
go gometrics.CaptureRuntimeMemStats(registry, RuntimeMemStatsSampleInterval)
|
||||
|
||||
return standardBucket{
|
||||
name: name,
|
||||
registry: registry,
|
||||
timers: make(map[string]Timer),
|
||||
gauges: make(map[string]Gauge),
|
||||
name: name,
|
||||
registry: registry,
|
||||
timers: make(map[string]Timer),
|
||||
gauges: make(map[string]Gauge),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"net/url"
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// deleteHandler remove a given leader.
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// getHandler retrieves the current leader.
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// prefix is appended to the lock's prefix since the leader mod uses the lock mod.
|
||||
@ -13,19 +13,19 @@ const prefix = "/_mod/leader"
|
||||
// handler manages the leader HTTP request.
|
||||
type handler struct {
|
||||
*mux.Router
|
||||
client *http.Client
|
||||
transport *http.Transport
|
||||
addr string
|
||||
client *http.Client
|
||||
transport *http.Transport
|
||||
addr string
|
||||
}
|
||||
|
||||
// NewHandler creates an HTTP handler that can be registered on a router.
|
||||
func NewHandler(addr string) http.Handler {
|
||||
transport := &http.Transport{DisableKeepAlives: false}
|
||||
h := &handler{
|
||||
Router: mux.NewRouter(),
|
||||
client: &http.Client{Transport: transport},
|
||||
transport: transport,
|
||||
addr: addr,
|
||||
Router: mux.NewRouter(),
|
||||
client: &http.Client{Transport: transport},
|
||||
transport: transport,
|
||||
addr: addr,
|
||||
}
|
||||
h.StrictSlash(false)
|
||||
h.handleFunc("/{key:.*}", h.getHandler).Methods("GET")
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"net/url"
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// setHandler attempts to set the current leader.
|
||||
|
@ -9,8 +9,8 @@ import (
|
||||
"time"
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// acquireHandler attempts to acquire a lock on the given key.
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"path"
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// getIndexHandler retrieves the current lock index.
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"net/http"
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
const prefix = "/_etcd/mod/lock"
|
||||
@ -13,14 +13,14 @@ const prefix = "/_etcd/mod/lock"
|
||||
// handler manages the lock HTTP request.
|
||||
type handler struct {
|
||||
*mux.Router
|
||||
client *etcd.Client
|
||||
client *etcd.Client
|
||||
}
|
||||
|
||||
// NewHandler creates an HTTP handler that can be registered on a router.
|
||||
func NewHandler(addr string) http.Handler {
|
||||
h := &handler{
|
||||
Router: mux.NewRouter(),
|
||||
client: etcd.NewClient([]string{addr}),
|
||||
Router: mux.NewRouter(),
|
||||
client: etcd.NewClient([]string{addr}),
|
||||
}
|
||||
h.StrictSlash(false)
|
||||
h.handleFunc("/{key:.*}", h.getIndexHandler).Methods("GET")
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
// lockNodes is a wrapper for go-etcd's Nodes to allow for sorting by numeric key.
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"path"
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// releaseLockHandler deletes the lock.
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// renewLockHandler attempts to update the TTL on an existing lock.
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"github.com/coreos/etcd/mod/dashboard"
|
||||
leader2 "github.com/coreos/etcd/mod/leader/v2"
|
||||
lock2 "github.com/coreos/etcd/mod/lock/v2"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
var ServeMux *http.Handler
|
||||
|
116
server/config.go
116
server/config.go
@ -13,7 +13,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/coreos/etcd/third_party/github.com/BurntSushi/toml"
|
||||
"github.com/coreos/etcd/log"
|
||||
)
|
||||
|
||||
@ -22,63 +22,63 @@ const DefaultSystemConfigPath = "/etc/etcd/etcd.conf"
|
||||
|
||||
// A lookup of deprecated flags to their new flag name.
|
||||
var newFlagNameLookup = map[string]string{
|
||||
"C": "peers",
|
||||
"CF": "peers-file",
|
||||
"n": "name",
|
||||
"c": "addr",
|
||||
"cl": "bind-addr",
|
||||
"s": "peer-addr",
|
||||
"sl": "peer-bind-addr",
|
||||
"d": "data-dir",
|
||||
"m": "max-result-buffer",
|
||||
"r": "max-retry-attempts",
|
||||
"maxsize": "max-cluster-size",
|
||||
"clientCAFile": "ca-file",
|
||||
"clientCert": "cert-file",
|
||||
"clientKey": "key-file",
|
||||
"serverCAFile": "peer-ca-file",
|
||||
"serverCert": "peer-cert-file",
|
||||
"serverKey": "peer-key-file",
|
||||
"snapshotCount": "snapshot-count",
|
||||
"C": "peers",
|
||||
"CF": "peers-file",
|
||||
"n": "name",
|
||||
"c": "addr",
|
||||
"cl": "bind-addr",
|
||||
"s": "peer-addr",
|
||||
"sl": "peer-bind-addr",
|
||||
"d": "data-dir",
|
||||
"m": "max-result-buffer",
|
||||
"r": "max-retry-attempts",
|
||||
"maxsize": "max-cluster-size",
|
||||
"clientCAFile": "ca-file",
|
||||
"clientCert": "cert-file",
|
||||
"clientKey": "key-file",
|
||||
"serverCAFile": "peer-ca-file",
|
||||
"serverCert": "peer-cert-file",
|
||||
"serverKey": "peer-key-file",
|
||||
"snapshotCount": "snapshot-count",
|
||||
}
|
||||
|
||||
// Config represents the server configuration.
|
||||
type Config struct {
|
||||
SystemPath string
|
||||
SystemPath string
|
||||
|
||||
Addr string `toml:"addr" env:"ETCD_ADDR"`
|
||||
BindAddr string `toml:"bind_addr" env:"ETCD_BIND_ADDR"`
|
||||
CAFile string `toml:"ca_file" env:"ETCD_CA_FILE"`
|
||||
CertFile string `toml:"cert_file" env:"ETCD_CERT_FILE"`
|
||||
CPUProfileFile string
|
||||
CorsOrigins []string `toml:"cors" env:"ETCD_CORS"`
|
||||
DataDir string `toml:"data_dir" env:"ETCD_DATA_DIR"`
|
||||
Force bool
|
||||
KeyFile string `toml:"key_file" env:"ETCD_KEY_FILE"`
|
||||
Peers []string `toml:"peers" env:"ETCD_PEERS"`
|
||||
PeersFile string `toml:"peers_file" env:"ETCD_PEERS_FILE"`
|
||||
MaxClusterSize int `toml:"max_cluster_size" env:"ETCD_MAX_CLUSTER_SIZE"`
|
||||
MaxResultBuffer int `toml:"max_result_buffer" env:"ETCD_MAX_RESULT_BUFFER"`
|
||||
MaxRetryAttempts int `toml:"max_retry_attempts" env:"ETCD_MAX_RETRY_ATTEMPTS"`
|
||||
Name string `toml:"name" env:"ETCD_NAME"`
|
||||
Snapshot bool `toml:"snapshot" env:"ETCD_SNAPSHOT"`
|
||||
SnapshotCount int `toml:"snapshot_count" env:"ETCD_SNAPSHOTCOUNT"`
|
||||
ShowHelp bool
|
||||
ShowVersion bool
|
||||
Verbose bool `toml:"verbose" env:"ETCD_VERBOSE"`
|
||||
VeryVerbose bool `toml:"very_verbose" env:"ETCD_VERY_VERBOSE"`
|
||||
VeryVeryVerbose bool `toml:"very_very_verbose" env:"ETCD_VERY_VERY_VERBOSE"`
|
||||
Peer struct {
|
||||
Addr string `toml:"addr" env:"ETCD_PEER_ADDR"`
|
||||
BindAddr string `toml:"bind_addr" env:"ETCD_PEER_BIND_ADDR"`
|
||||
CAFile string `toml:"ca_file" env:"ETCD_PEER_CA_FILE"`
|
||||
CertFile string `toml:"cert_file" env:"ETCD_PEER_CERT_FILE"`
|
||||
KeyFile string `toml:"key_file" env:"ETCD_PEER_KEY_FILE"`
|
||||
HeartbeatTimeout int `toml:"heartbeat_timeout" env:"ETCD_PEER_HEARTBEAT_TIMEOUT"`
|
||||
ElectionTimeout int `toml:"election_timeout" env:"ETCD_PEER_ELECTION_TIMEOUT"`
|
||||
Addr string `toml:"addr" env:"ETCD_ADDR"`
|
||||
BindAddr string `toml:"bind_addr" env:"ETCD_BIND_ADDR"`
|
||||
CAFile string `toml:"ca_file" env:"ETCD_CA_FILE"`
|
||||
CertFile string `toml:"cert_file" env:"ETCD_CERT_FILE"`
|
||||
CPUProfileFile string
|
||||
CorsOrigins []string `toml:"cors" env:"ETCD_CORS"`
|
||||
DataDir string `toml:"data_dir" env:"ETCD_DATA_DIR"`
|
||||
Force bool
|
||||
KeyFile string `toml:"key_file" env:"ETCD_KEY_FILE"`
|
||||
Peers []string `toml:"peers" env:"ETCD_PEERS"`
|
||||
PeersFile string `toml:"peers_file" env:"ETCD_PEERS_FILE"`
|
||||
MaxClusterSize int `toml:"max_cluster_size" env:"ETCD_MAX_CLUSTER_SIZE"`
|
||||
MaxResultBuffer int `toml:"max_result_buffer" env:"ETCD_MAX_RESULT_BUFFER"`
|
||||
MaxRetryAttempts int `toml:"max_retry_attempts" env:"ETCD_MAX_RETRY_ATTEMPTS"`
|
||||
Name string `toml:"name" env:"ETCD_NAME"`
|
||||
Snapshot bool `toml:"snapshot" env:"ETCD_SNAPSHOT"`
|
||||
SnapshotCount int `toml:"snapshot_count" env:"ETCD_SNAPSHOTCOUNT"`
|
||||
ShowHelp bool
|
||||
ShowVersion bool
|
||||
Verbose bool `toml:"verbose" env:"ETCD_VERBOSE"`
|
||||
VeryVerbose bool `toml:"very_verbose" env:"ETCD_VERY_VERBOSE"`
|
||||
VeryVeryVerbose bool `toml:"very_very_verbose" env:"ETCD_VERY_VERY_VERBOSE"`
|
||||
Peer struct {
|
||||
Addr string `toml:"addr" env:"ETCD_PEER_ADDR"`
|
||||
BindAddr string `toml:"bind_addr" env:"ETCD_PEER_BIND_ADDR"`
|
||||
CAFile string `toml:"ca_file" env:"ETCD_PEER_CA_FILE"`
|
||||
CertFile string `toml:"cert_file" env:"ETCD_PEER_CERT_FILE"`
|
||||
KeyFile string `toml:"key_file" env:"ETCD_PEER_KEY_FILE"`
|
||||
HeartbeatTimeout int `toml:"heartbeat_timeout" env:"ETCD_PEER_HEARTBEAT_TIMEOUT"`
|
||||
ElectionTimeout int `toml:"election_timeout" env:"ETCD_PEER_ELECTION_TIMEOUT"`
|
||||
}
|
||||
strTrace string `toml:"trace" env:"ETCD_TRACE"`
|
||||
GraphiteHost string `toml:"graphite_host" env:"ETCD_GRAPHITE_HOST"`
|
||||
strTrace string `toml:"trace" env:"ETCD_TRACE"`
|
||||
GraphiteHost string `toml:"graphite_host" env:"ETCD_GRAPHITE_HOST"`
|
||||
}
|
||||
|
||||
// NewConfig returns a Config initialized with default values.
|
||||
@ -433,9 +433,9 @@ func (c *Config) Sanitize() error {
|
||||
// TLSInfo retrieves a TLSInfo object for the client server.
|
||||
func (c *Config) TLSInfo() TLSInfo {
|
||||
return TLSInfo{
|
||||
CAFile: c.CAFile,
|
||||
CertFile: c.CertFile,
|
||||
KeyFile: c.KeyFile,
|
||||
CAFile: c.CAFile,
|
||||
CertFile: c.CertFile,
|
||||
KeyFile: c.KeyFile,
|
||||
}
|
||||
}
|
||||
|
||||
@ -447,9 +447,9 @@ func (c *Config) TLSConfig() (TLSConfig, error) {
|
||||
// PeerTLSInfo retrieves a TLSInfo object for the peer server.
|
||||
func (c *Config) PeerTLSInfo() TLSInfo {
|
||||
return TLSInfo{
|
||||
CAFile: c.Peer.CAFile,
|
||||
CertFile: c.Peer.CertFile,
|
||||
KeyFile: c.Peer.KeyFile,
|
||||
CAFile: c.Peer.CAFile,
|
||||
CertFile: c.Peer.CertFile,
|
||||
KeyFile: c.Peer.KeyFile,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/coreos/etcd/third_party/github.com/BurntSushi/toml"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/coreos/etcd/log"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -14,20 +14,20 @@ func init() {
|
||||
|
||||
// The JoinCommand adds a node to the cluster.
|
||||
type JoinCommand struct {
|
||||
MinVersion int `json:"minVersion"`
|
||||
MaxVersion int `json:"maxVersion"`
|
||||
Name string `json:"name"`
|
||||
RaftURL string `json:"raftURL"`
|
||||
EtcdURL string `json:"etcdURL"`
|
||||
MinVersion int `json:"minVersion"`
|
||||
MaxVersion int `json:"maxVersion"`
|
||||
Name string `json:"name"`
|
||||
RaftURL string `json:"raftURL"`
|
||||
EtcdURL string `json:"etcdURL"`
|
||||
}
|
||||
|
||||
func NewJoinCommand(minVersion int, maxVersion int, name, raftUrl, etcdUrl string) *JoinCommand {
|
||||
return &JoinCommand{
|
||||
MinVersion: minVersion,
|
||||
MaxVersion: maxVersion,
|
||||
Name: name,
|
||||
RaftURL: raftUrl,
|
||||
EtcdURL: etcdUrl,
|
||||
MinVersion: minVersion,
|
||||
MaxVersion: maxVersion,
|
||||
Name: name,
|
||||
RaftURL: raftUrl,
|
||||
EtcdURL: etcdUrl,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/raft"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/coreos/etcd/log"
|
||||
@ -25,55 +25,55 @@ const retryInterval = 10
|
||||
const ThresholdMonitorTimeout = 5 * time.Second
|
||||
|
||||
type PeerServerConfig struct {
|
||||
Name string
|
||||
Scheme string
|
||||
URL string
|
||||
SnapshotCount int
|
||||
MaxClusterSize int
|
||||
RetryTimes int
|
||||
Name string
|
||||
Scheme string
|
||||
URL string
|
||||
SnapshotCount int
|
||||
MaxClusterSize int
|
||||
RetryTimes int
|
||||
}
|
||||
|
||||
type PeerServer struct {
|
||||
Config PeerServerConfig
|
||||
raftServer raft.Server
|
||||
server *Server
|
||||
joinIndex uint64
|
||||
followersStats *raftFollowersStats
|
||||
serverStats *raftServerStats
|
||||
registry *Registry
|
||||
store store.Store
|
||||
snapConf *snapshotConf
|
||||
Config PeerServerConfig
|
||||
raftServer raft.Server
|
||||
server *Server
|
||||
joinIndex uint64
|
||||
followersStats *raftFollowersStats
|
||||
serverStats *raftServerStats
|
||||
registry *Registry
|
||||
store store.Store
|
||||
snapConf *snapshotConf
|
||||
|
||||
closeChan chan bool
|
||||
timeoutThresholdChan chan interface{}
|
||||
closeChan chan bool
|
||||
timeoutThresholdChan chan interface{}
|
||||
|
||||
metrics *metrics.Bucket
|
||||
metrics *metrics.Bucket
|
||||
}
|
||||
|
||||
// TODO: find a good policy to do snapshot
|
||||
type snapshotConf struct {
|
||||
// Etcd will check if snapshot is need every checkingInterval
|
||||
checkingInterval time.Duration
|
||||
checkingInterval time.Duration
|
||||
|
||||
// The index when the last snapshot happened
|
||||
lastIndex uint64
|
||||
lastIndex uint64
|
||||
|
||||
// If the incremental number of index since the last snapshot
|
||||
// exceeds the snapshot Threshold, etcd will do a snapshot
|
||||
snapshotThr uint64
|
||||
snapshotThr uint64
|
||||
}
|
||||
|
||||
func NewPeerServer(psConfig PeerServerConfig, registry *Registry, store store.Store, mb *metrics.Bucket, followersStats *raftFollowersStats, serverStats *raftServerStats) *PeerServer {
|
||||
s := &PeerServer{
|
||||
Config: psConfig,
|
||||
registry: registry,
|
||||
store: store,
|
||||
followersStats: followersStats,
|
||||
serverStats: serverStats,
|
||||
Config: psConfig,
|
||||
registry: registry,
|
||||
store: store,
|
||||
followersStats: followersStats,
|
||||
serverStats: serverStats,
|
||||
|
||||
timeoutThresholdChan: make(chan interface{}, 1),
|
||||
timeoutThresholdChan: make(chan interface{}, 1),
|
||||
|
||||
metrics: mb,
|
||||
metrics: mb,
|
||||
}
|
||||
|
||||
return s
|
||||
@ -81,10 +81,10 @@ func NewPeerServer(psConfig PeerServerConfig, registry *Registry, store store.St
|
||||
|
||||
func (s *PeerServer) SetRaftServer(raftServer raft.Server) {
|
||||
s.snapConf = &snapshotConf{
|
||||
checkingInterval: time.Second * 3,
|
||||
checkingInterval: time.Second * 3,
|
||||
// this is not accurate, we will update raft to provide an api
|
||||
lastIndex: raftServer.CommitIndex(),
|
||||
snapshotThr: uint64(s.Config.SnapshotCount),
|
||||
lastIndex: raftServer.CommitIndex(),
|
||||
snapshotThr: uint64(s.Config.SnapshotCount),
|
||||
}
|
||||
|
||||
raftServer.AddEventListener(raft.StateChangeEventType, s.raftEventLogger)
|
||||
|
@ -9,8 +9,8 @@ import (
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/coreos/etcd/log"
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// Get all the current logs
|
||||
|
@ -3,36 +3,36 @@ package server
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
)
|
||||
|
||||
type raftServerStats struct {
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
StartTime time.Time `json:"startTime"`
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
StartTime time.Time `json:"startTime"`
|
||||
|
||||
LeaderInfo struct {
|
||||
Name string `json:"leader"`
|
||||
Uptime string `json:"uptime"`
|
||||
startTime time.Time
|
||||
} `json:"leaderInfo"`
|
||||
LeaderInfo struct {
|
||||
Name string `json:"leader"`
|
||||
Uptime string `json:"uptime"`
|
||||
startTime time.Time
|
||||
} `json:"leaderInfo"`
|
||||
|
||||
RecvAppendRequestCnt uint64 `json:"recvAppendRequestCnt,"`
|
||||
RecvingPkgRate float64 `json:"recvPkgRate,omitempty"`
|
||||
RecvingBandwidthRate float64 `json:"recvBandwidthRate,omitempty"`
|
||||
RecvAppendRequestCnt uint64 `json:"recvAppendRequestCnt,"`
|
||||
RecvingPkgRate float64 `json:"recvPkgRate,omitempty"`
|
||||
RecvingBandwidthRate float64 `json:"recvBandwidthRate,omitempty"`
|
||||
|
||||
SendAppendRequestCnt uint64 `json:"sendAppendRequestCnt"`
|
||||
SendingPkgRate float64 `json:"sendPkgRate,omitempty"`
|
||||
SendingBandwidthRate float64 `json:"sendBandwidthRate,omitempty"`
|
||||
SendAppendRequestCnt uint64 `json:"sendAppendRequestCnt"`
|
||||
SendingPkgRate float64 `json:"sendPkgRate,omitempty"`
|
||||
SendingBandwidthRate float64 `json:"sendBandwidthRate,omitempty"`
|
||||
|
||||
sendRateQueue *statsQueue
|
||||
recvRateQueue *statsQueue
|
||||
sendRateQueue *statsQueue
|
||||
recvRateQueue *statsQueue
|
||||
}
|
||||
|
||||
func NewRaftServerStats(name string) *raftServerStats {
|
||||
return &raftServerStats{
|
||||
Name: name,
|
||||
StartTime: time.Now(),
|
||||
Name: name,
|
||||
StartTime: time.Now(),
|
||||
sendRateQueue: &statsQueue{
|
||||
back: -1,
|
||||
},
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/coreos/etcd/log"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/raft"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/coreos/etcd/log"
|
||||
@ -23,26 +23,26 @@ import (
|
||||
|
||||
// This is the default implementation of the Server interface.
|
||||
type Server struct {
|
||||
Name string
|
||||
url string
|
||||
handler http.Handler
|
||||
peerServer *PeerServer
|
||||
registry *Registry
|
||||
store store.Store
|
||||
metrics *metrics.Bucket
|
||||
Name string
|
||||
url string
|
||||
handler http.Handler
|
||||
peerServer *PeerServer
|
||||
registry *Registry
|
||||
store store.Store
|
||||
metrics *metrics.Bucket
|
||||
|
||||
trace bool
|
||||
trace bool
|
||||
}
|
||||
|
||||
// Creates a new Server.
|
||||
func New(name, url string, peerServer *PeerServer, registry *Registry, store store.Store, mb *metrics.Bucket) *Server {
|
||||
s := &Server{
|
||||
Name: name,
|
||||
url: url,
|
||||
store: store,
|
||||
registry: registry,
|
||||
peerServer: peerServer,
|
||||
metrics: mb,
|
||||
Name: name,
|
||||
url: url,
|
||||
store: store,
|
||||
registry: registry,
|
||||
peerServer: peerServer,
|
||||
metrics: mb,
|
||||
}
|
||||
|
||||
return s
|
||||
|
@ -10,18 +10,18 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/coreos/etcd/log"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
)
|
||||
|
||||
// Transporter layer for communication between raft nodes
|
||||
type transporter struct {
|
||||
requestTimeout time.Duration
|
||||
followersStats *raftFollowersStats
|
||||
serverStats *raftServerStats
|
||||
registry *Registry
|
||||
requestTimeout time.Duration
|
||||
followersStats *raftFollowersStats
|
||||
serverStats *raftServerStats
|
||||
registry *Registry
|
||||
|
||||
client *http.Client
|
||||
transport *http.Transport
|
||||
client *http.Client
|
||||
transport *http.Transport
|
||||
}
|
||||
|
||||
type dialer func(network, addr string) (net.Conn, error)
|
||||
@ -34,16 +34,16 @@ func NewTransporter(followersStats *raftFollowersStats, serverStats *raftServerS
|
||||
Dial: func(network, addr string) (net.Conn, error) {
|
||||
return net.DialTimeout(network, addr, dialTimeout)
|
||||
},
|
||||
ResponseHeaderTimeout: responseHeaderTimeout,
|
||||
ResponseHeaderTimeout: responseHeaderTimeout,
|
||||
}
|
||||
|
||||
t := transporter{
|
||||
client: &http.Client{Transport: tr},
|
||||
transport: tr,
|
||||
requestTimeout: requestTimeout,
|
||||
followersStats: followersStats,
|
||||
serverStats: serverStats,
|
||||
registry: registry,
|
||||
client: &http.Client{Transport: tr},
|
||||
transport: tr,
|
||||
requestTimeout: requestTimeout,
|
||||
followersStats: followersStats,
|
||||
serverStats: serverStats,
|
||||
registry: registry,
|
||||
}
|
||||
|
||||
return &t
|
||||
@ -73,7 +73,7 @@ func (t *transporter) SendAppendEntriesRequest(server raft.Server, peer *raft.Pe
|
||||
|
||||
thisFollowerStats, ok := t.followersStats.Followers[peer.Name]
|
||||
|
||||
if !ok { //this is the first time this follower has been seen
|
||||
if !ok { //this is the first time this follower has been seen
|
||||
thisFollowerStats = &raftFollowerStats{}
|
||||
thisFollowerStats.Latency.Minimum = 1 << 63
|
||||
t.followersStats.Followers[peer.Name] = thisFollowerStats
|
||||
|
@ -1,7 +1,7 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// Retrieves the value for a given key.
|
||||
|
@ -5,8 +5,8 @@ import (
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// Sets the value for a given key.
|
||||
|
@ -2,7 +2,7 @@ package v1
|
||||
|
||||
import (
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// Watches a given key prefix for changes.
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func DeleteHandler(w http.ResponseWriter, req *http.Request, s Server) error {
|
||||
|
@ -9,8 +9,8 @@ import (
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/coreos/etcd/log"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error {
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func PostHandler(w http.ResponseWriter, req *http.Request, s Server) error {
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func PutHandler(w http.ResponseWriter, req *http.Request, s Server) error {
|
||||
|
@ -2,7 +2,7 @@ package v2
|
||||
|
||||
import (
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
)
|
||||
|
||||
// A lookup of factories by version.
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -28,59 +28,59 @@ func (f *CommandFactory) CreateUpgradeCommand() raft.Command {
|
||||
// CreateSetCommand creates a version 2 command to set a key to a given value in the store.
|
||||
func (f *CommandFactory) CreateSetCommand(key string, dir bool, value string, expireTime time.Time) raft.Command {
|
||||
return &SetCommand{
|
||||
Key: key,
|
||||
Value: value,
|
||||
ExpireTime: expireTime,
|
||||
Dir: dir,
|
||||
Key: key,
|
||||
Value: value,
|
||||
ExpireTime: expireTime,
|
||||
Dir: dir,
|
||||
}
|
||||
}
|
||||
|
||||
// CreateCreateCommand creates a version 2 command to create a new key in the store.
|
||||
func (f *CommandFactory) CreateCreateCommand(key string, dir bool, value string, expireTime time.Time, unique bool) raft.Command {
|
||||
return &CreateCommand{
|
||||
Key: key,
|
||||
Value: value,
|
||||
ExpireTime: expireTime,
|
||||
Unique: unique,
|
||||
Dir: dir,
|
||||
Key: key,
|
||||
Value: value,
|
||||
ExpireTime: expireTime,
|
||||
Unique: unique,
|
||||
Dir: dir,
|
||||
}
|
||||
}
|
||||
|
||||
// CreateUpdateCommand creates a version 2 command to update a key to a given value in the store.
|
||||
func (f *CommandFactory) CreateUpdateCommand(key string, value string, expireTime time.Time) raft.Command {
|
||||
return &UpdateCommand{
|
||||
Key: key,
|
||||
Value: value,
|
||||
ExpireTime: expireTime,
|
||||
Key: key,
|
||||
Value: value,
|
||||
ExpireTime: expireTime,
|
||||
}
|
||||
}
|
||||
|
||||
// CreateDeleteCommand creates a version 2 command to delete a key from the store.
|
||||
func (f *CommandFactory) CreateDeleteCommand(key string, dir, recursive bool) raft.Command {
|
||||
return &DeleteCommand{
|
||||
Key: key,
|
||||
Recursive: recursive,
|
||||
Dir: dir,
|
||||
Key: key,
|
||||
Recursive: recursive,
|
||||
Dir: dir,
|
||||
}
|
||||
}
|
||||
|
||||
// CreateCompareAndSwapCommand creates a version 2 command to conditionally set a key in the store.
|
||||
func (f *CommandFactory) CreateCompareAndSwapCommand(key string, value string, prevValue string, prevIndex uint64, expireTime time.Time) raft.Command {
|
||||
return &CompareAndSwapCommand{
|
||||
Key: key,
|
||||
Value: value,
|
||||
PrevValue: prevValue,
|
||||
PrevIndex: prevIndex,
|
||||
ExpireTime: expireTime,
|
||||
Key: key,
|
||||
Value: value,
|
||||
PrevValue: prevValue,
|
||||
PrevIndex: prevIndex,
|
||||
ExpireTime: expireTime,
|
||||
}
|
||||
}
|
||||
|
||||
// CreateCompareAndDeleteCommand creates a version 2 command to conditionally delete a key from the store.
|
||||
func (f *CommandFactory) CreateCompareAndDeleteCommand(key string, prevValue string, prevIndex uint64) raft.Command {
|
||||
return &CompareAndDeleteCommand{
|
||||
Key: key,
|
||||
PrevValue: prevValue,
|
||||
PrevIndex: prevIndex,
|
||||
Key: key,
|
||||
PrevValue: prevValue,
|
||||
PrevIndex: prevIndex,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ package v2
|
||||
import (
|
||||
"github.com/coreos/etcd/log"
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -12,9 +12,9 @@ func init() {
|
||||
|
||||
// The CompareAndDelete performs a conditional delete on a key in the store.
|
||||
type CompareAndDeleteCommand struct {
|
||||
Key string `json:"key"`
|
||||
PrevValue string `json:"prevValue"`
|
||||
PrevIndex uint64 `json:"prevIndex"`
|
||||
Key string `json:"key"`
|
||||
PrevValue string `json:"prevValue"`
|
||||
PrevIndex uint64 `json:"prevIndex"`
|
||||
}
|
||||
|
||||
// The name of the compareAndDelete command in the log
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/coreos/etcd/log"
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -14,11 +14,11 @@ func init() {
|
||||
|
||||
// The CompareAndSwap performs a conditional update on a key in the store.
|
||||
type CompareAndSwapCommand struct {
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
ExpireTime time.Time `json:"expireTime"`
|
||||
PrevValue string `json:"prevValue"`
|
||||
PrevIndex uint64 `json:"prevIndex"`
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
ExpireTime time.Time `json:"expireTime"`
|
||||
PrevValue string `json:"prevValue"`
|
||||
PrevIndex uint64 `json:"prevIndex"`
|
||||
}
|
||||
|
||||
// The name of the testAndSet command in the log
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/coreos/etcd/log"
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -14,11 +14,11 @@ func init() {
|
||||
|
||||
// Create command
|
||||
type CreateCommand struct {
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
ExpireTime time.Time `json:"expireTime"`
|
||||
Unique bool `json:"unique"`
|
||||
Dir bool `json:"dir"`
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
ExpireTime time.Time `json:"expireTime"`
|
||||
Unique bool `json:"unique"`
|
||||
Dir bool `json:"dir"`
|
||||
}
|
||||
|
||||
// The name of the create command in the log
|
||||
|
@ -3,7 +3,7 @@ package v2
|
||||
import (
|
||||
"github.com/coreos/etcd/log"
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -12,9 +12,9 @@ func init() {
|
||||
|
||||
// The DeleteCommand removes a key from the Store.
|
||||
type DeleteCommand struct {
|
||||
Key string `json:"key"`
|
||||
Recursive bool `json:"recursive"`
|
||||
Dir bool `json:"dir"`
|
||||
Key string `json:"key"`
|
||||
Recursive bool `json:"recursive"`
|
||||
Dir bool `json:"dir"`
|
||||
}
|
||||
|
||||
// The name of the delete command in the log
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/coreos/etcd/log"
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -14,10 +14,10 @@ func init() {
|
||||
|
||||
// Create command
|
||||
type SetCommand struct {
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
ExpireTime time.Time `json:"expireTime"`
|
||||
Dir bool `json:"dir"`
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
ExpireTime time.Time `json:"expireTime"`
|
||||
Dir bool `json:"dir"`
|
||||
}
|
||||
|
||||
// The name of the create command in the log
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -3,7 +3,7 @@ package v2
|
||||
import (
|
||||
"github.com/coreos/etcd/log"
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -13,9 +13,9 @@ func init() {
|
||||
|
||||
// Update command
|
||||
type UpdateCommand struct {
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
ExpireTime time.Time `json:"expireTime"`
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
ExpireTime time.Time `json:"expireTime"`
|
||||
}
|
||||
|
||||
// The name of the update command in the log
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
// Create a five nodes
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
// Create a five nodes
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
// remove the node and node rejoin with previous log
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
func TestSimpleMultiNode(t *testing.T) {
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
// This test creates a single node and then set a value to it to trigger snapshot
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
// This test creates a single node and then set a value to it.
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
// Create a single node and try to set value
|
||||
|
@ -18,7 +18,7 @@ package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
|
@ -6,19 +6,19 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/raft"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
||||
|
||||
"github.com/coreos/etcd/server"
|
||||
"github.com/coreos/etcd/store"
|
||||
)
|
||||
|
||||
const (
|
||||
testName = "ETCDTEST"
|
||||
testClientURL = "localhost:4401"
|
||||
testRaftURL = "localhost:7701"
|
||||
testSnapshotCount = 10000
|
||||
testHeartbeatTimeout = time.Duration(50) * time.Millisecond
|
||||
testElectionTimeout = time.Duration(200) * time.Millisecond
|
||||
testName = "ETCDTEST"
|
||||
testClientURL = "localhost:4401"
|
||||
testRaftURL = "localhost:7701"
|
||||
testSnapshotCount = 10000
|
||||
testHeartbeatTimeout = time.Duration(50) * time.Millisecond
|
||||
testElectionTimeout = time.Duration(200) * time.Millisecond
|
||||
)
|
||||
|
||||
// Starts a server in a temporary directory.
|
||||
@ -33,11 +33,11 @@ func RunServer(f func(*server.Server)) {
|
||||
followersStats := server.NewRaftFollowersStats(testName)
|
||||
|
||||
psConfig := server.PeerServerConfig{
|
||||
Name: testName,
|
||||
URL: "http://" + testRaftURL,
|
||||
Scheme: "http",
|
||||
SnapshotCount: testSnapshotCount,
|
||||
MaxClusterSize: 9,
|
||||
Name: testName,
|
||||
URL: "http://" + testRaftURL,
|
||||
Scheme: "http",
|
||||
SnapshotCount: testSnapshotCount,
|
||||
MaxClusterSize: 9,
|
||||
}
|
||||
ps := server.NewPeerServer(psConfig, registry, store, nil, followersStats, serverStats)
|
||||
psListener, err := server.NewListener(testRaftURL)
|
||||
|
11
third_party/README
vendored
11
third_party/README
vendored
@ -1,11 +0,0 @@
|
||||
# Third Party Libraries
|
||||
|
||||
The third_party directory has all of the dependencies needed to build
|
||||
etcd so that we can have a consistent build. `go get` should not be
|
||||
called at any point during the build process.
|
||||
|
||||
## Usage
|
||||
|
||||
To update all of the third party libraries call
|
||||
|
||||
./update
|
@ -44,7 +44,7 @@ import (
|
||||
"time"
|
||||
|
||||
. "./testdata"
|
||||
. "code.google.com/p/goprotobuf/proto"
|
||||
. "github.com/coreos/etcd/third_party/code.google.com/p/goprotobuf/proto"
|
||||
)
|
||||
|
||||
var globalO *Buffer
|
||||
@ -507,61 +507,61 @@ func TestReset(t *testing.T) {
|
||||
func TestEncodeDecode1(t *testing.T) {
|
||||
pb := initGoTest(false)
|
||||
overify(t, pb,
|
||||
"0807"+ // field 1, encoding 0, value 7
|
||||
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
|
||||
"5001"+ // field 10, encoding 0, value 1
|
||||
"5803"+ // field 11, encoding 0, value 3
|
||||
"6006"+ // field 12, encoding 0, value 6
|
||||
"6d20000000"+ // field 13, encoding 5, value 0x20
|
||||
"714000000000000000"+ // field 14, encoding 1, value 0x40
|
||||
"78a019"+ // field 15, encoding 0, value 0xca0 = 3232
|
||||
"8001c032"+ // field 16, encoding 0, value 0x1940 = 6464
|
||||
"8d0100004a45"+ // field 17, encoding 5, value 3232.0
|
||||
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0
|
||||
"9a0106"+"737472696e67"+ // field 19, encoding 2, string "string"
|
||||
"b304"+ // field 70, encoding 3, start group
|
||||
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
|
||||
"b404"+ // field 70, encoding 4, end group
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2, string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f") // field 103, encoding 0, 0x7f zigzag64
|
||||
"0807"+ // field 1, encoding 0, value 7
|
||||
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
|
||||
"5001"+ // field 10, encoding 0, value 1
|
||||
"5803"+ // field 11, encoding 0, value 3
|
||||
"6006"+ // field 12, encoding 0, value 6
|
||||
"6d20000000"+ // field 13, encoding 5, value 0x20
|
||||
"714000000000000000"+ // field 14, encoding 1, value 0x40
|
||||
"78a019"+ // field 15, encoding 0, value 0xca0 = 3232
|
||||
"8001c032"+ // field 16, encoding 0, value 0x1940 = 6464
|
||||
"8d0100004a45"+ // field 17, encoding 5, value 3232.0
|
||||
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0
|
||||
"9a0106"+"737472696e67"+ // field 19, encoding 2, string "string"
|
||||
"b304"+ // field 70, encoding 3, start group
|
||||
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
|
||||
"b404"+ // field 70, encoding 4, end group
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2, string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f") // field 103, encoding 0, 0x7f zigzag64
|
||||
}
|
||||
|
||||
// All required fields set, defaults provided.
|
||||
func TestEncodeDecode2(t *testing.T) {
|
||||
pb := initGoTest(true)
|
||||
overify(t, pb,
|
||||
"0807"+ // field 1, encoding 0, value 7
|
||||
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
|
||||
"5001"+ // field 10, encoding 0, value 1
|
||||
"5803"+ // field 11, encoding 0, value 3
|
||||
"6006"+ // field 12, encoding 0, value 6
|
||||
"6d20000000"+ // field 13, encoding 5, value 32
|
||||
"714000000000000000"+ // field 14, encoding 1, value 64
|
||||
"78a019"+ // field 15, encoding 0, value 3232
|
||||
"8001c032"+ // field 16, encoding 0, value 6464
|
||||
"8d0100004a45"+ // field 17, encoding 5, value 3232.0
|
||||
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0
|
||||
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
|
||||
"c00201"+ // field 40, encoding 0, value 1
|
||||
"c80220"+ // field 41, encoding 0, value 32
|
||||
"d00240"+ // field 42, encoding 0, value 64
|
||||
"dd0240010000"+ // field 43, encoding 5, value 320
|
||||
"e1028002000000000000"+ // field 44, encoding 1, value 640
|
||||
"e8028019"+ // field 45, encoding 0, value 3200
|
||||
"f0028032"+ // field 46, encoding 0, value 6400
|
||||
"fd02e0659948"+ // field 47, encoding 5, value 314159.0
|
||||
"81030000000050971041"+ // field 48, encoding 1, value 271828.0
|
||||
"8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
|
||||
"b304"+ // start group field 70 level 1
|
||||
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
|
||||
"b404"+ // end group field 70 level 1
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
|
||||
"90193f"+ // field 402, encoding 0, value 63
|
||||
"98197f") // field 403, encoding 0, value 127
|
||||
"0807"+ // field 1, encoding 0, value 7
|
||||
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
|
||||
"5001"+ // field 10, encoding 0, value 1
|
||||
"5803"+ // field 11, encoding 0, value 3
|
||||
"6006"+ // field 12, encoding 0, value 6
|
||||
"6d20000000"+ // field 13, encoding 5, value 32
|
||||
"714000000000000000"+ // field 14, encoding 1, value 64
|
||||
"78a019"+ // field 15, encoding 0, value 3232
|
||||
"8001c032"+ // field 16, encoding 0, value 6464
|
||||
"8d0100004a45"+ // field 17, encoding 5, value 3232.0
|
||||
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0
|
||||
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
|
||||
"c00201"+ // field 40, encoding 0, value 1
|
||||
"c80220"+ // field 41, encoding 0, value 32
|
||||
"d00240"+ // field 42, encoding 0, value 64
|
||||
"dd0240010000"+ // field 43, encoding 5, value 320
|
||||
"e1028002000000000000"+ // field 44, encoding 1, value 640
|
||||
"e8028019"+ // field 45, encoding 0, value 3200
|
||||
"f0028032"+ // field 46, encoding 0, value 6400
|
||||
"fd02e0659948"+ // field 47, encoding 5, value 314159.0
|
||||
"81030000000050971041"+ // field 48, encoding 1, value 271828.0
|
||||
"8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
|
||||
"b304"+ // start group field 70 level 1
|
||||
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
|
||||
"b404"+ // end group field 70 level 1
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
|
||||
"90193f"+ // field 402, encoding 0, value 63
|
||||
"98197f") // field 403, encoding 0, value 127
|
||||
|
||||
}
|
||||
|
||||
@ -583,37 +583,37 @@ func TestEncodeDecode3(t *testing.T) {
|
||||
pb.F_Sint64Defaulted = Int64(-64)
|
||||
|
||||
overify(t, pb,
|
||||
"0807"+ // field 1, encoding 0, value 7
|
||||
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
|
||||
"5001"+ // field 10, encoding 0, value 1
|
||||
"5803"+ // field 11, encoding 0, value 3
|
||||
"6006"+ // field 12, encoding 0, value 6
|
||||
"6d20000000"+ // field 13, encoding 5, value 32
|
||||
"714000000000000000"+ // field 14, encoding 1, value 64
|
||||
"78a019"+ // field 15, encoding 0, value 3232
|
||||
"8001c032"+ // field 16, encoding 0, value 6464
|
||||
"8d0100004a45"+ // field 17, encoding 5, value 3232.0
|
||||
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0
|
||||
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
|
||||
"c00201"+ // field 40, encoding 0, value 1
|
||||
"c80220"+ // field 41, encoding 0, value 32
|
||||
"d00240"+ // field 42, encoding 0, value 64
|
||||
"dd0240010000"+ // field 43, encoding 5, value 320
|
||||
"e1028002000000000000"+ // field 44, encoding 1, value 640
|
||||
"e8028019"+ // field 45, encoding 0, value 3200
|
||||
"f0028032"+ // field 46, encoding 0, value 6400
|
||||
"fd02e0659948"+ // field 47, encoding 5, value 314159.0
|
||||
"81030000000050971041"+ // field 48, encoding 1, value 271828.0
|
||||
"8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
|
||||
"b304"+ // start group field 70 level 1
|
||||
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
|
||||
"b404"+ // end group field 70 level 1
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
|
||||
"90193f"+ // field 402, encoding 0, value 63
|
||||
"98197f") // field 403, encoding 0, value 127
|
||||
"0807"+ // field 1, encoding 0, value 7
|
||||
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
|
||||
"5001"+ // field 10, encoding 0, value 1
|
||||
"5803"+ // field 11, encoding 0, value 3
|
||||
"6006"+ // field 12, encoding 0, value 6
|
||||
"6d20000000"+ // field 13, encoding 5, value 32
|
||||
"714000000000000000"+ // field 14, encoding 1, value 64
|
||||
"78a019"+ // field 15, encoding 0, value 3232
|
||||
"8001c032"+ // field 16, encoding 0, value 6464
|
||||
"8d0100004a45"+ // field 17, encoding 5, value 3232.0
|
||||
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0
|
||||
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
|
||||
"c00201"+ // field 40, encoding 0, value 1
|
||||
"c80220"+ // field 41, encoding 0, value 32
|
||||
"d00240"+ // field 42, encoding 0, value 64
|
||||
"dd0240010000"+ // field 43, encoding 5, value 320
|
||||
"e1028002000000000000"+ // field 44, encoding 1, value 640
|
||||
"e8028019"+ // field 45, encoding 0, value 3200
|
||||
"f0028032"+ // field 46, encoding 0, value 6400
|
||||
"fd02e0659948"+ // field 47, encoding 5, value 314159.0
|
||||
"81030000000050971041"+ // field 48, encoding 1, value 271828.0
|
||||
"8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
|
||||
"b304"+ // start group field 70 level 1
|
||||
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
|
||||
"b404"+ // end group field 70 level 1
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
|
||||
"90193f"+ // field 402, encoding 0, value 63
|
||||
"98197f") // field 403, encoding 0, value 127
|
||||
|
||||
}
|
||||
|
||||
@ -639,56 +639,56 @@ func TestEncodeDecode4(t *testing.T) {
|
||||
pb.Optionalgroup = initGoTest_OptionalGroup()
|
||||
|
||||
overify(t, pb,
|
||||
"0807"+ // field 1, encoding 0, value 7
|
||||
"1205"+"68656c6c6f"+ // field 2, encoding 2, string "hello"
|
||||
"1807"+ // field 3, encoding 0, value 7
|
||||
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
|
||||
"320d"+"0a056c6162656c120474797065"+ // field 6, encoding 2 (GoTestField)
|
||||
"5001"+ // field 10, encoding 0, value 1
|
||||
"5803"+ // field 11, encoding 0, value 3
|
||||
"6006"+ // field 12, encoding 0, value 6
|
||||
"6d20000000"+ // field 13, encoding 5, value 32
|
||||
"714000000000000000"+ // field 14, encoding 1, value 64
|
||||
"78a019"+ // field 15, encoding 0, value 3232
|
||||
"8001c032"+ // field 16, encoding 0, value 6464
|
||||
"8d0100004a45"+ // field 17, encoding 5, value 3232.0
|
||||
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0
|
||||
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
|
||||
"f00101"+ // field 30, encoding 0, value 1
|
||||
"f80120"+ // field 31, encoding 0, value 32
|
||||
"800240"+ // field 32, encoding 0, value 64
|
||||
"8d02a00c0000"+ // field 33, encoding 5, value 3232
|
||||
"91024019000000000000"+ // field 34, encoding 1, value 6464
|
||||
"9802a0dd13"+ // field 35, encoding 0, value 323232
|
||||
"a002c0ba27"+ // field 36, encoding 0, value 646464
|
||||
"ad0200000042"+ // field 37, encoding 5, value 32.0
|
||||
"b1020000000000005040"+ // field 38, encoding 1, value 64.0
|
||||
"ba0205"+"68656c6c6f"+ // field 39, encoding 2, string "hello"
|
||||
"c00201"+ // field 40, encoding 0, value 1
|
||||
"c80220"+ // field 41, encoding 0, value 32
|
||||
"d00240"+ // field 42, encoding 0, value 64
|
||||
"dd0240010000"+ // field 43, encoding 5, value 320
|
||||
"e1028002000000000000"+ // field 44, encoding 1, value 640
|
||||
"e8028019"+ // field 45, encoding 0, value 3200
|
||||
"f0028032"+ // field 46, encoding 0, value 6400
|
||||
"fd02e0659948"+ // field 47, encoding 5, value 314159.0
|
||||
"81030000000050971041"+ // field 48, encoding 1, value 271828.0
|
||||
"8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
|
||||
"b304"+ // start group field 70 level 1
|
||||
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
|
||||
"b404"+ // end group field 70 level 1
|
||||
"d305"+ // start group field 90 level 1
|
||||
"da0508"+"6f7074696f6e616c"+ // field 91, encoding 2, string "optional"
|
||||
"d405"+ // end group field 90 level 1
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"ea1207"+"4269676e6f7365"+ // field 301, encoding 2, string "Bignose"
|
||||
"f0123f"+ // field 302, encoding 0, value 63
|
||||
"f8127f"+ // field 303, encoding 0, value 127
|
||||
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
|
||||
"90193f"+ // field 402, encoding 0, value 63
|
||||
"98197f") // field 403, encoding 0, value 127
|
||||
"0807"+ // field 1, encoding 0, value 7
|
||||
"1205"+"68656c6c6f"+ // field 2, encoding 2, string "hello"
|
||||
"1807"+ // field 3, encoding 0, value 7
|
||||
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
|
||||
"320d"+"0a056c6162656c120474797065"+ // field 6, encoding 2 (GoTestField)
|
||||
"5001"+ // field 10, encoding 0, value 1
|
||||
"5803"+ // field 11, encoding 0, value 3
|
||||
"6006"+ // field 12, encoding 0, value 6
|
||||
"6d20000000"+ // field 13, encoding 5, value 32
|
||||
"714000000000000000"+ // field 14, encoding 1, value 64
|
||||
"78a019"+ // field 15, encoding 0, value 3232
|
||||
"8001c032"+ // field 16, encoding 0, value 6464
|
||||
"8d0100004a45"+ // field 17, encoding 5, value 3232.0
|
||||
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0
|
||||
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
|
||||
"f00101"+ // field 30, encoding 0, value 1
|
||||
"f80120"+ // field 31, encoding 0, value 32
|
||||
"800240"+ // field 32, encoding 0, value 64
|
||||
"8d02a00c0000"+ // field 33, encoding 5, value 3232
|
||||
"91024019000000000000"+ // field 34, encoding 1, value 6464
|
||||
"9802a0dd13"+ // field 35, encoding 0, value 323232
|
||||
"a002c0ba27"+ // field 36, encoding 0, value 646464
|
||||
"ad0200000042"+ // field 37, encoding 5, value 32.0
|
||||
"b1020000000000005040"+ // field 38, encoding 1, value 64.0
|
||||
"ba0205"+"68656c6c6f"+ // field 39, encoding 2, string "hello"
|
||||
"c00201"+ // field 40, encoding 0, value 1
|
||||
"c80220"+ // field 41, encoding 0, value 32
|
||||
"d00240"+ // field 42, encoding 0, value 64
|
||||
"dd0240010000"+ // field 43, encoding 5, value 320
|
||||
"e1028002000000000000"+ // field 44, encoding 1, value 640
|
||||
"e8028019"+ // field 45, encoding 0, value 3200
|
||||
"f0028032"+ // field 46, encoding 0, value 6400
|
||||
"fd02e0659948"+ // field 47, encoding 5, value 314159.0
|
||||
"81030000000050971041"+ // field 48, encoding 1, value 271828.0
|
||||
"8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
|
||||
"b304"+ // start group field 70 level 1
|
||||
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
|
||||
"b404"+ // end group field 70 level 1
|
||||
"d305"+ // start group field 90 level 1
|
||||
"da0508"+"6f7074696f6e616c"+ // field 91, encoding 2, string "optional"
|
||||
"d405"+ // end group field 90 level 1
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"ea1207"+"4269676e6f7365"+ // field 301, encoding 2, string "Bignose"
|
||||
"f0123f"+ // field 302, encoding 0, value 63
|
||||
"f8127f"+ // field 303, encoding 0, value 127
|
||||
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
|
||||
"90193f"+ // field 402, encoding 0, value 63
|
||||
"98197f") // field 403, encoding 0, value 127
|
||||
|
||||
}
|
||||
|
||||
@ -712,71 +712,71 @@ func TestEncodeDecode5(t *testing.T) {
|
||||
pb.Repeatedgroup = []*GoTest_RepeatedGroup{initGoTest_RepeatedGroup(), initGoTest_RepeatedGroup()}
|
||||
|
||||
overify(t, pb,
|
||||
"0807"+ // field 1, encoding 0, value 7
|
||||
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
|
||||
"2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField)
|
||||
"2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField)
|
||||
"5001"+ // field 10, encoding 0, value 1
|
||||
"5803"+ // field 11, encoding 0, value 3
|
||||
"6006"+ // field 12, encoding 0, value 6
|
||||
"6d20000000"+ // field 13, encoding 5, value 32
|
||||
"714000000000000000"+ // field 14, encoding 1, value 64
|
||||
"78a019"+ // field 15, encoding 0, value 3232
|
||||
"8001c032"+ // field 16, encoding 0, value 6464
|
||||
"8d0100004a45"+ // field 17, encoding 5, value 3232.0
|
||||
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0
|
||||
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
|
||||
"a00100"+ // field 20, encoding 0, value 0
|
||||
"a00101"+ // field 20, encoding 0, value 1
|
||||
"a80120"+ // field 21, encoding 0, value 32
|
||||
"a80121"+ // field 21, encoding 0, value 33
|
||||
"b00140"+ // field 22, encoding 0, value 64
|
||||
"b00141"+ // field 22, encoding 0, value 65
|
||||
"bd01a00c0000"+ // field 23, encoding 5, value 3232
|
||||
"bd01050d0000"+ // field 23, encoding 5, value 3333
|
||||
"c1014019000000000000"+ // field 24, encoding 1, value 6464
|
||||
"c101a519000000000000"+ // field 24, encoding 1, value 6565
|
||||
"c801a0dd13"+ // field 25, encoding 0, value 323232
|
||||
"c80195ac14"+ // field 25, encoding 0, value 333333
|
||||
"d001c0ba27"+ // field 26, encoding 0, value 646464
|
||||
"d001b58928"+ // field 26, encoding 0, value 656565
|
||||
"dd0100000042"+ // field 27, encoding 5, value 32.0
|
||||
"dd0100000442"+ // field 27, encoding 5, value 33.0
|
||||
"e1010000000000005040"+ // field 28, encoding 1, value 64.0
|
||||
"e1010000000000405040"+ // field 28, encoding 1, value 65.0
|
||||
"ea0105"+"68656c6c6f"+ // field 29, encoding 2, string "hello"
|
||||
"ea0106"+"7361696c6f72"+ // field 29, encoding 2, string "sailor"
|
||||
"c00201"+ // field 40, encoding 0, value 1
|
||||
"c80220"+ // field 41, encoding 0, value 32
|
||||
"d00240"+ // field 42, encoding 0, value 64
|
||||
"dd0240010000"+ // field 43, encoding 5, value 320
|
||||
"e1028002000000000000"+ // field 44, encoding 1, value 640
|
||||
"e8028019"+ // field 45, encoding 0, value 3200
|
||||
"f0028032"+ // field 46, encoding 0, value 6400
|
||||
"fd02e0659948"+ // field 47, encoding 5, value 314159.0
|
||||
"81030000000050971041"+ // field 48, encoding 1, value 271828.0
|
||||
"8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
|
||||
"b304"+ // start group field 70 level 1
|
||||
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
|
||||
"b404"+ // end group field 70 level 1
|
||||
"8305"+ // start group field 80 level 1
|
||||
"8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated"
|
||||
"8405"+ // end group field 80 level 1
|
||||
"8305"+ // start group field 80 level 1
|
||||
"8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated"
|
||||
"8405"+ // end group field 80 level 1
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"ca0c03"+"626967"+ // field 201, encoding 2, string "big"
|
||||
"ca0c04"+"6e6f7365"+ // field 201, encoding 2, string "nose"
|
||||
"d00c40"+ // field 202, encoding 0, value 32
|
||||
"d00c3f"+ // field 202, encoding 0, value -32
|
||||
"d80c8001"+ // field 203, encoding 0, value 64
|
||||
"d80c7f"+ // field 203, encoding 0, value -64
|
||||
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
|
||||
"90193f"+ // field 402, encoding 0, value 63
|
||||
"98197f") // field 403, encoding 0, value 127
|
||||
"0807"+ // field 1, encoding 0, value 7
|
||||
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
|
||||
"2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField)
|
||||
"2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField)
|
||||
"5001"+ // field 10, encoding 0, value 1
|
||||
"5803"+ // field 11, encoding 0, value 3
|
||||
"6006"+ // field 12, encoding 0, value 6
|
||||
"6d20000000"+ // field 13, encoding 5, value 32
|
||||
"714000000000000000"+ // field 14, encoding 1, value 64
|
||||
"78a019"+ // field 15, encoding 0, value 3232
|
||||
"8001c032"+ // field 16, encoding 0, value 6464
|
||||
"8d0100004a45"+ // field 17, encoding 5, value 3232.0
|
||||
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0
|
||||
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
|
||||
"a00100"+ // field 20, encoding 0, value 0
|
||||
"a00101"+ // field 20, encoding 0, value 1
|
||||
"a80120"+ // field 21, encoding 0, value 32
|
||||
"a80121"+ // field 21, encoding 0, value 33
|
||||
"b00140"+ // field 22, encoding 0, value 64
|
||||
"b00141"+ // field 22, encoding 0, value 65
|
||||
"bd01a00c0000"+ // field 23, encoding 5, value 3232
|
||||
"bd01050d0000"+ // field 23, encoding 5, value 3333
|
||||
"c1014019000000000000"+ // field 24, encoding 1, value 6464
|
||||
"c101a519000000000000"+ // field 24, encoding 1, value 6565
|
||||
"c801a0dd13"+ // field 25, encoding 0, value 323232
|
||||
"c80195ac14"+ // field 25, encoding 0, value 333333
|
||||
"d001c0ba27"+ // field 26, encoding 0, value 646464
|
||||
"d001b58928"+ // field 26, encoding 0, value 656565
|
||||
"dd0100000042"+ // field 27, encoding 5, value 32.0
|
||||
"dd0100000442"+ // field 27, encoding 5, value 33.0
|
||||
"e1010000000000005040"+ // field 28, encoding 1, value 64.0
|
||||
"e1010000000000405040"+ // field 28, encoding 1, value 65.0
|
||||
"ea0105"+"68656c6c6f"+ // field 29, encoding 2, string "hello"
|
||||
"ea0106"+"7361696c6f72"+ // field 29, encoding 2, string "sailor"
|
||||
"c00201"+ // field 40, encoding 0, value 1
|
||||
"c80220"+ // field 41, encoding 0, value 32
|
||||
"d00240"+ // field 42, encoding 0, value 64
|
||||
"dd0240010000"+ // field 43, encoding 5, value 320
|
||||
"e1028002000000000000"+ // field 44, encoding 1, value 640
|
||||
"e8028019"+ // field 45, encoding 0, value 3200
|
||||
"f0028032"+ // field 46, encoding 0, value 6400
|
||||
"fd02e0659948"+ // field 47, encoding 5, value 314159.0
|
||||
"81030000000050971041"+ // field 48, encoding 1, value 271828.0
|
||||
"8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
|
||||
"b304"+ // start group field 70 level 1
|
||||
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
|
||||
"b404"+ // end group field 70 level 1
|
||||
"8305"+ // start group field 80 level 1
|
||||
"8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated"
|
||||
"8405"+ // end group field 80 level 1
|
||||
"8305"+ // start group field 80 level 1
|
||||
"8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated"
|
||||
"8405"+ // end group field 80 level 1
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"ca0c03"+"626967"+ // field 201, encoding 2, string "big"
|
||||
"ca0c04"+"6e6f7365"+ // field 201, encoding 2, string "nose"
|
||||
"d00c40"+ // field 202, encoding 0, value 32
|
||||
"d00c3f"+ // field 202, encoding 0, value -32
|
||||
"d80c8001"+ // field 203, encoding 0, value 64
|
||||
"d80c7f"+ // field 203, encoding 0, value -64
|
||||
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
|
||||
"90193f"+ // field 402, encoding 0, value 63
|
||||
"98197f") // field 403, encoding 0, value 127
|
||||
|
||||
}
|
||||
|
||||
@ -796,43 +796,43 @@ func TestEncodeDecode6(t *testing.T) {
|
||||
pb.F_Sint64RepeatedPacked = []int64{64, -64}
|
||||
|
||||
overify(t, pb,
|
||||
"0807"+ // field 1, encoding 0, value 7
|
||||
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
|
||||
"5001"+ // field 10, encoding 0, value 1
|
||||
"5803"+ // field 11, encoding 0, value 3
|
||||
"6006"+ // field 12, encoding 0, value 6
|
||||
"6d20000000"+ // field 13, encoding 5, value 32
|
||||
"714000000000000000"+ // field 14, encoding 1, value 64
|
||||
"78a019"+ // field 15, encoding 0, value 3232
|
||||
"8001c032"+ // field 16, encoding 0, value 6464
|
||||
"8d0100004a45"+ // field 17, encoding 5, value 3232.0
|
||||
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0
|
||||
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
|
||||
"9203020001"+ // field 50, encoding 2, 2 bytes, value 0, value 1
|
||||
"9a03022021"+ // field 51, encoding 2, 2 bytes, value 32, value 33
|
||||
"a203024041"+ // field 52, encoding 2, 2 bytes, value 64, value 65
|
||||
"aa0308"+ // field 53, encoding 2, 8 bytes
|
||||
"a00c0000050d0000"+ // value 3232, value 3333
|
||||
"b20310"+ // field 54, encoding 2, 16 bytes
|
||||
"4019000000000000a519000000000000"+ // value 6464, value 6565
|
||||
"ba0306"+ // field 55, encoding 2, 6 bytes
|
||||
"a0dd1395ac14"+ // value 323232, value 333333
|
||||
"c20306"+ // field 56, encoding 2, 6 bytes
|
||||
"c0ba27b58928"+ // value 646464, value 656565
|
||||
"ca0308"+ // field 57, encoding 2, 8 bytes
|
||||
"0000004200000442"+ // value 32.0, value 33.0
|
||||
"d20310"+ // field 58, encoding 2, 16 bytes
|
||||
"00000000000050400000000000405040"+ // value 64.0, value 65.0
|
||||
"b304"+ // start group field 70 level 1
|
||||
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
|
||||
"b404"+ // end group field 70 level 1
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"b21f02"+ // field 502, encoding 2, 2 bytes
|
||||
"403f"+ // value 32, value -32
|
||||
"ba1f03"+ // field 503, encoding 2, 3 bytes
|
||||
"80017f") // value 64, value -64
|
||||
"0807"+ // field 1, encoding 0, value 7
|
||||
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
|
||||
"5001"+ // field 10, encoding 0, value 1
|
||||
"5803"+ // field 11, encoding 0, value 3
|
||||
"6006"+ // field 12, encoding 0, value 6
|
||||
"6d20000000"+ // field 13, encoding 5, value 32
|
||||
"714000000000000000"+ // field 14, encoding 1, value 64
|
||||
"78a019"+ // field 15, encoding 0, value 3232
|
||||
"8001c032"+ // field 16, encoding 0, value 6464
|
||||
"8d0100004a45"+ // field 17, encoding 5, value 3232.0
|
||||
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0
|
||||
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
|
||||
"9203020001"+ // field 50, encoding 2, 2 bytes, value 0, value 1
|
||||
"9a03022021"+ // field 51, encoding 2, 2 bytes, value 32, value 33
|
||||
"a203024041"+ // field 52, encoding 2, 2 bytes, value 64, value 65
|
||||
"aa0308"+ // field 53, encoding 2, 8 bytes
|
||||
"a00c0000050d0000"+ // value 3232, value 3333
|
||||
"b20310"+ // field 54, encoding 2, 16 bytes
|
||||
"4019000000000000a519000000000000"+ // value 6464, value 6565
|
||||
"ba0306"+ // field 55, encoding 2, 6 bytes
|
||||
"a0dd1395ac14"+ // value 323232, value 333333
|
||||
"c20306"+ // field 56, encoding 2, 6 bytes
|
||||
"c0ba27b58928"+ // value 646464, value 656565
|
||||
"ca0308"+ // field 57, encoding 2, 8 bytes
|
||||
"0000004200000442"+ // value 32.0, value 33.0
|
||||
"d20310"+ // field 58, encoding 2, 16 bytes
|
||||
"00000000000050400000000000405040"+ // value 64.0, value 65.0
|
||||
"b304"+ // start group field 70 level 1
|
||||
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
|
||||
"b404"+ // end group field 70 level 1
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"b21f02"+ // field 502, encoding 2, 2 bytes
|
||||
"403f"+ // value 32, value -32
|
||||
"ba1f03"+ // field 503, encoding 2, 3 bytes
|
||||
"80017f") // value 64, value -64
|
||||
}
|
||||
|
||||
// Test that we can encode empty bytes fields.
|
||||
@ -898,13 +898,13 @@ func TestSkippingUnrecognizedFields(t *testing.T) {
|
||||
|
||||
// Now new a GoSkipTest record.
|
||||
skip := &GoSkipTest{
|
||||
SkipInt32: Int32(32),
|
||||
SkipFixed32: Uint32(3232),
|
||||
SkipFixed64: Uint64(6464),
|
||||
SkipString: String("skipper"),
|
||||
SkipInt32: Int32(32),
|
||||
SkipFixed32: Uint32(3232),
|
||||
SkipFixed64: Uint64(6464),
|
||||
SkipString: String("skipper"),
|
||||
Skipgroup: &GoSkipTest_SkipGroup{
|
||||
GroupInt32: Int32(75),
|
||||
GroupString: String("wxyz"),
|
||||
GroupInt32: Int32(75),
|
||||
GroupString: String("wxyz"),
|
||||
},
|
||||
}
|
||||
|
||||
@ -944,8 +944,8 @@ func TestSkippingUnrecognizedFields(t *testing.T) {
|
||||
func TestSubmessageUnrecognizedFields(t *testing.T) {
|
||||
nm := &NewMessage{
|
||||
Nested: &NewMessage_Nested{
|
||||
Name: String("Nigel"),
|
||||
FoodGroup: String("carbs"),
|
||||
Name: String("Nigel"),
|
||||
FoodGroup: String("carbs"),
|
||||
},
|
||||
}
|
||||
b, err := Marshal(nm)
|
||||
@ -960,9 +960,9 @@ func TestSubmessageUnrecognizedFields(t *testing.T) {
|
||||
}
|
||||
exp := &OldMessage{
|
||||
Nested: &OldMessage_Nested{
|
||||
Name: String("Nigel"),
|
||||
Name: String("Nigel"),
|
||||
// normal protocol buffer users should not do this
|
||||
XXX_unrecognized: []byte("\x12\x05carbs"),
|
||||
XXX_unrecognized: []byte("\x12\x05carbs"),
|
||||
},
|
||||
}
|
||||
if !Equal(om, exp) {
|
||||
@ -999,7 +999,7 @@ func TestBigRepeated(t *testing.T) {
|
||||
pb := initGoTest(true)
|
||||
|
||||
// Create the arrays
|
||||
const N = 50 // Internally the library starts much smaller.
|
||||
const N = 50 // Internally the library starts much smaller.
|
||||
pb.Repeatedgroup = make([]*GoTest_RepeatedGroup, N)
|
||||
pb.F_Sint64Repeated = make([]int64, N)
|
||||
pb.F_Sint32Repeated = make([]int32, N)
|
||||
@ -1047,7 +1047,7 @@ func TestBigRepeated(t *testing.T) {
|
||||
|
||||
// Check the checkable values
|
||||
for i := uint64(0); i < N; i++ {
|
||||
if pbd.Repeatedgroup[i] == nil { // TODO: more checking?
|
||||
if pbd.Repeatedgroup[i] == nil { // TODO: more checking?
|
||||
t.Error("pbd.Repeatedgroup bad")
|
||||
}
|
||||
var x uint64
|
||||
@ -1099,7 +1099,7 @@ func TestBigRepeated(t *testing.T) {
|
||||
if pbd.F_BoolRepeated[i] != (i%2 == 0) {
|
||||
t.Error("pbd.F_BoolRepeated bad", x, i)
|
||||
}
|
||||
if pbd.RepeatedField[i] == nil { // TODO: more checking?
|
||||
if pbd.RepeatedField[i] == nil { // TODO: more checking?
|
||||
t.Error("pbd.RepeatedField bad")
|
||||
}
|
||||
}
|
||||
@ -1159,8 +1159,8 @@ func TestProto1RepeatedGroup(t *testing.T) {
|
||||
pb := &MessageList{
|
||||
Message: []*MessageList_Message{
|
||||
{
|
||||
Name: String("blah"),
|
||||
Count: Int32(7),
|
||||
Name: String("blah"),
|
||||
Count: Int32(7),
|
||||
},
|
||||
// NOTE: pb.Message[1] is a nil
|
||||
nil,
|
||||
@ -1240,9 +1240,9 @@ type NNIMessage struct {
|
||||
nni nonNillableInt
|
||||
}
|
||||
|
||||
func (*NNIMessage) Reset() {}
|
||||
func (*NNIMessage) String() string { return "" }
|
||||
func (*NNIMessage) ProtoMessage() {}
|
||||
func (*NNIMessage) Reset() {}
|
||||
func (*NNIMessage) String() string { return "" }
|
||||
func (*NNIMessage) ProtoMessage() {}
|
||||
|
||||
// A type that implements the Marshaler interface and is nillable.
|
||||
type nillableMessage struct {
|
||||
@ -1257,9 +1257,9 @@ type NMMessage struct {
|
||||
nm *nillableMessage
|
||||
}
|
||||
|
||||
func (*NMMessage) Reset() {}
|
||||
func (*NMMessage) String() string { return "" }
|
||||
func (*NMMessage) ProtoMessage() {}
|
||||
func (*NMMessage) Reset() {}
|
||||
func (*NMMessage) String() string { return "" }
|
||||
func (*NMMessage) ProtoMessage() {}
|
||||
|
||||
// Verify a type that uses the Marshaler interface, but has a nil pointer.
|
||||
func TestNilMarshaler(t *testing.T) {
|
||||
@ -1273,7 +1273,7 @@ func TestNilMarshaler(t *testing.T) {
|
||||
// Try a struct with a Marshaler field that is not nillable.
|
||||
nnim := new(NNIMessage)
|
||||
nnim.nni = 7
|
||||
var _ Marshaler = nnim.nni // verify it is truly a Marshaler
|
||||
var _ Marshaler = nnim.nni // verify it is truly a Marshaler
|
||||
if _, err := Marshal(nnim); err != nil {
|
||||
t.Error("unexpected error marshaling nnim: ", err)
|
||||
}
|
||||
@ -1286,23 +1286,23 @@ func TestAllSetDefaults(t *testing.T) {
|
||||
F_Nan: Float32(1.7),
|
||||
}
|
||||
expected := &Defaults{
|
||||
F_Bool: Bool(true),
|
||||
F_Int32: Int32(32),
|
||||
F_Int64: Int64(64),
|
||||
F_Fixed32: Uint32(320),
|
||||
F_Fixed64: Uint64(640),
|
||||
F_Uint32: Uint32(3200),
|
||||
F_Uint64: Uint64(6400),
|
||||
F_Float: Float32(314159),
|
||||
F_Double: Float64(271828),
|
||||
F_String: String(`hello, "world!"` + "\n"),
|
||||
F_Bytes: []byte("Bignose"),
|
||||
F_Sint32: Int32(-32),
|
||||
F_Sint64: Int64(-64),
|
||||
F_Enum: Defaults_GREEN.Enum(),
|
||||
F_Pinf: Float32(float32(math.Inf(1))),
|
||||
F_Ninf: Float32(float32(math.Inf(-1))),
|
||||
F_Nan: Float32(1.7),
|
||||
F_Bool: Bool(true),
|
||||
F_Int32: Int32(32),
|
||||
F_Int64: Int64(64),
|
||||
F_Fixed32: Uint32(320),
|
||||
F_Fixed64: Uint64(640),
|
||||
F_Uint32: Uint32(3200),
|
||||
F_Uint64: Uint64(6400),
|
||||
F_Float: Float32(314159),
|
||||
F_Double: Float64(271828),
|
||||
F_String: String(`hello, "world!"` + "\n"),
|
||||
F_Bytes: []byte("Bignose"),
|
||||
F_Sint32: Int32(-32),
|
||||
F_Sint64: Int64(-64),
|
||||
F_Enum: Defaults_GREEN.Enum(),
|
||||
F_Pinf: Float32(float32(math.Inf(1))),
|
||||
F_Ninf: Float32(float32(math.Inf(-1))),
|
||||
F_Nan: Float32(1.7),
|
||||
}
|
||||
SetDefaults(m)
|
||||
if !Equal(m, expected) {
|
||||
@ -1323,16 +1323,16 @@ func TestSetDefaultsWithSetField(t *testing.T) {
|
||||
|
||||
func TestSetDefaultsWithSubMessage(t *testing.T) {
|
||||
m := &OtherMessage{
|
||||
Key: Int64(123),
|
||||
Key: Int64(123),
|
||||
Inner: &InnerMessage{
|
||||
Host: String("gopher"),
|
||||
},
|
||||
}
|
||||
expected := &OtherMessage{
|
||||
Key: Int64(123),
|
||||
Key: Int64(123),
|
||||
Inner: &InnerMessage{
|
||||
Host: String("gopher"),
|
||||
Port: Int32(4000),
|
||||
Host: String("gopher"),
|
||||
Port: Int32(4000),
|
||||
},
|
||||
}
|
||||
SetDefaults(m)
|
||||
@ -1375,12 +1375,12 @@ func TestMaximumTagNumber(t *testing.T) {
|
||||
|
||||
func TestJSON(t *testing.T) {
|
||||
m := &MyMessage{
|
||||
Count: Int32(4),
|
||||
Pet: []string{"bunny", "kitty"},
|
||||
Count: Int32(4),
|
||||
Pet: []string{"bunny", "kitty"},
|
||||
Inner: &InnerMessage{
|
||||
Host: String("cauchy"),
|
||||
},
|
||||
Bikeshed: MyMessage_GREEN.Enum(),
|
||||
Bikeshed: MyMessage_GREEN.Enum(),
|
||||
}
|
||||
const expected = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":1}`
|
||||
|
||||
@ -1413,7 +1413,7 @@ func TestJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBadWireType(t *testing.T) {
|
||||
b := []byte{7<<3 | 6} // field 7, wire type 6
|
||||
b := []byte{7<<3 | 6} // field 7, wire type 6
|
||||
pb := new(OtherMessage)
|
||||
if err := Unmarshal(b, pb); err == nil {
|
||||
t.Errorf("Unmarshal did not fail")
|
||||
@ -1610,10 +1610,10 @@ func TestUnmarshalMergesMessages(t *testing.T) {
|
||||
// If a nested message occurs twice in the input,
|
||||
// the fields should be merged when decoding.
|
||||
a := &OtherMessage{
|
||||
Key: Int64(123),
|
||||
Key: Int64(123),
|
||||
Inner: &InnerMessage{
|
||||
Host: String("polhode"),
|
||||
Port: Int32(1234),
|
||||
Host: String("polhode"),
|
||||
Port: Int32(1234),
|
||||
},
|
||||
}
|
||||
aData, err := Marshal(a)
|
||||
@ -1621,10 +1621,10 @@ func TestUnmarshalMergesMessages(t *testing.T) {
|
||||
t.Fatalf("Marshal(a): %v", err)
|
||||
}
|
||||
b := &OtherMessage{
|
||||
Weight: Float32(1.2),
|
||||
Weight: Float32(1.2),
|
||||
Inner: &InnerMessage{
|
||||
Host: String("herpolhode"),
|
||||
Connected: Bool(true),
|
||||
Host: String("herpolhode"),
|
||||
Connected: Bool(true),
|
||||
},
|
||||
}
|
||||
bData, err := Marshal(b)
|
||||
@ -1632,12 +1632,12 @@ func TestUnmarshalMergesMessages(t *testing.T) {
|
||||
t.Fatalf("Marshal(b): %v", err)
|
||||
}
|
||||
want := &OtherMessage{
|
||||
Key: Int64(123),
|
||||
Weight: Float32(1.2),
|
||||
Key: Int64(123),
|
||||
Weight: Float32(1.2),
|
||||
Inner: &InnerMessage{
|
||||
Host: String("herpolhode"),
|
||||
Port: Int32(1234),
|
||||
Connected: Bool(true),
|
||||
Host: String("herpolhode"),
|
||||
Port: Int32(1234),
|
||||
Connected: Bool(true),
|
||||
},
|
||||
}
|
||||
got := new(OtherMessage)
|
||||
@ -1651,8 +1651,8 @@ func TestUnmarshalMergesMessages(t *testing.T) {
|
||||
|
||||
func TestEncodingSizes(t *testing.T) {
|
||||
tests := []struct {
|
||||
m Message
|
||||
n int
|
||||
m Message
|
||||
n int
|
||||
}{
|
||||
{&Defaults{F_Int32: Int32(math.MaxInt32)}, 6},
|
||||
{&Defaults{F_Int32: Int32(math.MinInt32)}, 6},
|
||||
@ -1676,22 +1676,22 @@ func TestRequiredNotSetError(t *testing.T) {
|
||||
pb.F_Int32Required = nil
|
||||
pb.F_Int64Required = nil
|
||||
|
||||
expected := "0807" + // field 1, encoding 0, value 7
|
||||
"2206" + "120474797065" + // field 4, encoding 2 (GoTestField)
|
||||
"5001" + // field 10, encoding 0, value 1
|
||||
"6d20000000" + // field 13, encoding 5, value 0x20
|
||||
"714000000000000000" + // field 14, encoding 1, value 0x40
|
||||
"78a019" + // field 15, encoding 0, value 0xca0 = 3232
|
||||
"8001c032" + // field 16, encoding 0, value 0x1940 = 6464
|
||||
"8d0100004a45" + // field 17, encoding 5, value 3232.0
|
||||
"9101000000000040b940" + // field 18, encoding 1, value 6464.0
|
||||
"9a0106" + "737472696e67" + // field 19, encoding 2, string "string"
|
||||
"b304" + // field 70, encoding 3, start group
|
||||
"ba0408" + "7265717569726564" + // field 71, encoding 2, string "required"
|
||||
"b404" + // field 70, encoding 4, end group
|
||||
"aa0605" + "6279746573" + // field 101, encoding 2, string "bytes"
|
||||
"b0063f" + // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f" // field 103, encoding 0, 0x7f zigzag64
|
||||
expected := "0807" + // field 1, encoding 0, value 7
|
||||
"2206" + "120474797065" + // field 4, encoding 2 (GoTestField)
|
||||
"5001" + // field 10, encoding 0, value 1
|
||||
"6d20000000" + // field 13, encoding 5, value 0x20
|
||||
"714000000000000000" + // field 14, encoding 1, value 0x40
|
||||
"78a019" + // field 15, encoding 0, value 0xca0 = 3232
|
||||
"8001c032" + // field 16, encoding 0, value 0x1940 = 6464
|
||||
"8d0100004a45" + // field 17, encoding 5, value 3232.0
|
||||
"9101000000000040b940" + // field 18, encoding 1, value 6464.0
|
||||
"9a0106" + "737472696e67" + // field 19, encoding 2, string "string"
|
||||
"b304" + // field 70, encoding 3, start group
|
||||
"ba0408" + "7265717569726564" + // field 71, encoding 2, string "required"
|
||||
"b404" + // field 70, encoding 4, end group
|
||||
"aa0605" + "6279746573" + // field 101, encoding 2, string "bytes"
|
||||
"b0063f" + // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f" // field 103, encoding 0, 0x7f zigzag64
|
||||
|
||||
o := old()
|
||||
bytes, err := Marshal(pb)
|
||||
@ -1751,7 +1751,7 @@ func fuzzUnmarshal(t *testing.T, data []byte) {
|
||||
|
||||
func testMsg() *GoTest {
|
||||
pb := initGoTest(true)
|
||||
const N = 1000 // Internally the library starts much smaller.
|
||||
const N = 1000 // Internally the library starts much smaller.
|
||||
pb.F_Int32Repeated = make([]int32, N)
|
||||
pb.F_DoubleRepeated = make([]float64, N)
|
||||
for i := 0; i < N; i++ {
|
||||
@ -1869,13 +1869,13 @@ func BenchmarkUnmarshalUnrecognizedFields(b *testing.B) {
|
||||
b.StopTimer()
|
||||
pb := initGoTestField()
|
||||
skip := &GoSkipTest{
|
||||
SkipInt32: Int32(32),
|
||||
SkipFixed32: Uint32(3232),
|
||||
SkipFixed64: Uint64(6464),
|
||||
SkipString: String("skipper"),
|
||||
SkipInt32: Int32(32),
|
||||
SkipFixed32: Uint32(3232),
|
||||
SkipFixed64: Uint64(6464),
|
||||
SkipString: String("skipper"),
|
||||
Skipgroup: &GoSkipTest_SkipGroup{
|
||||
GroupInt32: Int32(75),
|
||||
GroupString: String("wxyz"),
|
||||
GroupInt32: Int32(75),
|
||||
GroupString: String("wxyz"),
|
||||
},
|
||||
}
|
||||
|
@ -34,19 +34,19 @@ package proto_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.google.com/p/goprotobuf/proto"
|
||||
"github.com/coreos/etcd/third_party/code.google.com/p/goprotobuf/proto"
|
||||
|
||||
pb "./testdata"
|
||||
)
|
||||
|
||||
var cloneTestMessage = &pb.MyMessage{
|
||||
Count: proto.Int32(42),
|
||||
Name: proto.String("Dave"),
|
||||
Pet: []string{"bunny", "kitty", "horsey"},
|
||||
Count: proto.Int32(42),
|
||||
Name: proto.String("Dave"),
|
||||
Pet: []string{"bunny", "kitty", "horsey"},
|
||||
Inner: &pb.InnerMessage{
|
||||
Host: proto.String("niles"),
|
||||
Port: proto.Int32(9099),
|
||||
Connected: proto.Bool(true),
|
||||
Host: proto.String("niles"),
|
||||
Port: proto.Int32(9099),
|
||||
Connected: proto.Bool(true),
|
||||
},
|
||||
Others: []*pb.OtherMessage{
|
||||
{
|
||||
@ -56,7 +56,7 @@ var cloneTestMessage = &pb.MyMessage{
|
||||
Somegroup: &pb.MyMessage_SomeGroup{
|
||||
GroupField: proto.Int32(6),
|
||||
},
|
||||
RepBytes: [][]byte{[]byte("sham"), []byte("wow")},
|
||||
RepBytes: [][]byte{[]byte("sham"), []byte("wow")},
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -99,17 +99,17 @@ var mergeTests = []struct {
|
||||
Name: proto.String("Dave"),
|
||||
},
|
||||
want: &pb.MyMessage{
|
||||
Count: proto.Int32(42),
|
||||
Name: proto.String("Dave"),
|
||||
Count: proto.Int32(42),
|
||||
Name: proto.String("Dave"),
|
||||
},
|
||||
},
|
||||
{
|
||||
src: &pb.MyMessage{
|
||||
Inner: &pb.InnerMessage{
|
||||
Host: proto.String("hey"),
|
||||
Connected: proto.Bool(true),
|
||||
Host: proto.String("hey"),
|
||||
Connected: proto.Bool(true),
|
||||
},
|
||||
Pet: []string{"horsey"},
|
||||
Pet: []string{"horsey"},
|
||||
Others: []*pb.OtherMessage{
|
||||
{
|
||||
Value: []byte("some bytes"),
|
||||
@ -118,10 +118,10 @@ var mergeTests = []struct {
|
||||
},
|
||||
dst: &pb.MyMessage{
|
||||
Inner: &pb.InnerMessage{
|
||||
Host: proto.String("niles"),
|
||||
Port: proto.Int32(9099),
|
||||
Host: proto.String("niles"),
|
||||
Port: proto.Int32(9099),
|
||||
},
|
||||
Pet: []string{"bunny", "kitty"},
|
||||
Pet: []string{"bunny", "kitty"},
|
||||
Others: []*pb.OtherMessage{
|
||||
{
|
||||
Key: proto.Int64(31415926535),
|
||||
@ -134,11 +134,11 @@ var mergeTests = []struct {
|
||||
},
|
||||
want: &pb.MyMessage{
|
||||
Inner: &pb.InnerMessage{
|
||||
Host: proto.String("hey"),
|
||||
Connected: proto.Bool(true),
|
||||
Port: proto.Int32(9099),
|
||||
Host: proto.String("hey"),
|
||||
Connected: proto.Bool(true),
|
||||
Port: proto.Int32(9099),
|
||||
},
|
||||
Pet: []string{"bunny", "kitty", "horsey"},
|
||||
Pet: []string{"bunny", "kitty", "horsey"},
|
||||
Others: []*pb.OtherMessage{
|
||||
{
|
||||
Key: proto.Int64(31415926535),
|
||||
@ -158,13 +158,13 @@ var mergeTests = []struct {
|
||||
Somegroup: &pb.MyMessage_SomeGroup{
|
||||
GroupField: proto.Int32(6),
|
||||
},
|
||||
RepBytes: [][]byte{[]byte("sham")},
|
||||
RepBytes: [][]byte{[]byte("sham")},
|
||||
},
|
||||
want: &pb.MyMessage{
|
||||
Somegroup: &pb.MyMessage_SomeGroup{
|
||||
GroupField: proto.Int32(6),
|
||||
},
|
||||
RepBytes: [][]byte{[]byte("sham"), []byte("wow")},
|
||||
RepBytes: [][]byte{[]byte("sham"), []byte("wow")},
|
||||
},
|
||||
},
|
||||
}
|
@ -35,7 +35,7 @@ import (
|
||||
"testing"
|
||||
|
||||
pb "./testdata"
|
||||
. "code.google.com/p/goprotobuf/proto"
|
||||
. "github.com/coreos/etcd/third_party/code.google.com/p/goprotobuf/proto"
|
||||
)
|
||||
|
||||
// Four identical base messages.
|
||||
@ -85,9 +85,9 @@ func init() {
|
||||
}
|
||||
|
||||
var EqualTests = []struct {
|
||||
desc string
|
||||
a, b Message
|
||||
exp bool
|
||||
desc string
|
||||
a, b Message
|
||||
exp bool
|
||||
}{
|
||||
{"different types", &pb.GoEnum{}, &pb.GoTestField{}, false},
|
||||
{"equal empty", &pb.GoEnum{}, &pb.GoEnum{}, true},
|
||||
@ -142,13 +142,13 @@ var EqualTests = []struct {
|
||||
{
|
||||
"message with group",
|
||||
&pb.MyMessage{
|
||||
Count: Int32(1),
|
||||
Count: Int32(1),
|
||||
Somegroup: &pb.MyMessage_SomeGroup{
|
||||
GroupField: Int32(5),
|
||||
},
|
||||
},
|
||||
&pb.MyMessage{
|
||||
Count: Int32(1),
|
||||
Count: Int32(1),
|
||||
Somegroup: &pb.MyMessage_SomeGroup{
|
||||
GroupField: Int32(5),
|
||||
},
|
@ -36,7 +36,7 @@ import (
|
||||
"testing"
|
||||
|
||||
pb "./testdata"
|
||||
. "code.google.com/p/goprotobuf/proto"
|
||||
. "github.com/coreos/etcd/third_party/code.google.com/p/goprotobuf/proto"
|
||||
)
|
||||
|
||||
var messageWithExtension1 = &pb.MyMessage{Count: Int32(7)}
|
||||
@ -58,8 +58,8 @@ func init() {
|
||||
}
|
||||
|
||||
var SizeTests = []struct {
|
||||
desc string
|
||||
pb Message
|
||||
desc string
|
||||
pb Message
|
||||
}{
|
||||
{"empty", &pb.OtherMessage{}},
|
||||
// Basic types.
|
2294
third_party/code.google.com/p/goprotobuf/proto/testdata/test.pb.go
vendored
Normal file
2294
third_party/code.google.com/p/goprotobuf/proto/testdata/test.pb.go
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -37,13 +37,13 @@ import (
|
||||
"testing"
|
||||
|
||||
. "./testdata"
|
||||
. "code.google.com/p/goprotobuf/proto"
|
||||
. "github.com/coreos/etcd/third_party/code.google.com/p/goprotobuf/proto"
|
||||
)
|
||||
|
||||
type UnmarshalTextTest struct {
|
||||
in string
|
||||
err string // if "", no error expected
|
||||
out *MyMessage
|
||||
in string
|
||||
err string // if "", no error expected
|
||||
out *MyMessage
|
||||
}
|
||||
|
||||
func buildExtStructTest(text string) UnmarshalTextTest {
|
||||
@ -78,97 +78,97 @@ func buildExtRepStringTest(text string) UnmarshalTextTest {
|
||||
var unMarshalTextTests = []UnmarshalTextTest{
|
||||
// Basic
|
||||
{
|
||||
in: " count:42\n name:\"Dave\" ",
|
||||
in: " count:42\n name:\"Dave\" ",
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Name: String("Dave"),
|
||||
Count: Int32(42),
|
||||
Name: String("Dave"),
|
||||
},
|
||||
},
|
||||
|
||||
// Empty quoted string
|
||||
{
|
||||
in: `count:42 name:""`,
|
||||
in: `count:42 name:""`,
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Name: String(""),
|
||||
Count: Int32(42),
|
||||
Name: String(""),
|
||||
},
|
||||
},
|
||||
|
||||
// Quoted string concatenation
|
||||
{
|
||||
in: `count:42 name: "My name is "` + "\n" + `"elsewhere"`,
|
||||
in: `count:42 name: "My name is "` + "\n" + `"elsewhere"`,
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Name: String("My name is elsewhere"),
|
||||
Count: Int32(42),
|
||||
Name: String("My name is elsewhere"),
|
||||
},
|
||||
},
|
||||
|
||||
// Quoted string with escaped apostrophe
|
||||
{
|
||||
in: `count:42 name: "HOLIDAY - New Year\'s Day"`,
|
||||
in: `count:42 name: "HOLIDAY - New Year\'s Day"`,
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Name: String("HOLIDAY - New Year's Day"),
|
||||
Count: Int32(42),
|
||||
Name: String("HOLIDAY - New Year's Day"),
|
||||
},
|
||||
},
|
||||
|
||||
// Quoted string with single quote
|
||||
{
|
||||
in: `count:42 name: 'Roger "The Ramster" Ramjet'`,
|
||||
in: `count:42 name: 'Roger "The Ramster" Ramjet'`,
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Name: String(`Roger "The Ramster" Ramjet`),
|
||||
Count: Int32(42),
|
||||
Name: String(`Roger "The Ramster" Ramjet`),
|
||||
},
|
||||
},
|
||||
|
||||
// Quoted string with all the accepted special characters from the C++ test
|
||||
{
|
||||
in: `count:42 name: ` + "\"\\\"A string with \\' characters \\n and \\r newlines and \\t tabs and \\001 slashes \\\\ and multiple spaces\"",
|
||||
in: `count:42 name: ` + "\"\\\"A string with \\' characters \\n and \\r newlines and \\t tabs and \\001 slashes \\\\ and multiple spaces\"",
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Name: String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces"),
|
||||
Count: Int32(42),
|
||||
Name: String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces"),
|
||||
},
|
||||
},
|
||||
|
||||
// Quoted string with quoted backslash
|
||||
{
|
||||
in: `count:42 name: "\\'xyz"`,
|
||||
in: `count:42 name: "\\'xyz"`,
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Name: String(`\'xyz`),
|
||||
Count: Int32(42),
|
||||
Name: String(`\'xyz`),
|
||||
},
|
||||
},
|
||||
|
||||
// Quoted string with UTF-8 bytes.
|
||||
{
|
||||
in: "count:42 name: '\303\277\302\201\xAB'",
|
||||
in: "count:42 name: '\303\277\302\201\xAB'",
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Name: String("\303\277\302\201\xAB"),
|
||||
Count: Int32(42),
|
||||
Name: String("\303\277\302\201\xAB"),
|
||||
},
|
||||
},
|
||||
|
||||
// Bad quoted string
|
||||
{
|
||||
in: `inner: < host: "\0" >` + "\n",
|
||||
err: `line 1.15: invalid quoted string "\0"`,
|
||||
in: `inner: < host: "\0" >` + "\n",
|
||||
err: `line 1.15: invalid quoted string "\0"`,
|
||||
},
|
||||
|
||||
// Number too large for int64
|
||||
{
|
||||
in: "count: 123456789012345678901",
|
||||
err: "line 1.7: invalid int32: 123456789012345678901",
|
||||
in: "count: 123456789012345678901",
|
||||
err: "line 1.7: invalid int32: 123456789012345678901",
|
||||
},
|
||||
|
||||
// Number too large for int32
|
||||
{
|
||||
in: "count: 1234567890123",
|
||||
err: "line 1.7: invalid int32: 1234567890123",
|
||||
in: "count: 1234567890123",
|
||||
err: "line 1.7: invalid int32: 1234567890123",
|
||||
},
|
||||
|
||||
// Number in hexadecimal
|
||||
{
|
||||
in: "count: 0x2beef",
|
||||
in: "count: 0x2beef",
|
||||
out: &MyMessage{
|
||||
Count: Int32(0x2beef),
|
||||
},
|
||||
@ -176,7 +176,7 @@ var unMarshalTextTests = []UnmarshalTextTest{
|
||||
|
||||
// Number in octal
|
||||
{
|
||||
in: "count: 024601",
|
||||
in: "count: 024601",
|
||||
out: &MyMessage{
|
||||
Count: Int32(024601),
|
||||
},
|
||||
@ -184,9 +184,9 @@ var unMarshalTextTests = []UnmarshalTextTest{
|
||||
|
||||
// Floating point number with "f" suffix
|
||||
{
|
||||
in: "count: 4 others:< weight: 17.0f >",
|
||||
in: "count: 4 others:< weight: 17.0f >",
|
||||
out: &MyMessage{
|
||||
Count: Int32(4),
|
||||
Count: Int32(4),
|
||||
Others: []*OtherMessage{
|
||||
{
|
||||
Weight: Float32(17),
|
||||
@ -197,69 +197,69 @@ var unMarshalTextTests = []UnmarshalTextTest{
|
||||
|
||||
// Floating point positive infinity
|
||||
{
|
||||
in: "count: 4 bigfloat: inf",
|
||||
in: "count: 4 bigfloat: inf",
|
||||
out: &MyMessage{
|
||||
Count: Int32(4),
|
||||
Bigfloat: Float64(math.Inf(1)),
|
||||
Count: Int32(4),
|
||||
Bigfloat: Float64(math.Inf(1)),
|
||||
},
|
||||
},
|
||||
|
||||
// Floating point negative infinity
|
||||
{
|
||||
in: "count: 4 bigfloat: -inf",
|
||||
in: "count: 4 bigfloat: -inf",
|
||||
out: &MyMessage{
|
||||
Count: Int32(4),
|
||||
Bigfloat: Float64(math.Inf(-1)),
|
||||
Count: Int32(4),
|
||||
Bigfloat: Float64(math.Inf(-1)),
|
||||
},
|
||||
},
|
||||
|
||||
// Number too large for float32
|
||||
{
|
||||
in: "others:< weight: 12345678901234567890123456789012345678901234567890 >",
|
||||
err: "line 1.17: invalid float32: 12345678901234567890123456789012345678901234567890",
|
||||
in: "others:< weight: 12345678901234567890123456789012345678901234567890 >",
|
||||
err: "line 1.17: invalid float32: 12345678901234567890123456789012345678901234567890",
|
||||
},
|
||||
|
||||
// Number posing as a quoted string
|
||||
{
|
||||
in: `inner: < host: 12 >` + "\n",
|
||||
err: `line 1.15: invalid string: 12`,
|
||||
in: `inner: < host: 12 >` + "\n",
|
||||
err: `line 1.15: invalid string: 12`,
|
||||
},
|
||||
|
||||
// Quoted string posing as int32
|
||||
{
|
||||
in: `count: "12"`,
|
||||
err: `line 1.7: invalid int32: "12"`,
|
||||
in: `count: "12"`,
|
||||
err: `line 1.7: invalid int32: "12"`,
|
||||
},
|
||||
|
||||
// Quoted string posing a float32
|
||||
{
|
||||
in: `others:< weight: "17.4" >`,
|
||||
err: `line 1.17: invalid float32: "17.4"`,
|
||||
in: `others:< weight: "17.4" >`,
|
||||
err: `line 1.17: invalid float32: "17.4"`,
|
||||
},
|
||||
|
||||
// Enum
|
||||
{
|
||||
in: `count:42 bikeshed: BLUE`,
|
||||
in: `count:42 bikeshed: BLUE`,
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Bikeshed: MyMessage_BLUE.Enum(),
|
||||
Count: Int32(42),
|
||||
Bikeshed: MyMessage_BLUE.Enum(),
|
||||
},
|
||||
},
|
||||
|
||||
// Repeated field
|
||||
{
|
||||
in: `count:42 pet: "horsey" pet:"bunny"`,
|
||||
in: `count:42 pet: "horsey" pet:"bunny"`,
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Pet: []string{"horsey", "bunny"},
|
||||
Count: Int32(42),
|
||||
Pet: []string{"horsey", "bunny"},
|
||||
},
|
||||
},
|
||||
|
||||
// Repeated message with/without colon and <>/{}
|
||||
{
|
||||
in: `count:42 others:{} others{} others:<> others:{}`,
|
||||
in: `count:42 others:{} others{} others:<> others:{}`,
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Count: Int32(42),
|
||||
Others: []*OtherMessage{
|
||||
{},
|
||||
{},
|
||||
@ -271,9 +271,9 @@ var unMarshalTextTests = []UnmarshalTextTest{
|
||||
|
||||
// Missing colon for inner message
|
||||
{
|
||||
in: `count:42 inner < host: "cauchy.syd" >`,
|
||||
in: `count:42 inner < host: "cauchy.syd" >`,
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Count: Int32(42),
|
||||
Inner: &InnerMessage{
|
||||
Host: String("cauchy.syd"),
|
||||
},
|
||||
@ -282,33 +282,33 @@ var unMarshalTextTests = []UnmarshalTextTest{
|
||||
|
||||
// Missing colon for string field
|
||||
{
|
||||
in: `name "Dave"`,
|
||||
err: `line 1.5: expected ':', found "\"Dave\""`,
|
||||
in: `name "Dave"`,
|
||||
err: `line 1.5: expected ':', found "\"Dave\""`,
|
||||
},
|
||||
|
||||
// Missing colon for int32 field
|
||||
{
|
||||
in: `count 42`,
|
||||
err: `line 1.6: expected ':', found "42"`,
|
||||
in: `count 42`,
|
||||
err: `line 1.6: expected ':', found "42"`,
|
||||
},
|
||||
|
||||
// Missing required field
|
||||
{
|
||||
in: ``,
|
||||
err: `line 1.0: message testdata.MyMessage missing required field "count"`,
|
||||
in: ``,
|
||||
err: `line 1.0: message testdata.MyMessage missing required field "count"`,
|
||||
},
|
||||
|
||||
// Repeated non-repeated field
|
||||
{
|
||||
in: `name: "Rob" name: "Russ"`,
|
||||
err: `line 1.12: non-repeated field "name" was repeated`,
|
||||
in: `name: "Rob" name: "Russ"`,
|
||||
err: `line 1.12: non-repeated field "name" was repeated`,
|
||||
},
|
||||
|
||||
// Group
|
||||
{
|
||||
in: `count: 17 SomeGroup { group_field: 12 }`,
|
||||
in: `count: 17 SomeGroup { group_field: 12 }`,
|
||||
out: &MyMessage{
|
||||
Count: Int32(17),
|
||||
Count: Int32(17),
|
||||
Somegroup: &MyMessage_SomeGroup{
|
||||
GroupField: Int32(12),
|
||||
},
|
||||
@ -317,18 +317,18 @@ var unMarshalTextTests = []UnmarshalTextTest{
|
||||
|
||||
// Semicolon between fields
|
||||
{
|
||||
in: `count:3;name:"Calvin"`,
|
||||
in: `count:3;name:"Calvin"`,
|
||||
out: &MyMessage{
|
||||
Count: Int32(3),
|
||||
Name: String("Calvin"),
|
||||
Count: Int32(3),
|
||||
Name: String("Calvin"),
|
||||
},
|
||||
},
|
||||
// Comma between fields
|
||||
{
|
||||
in: `count:4,name:"Ezekiel"`,
|
||||
in: `count:4,name:"Ezekiel"`,
|
||||
out: &MyMessage{
|
||||
Count: Int32(4),
|
||||
Name: String("Ezekiel"),
|
||||
Count: Int32(4),
|
||||
Name: String("Ezekiel"),
|
||||
},
|
||||
},
|
||||
|
||||
@ -363,25 +363,25 @@ var unMarshalTextTests = []UnmarshalTextTest{
|
||||
` >` +
|
||||
`>`,
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Name: String("Dave"),
|
||||
Quote: String(`"I didn't want to go."`),
|
||||
Pet: []string{"bunny", "kitty", "horsey"},
|
||||
Count: Int32(42),
|
||||
Name: String("Dave"),
|
||||
Quote: String(`"I didn't want to go."`),
|
||||
Pet: []string{"bunny", "kitty", "horsey"},
|
||||
Inner: &InnerMessage{
|
||||
Host: String("footrest.syd"),
|
||||
Port: Int32(7001),
|
||||
Connected: Bool(true),
|
||||
Host: String("footrest.syd"),
|
||||
Port: Int32(7001),
|
||||
Connected: Bool(true),
|
||||
},
|
||||
Others: []*OtherMessage{
|
||||
{
|
||||
Key: Int64(3735928559),
|
||||
Value: []byte{0x1, 'A', '\a', '\f'},
|
||||
Key: Int64(3735928559),
|
||||
Value: []byte{0x1, 'A', '\a', '\f'},
|
||||
},
|
||||
{
|
||||
Weight: Float32(58.9),
|
||||
Weight: Float32(58.9),
|
||||
Inner: &InnerMessage{
|
||||
Host: String("lesha.mtv"),
|
||||
Port: Int32(8002),
|
||||
Host: String("lesha.mtv"),
|
||||
Port: Int32(8002),
|
||||
},
|
||||
},
|
||||
},
|
@ -39,42 +39,42 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.google.com/p/goprotobuf/proto"
|
||||
"github.com/coreos/etcd/third_party/code.google.com/p/goprotobuf/proto"
|
||||
|
||||
pb "./testdata"
|
||||
)
|
||||
|
||||
func newTestMessage() *pb.MyMessage {
|
||||
msg := &pb.MyMessage{
|
||||
Count: proto.Int32(42),
|
||||
Name: proto.String("Dave"),
|
||||
Quote: proto.String(`"I didn't want to go."`),
|
||||
Pet: []string{"bunny", "kitty", "horsey"},
|
||||
Count: proto.Int32(42),
|
||||
Name: proto.String("Dave"),
|
||||
Quote: proto.String(`"I didn't want to go."`),
|
||||
Pet: []string{"bunny", "kitty", "horsey"},
|
||||
Inner: &pb.InnerMessage{
|
||||
Host: proto.String("footrest.syd"),
|
||||
Port: proto.Int32(7001),
|
||||
Connected: proto.Bool(true),
|
||||
Host: proto.String("footrest.syd"),
|
||||
Port: proto.Int32(7001),
|
||||
Connected: proto.Bool(true),
|
||||
},
|
||||
Others: []*pb.OtherMessage{
|
||||
{
|
||||
Key: proto.Int64(0xdeadbeef),
|
||||
Value: []byte{1, 65, 7, 12},
|
||||
Key: proto.Int64(0xdeadbeef),
|
||||
Value: []byte{1, 65, 7, 12},
|
||||
},
|
||||
{
|
||||
Weight: proto.Float32(6.022),
|
||||
Weight: proto.Float32(6.022),
|
||||
Inner: &pb.InnerMessage{
|
||||
Host: proto.String("lesha.mtv"),
|
||||
Port: proto.Int32(8002),
|
||||
Host: proto.String("lesha.mtv"),
|
||||
Port: proto.Int32(8002),
|
||||
},
|
||||
},
|
||||
},
|
||||
Bikeshed: pb.MyMessage_BLUE.Enum(),
|
||||
Bikeshed: pb.MyMessage_BLUE.Enum(),
|
||||
Somegroup: &pb.MyMessage_SomeGroup{
|
||||
GroupField: proto.Int32(8),
|
||||
},
|
||||
// One normally wouldn't do this.
|
||||
// This is an undeclared tag 13, as a varint (wire type 0) with value 4.
|
||||
XXX_unrecognized: []byte{13<<3 | 0, 4},
|
||||
XXX_unrecognized: []byte{13<<3 | 0, 4},
|
||||
}
|
||||
ext := &pb.Ext{
|
||||
Data: proto.String("Big gobs for big rats"),
|
||||
@ -250,8 +250,8 @@ func TestCompactText(t *testing.T) {
|
||||
|
||||
func TestStringEscaping(t *testing.T) {
|
||||
testCases := []struct {
|
||||
in *pb.Strings
|
||||
out string
|
||||
in *pb.Strings
|
||||
out string
|
||||
}{
|
||||
{
|
||||
// Test data from C++ test (TextFormatTest.StringEscape).
|
||||
@ -299,8 +299,8 @@ func TestStringEscaping(t *testing.T) {
|
||||
// This is a proxy for something like a nearly-full or imminently-failing disk,
|
||||
// or a network connection that is about to die.
|
||||
type limitedWriter struct {
|
||||
b bytes.Buffer
|
||||
limit int
|
||||
b bytes.Buffer
|
||||
limit int
|
||||
}
|
||||
|
||||
var outOfSpace = errors.New("proto: insufficient space")
|
||||
@ -337,8 +337,8 @@ func TestMarshalTextFailing(t *testing.T) {
|
||||
|
||||
func TestFloats(t *testing.T) {
|
||||
tests := []struct {
|
||||
f float64
|
||||
want string
|
||||
f float64
|
||||
want string
|
||||
}{
|
||||
{0, "0"},
|
||||
{4.7, "4.7"},
|
@ -4,39 +4,39 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/coreos/etcd/third_party/github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
type tomlConfig struct {
|
||||
Title string
|
||||
Owner ownerInfo
|
||||
DB database `toml:"database"`
|
||||
Servers map[string]server
|
||||
Clients clients
|
||||
Title string
|
||||
Owner ownerInfo
|
||||
DB database `toml:"database"`
|
||||
Servers map[string]server
|
||||
Clients clients
|
||||
}
|
||||
|
||||
type ownerInfo struct {
|
||||
Name string
|
||||
Org string `toml:"organization"`
|
||||
Bio string
|
||||
DOB time.Time
|
||||
Name string
|
||||
Org string `toml:"organization"`
|
||||
Bio string
|
||||
DOB time.Time
|
||||
}
|
||||
|
||||
type database struct {
|
||||
Server string
|
||||
Ports []int
|
||||
ConnMax int `toml:"connection_max"`
|
||||
Enabled bool
|
||||
Server string
|
||||
Ports []int
|
||||
ConnMax int `toml:"connection_max"`
|
||||
Enabled bool
|
||||
}
|
||||
|
||||
type server struct {
|
||||
IP string
|
||||
DC string
|
||||
IP string
|
||||
DC string
|
||||
}
|
||||
|
||||
type clients struct {
|
||||
Data [][]interface{}
|
||||
Hosts []string
|
||||
Data [][]interface{}
|
||||
Hosts []string
|
||||
}
|
||||
|
||||
func main() {
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user