io_shuten 0.0.3.dev1 → 0.1.0.dev6
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/Gemfile +11 -2
- data/Gemfile.lock +25 -0
- data/README.md +7 -0
- data/Rakefile +7 -1
- data/benchmark/viiite-template.rb +79 -0
- data/benchmarks/buffer.rb +7 -0
- data/benchmarks/memory.rb +7 -0
- data/benchmarks.sh +59 -0
- data/io_shuten.gemspec +35 -6
- data/lib/io_shuten/redis.rb +21 -21
- data/lib/io_shuten/stores/base_container.rb +20 -0
- data/lib/io_shuten/stores/redis/container.rb +38 -0
- data/lib/io_shuten/stores/redis/key_value/collection.rb +31 -0
- data/lib/io_shuten/stores/redis/key_value/single.rb +25 -0
- data/lib/io_shuten/stores/redis/key_value.rb +14 -0
- data/lib/io_shuten/stores/redis/pub_sub/publisher.rb +0 -0
- data/lib/io_shuten/stores/redis/pub_sub/subscriber.rb +0 -0
- data/lib/io_shuten/stores/redis/pub_sub.rb +12 -0
- data/lib/io_shuten/stores/redis.rb +4 -1
- data/lib/io_shuten/stores.rb +1 -1
- data/lib/io_shuten/version.rb +1 -1
- data/lib/io_shuten/zmq.rb +10 -0
- data/lib/io_shuten.rb +1 -1
- data/spec/examples/logger_spec.rb +36 -2
- data/spec/lib/buffer_spec.rb +5 -3
- data/spec/lib/memory_spec.rb +5 -3
- data/spec/lib/redis_spec.rb +104 -2
- data/spec/lib/zmq_spec.rb +7 -0
- data/spec/spec_helper.rb +10 -0
- metadata +221 -218
- data/benchmark/compare_mem_w_buf.rb +0 -134
data/lib/io_shuten/version.rb
CHANGED
data/lib/io_shuten.rb
CHANGED
@@ -10,10 +10,10 @@ require "io_shuten/buffer"
|
|
10
10
|
require "io_shuten/stores"
|
11
11
|
require "io_shuten/mongo"
|
12
12
|
require "io_shuten/redis"
|
13
|
+
require "io_shuten/zmq"
|
13
14
|
|
14
15
|
# IO::Mongo for a more intuitive usage
|
15
16
|
IO::Mongo = IO_shuten::Mongo
|
16
17
|
|
17
18
|
# IO::Redis for a more intuitive usage
|
18
19
|
IO::Redis = IO_shuten::Redis
|
19
|
-
|
@@ -24,8 +24,42 @@ describe "Logger" do
|
|
24
24
|
logdev.read.should =~ /Test message/
|
25
25
|
end
|
26
26
|
|
27
|
-
it "accepts an IO_shuten::Redis as logdev"
|
28
|
-
|
29
27
|
it "accepts an IO_shuten::Mongo as logdev"
|
30
28
|
|
29
|
+
describe "accepts an IO_shuten::Redis as logdev" do
|
30
|
+
before do
|
31
|
+
IO_shuten::Redis.purge_instances!
|
32
|
+
IO_shuten::Redis.redis = Redis::Namespace.new(:logging, :redis => REDIS)
|
33
|
+
IO_shuten::Redis.redis_clear!
|
34
|
+
end
|
35
|
+
|
36
|
+
after do
|
37
|
+
IO_shuten::Redis.redis_clear!
|
38
|
+
end
|
39
|
+
|
40
|
+
it "by using KeyValue::Single" do
|
41
|
+
logdev = IO_shuten::Redis.new(:rlogdev_kvs, :key_value, :single)
|
42
|
+
logger = Logger.new(logdev)
|
43
|
+
logger.info "Foo log."
|
44
|
+
logger.info "Test message."
|
45
|
+
logger.info "Bar log."
|
46
|
+
|
47
|
+
logdev.read.should =~ /Test message/
|
48
|
+
end
|
49
|
+
|
50
|
+
it "by using KeyValue::Collection" do
|
51
|
+
logdev = IO_shuten::Redis.new(:rlogdev_kvc, :key_value, :collection)
|
52
|
+
logger = Logger.new(logdev)
|
53
|
+
logger.info "Foo log."
|
54
|
+
logger.info "Test message."
|
55
|
+
logger.info "Bar log."
|
56
|
+
|
57
|
+
logdev.read.should =~ /Test message/
|
58
|
+
end
|
59
|
+
|
60
|
+
it "by using PubSub::Publisher"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "accepts an IO_shuten::Zmq as logdev"
|
64
|
+
|
31
65
|
end
|
data/spec/lib/buffer_spec.rb
CHANGED
@@ -4,6 +4,8 @@ require File.expand_path("../../spec_helper.rb", __FILE__)
|
|
4
4
|
include IO_shuten
|
5
5
|
describe Buffer do
|
6
6
|
|
7
|
+
it { IO_shuten::Buffer.should inherit_from(IO_shuten::Base) }
|
8
|
+
|
7
9
|
describe "Class Methods" do
|
8
10
|
|
9
11
|
describe :new do
|
@@ -355,7 +357,7 @@ describe Buffer do
|
|
355
357
|
context "with container name as default" do
|
356
358
|
it "writes container into the file" do
|
357
359
|
iob = Buffer.new(@tmp_save_file)
|
358
|
-
iob.
|
360
|
+
iob.write "Test string"
|
359
361
|
iob.save_to_file.should be_true
|
360
362
|
end
|
361
363
|
end
|
@@ -363,7 +365,7 @@ describe Buffer do
|
|
363
365
|
context "with custom name" do
|
364
366
|
it "writes container into the file" do
|
365
367
|
iob = Buffer.new(:different_name)
|
366
|
-
iob.
|
368
|
+
iob.write "Test string"
|
367
369
|
iob.save_to_file(@tmp_save_file).should be_true
|
368
370
|
end
|
369
371
|
end
|
@@ -373,7 +375,7 @@ describe Buffer do
|
|
373
375
|
context "path not accessible" do
|
374
376
|
it "raises FileAccessError with corresponding reason" do
|
375
377
|
iob = Buffer.new(@denied_path)
|
376
|
-
iob.
|
378
|
+
iob.write "Test string"
|
377
379
|
expect { iob.save_to_file }.to raise_error(Errors::FileAccessError, /Reason/)
|
378
380
|
end
|
379
381
|
end
|
data/spec/lib/memory_spec.rb
CHANGED
@@ -4,6 +4,8 @@ require File.expand_path("../../spec_helper.rb", __FILE__)
|
|
4
4
|
include IO_shuten
|
5
5
|
describe Memory do
|
6
6
|
|
7
|
+
it { IO_shuten::Memory.should inherit_from(IO_shuten::Base) }
|
8
|
+
|
7
9
|
describe "Class Methods" do
|
8
10
|
|
9
11
|
describe :new do
|
@@ -392,7 +394,7 @@ describe Memory do
|
|
392
394
|
context "with container name as default" do
|
393
395
|
it "writes container into the file" do
|
394
396
|
iom = Memory.new(@tmp_save_file)
|
395
|
-
iom.
|
397
|
+
iom.write "Test string"
|
396
398
|
iom.save_to_file.should be_true
|
397
399
|
end
|
398
400
|
end
|
@@ -400,7 +402,7 @@ describe Memory do
|
|
400
402
|
context "with custom name" do
|
401
403
|
it "writes container into the file" do
|
402
404
|
iom = Memory.new(:different_name)
|
403
|
-
iom.
|
405
|
+
iom.write "Test string"
|
404
406
|
iom.save_to_file(@tmp_save_file).should be_true
|
405
407
|
end
|
406
408
|
end
|
@@ -410,7 +412,7 @@ describe Memory do
|
|
410
412
|
context "path not accessible" do
|
411
413
|
it "raises FileAccessError with corresponding reason" do
|
412
414
|
iom = Memory.new(@denied_path)
|
413
|
-
iom.
|
415
|
+
iom.write "Test string"
|
414
416
|
expect { iom.save_to_file }.to raise_error(Errors::FileAccessError, /Reason/)
|
415
417
|
end
|
416
418
|
end
|
data/spec/lib/redis_spec.rb
CHANGED
@@ -1,7 +1,109 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.expand_path("../../spec_helper.rb", __FILE__)
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
IOR = IO_shuten::Redis
|
5
|
+
|
6
|
+
describe IO_shuten::Redis do
|
6
7
|
it { IO_shuten::Redis.should inherit_from(IO_shuten::Base) }
|
8
|
+
|
9
|
+
describe "Class Methods" do
|
10
|
+
|
11
|
+
describe :new do
|
12
|
+
|
13
|
+
before do
|
14
|
+
IOR.purge_instances!
|
15
|
+
end
|
16
|
+
|
17
|
+
it "creates a node with KeyValue as :single" do
|
18
|
+
ior = IOR.new(:test, :key_value, :single)
|
19
|
+
ior.backend_spec.should == [:key_value,:single]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "creates a node with KeyValue as :collection" do
|
23
|
+
ior = IOR.new(:test, :key_value, :collection)
|
24
|
+
ior.backend_spec.should == [:key_value,:collection]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "creates a node with PubSub as :publisher" do
|
28
|
+
ior = IOR.new(:test, :pub_sub, :publisher)
|
29
|
+
ior.backend_spec.should == [:pub_sub,:publisher]
|
30
|
+
end
|
31
|
+
|
32
|
+
it "creates a node with PubSub as :subscriber" do
|
33
|
+
ior = IOR.new(:test, :pub_sub, :subscriber)
|
34
|
+
ior.backend_spec.should == [:pub_sub,:subscriber]
|
35
|
+
end
|
36
|
+
|
37
|
+
it "fails, if backend is not known" do
|
38
|
+
expect { IOR.new(:will_fail, :unknown_backend) }.to raise_error(ArgumentError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "fails, if type is not known" do
|
42
|
+
expect { IOR.new(:will_fail, :key_value, :unknown_type) }.to raise_error(ArgumentError)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "Instance Methods" do
|
48
|
+
|
49
|
+
before do
|
50
|
+
IOR.purge_instances!
|
51
|
+
IOR.redis = Redis::Namespace.new(:instances, :redis => REDIS)
|
52
|
+
end
|
53
|
+
|
54
|
+
after do
|
55
|
+
IOR.redis_clear!
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "KeyValue backend" do
|
59
|
+
|
60
|
+
describe "Single type" do
|
61
|
+
|
62
|
+
it "writes data" do
|
63
|
+
data = %w[first_entry more_data last_entry]
|
64
|
+
ior = IOR.new(:kvs_test_write, :key_value, :single)
|
65
|
+
data.each{ |line| ior.write line }
|
66
|
+
|
67
|
+
IOR.redis.lrange(:kvs_test_write,0,-1).should == data
|
68
|
+
end
|
69
|
+
|
70
|
+
it "reads data" do
|
71
|
+
data = %w[first_entry more_data last_entry]
|
72
|
+
ior = IOR.new(:kvs_test_read, :key_value, :single)
|
73
|
+
data.each{ |line| ior.write line }
|
74
|
+
|
75
|
+
ior.read.should == data.join
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "Collection type" do
|
81
|
+
|
82
|
+
it "writes data" do
|
83
|
+
data = %w[first_entry more_data last_entry]
|
84
|
+
ior = IOR.new(:kvc_test_write, :key_value, :collection)
|
85
|
+
data.each{ |line| ior.write line }
|
86
|
+
|
87
|
+
keys = IOR.redis.keys("kvc_test_write:*").sort
|
88
|
+
res = keys.inject([]){|m,k|m << IOR.redis.get(k); m}
|
89
|
+
|
90
|
+
res.should == data
|
91
|
+
end
|
92
|
+
|
93
|
+
it "reads data" do
|
94
|
+
data = %w[first_entry more_data last_entry]
|
95
|
+
ior = IOR.new(:kvc_test_read, :key_value, :collection)
|
96
|
+
data.each{ |line| ior.write line }
|
97
|
+
|
98
|
+
ior.read.should == data.join
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
7
109
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,7 @@ require 'simplecov'
|
|
4
4
|
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
5
5
|
require "io_shuten"
|
6
6
|
|
7
|
+
|
7
8
|
### MONKEY PATCH raise
|
8
9
|
|
9
10
|
RUBY_ENGINE = '(no engine)' unless defined? RUBY_ENGINE
|
@@ -41,3 +42,12 @@ RSpec::Matchers.define :inherit_from do |expected|
|
|
41
42
|
actual.ancestors.include?(expected)
|
42
43
|
end
|
43
44
|
end
|
45
|
+
|
46
|
+
### Configuration
|
47
|
+
|
48
|
+
Rspec.configure do |conf|
|
49
|
+
conf.before(:suite) do
|
50
|
+
REDIS = Redis::Namespace.new("io_shuten/test", :redis => Redis.new) unless defined? REDIS
|
51
|
+
IO_shuten::Redis.redis_clear!
|
52
|
+
end
|
53
|
+
end
|