Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
beaulian committed Nov 27, 2017
1 parent 60bcbc0 commit 60af09e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 17 deletions.
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM daocloud.io/library/ubuntu:16.04

MAINTAINER Jiawen Guan <[email protected]>

WORKDIR /pentadb

ADD . /pentadb

ENV GOPATH=/pentadb

RUN apt update && apt install golang -y

RUN chmod +x /pentadb/entry.sh

CMD . /pentadb/entry.sh
24 changes: 24 additions & 0 deletions entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

port=${PENTADB_PORT:-'4567'}
path=${PENTADB_PATH:-'/tmp/pentadb'}

base_dir="/pentadb/src/"

packages=(
"github.com/golang/snappy",
"github.com/satori/go.uuid",
"github.com/syndtr/goleveldb/leveldb"
)

# delete invalid packages
# then download the newer packages
for package in packages
do
rm -r ${base_dir}${package}
go get ${package}
done

# exec
cd /pentadb/src/github.com/shenaishiren/pentadb/commands
go run server.go -p ${port} -a ${path}
21 changes: 11 additions & 10 deletions src/github.com/shenaishiren/pentadb/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import (
"testing"
)

//func TestNewClient_NoEnoughNodes(t *testing.T) {
// var nodes = []string{"127.0.0.1:5000"}
// var weights = map[string]int{"127.0.0.1:5000": 1}
// if _, err := NewClient(nodes, weights, 3); err != nil {
// t.Errorf(err.Error())
// }
//}
func TestNewClient_NoEnoughNodes(t *testing.T) {
var nodes = []string{"127.0.0.1:5000"}
if _, err := NewClient(nodes, nil, 3); err != nil {
t.Errorf(err.Error())
}
}

func TestNewClient_WrongReplicas(t *testing.T) {
var nodes = []string{"127.0.0.1:5000"}
var weights = map[string]int{"127.0.0.1:5000": 1}
if _, err := NewClient(nodes, weights, 3); err != nil {
var nodes = []string{
"127.0.0.1:5000",
"10.19.126.55:4567",
}
if _, err := NewClient(nodes, nil, 3); err != nil {
t.Errorf(err.Error())
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/github.com/shenaishiren/pentadb/client/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ func NewNode(ipaddr string) *Node {
}
// check whether this node is connectable or not
// TODO
//proxy := NewNodeProxy(node)
//if proxy == nil {
// return nil
//}
//node.Proxy = proxy
proxy := NewNodeProxy(node)
if proxy == nil {
return nil
}
node.Proxy = proxy
return node
}
6 changes: 5 additions & 1 deletion src/github.com/shenaishiren/pentadb/commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func (s *Server) listen(port string, path string) error {
return nil
}


func main() {
var (
help bool
Expand All @@ -101,6 +100,11 @@ func main() {
flag.StringVar(&port, "p", "4567", "The port to listen on (default: 4567)")
flag.StringVar(&path, "a", opt.DeafultPath, "The path to use for the LevelDB store")

// change default usage
flag.Usage = func() {
fmt.Println(helpPrompt)
}

// run
flag.Parse()

Expand Down
2 changes: 1 addition & 1 deletion src/github.com/shenaishiren/pentadb/opt/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package opt
import "time"

const (
DefaultReplicas = 0 // default replicas for raft algorithm
DefaultReplicas = 1 // default replicas for raft algorithm
DeafultPath = "/tmp/pentadb" // default path for levelDB
DefaultProtocol = "tcp"
DefaultTimeout = 3 * time.Second
Expand Down

0 comments on commit 60af09e

Please sign in to comment.