crate_ruby 0.2.0 → 0.2.1

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.
@@ -1,107 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
4
- # license agreements. See the NOTICE file distributed with this work for
5
- # additional information regarding copyright ownership. Crate licenses
6
- # this file to you under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License. You may
8
- # obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
- # License for the specific language governing permissions and limitations
16
- # under the License.
17
- #
18
- # However, if you have executed another commercial license agreement
19
- # with Crate these terms will supersede the license and you may use the
20
- # software solely pursuant to the terms of the relevant commercial agreement.
21
-
22
- require 'net/http'
23
-
24
- class TestCluster
25
- def initialize(num_nodes = 1, http_port = 44_200)
26
- @nodes = []
27
- idx = 0
28
- while idx < num_nodes
29
- name = "crate#{idx - 1}"
30
- port = http_port + idx
31
- @nodes << TestServer.new(name, port)
32
- idx += 1
33
- end
34
- end
35
-
36
- def start_nodes
37
- @nodes.each(&:start)
38
- end
39
-
40
- def stop_nodes
41
- @nodes.each(&:stop)
42
- end
43
- end
44
-
45
- class TestServer
46
- STARTUP_TIMEOUT = 30
47
-
48
- def initialize(name, http_port)
49
- @node_name = name
50
- @http_port = http_port
51
-
52
- @crate_bin = File.join('parts', 'crate', 'bin', 'crate')
53
- unless File.file?(@crate_bin)
54
- puts "Crate is not available. Please run 'bundle exec ruby spec/bootstrap.rb' first."
55
- exit 1
56
- end
57
- end
58
-
59
- def start
60
- cmd = "sh #{@crate_bin} #{start_params}"
61
- @pid = spawn(cmd)
62
- wait_for
63
- Process.detach(@pid)
64
-
65
- File.write(__dir__ + '/testnode.pid', @pid)
66
- end
67
-
68
- def wait_for
69
- time_slept = 0
70
- interval = 1
71
- loop do
72
- if !alive? && (time_slept > STARTUP_TIMEOUT)
73
- puts "Crate hasn't started for #{STARTUP_TIMEOUT} seconds. Giving up now..."
74
- exit 1
75
- end
76
- if alive?
77
- break
78
- else
79
- sleep(interval)
80
- time_slept += interval
81
- end
82
- end
83
- end
84
-
85
- def stop
86
- Process.kill('HUP', @pid)
87
- end
88
-
89
- private
90
-
91
- def start_params
92
- "-Cnode.name=#{@node_name} " \
93
- "-Chttp.port=#{@http_port} " \
94
- '-Cnetwork.host=localhost '
95
- end
96
-
97
- def alive?
98
- req = Net::HTTP::Get.new('/')
99
- resp = Net::HTTP.new('localhost', @http_port)
100
- begin
101
- response = resp.start { |http| http.request(req) }
102
- response.code == '200'
103
- rescue Errno::ECONNREFUSED
104
- false
105
- end
106
- end
107
- end
Binary file
Binary file
@@ -1 +0,0 @@
1
- TEST