riak_test_server 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/ruby/riak_test_server/version.rb +3 -0
- data/ruby/riak_test_server.rb +110 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 21a506f0cbd9517f343ef7858722f568b553534e
|
4
|
+
data.tar.gz: a7daf07b12c6accc1a364863ec8658551e2a938c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 50466f16b873b69a60ff6bf1fb4cda921e63c2bdc580d867ff0a493c4349047ea1be830c6a0c0a30735ebe3d7688587cd32a753e441e76f8cc19c60859ac6d79
|
7
|
+
data.tar.gz: 60c907d88d571b98160e7129e5c3d4ca81bfae980a1c70a6a72defc45c51c3fefa72a1dc3d2df279e787dafdaec5294b50dcdf94bdcb7711a22c1eba28bb2fee
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Nathaniel Talbott
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Riak Test Server
|
2
|
+
|
3
|
+
Basho has (for good reasons) discontinued support for test servers in their
|
4
|
+
client libraries, but it turns out the critical functionality is built into Riak
|
5
|
+
regardless. This project wraps some drop in code (currently just Ruby) around a
|
6
|
+
Docker container that gives the same functionality and allows rapidly resetting
|
7
|
+
the Riak backend inbetween tests.
|
8
|
+
|
9
|
+
## Pre-requisites
|
10
|
+
|
11
|
+
* [docker](https://docs.docker.com/installation/)
|
12
|
+
* A working docker host environment (I like [dvm](https://github.com/fnichol/dvm) on OS X)
|
13
|
+
* A hostname of `docker` mapped to the IP of your container host (192.168.42.43 for dvm)
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile and `bundle`:
|
18
|
+
|
19
|
+
gem 'riak_test_server'
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install riak_test_server
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Setup
|
28
|
+
|
29
|
+
Near the top of `test_helper.rb` or the like:
|
30
|
+
|
31
|
+
```
|
32
|
+
require "riak_test_server"
|
33
|
+
RiakTestServer.setup
|
34
|
+
```
|
35
|
+
|
36
|
+
### Clearing
|
37
|
+
|
38
|
+
Wherever you want to clear out Riak, say in `setup`:
|
39
|
+
|
40
|
+
```
|
41
|
+
RiakTestServer.clear
|
42
|
+
```
|
43
|
+
|
44
|
+
### Options
|
45
|
+
|
46
|
+
You can override a bunch of defaults by passing options to `RiakTestServer.setup`:
|
47
|
+
|
48
|
+
* `:container_host` - hostname or IP of the container host [default: `"docker"`]
|
49
|
+
* `:http_port` - port to expose Riak HTTP on on the `container_host` [default: `"8098"`]
|
50
|
+
* `:pb_port` - port to expose Riak Protocol Buffers on on the `container_host` [default: `"8087"`]
|
51
|
+
* `:container_name` - name to use for the container when `docker run`-ing it; handy to change if you want different containers for different apps [default: `"riak_test_server"`]
|
52
|
+
* `:repository` - supplier of docker images [default: `"ntalbott/riak_test_server"`]
|
53
|
+
* `:tag` - docker image to use; `docker search ntalbott/riak_test_server` to see if other Riak versions are available [default: `"latest"`]
|
54
|
+
* `:docker_bin` - name of the docker binary [default: `"docker"`]
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require "expect"
|
2
|
+
|
3
|
+
module RiakTestServer
|
4
|
+
def self.setup(options={})
|
5
|
+
@server.stop if @server
|
6
|
+
@server = Server.new(options)
|
7
|
+
|
8
|
+
@server.setup
|
9
|
+
@server.start
|
10
|
+
@server.check
|
11
|
+
@server.clear
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.clear
|
15
|
+
@server.clear
|
16
|
+
end
|
17
|
+
|
18
|
+
class Server
|
19
|
+
attr_reader :repository, :tag
|
20
|
+
def initialize(options)
|
21
|
+
@container_host = (options[:container_host] || "docker")
|
22
|
+
@container_name = (options[:container_name] || "riak_test_server")
|
23
|
+
@http_port = (options[:http_port] || "8098")
|
24
|
+
@pb_port = (options[:pb_port] || "8087")
|
25
|
+
@repository = (options[:docker_repository] || "ntalbott/riak_test_server")
|
26
|
+
@tag = (options[:docker_tag] || "latest")
|
27
|
+
@docker_bin = (options[:docker_bin] || "docker")
|
28
|
+
end
|
29
|
+
|
30
|
+
def start
|
31
|
+
if docker("ps -a") =~ /\b#{@container_name}\b/
|
32
|
+
docker "stop #{@container_name}"
|
33
|
+
docker "rm #{@container_name}"
|
34
|
+
end
|
35
|
+
|
36
|
+
docker %W(
|
37
|
+
run
|
38
|
+
--name #{@container_name}
|
39
|
+
--detach=true
|
40
|
+
--interactive=true
|
41
|
+
--publish=#{@http_port}:8098
|
42
|
+
--publish=#{@pb_port}:8087
|
43
|
+
#{@repository}:#{@tag}
|
44
|
+
).join(" ")
|
45
|
+
end
|
46
|
+
|
47
|
+
def stop
|
48
|
+
@console_io.close if @console_io
|
49
|
+
docker "stop #{@container_name}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def setup
|
53
|
+
unless docker("images") =~ /#{repository}\s+#{tag}/
|
54
|
+
docker "pull #{repository}:#{tag}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def clear
|
59
|
+
result = console("{riak_kv_memory_backend:reset(), boom}.").chomp.strip
|
60
|
+
raise "Unable to reset backend (#{result})" unless result == "{ok,boom}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def check
|
64
|
+
retries = 20
|
65
|
+
loop do
|
66
|
+
result = console("riak_kv_console:vnode_status([]).")
|
67
|
+
break if result.split(/^VNode: \w+$/i).size >= 4 # at least 3 vnodes are available
|
68
|
+
|
69
|
+
raise "vnodes not starting in time" if retries == 0
|
70
|
+
retries -= 1
|
71
|
+
sleep 1
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def docker(command)
|
78
|
+
full_command = "#{@docker_bin} #{command}"
|
79
|
+
`#{full_command} 2>&1`.tap do |output|
|
80
|
+
raise "#{full_command} failed: #{output}" unless $?.exitstatus == 0
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
PROMPT = /\(riak@[\w\.]+\)(\d+)>\s*/
|
85
|
+
def console(command)
|
86
|
+
raise "Command not terminated with a `.`: #{command}" unless command =~ /\.\s*\z/
|
87
|
+
attach do |io|
|
88
|
+
io.puts(command)
|
89
|
+
response = io.expect(PROMPT, 10)
|
90
|
+
if response
|
91
|
+
PROMPT.match(response.first).pre_match
|
92
|
+
else
|
93
|
+
raise "Prompt not returned after sending #{command} to Riak console"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def attach
|
99
|
+
unless @console_io
|
100
|
+
@console_io = IO.popen([@docker_bin, "attach", @container_name], "r+", err: :out).tap{|io| io.sync = true}
|
101
|
+
@console_io.puts("ok.")
|
102
|
+
unless @console_io.expect(PROMPT, 10)
|
103
|
+
raise "Unable to get a prompt on the console"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
yield(@console_io)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: riak_test_server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nathaniel Talbott
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: excon
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: erubis
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Makes it easy to run tests against Riak and wipe all data between each
|
84
|
+
test (or whenever you want).
|
85
|
+
email:
|
86
|
+
- nathaniel@talbott.ws
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.md
|
93
|
+
- ruby/riak_test_server.rb
|
94
|
+
- ruby/riak_test_server/version.rb
|
95
|
+
homepage: https://github.com/ntalbott/riak_test_server
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- ruby
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.2.2
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: A drop-in Riak test server. Uses Docker.
|
119
|
+
test_files: []
|
120
|
+
has_rdoc:
|