Update godeps with 0.1.2

This commit is contained in:
Mitchell Hashimoto 2015-05-11 11:30:01 -07:00
parent afbe744629
commit 756fcba604
14 changed files with 165 additions and 108 deletions

18
Godeps/Godeps.json generated
View File

@ -48,8 +48,8 @@
},
{
"ImportPath": "github.com/hashicorp/consul/api",
"Comment": "v0.5.0-199-g205af6b",
"Rev": "205af6ba750b88863e6ee50c7c3d19edc180a6f6"
"Comment": "v0.5.0-253-g7062ecc",
"Rev": "7062ecc50fef9307e532c4a188da7ce1dd759dde"
},
{
"ImportPath": "github.com/hashicorp/errwrap",
@ -86,7 +86,7 @@
},
{
"ImportPath": "github.com/mitchellh/cli",
"Rev": "afc399c273e70173826fb6f518a48edff23fe897"
"Rev": "6cc8bc522243675a2882b81662b0b0d2e04b99c9"
},
{
"ImportPath": "github.com/mitchellh/copystructure",
@ -109,6 +109,10 @@
"Comment": "v2.0.1-6-g44cb478",
"Rev": "44cb4788b2ec3c3d158dd3d1b50aba7d66f4b59a"
},
{
"ImportPath": "github.com/samuel/go-zookeeper/zk",
"Rev": "d0e0d8e11f318e000a8cc434616d69e329edc374"
},
{
"ImportPath": "github.com/vanackere/asn1-ber",
"Rev": "295c7b21db5d9525ad959e3382610f3aff029663"
@ -123,19 +127,15 @@
},
{
"ImportPath": "golang.org/x/crypto/ssh/terminal",
"Rev": "c84e1f8e3a7e322d497cd16c0e8a13c7e127baf3"
"Rev": "59435533c88bd0b1254c738244da1fe96b59d05d"
},
{
"ImportPath": "golang.org/x/net/context",
"Rev": "ff8eb9a34a5cbb9941ffc6f84a19a8014c2646ad"
"Rev": "a8c61998a557a37435f719980da368469c10bfed"
},
{
"ImportPath": "golang.org/x/oauth2",
"Rev": "ec6d5d770f531108a6464462b2201b74fcd09314"
},
{
"ImportPath": "github.com/samuel/go-zookeeper/zk",
"Rev": "d0e0d8e11f318e000a8cc434616d69e329edc374"
}
]
}

View File

@ -165,14 +165,18 @@ WAIT:
if pair != nil && pair.Flags != LockFlagValue {
return nil, ErrLockConflict
}
locked := false
if pair != nil && pair.Session == l.lockSession {
goto HELD
}
if pair != nil && pair.Session != "" {
qOpts.WaitIndex = meta.LastIndex
goto WAIT
}
// Try to acquire the lock
lockEnt := l.lockEntry(l.lockSession)
locked, _, err := kv.Acquire(lockEnt, nil)
pair = l.lockEntry(l.lockSession)
locked, _, err = kv.Acquire(pair, nil)
if err != nil {
return nil, fmt.Errorf("failed to acquire lock: %v", err)
}
@ -187,6 +191,7 @@ WAIT:
}
}
HELD:
// Watch to ensure we maintain leadership
leaderCh := make(chan struct{})
go l.monitorLock(l.lockSession, leaderCh)

View File

@ -287,3 +287,70 @@ func TestLock_Conflict(t *testing.T) {
t.Fatalf("err: %v", err)
}
}
func TestLock_ReclaimLock(t *testing.T) {
c, s := makeClient(t)
defer s.Stop()
session, _, err := c.Session().Create(&SessionEntry{}, nil)
if err != nil {
t.Fatalf("err: %v", err)
}
lock, err := c.LockOpts(&LockOptions{Key: "test/lock", Session: session})
if err != nil {
t.Fatalf("err: %v", err)
}
// Should work
leaderCh, err := lock.Lock(nil)
if err != nil {
t.Fatalf("err: %v", err)
}
if leaderCh == nil {
t.Fatalf("not leader")
}
defer lock.Unlock()
l2, err := c.LockOpts(&LockOptions{Key: "test/lock", Session: session})
if err != nil {
t.Fatalf("err: %v", err)
}
reclaimed := make(chan (<-chan struct{}), 1)
go func() {
l2Ch, err := l2.Lock(nil)
if err != nil {
t.Fatalf("not locked: %v", err)
}
reclaimed <- l2Ch
}()
// Should reclaim the lock
var leader2Ch <-chan struct{}
select {
case leader2Ch = <-reclaimed:
case <-time.After(time.Second):
t.Fatalf("should have locked")
}
// unlock should work
err = l2.Unlock()
if err != nil {
t.Fatalf("err: %v", err)
}
//Both locks should see the unlock
select {
case <-leader2Ch:
case <-time.After(time.Second):
t.Fatalf("should not be leader")
}
select {
case <-leaderCh:
case <-time.After(time.Second):
t.Fatalf("should not be leader")
}
}

View File

@ -8,6 +8,8 @@ import (
"os"
"os/signal"
"strings"
"golang.org/x/crypto/ssh/terminal"
)
// Ui is an interface for interacting with the terminal, or "interface"
@ -18,6 +20,10 @@ type Ui interface {
// returned as the given string, or an error.
Ask(string) (string, error)
// AskSecret asks the user for input using the given query, but does not echo
// the keystrokes to the terminal.
AskSecret(string) (string, error)
// Output is called for normal standard output.
Output(string)
@ -45,6 +51,14 @@ type BasicUi struct {
}
func (u *BasicUi) Ask(query string) (string, error) {
return u.ask(query, false)
}
func (u *BasicUi) AskSecret(query string) (string, error) {
return u.ask(query, true)
}
func (u *BasicUi) ask(query string, secret bool) (string, error) {
if _, err := fmt.Fprint(u.Writer, query+" "); err != nil {
return "", err
}
@ -59,8 +73,17 @@ func (u *BasicUi) Ask(query string) (string, error) {
errCh := make(chan error, 1)
lineCh := make(chan string, 1)
go func() {
r := bufio.NewReader(u.Reader)
line, err := r.ReadString('\n')
var line string
var err error
stdin := int(os.Stdin.Fd())
if secret && terminal.IsTerminal(stdin) {
var lineBytes []byte
lineBytes, err = terminal.ReadPassword(stdin)
line = string(lineBytes)
} else {
r := bufio.NewReader(u.Reader)
line, err = r.ReadString('\n')
}
if err != nil {
errCh <- err
return
@ -108,12 +131,13 @@ func (u *BasicUi) Warn(message string) {
// PrefixedUi is an implementation of Ui that prefixes messages.
type PrefixedUi struct {
AskPrefix string
OutputPrefix string
InfoPrefix string
ErrorPrefix string
WarnPrefix string
Ui Ui
AskPrefix string
AskSecretPrefix string
OutputPrefix string
InfoPrefix string
ErrorPrefix string
WarnPrefix string
Ui Ui
}
func (u *PrefixedUi) Ask(query string) (string, error) {
@ -124,6 +148,14 @@ func (u *PrefixedUi) Ask(query string) (string, error) {
return u.Ui.Ask(query)
}
func (u *PrefixedUi) AskSecret(query string) (string, error) {
if query != "" {
query = fmt.Sprintf("%s%s", u.AskSecretPrefix, query)
}
return u.Ui.AskSecret(query)
}
func (u *PrefixedUi) Error(message string) {
if message != "" {
message = fmt.Sprintf("%s%s", u.ErrorPrefix, message)

View File

@ -35,6 +35,10 @@ func (u *ColoredUi) Ask(query string) (string, error) {
return u.Ui.Ask(u.colorize(query, u.OutputColor))
}
func (u *ColoredUi) AskSecret(query string) (string, error) {
return u.Ui.AskSecret(u.colorize(query, u.OutputColor))
}
func (u *ColoredUi) Output(message string) {
u.Ui.Output(u.colorize(message, u.OutputColor))
}

View File

@ -18,6 +18,13 @@ func (u *ConcurrentUi) Ask(query string) (string, error) {
return u.Ui.Ask(query)
}
func (u *ConcurrentUi) AskSecret(query string) (string, error) {
u.l.Lock()
defer u.l.Unlock()
return u.Ui.AskSecret(query)
}
func (u *ConcurrentUi) Error(message string) {
u.l.Lock()
defer u.l.Unlock()

View File

@ -29,6 +29,10 @@ func (u *MockUi) Ask(query string) (string, error) {
return result, nil
}
func (u *MockUi) AskSecret(query string) (string, error) {
return u.Ask(query)
}
func (u *MockUi) Error(message string) {
u.once.Do(u.init)

View File

@ -37,6 +37,33 @@ func TestBasicUi_Ask(t *testing.T) {
}
}
func TestBasicUi_AskSecret(t *testing.T) {
in_r, in_w := io.Pipe()
defer in_r.Close()
defer in_w.Close()
writer := new(bytes.Buffer)
ui := &BasicUi{
Reader: in_r,
Writer: writer,
}
go in_w.Write([]byte("foo bar\nbaz\n"))
result, err := ui.AskSecret("Name?")
if err != nil {
t.Fatalf("err: %s", err)
}
if writer.String() != "Name? " {
t.Fatalf("bad: %#v", writer.String())
}
if result != "foo bar" {
t.Fatalf("bad: %#v", result)
}
}
func TestBasicUi_Error(t *testing.T) {
writer := new(bytes.Buffer)
ui := &BasicUi{Writer: writer}

View File

@ -1 +0,0 @@
.DS_Store

View File

@ -1,21 +0,0 @@
language: go
go:
- 1.4
sudo: false
branches:
only:
- master
before_install:
- wget http://apache.claz.org/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
- tar -zxvf zookeeper*tar.gz
script:
- go build ./...
- go fmt ./...
- go get golang.org/x/tools/cmd/vet
- go vet ./...
- go test -i -race ./...
- go test -v -race ./...

View File

@ -1,25 +0,0 @@
Copyright (c) 2013, Samuel Stauffer <samuel@descolada.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,11 +0,0 @@
Native Go Zookeeper Client Library
===================================
[![Build Status](https://travis-ci.org/samuel/go-zookeeper.png)](https://travis-ci.org/samuel/go-zookeeper)
Documentation: http://godoc.org/github.com/samuel/go-zookeeper/zk
License
-------
3-clause BSD. See LICENSE file.

View File

@ -1,22 +0,0 @@
package main
import (
"fmt"
"time"
"github.com/samuel/go-zookeeper/zk"
)
func main() {
c, _, err := zk.Connect([]string{"127.0.0.1"}, time.Second) //*10)
if err != nil {
panic(err)
}
children, stat, ch, err := c.ChildrenW("/")
if err != nil {
panic(err)
}
fmt.Printf("%+v %+v\n", children, stat)
e := <-ch
fmt.Printf("%+v\n", e)
}

View File

@ -1,9 +0,0 @@
package main
import (
"github.com/samuel/go-zookeeper/zk"
)
func main() {
zk.StartTracer("127.0.0.1:2182", "127.0.0.1:2181")
}