bloom_filter 0.6.5 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bloom_filter.gemspec +2 -2
- data/lib/bloom_filter.rb +10 -2
- data/lib/bloom_filter/client.rb +1 -0
- data/lib/bloom_filter/server.rb +24 -6
- data/test/bloom_filter_client_test.rb +1 -0
- data/test/bloom_filter_server_test.rb +13 -5
- metadata +2 -2
data/Rakefile
CHANGED
@@ -15,6 +15,7 @@ begin
|
|
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
|
17
17
|
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
18
19
|
rescue LoadError
|
19
20
|
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
21
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.6
|
data/bloom_filter.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bloom_filter}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.6"
|
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-02-
|
12
|
+
s.date = %q{2010-02-07}
|
13
13
|
s.default_executable = %q{bloom_filter_server}
|
14
14
|
s.description = %q{}
|
15
15
|
s.email = %q{misterfunnyarsal@gmail.com}
|
data/lib/bloom_filter.rb
CHANGED
@@ -57,8 +57,16 @@ class BloomFilter
|
|
57
57
|
[@m, @k, *@bits].join(DUMP_SEPARATOR)
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
61
|
-
m, k, bits
|
60
|
+
def dup
|
61
|
+
self.class.new(@m, @k, @bits.dup)
|
62
|
+
end
|
63
|
+
|
64
|
+
def replace(*args)
|
65
|
+
m, k, bits = if args.size == 1
|
66
|
+
self.class.read(args.first)
|
67
|
+
else
|
68
|
+
args
|
69
|
+
end
|
62
70
|
@m, @k = m, k
|
63
71
|
@bits.replace(bits)
|
64
72
|
end
|
data/lib/bloom_filter/client.rb
CHANGED
data/lib/bloom_filter/server.rb
CHANGED
@@ -67,18 +67,14 @@ class BloomFilter
|
|
67
67
|
write_response(request_body.split(Protocol::DEFAULT_SEPARATOR).collect { |el| self.class.filter.include?(el) })
|
68
68
|
when Protocol::DUMP
|
69
69
|
begin
|
70
|
-
|
71
|
-
f.write(self.class.filter.dump)
|
72
|
-
end
|
70
|
+
deferred_dump(request_body)
|
73
71
|
write_response(true)
|
74
72
|
rescue Exception => e
|
75
73
|
write_response(false)
|
76
74
|
end
|
77
75
|
when Protocol::LOAD
|
78
76
|
begin
|
79
|
-
|
80
|
-
self.class.filter.replace(file)
|
81
|
-
end
|
77
|
+
deferred_load(request_body)
|
82
78
|
write_response(true)
|
83
79
|
rescue Exception => e
|
84
80
|
write_response(false)
|
@@ -93,5 +89,27 @@ class BloomFilter
|
|
93
89
|
str = vector.to_s
|
94
90
|
send_data([str.size].pack(PACK_N) + str)
|
95
91
|
end
|
92
|
+
|
93
|
+
def deferred_load(file_name)
|
94
|
+
file = File.open(file_name, "r") # open here so IO errors are thrown to the caller
|
95
|
+
|
96
|
+
loader = lambda do
|
97
|
+
attrs = BloomFilter.read(file)
|
98
|
+
file.close unless file.nil? || file.closed?
|
99
|
+
attrs
|
100
|
+
end
|
101
|
+
|
102
|
+
setter = lambda do |attributes|
|
103
|
+
self.class.filter.replace(*attributes)
|
104
|
+
end
|
105
|
+
|
106
|
+
EM.defer(loader, setter)
|
107
|
+
end
|
108
|
+
|
109
|
+
def deferred_dump(file_name)
|
110
|
+
file = File.open(file_name, "w")
|
111
|
+
duped = self.class.filter.dup
|
112
|
+
EM.defer { file.write(duped.dump) }
|
113
|
+
end
|
96
114
|
end
|
97
115
|
end
|
@@ -123,6 +123,7 @@ class BloomFilterClientTest < Test::Unit::TestCase
|
|
123
123
|
socket = mock()
|
124
124
|
|
125
125
|
socket.stubs(:closed?).returns(false)
|
126
|
+
socket.stubs(:close)
|
126
127
|
TCPSocket.stubs(:new).with("localhost", 4111).returns(socket)
|
127
128
|
IO.stubs(:select).returns(socket)
|
128
129
|
socket.stubs(:write)
|
@@ -38,11 +38,14 @@ class BloomFilterServerTest < Test::Unit::TestCase
|
|
38
38
|
|
39
39
|
should "send dump" do
|
40
40
|
path = "/tmp/f"
|
41
|
-
|
41
|
+
dupped = mock()
|
42
|
+
@filter.expects(:dup).returns(dupped)
|
43
|
+
dupped.expects(:dump).returns("dumped_data")
|
42
44
|
|
43
45
|
file = mock()
|
44
|
-
File.expects(:open).with(path, 'w').
|
46
|
+
File.expects(:open).with(path, 'w').returns(file)
|
45
47
|
file.expects(:write).with("dumped_data")
|
48
|
+
EM.expects(:defer).with().yields()
|
46
49
|
|
47
50
|
expects_send_data("#{[1].pack("N")}#{BloomFilter::Protocol::TRUE}")
|
48
51
|
|
@@ -53,9 +56,14 @@ class BloomFilterServerTest < Test::Unit::TestCase
|
|
53
56
|
should "send load" do
|
54
57
|
path = "/tmp/f"
|
55
58
|
file = mock()
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
+
file.stubs(:closed?)
|
60
|
+
file.stubs(:close)
|
61
|
+
attrs = [1,2,3]
|
62
|
+
BloomFilter.stubs(:read).with(file).returns(attrs)
|
63
|
+
@filter.expects(:replace).with(*attrs)
|
64
|
+
EM.expects(:defer).with {|loader, setter| setter.call(loader.call); true}
|
65
|
+
File.expects(:open).with(path, 'r').returns(file)
|
66
|
+
|
59
67
|
expects_send_data("#{[1].pack("N")}#{BloomFilter::Protocol::TRUE}")
|
60
68
|
|
61
69
|
@server.receive_data("#{[path.size + 1].pack("N")}#{BloomFilter::Protocol::LOAD}#{path}")
|
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.
|
4
|
+
version: 0.6.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arya Asemanfar
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-07 00:00:00 -08:00
|
13
13
|
default_executable: bloom_filter_server
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|