Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test examples/ping-*/README.md #157

Merged
merged 11 commits into from
Jul 6, 2016
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ hosts.json
coverage.out
lint.log
/vendor/
/_venv/
README.md.err
tick-cluster.log
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ go:
- 1.6
- 1.5

sudo: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is sudo: false required? IIRC, this is the default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftovers from development process. Good catch, removed.

addons:
apt:
packages:
- python-virtualenv

install:
- go get -u github.com/Masterminds/glide
- go get github.com/axw/gocov/gocov
Expand All @@ -11,17 +17,22 @@ install:
- go get github.com/golang/lint/golint
- ./scripts/travis/get-thrift.sh
- ./scripts/travis/get-thrift-gen.sh
- ./scripts/travis/get-cram.sh
- npm install -g tcurl
- make setup

env:
- RUN="make lint"
- RUN="make test-unit"
- RUN="make test-integration"
- RUN="make test-race"
- RUN="make test-examples"

matrix:
allow_failures:
- env: RUN="make test-race"
- env: RUN="make test-examples"

fast_finish: true

script:
Expand All @@ -33,3 +44,4 @@ after_success:
cache:
directories:
- $HOME/.glide/cache
- _venv
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,15 @@ test-unit:
go generate $(NOVENDOR)
test/go-test-prettify $(NOVENDOR)

test-examples: _venv/bin/cram vendor
. _venv/bin/activate && ./test/run-example-tests

test-race:
go generate $(NOVENDOR)
test/go-test-prettify -race $(NOVENDOR)

_venv/bin/cram:
./scripts/travis/get-cram.sh

testpop: clean
go build ./scripts/testpop/
38 changes: 16 additions & 22 deletions examples/ping-json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,31 @@ A simple ping-pong service implementation that that integrates ringpop to forwar
# Running the example

All commands are relative to this directory:
```bash
cd examples/ping-json
```

Build the example binary:
```bash
go build
```
$ cd ${TESTDIR} # examples/ping-json
$ go build

Start a custer of 5 nodes using [tick-cluster][1]:
```bash
tick-cluster.js -n 5 ping-json
```

$ tick-cluster.js --interface=127.0.0.1 -n 5 ping-json &> tick-cluster.log &
$ sleep 5

Lookup the node `my_key` key belongs to using [tcurl][2]:
```bash
$ tcurl ringpop -P hosts.json /admin/lookup '{"key": "my_key"}'
{"ok":true,"head":null,"body":{"dest":"127.0.0.1:3002"},"headers":{"as":"json"},"trace":"88c8217f8ce220fd"}
```

$ tcurl ringpop -P hosts.json /admin/lookup '{"key": "my_key"}'
{"ok":true,"head":null,"body":{"dest":"127.0.0.1:300?"},"headers":{"as":"json"},"trace":"*"} (glob)

Call the `/ping` endpoint (multiple times) and see the request being forwarded. Each request is sent to a random node in the cluster because of the `-P hosts.json` argument--but is always handled by the node owning the key. This can be seen in the `from` field of the response:
```bash
$ tcurl pingchannel -P hosts.json /ping '{"key": "my_key"}'
{"ok":true,"head":null,"body":{"message":"Hello, world!","from":"127.0.0.1:3002","p":""},"headers":{"as":"json"},"trace":"825d0c582c758aa5"}
```

$ tcurl pingchannel -P hosts.json /ping '{"key": "my_key"}'
{"ok":true,"head":null,"body":{"message":"Hello, world!","from":"127.0.0.1:300?","p":""},"headers":{"as":"json"},"trace":"*"} (glob)

Optionally, set the `p` header. This value will be forwarded together with the request body to the node owning the key. Its value is returned in the response body in the `pheader` field:
```bash
$ tcurl pingchannel -P hosts.json /ping '{"key": "my_key"}' --headers '{"p": "my_header"}'
{"ok":true,"head":null,"body":{"message":"Hello, world!","from":"127.0.0.1:3002","pheader":"my_header"},"headers":{"as":"json"},"trace":"36b2a16b57b92945"}
```

$ tcurl pingchannel -P hosts.json /ping '{"key": "my_key"}' --headers '{"p": "my_header"}'
{"ok":true,"head":null,"body":{"message":"Hello, world!","from":"127.0.0.1:300?","pheader":"my_header"},"headers":{"as":"json"},"trace":"*"} (glob)

$ kill %1

[1]:https://github.com/uber/ringpop-common/
[2]:https://github.com/uber/tcurl
44 changes: 20 additions & 24 deletions examples/ping-thrift-gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,38 @@ This example it's different than the others because it uses ringpop specific gen
# Running the example

All commands are relative to this directory:
```bash
cd examples/ping-thrift-gen
```

$ cd ${TESTDIR} # examples/ping-thrift-gen

(optional, the files are already included) Generate the thrift code:
```bash
thrift-gen --generateThrift --outputDir gen-go --inputFile ping.thrift --template github.com/uber/ringpop-go/ringpop.thrift-gen
```

$ thrift-gen --generateThrift --outputDir gen-go --inputFile ping.thrift --template github.com/uber/ringpop-go/ringpop.thrift-gen

Build the example binary:
```bash
go build
```

$ go build

Start a custer of 5 nodes using [tick-cluster][1]:
```bash
tick-cluster.js -n 5 ping-thrift-gen
```

$ tick-cluster.js --interface=127.0.0.1 -n 5 ping-thrift-gen &> tick-cluster.log &
$ sleep 5

Lookup the node `my_key` key belongs to using [tcurl][2]:
```bash
$ tcurl ringpop -P hosts.json /admin/lookup '{"key": "my_key"}'
{"ok":true,"head":null,"body":{"dest":"127.0.0.1:3002"},"headers":{"as":"json"},"trace":"7a612e506428cec2"}
```

$ tcurl ringpop -P hosts.json /admin/lookup '{"key": "my_key"}'
{"ok":true,"head":null,"body":{"dest":"127.0.0.1:300?"},"headers":{"as":"json"},"trace":"*"} (glob)

Call the `PingPongService::Ping` endpoint (multiple times) and see the request being forwarded. Each request is sent to a random node in the cluster because of the `-P hosts.json` argument--but is always handled by the node owning the key. This can be seen in the `from` field of the response:
```bash
$ tcurl pingchannel -P hosts.json --thrift ./ping.thrift PingPongService::Ping '{"request": {"key": "my_key"}}'
{"ok":true,"head":{},"body":{"message":"Hello, world!","from_":"127.0.0.1:3002","pheader":""},"headers":{"as":"thrift"},"trace":"650cbf0656e215e2"}
```

$ tcurl pingchannel -P hosts.json --thrift ./ping.thrift PingPongService::Ping '{"request": {"key": "my_key"}}'
{"ok":true,"head":{},"body":{"message":"Hello, world!","from_":"127.0.0.1:300?","pheader":""},"headers":{"as":"thrift"},"trace":"*"} (glob)

Optionally, set the `p` header. This value will be forwarded together with the request body to the node owning the key. Its value is returned in the response body in the `pheader` field:
```bash
$ tcurl pingchannel -P hosts.json /ping '{"key": "my_key"}' --headers '{"p": "my_header"}'
{"ok":true,"head":{},"body":{"message":"Hello, world!","from_":"127.0.0.1:3002","pheader":"my_header"},"headers":{"as":"thrift"},"trace":"b5526f9625a88347"}
```

$ tcurl pingchannel -P hosts.json /ping '{"key": "my_key"}' --headers '{"p": "my_header"}'
{"ok":true,"head":{},"body":{"message":"Hello, world!","from_":"127.0.0.1:300?","pheader":"my_header"},"headers":{"as":"thrift"},"trace":"*"} (glob)

$ kill %1

[1]:https://github.com/uber/ringpop-common/
[2]:https://github.com/uber/tcurl
45 changes: 21 additions & 24 deletions examples/ping-thrift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,39 @@ A simple ping-pong service implementation that that integrates ringpop to forwar
# Running the example

All commands are relative to this directory:
```bash
cd examples/ping-thrift
```

$ cd ${TESTDIR} # examples/ping-thrift

(optional, the files are already included) Generate the thrift code:
```bash
thrift-gen --generateThrift --outputDir gen-go --inputFile ping.thrift
```

$ thrift-gen --generateThrift --outputDir gen-go --inputFile ping.thrift

Build the example binary:
```bash
go build
```

$ go build


Start a custer of 5 nodes using [tick-cluster][1]:
```bash
tick-cluster.js -n 5 ping-thrift
```

$ tick-cluster.js --interface=127.0.0.1 -n 5 ping-thrift &> tick-cluster.log &
$ sleep 5

Lookup the node `my_key` key belongs to using [tcurl][2]:
```bash
$ tcurl ringpop -P hosts.json /admin/lookup '{"key": "my_key"}'
{"ok":true,"head":null,"body":{"dest":"127.0.0.1:3002"},"headers":{"as":"json"},"trace":"7a612e506428cec2"}
```

$ tcurl ringpop -P hosts.json /admin/lookup '{"key": "my_key"}'
{"ok":true,"head":null,"body":{"dest":"127.0.0.1:300?"},"headers":{"as":"json"},"trace":"*"} (glob)

Call the `PingPongService::Ping` endpoint (multiple times) and see the request being forwarded. Each request is sent to a random node in the cluster because of the `-P hosts.json` argument--but is always handled by the node owning the key. This can be seen in the `from` field of the response:
```bash
$ tcurl pingchannel -P hosts.json --thrift ./ping.thrift PingPongService::Ping '{"request": {"key": "my_key"}}'
{"ok":true,"head":{},"body":{"message":"Hello, world!","from_":"127.0.0.1:3002","pheader":""},"headers":{"as":"thrift"},"trace":"650cbf0656e215e2"}
```

$ tcurl pingchannel -P hosts.json --thrift ./ping.thrift PingPongService::Ping '{"request": {"key": "my_key"}}'
{"ok":true,"head":{},"body":{"message":"Hello, world!","from_":"127.0.0.1:300?","pheader":""},"headers":{"as":"thrift"},"trace":"*"} (glob)

Optionally, set the `p` header. This value will be forwarded together with the request body to the node owning the key. Its value is returned in the response body in the `pheader` field:
```bash
$ tcurl pingchannel -P hosts.json /ping '{"key": "my_key"}' --headers '{"p": "my_header"}'
{"ok":true,"head":{},"body":{"message":"Hello, world!","from_":"127.0.0.1:3002","pheader":"my_header"},"headers":{"as":"thrift"},"trace":"b5526f9625a88347"}
```

$ tcurl pingchannel -P hosts.json /ping '{"key": "my_key"}' --headers '{"p": "my_header"}'
{"ok":true,"head":{},"body":{"message":"Hello, world!","from_":"127.0.0.1:300?","pheader":"my_header"},"headers":{"as":"thrift"},"trace":"*"} (glob)

$ kill %1

[1]:https://github.com/uber/ringpop-common/
[2]:https://github.com/uber/tcurl
12 changes: 12 additions & 0 deletions scripts/travis/get-cram.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e

if [[ ! -f "_venv/bin/activate" ]]; then
virtualenv _venv
fi

. _venv/bin/activate

if [[ -z "$(which cram)" ]]; then
./_venv/bin/pip install cram
fi
47 changes: 47 additions & 0 deletions test/lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Common functions for test code

declare project_root="${0%/*}/.."
declare ringpop_common_dir="${0%/*}/ringpop-common"
declare ringpop_common_branch="master"

#
# Clones or updates the ringpop-common repository.
#
fetch-ringpop-common() {
if [ ! -e "$ringpop_common_dir" ]; then
run git clone --depth=1 https://github.com/uber/ringpop-common.git "$ringpop_common_dir" --branch "$ringpop_common_branch"
fi

run cd "$ringpop_common_dir"
#run git checkout latest version of $ringpop_common_branch
run git fetch origin "$ringpop_common_branch"
run git checkout "FETCH_HEAD"

run cd - >/dev/null

run cd "${ringpop_common_dir}/$1"
if [[ ! -d "node_modules" && ! -d "../node_modules" ]]; then
run npm install #>/dev/null
fi
run cd - >/dev/null
}

#
# Copy stdin to stdout but prefix each line with the specified string.
#
prefix() {
local _prefix=

[ -n "$1" ] && _prefix="[$1] "
while IFS= read -r -t 30 line; do
echo "${_prefix}${line}"
done
}

#
# Echos and runs the specified command.
#
run() {
echo "+ $@" >&2
"$@"
}
Loading