aggro 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0390645ca46508f02d985623d99edef035ab1dbe
4
+ data.tar.gz: d4835e34b8fbf89d108a9b349b603ce6f677de9d
5
+ SHA512:
6
+ metadata.gz: 20423f5017bd38745a381efa55e7e863269e9e568ea47456587a0977e2cd96c8edd147e97001dccaa0ea70a4a6c3f54e270c59a346b905130037b9a9b72ca20e
7
+ data.tar.gz: ca72c456d6292cc417f2629449efed271189327b06da282be82b10cb269322d613029e6e0882f0ec5d3884e1acf36d7bef1da6e23ce3481929b7778978db8414
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .ruby-gemset
16
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ Exclude:
3
+ - aggro.gemspec
4
+ - lib/aggro/version.rb
5
+
6
+ Eval:
7
+ Exclude:
8
+ - spec/spec_helper.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aggro.gemspec
4
+ gemspec
@@ -0,0 +1,14 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ require 'guard/rspec/dsl'
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
14
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Sebastian Edwards
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Aggro
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'aggro'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install aggro
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/aggro/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aggro/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'aggro'
8
+ spec.version = Aggro::VERSION
9
+ spec.authors = ['Sebastian Edwards']
10
+ spec.email = ['me@sebastianedwards.co.nz']
11
+ spec.summary = 'Distributed in-memory aggregates.'
12
+ spec.description = ''
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ spec.add_development_dependency 'guard-rspec'
25
+ spec.add_development_dependency 'rubocop'
26
+
27
+ spec.add_runtime_dependency 'consistent-hashing'
28
+ end
@@ -0,0 +1,22 @@
1
+ require 'aggro/version'
2
+
3
+ require 'consistent_hashing'
4
+
5
+ require 'aggro/aggregate_ref'
6
+
7
+ # Public: Module for namespacing and configuration methods.
8
+ module Aggro
9
+ def self.initialize_hash_ring(servers = servers_from_env)
10
+ ConsistentHashing::Ring.new.tap do |ring|
11
+ servers.each { |server| ring.add server }
12
+ end
13
+ end
14
+
15
+ def self.hash_ring
16
+ @hash_ring ||= initialize_hash_ring
17
+ end
18
+
19
+ def self.servers_from_env
20
+ ENV['AGGRO_SERVERS'] ? ENV['AGGRO_SERVERS'].split(',') : []
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ module Aggro
2
+ # Public: Reference to an Aggregate which may be local or remote.
3
+ class AggregateRef
4
+ attr_reader :id
5
+
6
+ def initialize(id)
7
+ @id = id
8
+ end
9
+
10
+ def server
11
+ @server ||= Aggro.hash_ring.node_for(id)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Aggro
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe AggregateRef do
4
+ subject(:ref) { AggregateRef.new(id) }
5
+
6
+ let(:id) { SecureRandom.uuid }
7
+ let(:fake_ring) { double(node_for: '10.0.0.70') }
8
+
9
+ before do
10
+ allow(Aggro).to receive(:hash_ring).and_return fake_ring
11
+ end
12
+
13
+ describe '#server' do
14
+ it 'should return the server on which the aggregate lives' do
15
+ expect(ref.server).to eq '10.0.0.70'
16
+ end
17
+
18
+ it 'should memorize the lookup to reduce hashing' do
19
+ expect(fake_ring).to receive(:node_for).once
20
+ 5.times { ref.server }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aggro do
4
+ describe '.initialize_hash_ring' do
5
+ context 'when called without args' do
6
+ it 'should initialize the hash ring from env variable' do
7
+ hash_ring = Aggro.initialize_hash_ring
8
+ expect(hash_ring.nodes).to include '10.0.0.1'
9
+ expect(hash_ring.nodes).to include '10.0.0.2'
10
+ end
11
+ end
12
+
13
+ context 'when called with an array' do
14
+ it 'should initialize the hash ring from given array' do
15
+ hash_ring = Aggro.initialize_hash_ring ['10.0.0.50']
16
+ expect(hash_ring.nodes).to_not include '10.0.0.1'
17
+ expect(hash_ring.nodes).to include '10.0.0.50'
18
+ end
19
+ end
20
+ end
21
+
22
+ describe '.hash_ring' do
23
+ it 'should return a hash ring' do
24
+ expect(Aggro.hash_ring).to be_a ConsistentHashing::Ring
25
+ end
26
+
27
+ it 'should return the same hash ring every time' do
28
+ expect(Aggro.hash_ring).to eq Aggro.hash_ring
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ RSpec.configure do |config|
2
+ config.order = :random
3
+ config.warnings = true
4
+
5
+ config.expect_with :rspec do |expectations|
6
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
7
+ end
8
+
9
+ config.mock_with :rspec do |mocks|
10
+ mocks.verify_partial_doubles = true
11
+ end
12
+ end
13
+
14
+ require 'aggro'
15
+
16
+ Aggro.constants.each do |const|
17
+ eval "#{const} = Aggro::#{const}"
18
+ end
19
+
20
+ ENV['AGGRO_SERVERS'] = '10.0.0.1,10.0.0.2'
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aggro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Edwards
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: consistent-hashing
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: ''
98
+ email:
99
+ - me@sebastianedwards.co.nz
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - Gemfile
108
+ - Guardfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - aggro.gemspec
113
+ - lib/aggro.rb
114
+ - lib/aggro/aggregate_ref.rb
115
+ - lib/aggro/version.rb
116
+ - spec/lib/aggro/aggregate_ref_spec.rb
117
+ - spec/lib/aggro_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: ''
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.4.5
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Distributed in-memory aggregates.
143
+ test_files:
144
+ - spec/lib/aggro/aggregate_ref_spec.rb
145
+ - spec/lib/aggro_spec.rb
146
+ - spec/spec_helper.rb