bloom_filter 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  gem.email = "misterfunnyarsal@gmail.com"
11
11
  gem.homepage = "http://github.com/arya/bloom_filter"
12
12
  gem.authors = ["Arya Asemanfar"]
13
- gem.add_development_dependency "thoughtbot-shoulda"
13
+ gem.add_development_dependency "shoulda"
14
14
  gem.add_development_dependency "mocha"
15
15
  gem.add_dependency "eventmachine", ">=0.12.8"
16
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
data/bloom_filter.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bloom_filter}
8
- s.version = "0.6.0"
8
+ s.version = "0.6.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Arya Asemanfar"]
12
- s.date = %q{2010-01-23}
12
+ s.date = %q{2010-01-26}
13
13
  s.default_executable = %q{bloom_filter_server}
14
14
  s.description = %q{}
15
15
  s.email = %q{misterfunnyarsal@gmail.com}
@@ -53,17 +53,18 @@ Gem::Specification.new do |s|
53
53
  s.specification_version = 3
54
54
 
55
55
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
57
57
  s.add_development_dependency(%q<mocha>, [">= 0"])
58
58
  s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.8"])
59
59
  else
60
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
60
+ s.add_dependency(%q<shoulda>, [">= 0"])
61
61
  s.add_dependency(%q<mocha>, [">= 0"])
62
62
  s.add_dependency(%q<eventmachine>, [">= 0.12.8"])
63
63
  end
64
64
  else
65
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
65
+ s.add_dependency(%q<shoulda>, [">= 0"])
66
66
  s.add_dependency(%q<mocha>, [">= 0"])
67
67
  s.add_dependency(%q<eventmachine>, [">= 0.12.8"])
68
68
  end
69
69
  end
70
+
@@ -2,12 +2,16 @@ require 'socket'
2
2
  require 'bloom_filter/protocol'
3
3
 
4
4
  class BloomFilter
5
- class Client
5
+ class Timeout < StandardError; end
6
+
7
+ class Client
8
+
6
9
  PACK_N = "N"
7
10
  def initialize(host, port, options = {})
8
11
  @host, @port = host, port
9
12
  @timeout = options[:timeout]
10
- reconnect
13
+ @raise_on_timeout = options[:raise_on_timeout] || false
14
+ self.connect
11
15
  end
12
16
 
13
17
  def add(el)
@@ -60,15 +64,25 @@ class BloomFilter
60
64
  end
61
65
  end
62
66
 
63
- def reconnect
64
- @socket.close if @socket && !@socket.closed?
65
- @socket = begin
66
- TCPSocket.new(@host, @port)
67
- rescue Exception => e
68
- nil
67
+ def connect
68
+ unless self.connected?
69
+ @socket = begin
70
+ TCPSocket.new(@host, @port)
71
+ rescue Exception => e
72
+ nil
73
+ end
69
74
  end
70
75
  end
71
76
 
77
+ def reconnect
78
+ self.disconnect
79
+ self.connect
80
+ end
81
+
82
+ def disconnect
83
+ @socket.close if self.connected?
84
+ end
85
+
72
86
  def connected?
73
87
  !!(@socket && !@socket.closed?)
74
88
  end
@@ -78,6 +92,8 @@ class BloomFilter
78
92
  ready = IO.select([@socket], nil, nil, timeout || @timeout)
79
93
  if ready
80
94
  block.call
95
+ elsif @raise_on_timeout
96
+ raise BloomFilter::Timeout
81
97
  else
82
98
  default
83
99
  end
@@ -57,5 +57,25 @@ class BloomFilterClientTest < Test::Unit::TestCase
57
57
  IO.expects(:select).with([@socket], nil, nil, 1)
58
58
  @client.add("hello")
59
59
  end
60
+
61
+ should "return false for add if it times out" do
62
+ @socket.expects(:write).with("#{[6].pack("N")}#{BloomFilter::Protocol::ADD}hello")
63
+ IO.expects(:select).with([@socket], nil, nil, 1).returns(nil)
64
+ assert !@client.add("hello")
65
+ end
66
+ end
67
+
68
+ should "raise on timeout if set to" do
69
+ socket = mock()
70
+ TCPSocket.expects(:new).with("localhost", 4111).returns(socket)
71
+ IO.stubs(:select).returns(socket)
72
+ client = BloomFilter::Client.new("localhost", 4111, :timeout => 1, :raise_on_timeout => true)
73
+
74
+
75
+ socket.expects(:write).with("#{[6].pack("N")}#{BloomFilter::Protocol::ADD}hello")
76
+ IO.expects(:select).with([socket], nil, nil, 1).returns(nil)
77
+ assert_raises(BloomFilter::Timeout) do
78
+ client.add("hello")
79
+ end
60
80
  end
61
81
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bloom_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arya Asemanfar
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-23 00:00:00 -08:00
12
+ date: 2010-01-26 00:00:00 -08:00
13
13
  default_executable: bloom_filter_server
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: thoughtbot-shoulda
16
+ name: shoulda
17
17
  type: :development
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement