jruby-bloomfilter 1.0.5 → 1.0.10
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.lock +1 -1
- data/bloomfilter.gemspec +6 -6
- data/lib/bloomfilter/serialization/file.rb +18 -3
- data/lib/bloomfilter/serialization/s3.rb +20 -7
- data/lib/bloomfilter/serializer.rb +1 -1
- data/spec/serialization_spec.rb +40 -5
- metadata +7 -7
data/Gemfile.lock
CHANGED
data/bloomfilter.gemspec
CHANGED
@@ -6,19 +6,19 @@ Dir['ext/*.jar'].each { |jar| require jar }
|
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = 'jruby-bloomfilter'
|
9
|
-
s.version = '1.0.
|
9
|
+
s.version = '1.0.10'
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
|
-
s.authors = ['Daniel Gaiottino']
|
12
|
-
s.email = ['daniel@burtcorp.com']
|
11
|
+
s.authors = ['Daniel Gaiottino', 'David Tollmyr']
|
12
|
+
s.email = ['daniel@burtcorp.com', 'david@burtcorp.com']
|
13
13
|
s.homepage = 'http://github.com/gaiottino/bloomfilter'
|
14
14
|
s.summary = %q{JRuby wrapper for java-bloomfilter}
|
15
15
|
s.description = %q{JRuby wrapper (+ some extra functionality) to http://code.google.com/p/java-bloomfilter}
|
16
16
|
|
17
17
|
s.rubyforge_project = 'jruby-bloomfilter'
|
18
|
-
s.add_dependency 'jets3t-rb'
|
18
|
+
s.add_dependency 'jets3t-rb', '>= 1.0.2'
|
19
19
|
|
20
20
|
s.files = `git ls-files`.split("\n")
|
21
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
#s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
#s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
23
|
s.require_paths = %w(lib)
|
24
24
|
end
|
@@ -1,15 +1,25 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
1
3
|
module Bloomfilter
|
2
4
|
module Serialization
|
3
5
|
class File
|
4
6
|
def store(path, filter)
|
5
7
|
dir = ::File.dirname(path)
|
6
8
|
unless ::File.directory?(dir)
|
7
|
-
|
9
|
+
begin
|
10
|
+
FileUtils.mkdir_p(dir)
|
11
|
+
rescue => e
|
12
|
+
$stderr.puts "Exception raised when trying to create directory: #{path} - #{e.message}"
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
16
|
unless ::File.directory?(dir)
|
11
17
|
$stderr.puts "Unable to create the directory #{dir}. Trying again."
|
12
|
-
|
18
|
+
begin
|
19
|
+
FileUtils.mkdir_p(dir)
|
20
|
+
rescue => e
|
21
|
+
$stderr.puts "Exception raised when trying to create directory: #{path} - #{e.message}"
|
22
|
+
end
|
13
23
|
end
|
14
24
|
|
15
25
|
unless ::File.directory?(dir)
|
@@ -25,8 +35,13 @@ module Bloomfilter
|
|
25
35
|
return nil unless ::File.exist?(path)
|
26
36
|
|
27
37
|
::File.open(path, 'r') do |f|
|
28
|
-
|
38
|
+
begin
|
39
|
+
@loaded_file = Marshal.load(f) unless f.size == 0
|
40
|
+
rescue => e
|
41
|
+
@loaded_file = nil
|
42
|
+
end
|
29
43
|
end
|
44
|
+
@loaded_file
|
30
45
|
end
|
31
46
|
|
32
47
|
private
|
@@ -12,19 +12,32 @@ module Bloomfilter
|
|
12
12
|
@bucket = s3_service.bucket(bucket_name)
|
13
13
|
end
|
14
14
|
|
15
|
+
def store_file(path, file_path)
|
16
|
+
begin
|
17
|
+
file = ::File.new(file_path)
|
18
|
+
path.slice!(0) if path[0] == '/'
|
19
|
+
@bucket.put(path, file)
|
20
|
+
rescue Exception => e
|
21
|
+
$stderr.puts "Exception when storing to S3 #{e.message}"
|
22
|
+
$stderr.puts e.backtrace
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
15
26
|
def store(path, filter)
|
16
|
-
|
17
|
-
|
18
|
-
|
27
|
+
begin
|
28
|
+
data = Marshal.dump(filter).to_java_bytes
|
29
|
+
@bucket.put_data(path, data)
|
30
|
+
end
|
19
31
|
end
|
20
32
|
|
21
33
|
def load(path)
|
22
34
|
s3_object = @bucket.get(path)
|
23
|
-
|
24
|
-
|
25
|
-
|
35
|
+
return nil if s3_object.nil?
|
36
|
+
begin
|
37
|
+
@loaded_file = Marshal.load(s3_object.data)
|
38
|
+
rescue Exception => e
|
39
|
+
nil
|
26
40
|
end
|
27
|
-
@file_serializer.load(tmp.path)
|
28
41
|
end
|
29
42
|
end
|
30
43
|
end
|
@@ -5,7 +5,7 @@ module Bloomfilter
|
|
5
5
|
class Serializer
|
6
6
|
|
7
7
|
def self.s3(access_key, secret_key, bucket_name)
|
8
|
-
credentials = JetS3t::AWSCredentials.new(
|
8
|
+
credentials = JetS3t::AWSCredentials.new(access_key, secret_key)
|
9
9
|
s3_service = JetS3t::RestS3Service.new(credentials)
|
10
10
|
return Serialization::S3.new(s3_service, bucket_name)
|
11
11
|
end
|
data/spec/serialization_spec.rb
CHANGED
@@ -11,12 +11,14 @@ module Bloomfilter
|
|
11
11
|
@filter << 'hello'
|
12
12
|
@filter << 'world'
|
13
13
|
@path = Tempfile.new('bloomfilter').path
|
14
|
+
%x(rm -rf /tmp/bloomfilter_spec)
|
15
|
+
@path2 = "/tmp/bloomfilter_spec/test1/test2/test3"
|
14
16
|
end
|
15
17
|
|
16
18
|
context 'File' do
|
17
19
|
it 'should be possible to store a filter to a file' do
|
18
20
|
Serializer.file.store(@path, @filter)
|
19
|
-
File.new(@path).size.should
|
21
|
+
File.new(@path).size.should > 0
|
20
22
|
end
|
21
23
|
|
22
24
|
it 'should be possible to load a filter from a file' do
|
@@ -26,9 +28,19 @@ module Bloomfilter
|
|
26
28
|
filter.include?('world').should be_true
|
27
29
|
filter.include?('bloomfilter').should be_false
|
28
30
|
end
|
31
|
+
|
32
|
+
it 'should create a recursive directory for storing stuff' do
|
33
|
+
1000.times do | i |
|
34
|
+
filename = @path2 + "/test#{i}/staticdir/filter"
|
35
|
+
Serializer.file.store(filename, @filter)
|
36
|
+
f = File.new(filename)
|
37
|
+
f.size.should > 0
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
29
41
|
end
|
30
42
|
|
31
|
-
context 'S3' do
|
43
|
+
context 'S3 stubbed' do
|
32
44
|
before do
|
33
45
|
bucket_name = 'test-bucket'
|
34
46
|
s3_service = stub('s3_service')
|
@@ -38,17 +50,40 @@ module Bloomfilter
|
|
38
50
|
@s3 = Serialization::S3.new(s3_service, bucket_name)
|
39
51
|
end
|
40
52
|
|
41
|
-
it 'should
|
42
|
-
@bucket.should_receive(:put).with('
|
53
|
+
it 'should send serialized file to S3 and strip leading /' do
|
54
|
+
@bucket.should_receive(:put).with('some/path', anything)
|
43
55
|
@s3.store('/some/path', @filter)
|
44
56
|
end
|
45
57
|
|
46
|
-
it 'should
|
58
|
+
it 'should try and get serialized file from S3' do
|
47
59
|
s3_object = stub('s3_object')
|
48
60
|
@bucket.should_receive(:get).with('/some/path').and_return(s3_object)
|
49
61
|
s3_object.should_receive(:data).and_return(Marshal.dump(@filter))
|
50
62
|
@s3.load('/some/path')
|
51
63
|
end
|
52
64
|
end
|
65
|
+
|
66
|
+
context 'S3' do
|
67
|
+
before do
|
68
|
+
aws_secret_path = '~/.awssecret'.freeze
|
69
|
+
raise "#{aws_secret_path} not found" unless File.exist?(File.expand_path(aws_secret_path))
|
70
|
+
access_key_id, secret_access_key = File.readlines(File.expand_path(aws_secret_path)).map(&:chomp)
|
71
|
+
@bucket_name = 'test-bucket-12345'
|
72
|
+
credentials = JetS3t::AWSCredentials.new(access_key_id, secret_access_key)
|
73
|
+
s3_service = JetS3t::RestS3Service.new(credentials)
|
74
|
+
@s3 = Serialization::S3.new(s3_service, @bucket_name)
|
75
|
+
@store_path = "/path/rspec_store_test.bin"
|
76
|
+
bucket = s3_service.bucket(@bucket_name)
|
77
|
+
bucket.delete(@store_path)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should be possible to store and load a filter from S3' do
|
81
|
+
@s3.store(@store_path, @filter)
|
82
|
+
filter = @s3.load(@store_path)
|
83
|
+
filter.include?('hello').should be_true
|
84
|
+
filter.include?('world').should be_true
|
85
|
+
filter.include?('bloomfilter').should be_false
|
86
|
+
end
|
87
|
+
end
|
53
88
|
end
|
54
89
|
end
|
metadata
CHANGED
@@ -2,15 +2,16 @@
|
|
2
2
|
name: jruby-bloomfilter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Daniel Gaiottino
|
9
|
+
- David Tollmyr
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
13
|
|
13
|
-
date: 2011-
|
14
|
+
date: 2011-08-04 00:00:00 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: jets3t-rb
|
@@ -20,12 +21,13 @@ dependencies:
|
|
20
21
|
requirements:
|
21
22
|
- - ">="
|
22
23
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
24
|
+
version: 1.0.2
|
24
25
|
type: :runtime
|
25
26
|
version_requirements: *id001
|
26
27
|
description: JRuby wrapper (+ some extra functionality) to http://code.google.com/p/java-bloomfilter
|
27
28
|
email:
|
28
29
|
- daniel@burtcorp.com
|
30
|
+
- david@burtcorp.com
|
29
31
|
executables: []
|
30
32
|
|
31
33
|
extensions: []
|
@@ -75,7 +77,5 @@ rubygems_version: 1.8.5
|
|
75
77
|
signing_key:
|
76
78
|
specification_version: 3
|
77
79
|
summary: JRuby wrapper for java-bloomfilter
|
78
|
-
test_files:
|
79
|
-
|
80
|
-
- spec/serialization_spec.rb
|
81
|
-
- spec/spec_helper.rb
|
80
|
+
test_files: []
|
81
|
+
|