logworm_amqp 0.8.9 → 0.9.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.
- data/CHANGELOG +103 -1
- data/Manifest +8 -7
- data/Rakefile +4 -4
- data/bin/lw-compute +66 -0
- data/bin/lw-tail +84 -0
- data/lib/base/db.rb +8 -6
- data/lib/client/logger.rb +93 -0
- data/lib/client/rack.rb +61 -0
- data/lib/client/rails.rb +105 -0
- data/lib/cmd/compute.rb +66 -0
- data/lib/cmd/tail.rb +106 -0
- data/lib/logworm_amqp.rb +61 -0
- data/lib/logworm_utils.rb +4 -0
- data/logworm_amqp.gemspec +20 -16
- metadata +64 -43
- data/README.md +0 -3
- data/spec/base_spec.rb +0 -143
- data/spec/builder_spec.rb +0 -26
- data/spec/config_spec.rb +0 -36
- data/spec/spec.opts +0 -4
- data/spec/spec_helper.rb +0 -8
- data/tests/builder_test.rb +0 -52
data/README.md
DELETED
data/spec/base_spec.rb
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'webmock'
|
3
|
-
|
4
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
5
|
-
|
6
|
-
$: << File.dirname(__FILE__) + '/../lib'
|
7
|
-
require 'logworm.rb'
|
8
|
-
|
9
|
-
describe Logworm::DB, " initialization" do
|
10
|
-
before do
|
11
|
-
File.delete(".logworm") if File.exist?(".logworm")
|
12
|
-
Logworm::Config.instance.reset
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should only accept proper URLs" do
|
16
|
-
lambda {Logworm::DB.new('')}.should raise_exception(Logworm::ForbiddenAccessException)
|
17
|
-
lambda {Logworm::DB.new('http://www.test.com')}.should raise_exception(Logworm::ForbiddenAccessException)
|
18
|
-
lambda {Logworm::DB.new('logworm://a:b@xxx/c/d')}.should raise_exception(Logworm::ForbiddenAccessException)
|
19
|
-
lambda {Logworm::DB.new('logworm://a:b@/c/d/')}.should raise_exception(Logworm::ForbiddenAccessException)
|
20
|
-
lambda {Logworm::DB.new('logworm://a:b@sda//d/')}.should raise_exception(Logworm::ForbiddenAccessException)
|
21
|
-
lambda {Logworm::DB.new('logworm://:b@sda//d/')}.should raise_exception(Logworm::ForbiddenAccessException)
|
22
|
-
lambda {Logworm::DB.new('logworm://a:b@xxx/c/d/')}.should_not raise_exception(Logworm::ForbiddenAccessException)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should be able to parse a proper logworm URL" do
|
26
|
-
db = Logworm::DB.new('logworm://a:b@localhost:9401/c/d/')
|
27
|
-
db.host.should == "localhost:9401"
|
28
|
-
db.consumer_key.should == "a"
|
29
|
-
db.consumer_secret.should == "b"
|
30
|
-
db.token.should == "c"
|
31
|
-
db.token_secret.should == "d"
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should be able to read its configuration from a file" do
|
35
|
-
File.open(".logworm", "w") do |f|
|
36
|
-
f.puts 'logworm://a:b@localhost:9401/c/d/'
|
37
|
-
end
|
38
|
-
db = Logworm::DB.from_config
|
39
|
-
db.host.should == "localhost:9401"
|
40
|
-
db.consumer_key.should == "a"
|
41
|
-
db.consumer_secret.should == "b"
|
42
|
-
db.token.should == "c"
|
43
|
-
db.token_secret.should == "d"
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should fail if no logworm file (and no current Heroku application)" do
|
47
|
-
db = Logworm::DB.from_config
|
48
|
-
db.should == nil
|
49
|
-
end
|
50
|
-
|
51
|
-
# Note that this will fail unless it's run from the command line!
|
52
|
-
it "should not be nil if we pass a proper app parameter" do
|
53
|
-
db = Logworm::DB.from_config("lw-client")
|
54
|
-
db.should_not == nil
|
55
|
-
db.host.should == "db.logworm.com"
|
56
|
-
end
|
57
|
-
|
58
|
-
# Note that this will fail unless it's run from the command line!
|
59
|
-
it "should not use a config file if app is passed" do
|
60
|
-
File.open(".logworm", "w") do |f|
|
61
|
-
f.puts 'logworm://a:b@xxx:9401/c/d/'
|
62
|
-
end
|
63
|
-
db = Logworm::DB.from_config("lw-client")
|
64
|
-
db.host.should == "db.logworm.com" # The one from the app, not the config file
|
65
|
-
end
|
66
|
-
|
67
|
-
# Note that this will fail unless it's run from the command line!
|
68
|
-
it "should not overwrite a config file if app is passed" do
|
69
|
-
File.open(".logworm", "w") do |f|
|
70
|
-
f.puts 'logworm://a:b@xxx:9401/c/d/'
|
71
|
-
end
|
72
|
-
|
73
|
-
db = Logworm::DB.from_config("lw-client")
|
74
|
-
Logworm::Config.instance.reset
|
75
|
-
Logworm::Config.instance.read
|
76
|
-
Logworm::Config.instance.url.should == 'logworm://a:b@xxx:9401/c/d/'
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
describe Logworm::DB, " functioning" do
|
82
|
-
|
83
|
-
host = "http://localhost:9401"
|
84
|
-
|
85
|
-
before(:all) do
|
86
|
-
@db = Logworm::DB.new('logworm://a:b@localhost:9401/c/d/')
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should offer a call to get the list of tables --> /" do
|
90
|
-
@db.should_receive(:db_call).with(:get, "#{host}/")
|
91
|
-
@db.tables
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should just parse and return the results of the call to get tables" do
|
95
|
-
return_body = [
|
96
|
-
{"tablename" => "table1", "url" => "/table1", "last_write" => "2010-03-20 18:10:22", "rows" => 50},
|
97
|
-
{"tablename" => "table2", "url" => "/table1", "last_write" => "2010-03-20 18:10:22", "rows" => 50}]
|
98
|
-
stub_request(:get, "#{host}/").to_return(:body => return_body.to_json)
|
99
|
-
@db.tables.should == return_body
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should support a call to start a query --> POST /queries" do
|
103
|
-
@db.should_receive(:db_call).with(:post, "#{host}/queries", {:table => "tbl1", :query => "a good query"})
|
104
|
-
@db.query("tbl1", "a good query")
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should just parse and return the results of the call to query" do
|
108
|
-
return_body = {"id" => 10, "query" => "q", "self_uri" => "/queries/10", "results_uri" => "/queries/10/results"}
|
109
|
-
stub_request(:post, "#{host}/queries").with(:body => "query=q&table=table1").to_return(:body => return_body.to_json)
|
110
|
-
@db.query("table1", "q").should == return_body
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should support a call to retrieve the results of a query --> GET /queries/10/results" do
|
114
|
-
@db.should_receive(:db_call).with(:get, "#{host}/queries/10/results")
|
115
|
-
@db.results("#{host}/queries/10/results") rescue Exception # Returns an error when trying to parse results
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should just parse and return the results of the call to retrieve results, but also add results field" do
|
119
|
-
results = [{"a" => 10, "b" => "2"}, {"a" => "x"}]
|
120
|
-
return_body = {"id" => 10, "execution_time" => "5",
|
121
|
-
"query_url" => "#{host}/queries/10", "results_url" => "#{host}/queries/10/results",
|
122
|
-
"results" => results.to_json}
|
123
|
-
stub_request(:get, "#{host}/queries/10/results").to_return(:body => return_body.to_json)
|
124
|
-
@db.results("#{host}/queries/10/results").should == return_body.merge("results" => results)
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should raise ForbiddenAccessException if 403" do
|
128
|
-
stub_request(:get, "#{host}/").to_return(:status => 403)
|
129
|
-
lambda {@db.tables}.should raise_exception(Logworm::ForbiddenAccessException)
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should raise InvalidQueryException if query is not valid" do
|
133
|
-
stub_request(:post, "#{host}/queries").to_return(:status => 400, :body => "Query error")
|
134
|
-
lambda {@db.query("tbl1", "bad query")}.should raise_exception(Logworm::InvalidQueryException)
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should raise DatabaseException if response from server is not JSON" do
|
138
|
-
stub_request(:get, "#{host}/").to_return(:body => "blah")
|
139
|
-
lambda {@db.tables}.should raise_exception(Logworm::DatabaseException)
|
140
|
-
end
|
141
|
-
|
142
|
-
|
143
|
-
end
|
data/spec/builder_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
-
|
5
|
-
$: << File.dirname(__FILE__) + '/../lib'
|
6
|
-
require 'logworm.rb'
|
7
|
-
|
8
|
-
describe Logworm::QueryBuilder, " timeframes" do
|
9
|
-
|
10
|
-
it " should accept Strings as time" do
|
11
|
-
Logworm::QueryBuilder.new(:start => "2010-01-01").to_json.should == '{"timeframe":{"start":"2010-01-01"}}'
|
12
|
-
Logworm::QueryBuilder.new(:end => "2010-01-01").to_json.should == '{"timeframe":{"end":"2010-01-01"}}'
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should accept an Integer as time, to mean the year" do
|
16
|
-
Logworm::QueryBuilder.new(:start => 2010).to_json.should == '{"timeframe":{"start":"2010"}}'
|
17
|
-
Logworm::QueryBuilder.new(:end => 2010).to_json.should == '{"timeframe":{"end":"2010"}}'
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should accept a Time object" do
|
21
|
-
ts = Time.now
|
22
|
-
Logworm::QueryBuilder.new(:start => ts).to_json.should == '{"timeframe":{"start":"' + ts.strftime("%Y-%m-%dT%H:%M:%SZ") + '"}}'
|
23
|
-
Logworm::QueryBuilder.new(:end => ts).to_json.should == '{"timeframe":{"end":"' + ts.strftime("%Y-%m-%dT%H:%M:%SZ") + '"}}'
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
data/spec/config_spec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'webmock'
|
3
|
-
|
4
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
5
|
-
|
6
|
-
$: << File.dirname(__FILE__) + '/../lib'
|
7
|
-
require 'logworm.rb'
|
8
|
-
|
9
|
-
describe Logworm::Config, " initialization" do
|
10
|
-
|
11
|
-
before do
|
12
|
-
%x[rm .logworm]
|
13
|
-
%x[mv .gitignore .gitignore_old]
|
14
|
-
end
|
15
|
-
|
16
|
-
after do
|
17
|
-
%x[mv .gitignore_old .gitignore]
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should create a new .logworm file on save" do
|
21
|
-
url = "xxx"
|
22
|
-
File.should_not exist(".logworm")
|
23
|
-
Logworm::Config.instance.save(url)
|
24
|
-
File.should exist(".logworm")
|
25
|
-
Logworm::Config.instance.read.should be_file_found
|
26
|
-
Logworm::Config.instance.url.should == url
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should add .logworm to .gitignore" do
|
30
|
-
File.should_not exist(".gitignore")
|
31
|
-
Logworm::Config.instance.save("xxx")
|
32
|
-
File.should exist(".gitignore")
|
33
|
-
File.open('.gitignore').readline.strip.should == ".logworm"
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
data/spec/spec.opts
DELETED
data/spec/spec_helper.rb
DELETED
data/tests/builder_test.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require '../lib/base/query_builder'
|
4
|
-
|
5
|
-
class BuilderTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_empty
|
14
|
-
assert_equal "{}", Logworm::QueryBuilder.new({}).to_json
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_fields
|
18
|
-
assert_equal '{"fields":["a","b"]}', Logworm::QueryBuilder.new(:fields => 'a, b').to_json
|
19
|
-
assert_equal '{"fields":["a","b"]}', Logworm::QueryBuilder.new(:fields => '"a", "b"').to_json
|
20
|
-
assert_equal '{"fields":["a","b"]}', Logworm::QueryBuilder.new(:fields => ["a", "b"]).to_json
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_aggregate
|
24
|
-
q = {:aggregate_function => "count"}
|
25
|
-
assert_equal '{"aggregate":{"function":"count"}}', Logworm::QueryBuilder.new(q).to_json
|
26
|
-
q = {:aggregate_function => "a", :aggregate_argument => "b"}
|
27
|
-
assert_equal '{"aggregate":{"argument":"b","function":"a"}}', Logworm::QueryBuilder.new(q).to_json
|
28
|
-
q = {:aggregate_function => "a", :aggregate_argument => "b", :aggregate_group => "a,b,c"}
|
29
|
-
assert_equal '{"aggregate":{"argument":"b","group_by":["a","b","c"],"function":"a"}}', Logworm::QueryBuilder.new(q).to_json
|
30
|
-
q = {:aggregate_function => "a", :aggregate_argument => "b", :aggregate_group => ["a","b","c"]}
|
31
|
-
assert_equal '{"aggregate":{"argument":"b","group_by":["a","b","c"],"function":"a"}}', Logworm::QueryBuilder.new(q).to_json
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_conditions
|
35
|
-
assert_equal '{"conditions":{"a":10,"b":"c"}}', Logworm::QueryBuilder.new(:conditions => '"a":10, "b":"c"').to_json
|
36
|
-
assert_equal '{"conditions":{"a":10,"b":"c"}}', Logworm::QueryBuilder.new(:conditions => ['"a":10', '"b":"c"']).to_json
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_times
|
40
|
-
assert_equal '{}', Logworm::QueryBuilder.new(:blah => "2009").to_json
|
41
|
-
assert_equal '{"timeframe":{"start":"2009"}}', Logworm::QueryBuilder.new(:start => "2009").to_json
|
42
|
-
assert_equal '{"timeframe":{"end":"2009"}}', Logworm::QueryBuilder.new(:end => "2009").to_json
|
43
|
-
assert_equal '{"timeframe":{"start":"2009","end":"2010"}}', Logworm::QueryBuilder.new(:start => "2009", :end => "2010").to_json
|
44
|
-
assert_equal '{"timeframe":{"start":"2009","end":"2010"}}', Logworm::QueryBuilder.new(:start => 2009, :end => 2010).to_json
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_limit
|
48
|
-
assert_equal '{"limit":10}', Logworm::QueryBuilder.new(:limit => 10).to_json
|
49
|
-
assert_equal '{}', Logworm::QueryBuilder.new(:limit => 200).to_json
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|