io_shuten 0.0.3.dev1 → 0.1.0.dev6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  module IO_shuten
3
3
  # @private
4
- VERSION = [0,0,3,'dev1'].join('.')
4
+ VERSION = [0,1,0,'dev6'].join('.')
5
5
  end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module IO_shuten
4
+ # Implementation of the ZMQ
5
+ #
6
+ # @todo Needs different backends (pub-sub, req-recv)!
7
+ class Zmq < IO_shuten::Base
8
+
9
+ end
10
+ end
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
@@ -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.puts "Test string"
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.puts "Test string"
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.puts "Test string"
378
+ iob.write "Test string"
377
379
  expect { iob.save_to_file }.to raise_error(Errors::FileAccessError, /Reason/)
378
380
  end
379
381
  end
@@ -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.puts "Test string"
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.puts "Test string"
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.puts "Test string"
415
+ iom.write "Test string"
414
416
  expect { iom.save_to_file }.to raise_error(Errors::FileAccessError, /Reason/)
415
417
  end
416
418
  end
@@ -1,7 +1,109 @@
1
1
  # encoding: utf-8
2
2
  require File.expand_path("../../spec_helper.rb", __FILE__)
3
3
 
4
- include IO_shuten
5
- describe Redis do
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
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../../spec_helper.rb", __FILE__)
3
+
4
+ include IO_shuten
5
+ describe Zmq do
6
+ it { IO_shuten::Zmq.should inherit_from(IO_shuten::Base) }
7
+ 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