influxdb-api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +208 -0
- data/Rakefile +6 -0
- data/influxdb-api.gemspec +27 -0
- data/lib/influxdb-api.rb +2 -0
- data/lib/influxdb.rb +4 -0
- data/lib/influxdb/api.rb +38 -0
- data/lib/influxdb/api/client.rb +99 -0
- data/lib/influxdb/api/client/connection.rb +55 -0
- data/lib/influxdb/api/client/connection_pool.rb +52 -0
- data/lib/influxdb/api/client/errors.rb +62 -0
- data/lib/influxdb/api/client/response.rb +14 -0
- data/lib/influxdb/api/client/selector.rb +27 -0
- data/lib/influxdb/api/configuration.rb +116 -0
- data/lib/influxdb/api/database.rb +29 -0
- data/lib/influxdb/api/extensions.rb +15 -0
- data/lib/influxdb/api/namespaces.rb +50 -0
- data/lib/influxdb/api/namespaces/base.rb +61 -0
- data/lib/influxdb/api/namespaces/cluster_admins.rb +14 -0
- data/lib/influxdb/api/namespaces/continuous_queries.rb +13 -0
- data/lib/influxdb/api/namespaces/databases.rb +13 -0
- data/lib/influxdb/api/namespaces/series.rb +52 -0
- data/lib/influxdb/api/namespaces/servers.rb +12 -0
- data/lib/influxdb/api/namespaces/shard_spaces.rb +33 -0
- data/lib/influxdb/api/namespaces/shards.rb +10 -0
- data/lib/influxdb/api/namespaces/users.rb +18 -0
- data/lib/influxdb/api/namespaces/with_database.rb +20 -0
- data/lib/influxdb/api/server_version.rb +62 -0
- data/lib/influxdb/api/version.rb +5 -0
- data/spec/lib/influxdb/api/client/connection_pool_spec.rb +61 -0
- data/spec/lib/influxdb/api/client/connection_spec.rb +72 -0
- data/spec/lib/influxdb/api/client/response_spec.rb +11 -0
- data/spec/lib/influxdb/api/client/selector_spec.rb +24 -0
- data/spec/lib/influxdb/api/client_spec.rb +110 -0
- data/spec/lib/influxdb/api/configuration_spec.rb +54 -0
- data/spec/lib/influxdb/api/database_spec.rb +32 -0
- data/spec/lib/influxdb/api/namespaces/cluster_admins_spec.rb +46 -0
- data/spec/lib/influxdb/api/namespaces/continuous_queries_spec.rb +42 -0
- data/spec/lib/influxdb/api/namespaces/databases_spec.rb +36 -0
- data/spec/lib/influxdb/api/namespaces/series_spec.rb +119 -0
- data/spec/lib/influxdb/api/namespaces/servers_spec.rb +30 -0
- data/spec/lib/influxdb/api/namespaces/shard_spaces_spec.rb +55 -0
- data/spec/lib/influxdb/api/namespaces/shards_spec.rb +52 -0
- data/spec/lib/influxdb/api/namespaces/users_spec.rb +55 -0
- data/spec/lib/influxdb/api/namespaces_spec.rb +65 -0
- data/spec/lib/influxdb/api/server_version_spec.rb +51 -0
- data/spec/spec_helper.rb +28 -0
- metadata +183 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Influxdb::Api::Configuration do
|
4
|
+
subject{ Influxdb::Api::Configuration.new }
|
5
|
+
|
6
|
+
describe '#hosts' do
|
7
|
+
specify{ expect(subject.hosts).to eq(['http://localhost:8086']) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#hosts=' do
|
11
|
+
context 'when passed host as string' do
|
12
|
+
before{ subject.hosts = 'localhost' }
|
13
|
+
specify{ expect(subject.hosts).to eq(['http://localhost:8086']) }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when passed host and port as string' do
|
17
|
+
before{ subject.hosts = 'localhost:9096' }
|
18
|
+
specify{ expect(subject.hosts).to eq(['http://localhost:9096']) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when passed scheme, host and port' do
|
22
|
+
before{ subject.hosts = 'http://localhost:8080' }
|
23
|
+
specify{ expect(subject.hosts).to eq(['http://localhost:8080']) }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when passed scheme, host, port and credentials' do
|
27
|
+
before{ subject.hosts = 'http://user:pass@localhost:8080' }
|
28
|
+
specify{ expect(subject.hosts).to eq(['http://user:pass@localhost:8080']) }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when passed host as URI' do
|
32
|
+
before{ subject.hosts = URI.parse('http://localhost:8080') }
|
33
|
+
specify{ expect(subject.hosts).to eq(['http://localhost:8080']) }
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when passed host as Hash' do
|
37
|
+
before{ subject.hosts = { host: 'localhost' } }
|
38
|
+
specify{ expect(subject.hosts).to eq(['http://localhost:8086']) }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when passed host as Hash' do
|
42
|
+
before{ subject.hosts = { host: 'localhost', port: '9000' } }
|
43
|
+
specify{ expect(subject.hosts).to eq(['http://localhost:9000']) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#selector' do
|
48
|
+
specify{ expect(subject.selector).to be_instance_of(Influxdb::Api::Client::Selector::RoundRobin) }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#serializer' do
|
52
|
+
specify{ expect(subject.serializer).to eq(::MultiJson) }
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Influxdb::Api::Namespaces do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
|
7
|
+
subject{ Influxdb::Api::Database.new(client, 'dbname') }
|
8
|
+
|
9
|
+
describe '#series' do
|
10
|
+
specify{ expect(subject.series).to be_instance_of(Influxdb::Api::Namespaces::Series) }
|
11
|
+
specify{ expect(subject.series.client).to eq(client) }
|
12
|
+
specify{ expect(subject.series.database_name).to eq('dbname') }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#users' do
|
16
|
+
specify{ expect(subject.users).to be_instance_of(Influxdb::Api::Namespaces::Users) }
|
17
|
+
specify{ expect(subject.users.client).to eq(client) }
|
18
|
+
specify{ expect(subject.users.database_name).to eq('dbname') }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#continuous_queries' do
|
22
|
+
specify{ expect(subject.continuous_queries).to be_instance_of(Influxdb::Api::Namespaces::ContinuousQueries) }
|
23
|
+
specify{ expect(subject.continuous_queries.client).to eq(client) }
|
24
|
+
specify{ expect(subject.continuous_queries.database_name).to eq('dbname') }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#shard_spaces' do
|
28
|
+
specify{ expect(subject.shard_spaces).to be_instance_of(Influxdb::Api::Namespaces::ShardSpaces) }
|
29
|
+
specify{ expect(subject.shard_spaces.client).to eq(client) }
|
30
|
+
specify{ expect(subject.shard_spaces.database_name).to eq('dbname') }
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Influxdb::Api::Namespaces::ClusterAdmins do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
|
7
|
+
subject{ Influxdb::Api::Namespaces::ClusterAdmins.new(client) }
|
8
|
+
|
9
|
+
describe '#all' do
|
10
|
+
before do
|
11
|
+
stub_request(:get, 'http://root:root@localhost:8086/cluster_admins').
|
12
|
+
to_return(status: 200, body: '[{"name":"root"}]', headers: { 'Content-Type' => 'application/json' })
|
13
|
+
end
|
14
|
+
|
15
|
+
specify{ expect(subject.all).to eq([{ 'name' => 'root' }]) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#create' do
|
19
|
+
before do
|
20
|
+
stub_request(:post, 'http://root:root@localhost:8086/cluster_admins').
|
21
|
+
with(body: '{"name":"username","password":"pass"}', headers: { 'Content-Type' => 'application/json' }).
|
22
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
23
|
+
end
|
24
|
+
|
25
|
+
specify{ expect(subject.create(name: 'username', password: 'pass')).to be_truthy }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#update' do
|
29
|
+
before do
|
30
|
+
stub_request(:post, 'http://root:root@localhost:8086/cluster_admins/username').
|
31
|
+
with(body: '{"password":"newpass"}', headers: { 'Content-Type' => 'application/json' }).
|
32
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
33
|
+
end
|
34
|
+
|
35
|
+
specify{ expect(subject.update('username', password: 'newpass')).to be_truthy }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#delete' do
|
39
|
+
before do
|
40
|
+
stub_request(:delete, 'http://root:root@localhost:8086/cluster_admins/username').
|
41
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
42
|
+
end
|
43
|
+
|
44
|
+
specify{ expect(subject.delete('username')).to be_truthy }
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Influxdb::Api::Namespaces::ContinuousQueries do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
|
7
|
+
subject{ Influxdb::Api::Namespaces::ContinuousQueries.new(client, 'dbname') }
|
8
|
+
|
9
|
+
describe '#all' do
|
10
|
+
before do
|
11
|
+
stub_request(:get, 'http://root:root@localhost:8086/db/dbname/continuous_queries').
|
12
|
+
to_return(
|
13
|
+
status: 200,
|
14
|
+
body: '[{"id":1,"query":"select type from events into events.[page_id]"}]',
|
15
|
+
headers: { 'Content-Type' => 'application/json' }
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
specify{ expect(subject.all).to eq([{ 'id' =>1, 'query' => 'select type from events into events.[page_id]' }]) }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#create' do
|
23
|
+
before do
|
24
|
+
stub_request(:post, 'http://root:root@localhost:8086/db/dbname/continuous_queries').
|
25
|
+
with(
|
26
|
+
body: '{"query":"select type from events into events.[page_id]"}',
|
27
|
+
headers: { 'Content-Type' => 'application/json' }
|
28
|
+
).to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
29
|
+
end
|
30
|
+
|
31
|
+
specify{ expect(subject.create('select type from events into events.[page_id]')).to be_truthy }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#delete' do
|
35
|
+
before do
|
36
|
+
stub_request(:delete, 'http://root:root@localhost:8086/db/dbname/continuous_queries/1').
|
37
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
38
|
+
end
|
39
|
+
|
40
|
+
specify{ expect(subject.delete(1)).to be_truthy }
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Influxdb::Api::Namespaces::Databases do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
|
7
|
+
subject{ Influxdb::Api::Namespaces::Databases.new(client) }
|
8
|
+
|
9
|
+
describe '#all' do
|
10
|
+
before do
|
11
|
+
stub_request(:get, 'http://root:root@localhost:8086/db').
|
12
|
+
to_return(status: 200, body: '[{"name":"dbname"}]', headers: { 'Content-Type' => 'application/json' })
|
13
|
+
end
|
14
|
+
|
15
|
+
specify{ expect(subject.all).to eq([{ 'name' => 'dbname' }]) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#create' do
|
19
|
+
before do
|
20
|
+
stub_request(:post, 'http://root:root@localhost:8086/db').
|
21
|
+
with(body: '{"name":"dbname"}', headers: { 'Content-Type' => 'application/json' }).
|
22
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
23
|
+
end
|
24
|
+
|
25
|
+
specify{ expect(subject.create('dbname')).to be_truthy }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#delete' do
|
29
|
+
before do
|
30
|
+
stub_request(:delete, 'http://root:root@localhost:8086/db/dbname').
|
31
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
32
|
+
end
|
33
|
+
|
34
|
+
specify{ expect(subject.delete('dbname')).to be_truthy }
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Influxdb::Api::Namespaces::Series do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
|
7
|
+
subject{ Influxdb::Api::Namespaces::Series.new(client, 'dbname') }
|
8
|
+
|
9
|
+
describe '#all' do
|
10
|
+
let(:response){ MultiJson.dump([{
|
11
|
+
"name"=>"cpu",
|
12
|
+
"columns"=>["time", "sequence_number"],
|
13
|
+
"points"=>[]
|
14
|
+
}]) }
|
15
|
+
|
16
|
+
before do
|
17
|
+
stub_request(:get, 'http://root:root@localhost:8086/db/dbname/series?q=list%20series').
|
18
|
+
to_return(status: 200, body: response, headers: { 'Content-Type' => 'application/json' })
|
19
|
+
end
|
20
|
+
|
21
|
+
specify{ expect(subject.all).to eq(['cpu']) }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#write' do
|
25
|
+
context 'one series of point' do
|
26
|
+
let(:request){ MultiJson.dump([{ name: :cpu, columns: [:value], points: [[1]] }]) }
|
27
|
+
|
28
|
+
before do
|
29
|
+
stub_request(:post, 'http://root:root@localhost:8086/db/dbname/series').
|
30
|
+
with(body: request, headers: { 'Content-Type' => 'application/json' }).
|
31
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
32
|
+
end
|
33
|
+
|
34
|
+
specify{ expect(subject.write('cpu', value: 1)).to be_truthy }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'one series of points' do
|
38
|
+
let(:request){ MultiJson.dump([{ name: :cpu, columns: [:value], points: [[1], [2]] }]) }
|
39
|
+
|
40
|
+
before do
|
41
|
+
stub_request(:post, 'http://root:root@localhost:8086/db/dbname/series').
|
42
|
+
with(body: request, headers: { 'Content-Type' => 'application/json' }).
|
43
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
44
|
+
end
|
45
|
+
|
46
|
+
specify{ expect(subject.write('cpu', [{ value: 1 }, { value: 2 }])).to be_truthy }
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'many series of point' do
|
50
|
+
let(:request){ MultiJson.dump([
|
51
|
+
{ name: :cpu, columns: [:value], points: [[1]] },
|
52
|
+
{ name: :memory, columns: [:value], points: [[1234567890]] }
|
53
|
+
]) }
|
54
|
+
|
55
|
+
before do
|
56
|
+
stub_request(:post, 'http://root:root@localhost:8086/db/dbname/series').
|
57
|
+
with(body: request, headers: { 'Content-Type' => 'application/json' }).
|
58
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
59
|
+
end
|
60
|
+
|
61
|
+
specify{ expect(subject.write(cpu: { value: 1 }, memory: { value: 1234567890 })).to be_truthy }
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'many series of points' do
|
65
|
+
let(:series){ { cpu: [{ value: 1 }, { value: 2 }], memory: [{ value: 1234567890 }, { value: 1234567899 }] } }
|
66
|
+
let(:request){ MultiJson.dump([
|
67
|
+
{ name: :cpu, columns: [:value], points: [[1], [2]] },
|
68
|
+
{ name: :memory, columns: [:value], points: [[1234567890], [1234567899]] }
|
69
|
+
]) }
|
70
|
+
|
71
|
+
before do
|
72
|
+
stub_request(:post, 'http://root:root@localhost:8086/db/dbname/series').
|
73
|
+
with(body: request, headers: { 'Content-Type' => 'application/json' }).
|
74
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
75
|
+
end
|
76
|
+
|
77
|
+
specify{ expect(subject.write(series)).to be_truthy }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#execute' do
|
82
|
+
let(:response){ [{
|
83
|
+
'name' => 'cpu',
|
84
|
+
'columns' => ['time', 'sequence_number', 'value'],
|
85
|
+
'points' => [[1411215771762, 440001, 1]]
|
86
|
+
}] }
|
87
|
+
|
88
|
+
before do
|
89
|
+
stub_request(:get, 'http://root:root@localhost:8086/db/dbname/series?q=select%20*%20from%20cpu').
|
90
|
+
with(headers: { 'Content-Type' => 'application/json' }).
|
91
|
+
to_return(status: 200, body: MultiJson.dump(response), headers: { 'Content-Type' => 'application/json' })
|
92
|
+
end
|
93
|
+
|
94
|
+
specify{ expect(subject.execute('select * from cpu')).to eq({
|
95
|
+
'cpu' => [{ 'time' => 1411215771762, 'sequence_number' => 440001, 'value' => 1 }]
|
96
|
+
}) }
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#raw_execute' do
|
100
|
+
let(:response){ [{ 'name' => 'cpu', 'columns' => ['time', 'sequence_number'], 'points' => [] }] }
|
101
|
+
|
102
|
+
before do
|
103
|
+
stub_request(:get, 'http://root:root@localhost:8086/db/dbname/series?q=list%20series').
|
104
|
+
with(headers: { 'Content-Type' => 'application/json' }).
|
105
|
+
to_return(status: 200, body: MultiJson.dump(response), headers: { 'Content-Type' => 'application/json' })
|
106
|
+
end
|
107
|
+
|
108
|
+
specify{ expect(subject.raw_execute('list series')).to eq(response) }
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#delete' do
|
112
|
+
before do
|
113
|
+
stub_request(:delete, 'http://root:root@localhost:8086/db/dbname/series/name').
|
114
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
115
|
+
end
|
116
|
+
|
117
|
+
specify{ expect(subject.delete('name')).to be_truthy }
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Influxdb::Api::Namespaces::Servers do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
|
7
|
+
subject{ Influxdb::Api::Namespaces::Servers.new(client) }
|
8
|
+
|
9
|
+
describe '#all' do
|
10
|
+
before do
|
11
|
+
stub_request(:get, 'http://root:root@localhost:8086/cluster/servers').
|
12
|
+
to_return(
|
13
|
+
status: 200,
|
14
|
+
body: '[{"id":1,"protobufConnectString":"localhost:8099"}]',
|
15
|
+
headers: { 'Content-Type' => 'application/json' }
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
specify{ expect(subject.all).to eq([{ 'id' => 1, 'protobufConnectString' => 'localhost:8099' }]) }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#delete' do
|
23
|
+
before do
|
24
|
+
stub_request(:delete, 'http://root:root@localhost:8086/cluster/servers/1').
|
25
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
26
|
+
end
|
27
|
+
|
28
|
+
specify{ expect(subject.delete(1)).to be_truthy }
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Influxdb::Api::Namespaces::ShardSpaces do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
let(:shard_spaces){ {
|
7
|
+
'name' => 'default',
|
8
|
+
'database' => 'dbname',
|
9
|
+
'retentionPolicy' => 'inf',
|
10
|
+
'shardDuration' => '7d',
|
11
|
+
'regex' => '/.*/',
|
12
|
+
'replicationFactor' => 1,
|
13
|
+
'split' => 1
|
14
|
+
} }
|
15
|
+
|
16
|
+
subject{ Influxdb::Api::Namespaces::ShardSpaces.new(client, 'dbname') }
|
17
|
+
|
18
|
+
describe '#all' do
|
19
|
+
before do
|
20
|
+
stub_request(:get, 'http://root:root@localhost:8086/cluster/shard_spaces').
|
21
|
+
to_return(status: 200, body: MultiJson.dump([shard_spaces]), headers: { 'Content-Type' => 'application/json' })
|
22
|
+
end
|
23
|
+
|
24
|
+
specify{ expect(subject.all).to eq([shard_spaces]) }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#create' do
|
28
|
+
before do
|
29
|
+
stub_request(:post, 'http://root:root@localhost:8086/cluster/shard_spaces/dbname').
|
30
|
+
with(body: MultiJson.dump(shard_spaces), headers: { 'Content-Type' => 'application/json' }).
|
31
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
32
|
+
end
|
33
|
+
|
34
|
+
specify{ expect(subject.create(shard_spaces)).to be_truthy }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#update' do
|
38
|
+
before do
|
39
|
+
stub_request(:post, 'http://root:root@localhost:8086/cluster/shard_spaces/dbname/default').
|
40
|
+
with(body: '{"shardDuration":"1d"}', headers: { 'Content-Type' => 'application/json' }).
|
41
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
42
|
+
end
|
43
|
+
|
44
|
+
specify{ expect(subject.update('default', shardDuration: '1d')).to be_truthy }
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#delete' do
|
48
|
+
before do
|
49
|
+
stub_request(:delete, 'http://root:root@localhost:8086/cluster/shard_spaces/dbname/default').
|
50
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
51
|
+
end
|
52
|
+
|
53
|
+
specify{ expect(subject.delete('default')).to be_truthy }
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Influxdb::Api::Namespaces::Shards do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
|
7
|
+
subject{ Influxdb::Api::Namespaces::Shards.new(client) }
|
8
|
+
|
9
|
+
describe '#all' do
|
10
|
+
let(:shards){ {
|
11
|
+
'longTerm' => [],
|
12
|
+
'shortTerm' => [{
|
13
|
+
'endTime' => 1411603200,
|
14
|
+
'id'=>2,
|
15
|
+
'serverIds' => [1],
|
16
|
+
'startTime' => 1410998400
|
17
|
+
}]
|
18
|
+
} }
|
19
|
+
|
20
|
+
before do
|
21
|
+
stub_request(:get, 'http://root:root@localhost:8086/cluster/shards').
|
22
|
+
to_return(status: 200, body: MultiJson.dump(shards), headers: { 'Content-Type' => 'application/json' })
|
23
|
+
end
|
24
|
+
|
25
|
+
specify{ expect(subject.all).to eq(shards) }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#create' do
|
29
|
+
let(:shard){ {
|
30
|
+
'endTime' => 1411603200,
|
31
|
+
'serverIds' => [1],
|
32
|
+
'startTime' => 1410998400
|
33
|
+
} }
|
34
|
+
|
35
|
+
before do
|
36
|
+
stub_request(:post, 'http://root:root@localhost:8086/cluster/shards').
|
37
|
+
with(body: MultiJson.dump(shard), headers: { 'Content-Type' => 'application/json' }).
|
38
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
39
|
+
end
|
40
|
+
|
41
|
+
specify{ expect(subject.create(shard)).to be_truthy }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#delete' do
|
45
|
+
before do
|
46
|
+
stub_request(:delete, 'http://root:root@localhost:8086/cluster/shards/1').
|
47
|
+
to_return(status: 200, body: '', headers: { 'Content-Type' => 'text/plain' })
|
48
|
+
end
|
49
|
+
|
50
|
+
specify{ expect(subject.delete(1)).to be_truthy }
|
51
|
+
end
|
52
|
+
end
|