sandthorn_driver_event_store 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72f4778deae2b0d24a481a8665fcdbb3ee98b55a
4
- data.tar.gz: b6474c0758bf60c41f95b4189229dd364dcc4bed
3
+ metadata.gz: 883266608d76e14b5ac8564cfda9772f6f57dab3
4
+ data.tar.gz: c03b2024c2e3b21045137ea17b5aad8361e1068a
5
5
  SHA512:
6
- metadata.gz: a693d6007d3b25e7d685c97458cf7ef58e02a4b66e376adb27238c6a88d706fc0203c01dcc21e555d8dc77edd914a448d52d880a78207ca23342c520c5251686
7
- data.tar.gz: 374ab395ffefc0f14d3d55922656db88ff2eaba211aafb2616785629af92d0c07e18fdfdf6aaed2f765512075ea45c21d30e2dffb3acaa484e08ab46fa938cf9
6
+ metadata.gz: 8678cae1ca039b20c79a1b489db66d3f5b2342d2d628be7d4274f3bed0c51d427c800f6352e8590759a0506794ad0c046ccd4e334ccb0f9d1a6a42ce81507134
7
+ data.tar.gz: f90332f8d8f7be8fff0787ecb8d7908e8911f9ed0eb17406ea8d6355245ee3ce5e5dec9906cebc52a8987eacd4aac6ead472f7378d6c960a13b9821348496ccf
@@ -1 +1 @@
1
- ruby-2.1
1
+ ruby-2.2.3
@@ -0,0 +1,16 @@
1
+ FROM ruby:2.5
2
+
3
+ WORKDIR .
4
+
5
+ ENV http_proxy "http://wwwproxy.se.axis.com:3128/"
6
+ ENV NO_PROXY "localhost,127.0.0.1,se.axis.com"
7
+ ENV HTTPS_PROXY "http://wwwproxy.se.axis.com:3128/"
8
+ ENV HTTP_PROXY "http://wwwproxy.se.axis.com:3128/"
9
+
10
+ RUN ["apt-get", "update"]
11
+ RUN ["apt-get", "install", "-y", "sqlite3"]
12
+
13
+ RUN ["gem", "install", "bundler"]
14
+
15
+ CMD ["/bin/bash"]
16
+
data/Gemfile CHANGED
@@ -1,5 +1,4 @@
1
1
  source 'https://rubygems.org'
2
-
3
2
  gemspec
4
3
 
5
- gem 'http_eventstore', git: 'git://github.com/hallgren/http_eventstore.git', branch: 'event_store_version_3' #path: '../http_eventstore'
4
+ gem "http_event_store", git: "https://github.com/hallgren/http_event_store.git"
data/README.md CHANGED
@@ -27,11 +27,10 @@ Or install it yourself as:
27
27
 
28
28
  SandthornDriverEventStore.driver host: "localhost", port: 2113
29
29
 
30
- ## Todo
30
+ ## Not supported
31
31
 
32
32
  * All - Get all events based on Aggregate type (Class)
33
33
  * Get events - Functionallity for [Sandthorn Sequel Projection](https://github.com/Sandthorn/sandthorn_sequel_projection)
34
- * Implement snapshoting, now all event of an aggregate has to be fetched to build the aggregate.
35
34
 
36
35
  ## Contributing
37
36
 
@@ -0,0 +1,24 @@
1
+ version: '3'
2
+ services:
3
+ db:
4
+ image: eventstore/eventstore
5
+ volumes:
6
+ - ./tmp/db:/var/lib/postgresql/data
7
+ environment:
8
+ EVENTSTORE_RUN_PROJECTIONS: All
9
+ EVENTSTORE_START_STANDARD_PROJECTIONS: All
10
+ ports:
11
+ - "2113:2113"
12
+ driver:
13
+ build:
14
+ context: .
15
+ dockerfile: Dockerfile
16
+ environment:
17
+ NO_PROXY: db
18
+ no_proxy: db
19
+ stdin_open: true
20
+ tty: true
21
+ volumes:
22
+ - .:/code
23
+ depends_on:
24
+ - db
@@ -6,7 +6,7 @@ module SandthornDriverEventStore
6
6
  def store_events(events = [])
7
7
  events = Utilities.array_wrap(events)
8
8
  timestamp = Time.now.utc
9
- stream_name = events.first[:aggregate_id]
9
+ stream_name = events.first[:aggregate_type].to_s + "-" +events.first[:aggregate_id]
10
10
 
11
11
  event_store_events = events.map do |event|
12
12
  build_event_data(timestamp, event)
@@ -18,11 +18,13 @@ module SandthornDriverEventStore
18
18
  end
19
19
  end
20
20
 
21
- def find_events_by_aggregate_id(aggregate_id)
22
- return storage.read_all_events_forward(aggregate_id).map { |event|
21
+ def find_events(aggregate_id, aggregate_type, after_aggregate_version = 0)
22
+ stream_name = aggregate_type.to_s + "-" + aggregate_id
23
+ return storage.read_events_forward(stream_name, after_aggregate_version, 2000).reverse.map { |event|
24
+ aggregate_id = event.stream_name.partition('-').last
23
25
  {
24
- event_args: JSON.parse(event.data.to_json, symbolize_names: true),
25
- aggregate_id: event.stream_name,
26
+ event_data: JSON.parse(event.data.to_json, symbolize_names: true),
27
+ aggregate_id: aggregate_id,
26
28
  aggregate_version: event.position+1,
27
29
  event_name: event.type
28
30
  }
@@ -45,7 +47,7 @@ module SandthornDriverEventStore
45
47
  def build_event_data(timestamp, event)
46
48
  {
47
49
  event_type: event[:event_name].to_s,
48
- data: event[:event_args],
50
+ data: event[:event_data],
49
51
  event_id: SecureRandom.uuid,
50
52
  id: event[:aggregate_id],
51
53
  position: event[:aggregate_version]-1,
@@ -10,18 +10,18 @@ module SandthornDriverEventStore
10
10
  end
11
11
  end
12
12
 
13
- def save_events events, aggregate_id, class_name
13
+ def save_events events, aggregate_id, aggregate_type
14
14
  driver.execute do |db|
15
15
  event_access = get_event_access(db)
16
- events = events.map { |event| event[:aggregate_type] = class_name; event[:aggregate_id] = aggregate_id; event;}
16
+ events = events.map { |event| event[:aggregate_type] = aggregate_type; event[:aggregate_id] = aggregate_id; event;}
17
17
  event_access.store_events(events)
18
18
  end
19
19
  end
20
20
 
21
- def find aggregate_id
21
+ def find aggregate_id, aggregate_type, after_aggregate_version = 0
22
22
  driver.execute do |db|
23
23
  event_access = get_event_access(db)
24
- event_access.find_events_by_aggregate_id(aggregate_id)
24
+ event_access.find_events(aggregate_id, aggregate_type, after_aggregate_version)
25
25
  end
26
26
  end
27
27
 
@@ -1,11 +1,11 @@
1
- require 'http_eventstore'
1
+ require 'http_event_store'
2
2
 
3
3
  module SandthornDriverEventStore
4
4
  class EventStoreDriver
5
5
 
6
6
  def initialize host:, port:, page_size:
7
7
 
8
- @connection = HttpEventstore::Connection.new do |config|
8
+ @connection = HttpEventStore::Connection.new do |config|
9
9
  #default value is '127.0.0.1'
10
10
  config.endpoint = host
11
11
  #default value is 2113
@@ -1,3 +1,3 @@
1
1
  module SandthornDriverEventStore
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
8
8
  spec.version = SandthornDriverEventStore::VERSION
9
9
  spec.authors = ["Morgan Hallgren"]
10
10
  spec.email = ["morgan.hallgren@gmail.com"]
11
- spec.description = %q{Event Store driver for Sandthorn}
11
+ spec.description = %q{Event Store driver}
12
12
  spec.summary = %q{Event Store driver for Sandthorn}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/Sandthorn/sandthorn_driver_event_store"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.required_ruby_version = ">= 2.0"
@@ -35,5 +35,5 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency "snappy"
36
36
  spec.add_development_dependency "guard-rspec"
37
37
 
38
- #spec.add_runtime_dependency "http_eventstore"
38
+ #spec.add_runtime_dependency "http_event_store"
39
39
  end
@@ -9,8 +9,9 @@ module SandthornDriverEventStore
9
9
 
10
10
  let(:db) { Sequel.connect(event_store_url)}
11
11
  let(:aggregate_id) { SecureRandom.uuid }
12
+ let(:aggregate_type) { "Foo"}
12
13
  let(:aggregate) do
13
- aggregate_access.register_aggregate(aggregate_id, "foo")
14
+ aggregate_access.register_aggregate(aggregate_id, aggregate_type)
14
15
  end
15
16
  let(:storage) { return event_store_driver.execute { |db| return db; } }
16
17
  let(:access) { EventAccess.new(storage) }
@@ -20,15 +21,15 @@ module SandthornDriverEventStore
20
21
  {
21
22
  aggregate_version: 1,
22
23
  aggregate_id: aggregate_id,
23
- aggregate_type: "Foo",
24
+ aggregate_type: aggregate_type,
24
25
  event_name: "new",
25
- event_args: {test: "new_data"}
26
+ event_data: {test: "new_data"}
26
27
  },{
27
28
  aggregate_version: 2,
28
29
  aggregate_id: aggregate_id,
29
- aggregate_type: "Foo",
30
+ aggregate_type: aggregate_type,
30
31
  event_name: "foo",
31
- event_args: {test: "foo_data"}
32
+ event_data: {test: "foo_data"}
32
33
  }
33
34
  ]
34
35
  end
@@ -37,26 +38,37 @@ module SandthornDriverEventStore
37
38
 
38
39
  it "handles both arrays and single events" do
39
40
  access.store_events(events[0])
40
- events = access.find_events_by_aggregate_id(aggregate_id)
41
+ events = access.find_events(aggregate_id, aggregate_type)
41
42
  expect(events.length).to eq(1)
42
43
  end
43
44
 
44
45
  context "when the aggregate version of an event is incorrect" do
45
46
  it "throws an error" do
46
47
  event = { aggregate_version: 100, aggregate_id: aggregate_id, aggregate_type: "Foo", event_name: "new", event_data: "noop" }
47
- expect { access.store_events([event])}.to raise_error
48
+ expect { access.store_events([event])}.to raise_error HttpEventStore::WrongExpectedEventNumber
48
49
  end
49
50
  end
50
51
  end
51
52
 
52
- describe "#find_events_by_aggregate_id" do
53
+ describe "#find_events" do
53
54
  context "when there are events" do
54
55
  it "returns correct events" do
55
56
  access.store_events(events)
56
57
 
57
- stored_events = access.find_events_by_aggregate_id(aggregate_id)
58
+ stored_events = access.find_events(aggregate_id, aggregate_type, 0)
58
59
  expect(stored_events.size).to eq(events.size)
59
- expect(stored_events).to all(respond_to(:merge))
60
+ stored_events.each { |event|
61
+ expect(event[:aggregate_id]).to eql aggregate_id
62
+ }
63
+ end
64
+ end
65
+
66
+ context "when getting with after_aggregate_version 1" do
67
+ it "returns correct events" do
68
+ access.store_events(events)
69
+
70
+ stored_events = access.find_events(aggregate_id, aggregate_type, 1)
71
+ expect(stored_events.size).to eq(events.size-1)
60
72
  stored_events.each { |event|
61
73
  expect(event[:aggregate_id]).to eql aggregate_id
62
74
  }
@@ -1,4 +1,4 @@
1
- require 'http_eventstore'
1
+ require 'http_event_store'
2
2
  require 'in_memory_es'
3
3
 
4
4
  module SandthornDriverEventStore
@@ -6,24 +6,25 @@ module SandthornDriverEventStore
6
6
  context "when saving a prefectly sane event stream" do
7
7
  let(:test_events) do
8
8
  e = []
9
- e << {aggregate_version: 1, event_name: "new", event_args: {:method_name=>"new", :method_args=>[], :attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>"e147e4bb-e98d-4008-ae9a-0bccce314d7b"}]}}
10
- e << {aggregate_version: 2, event_name: "foo", event_args: {:method_name=>"foo", :method_args=>[], :attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>"e147e4bb-e98d-4008-ae9a-0bccce314d7b"}]}}
11
- e << {aggregate_version: 3, event_name: "flubber", event_args: {:method_name=>"flubber", :method_args=>["bar"], :attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>"e147e4bb-e98d-4008-ae9a-0bccce314d7b"}]}}
9
+ e << {aggregate_version: 1, aggregate_id: aggregate_id, event_name: "new", event_data: {}}
10
+ e << {aggregate_version: 2, aggregate_id: aggregate_id, event_name: "foo", event_data: {}}
11
+ e << {aggregate_version: 3, aggregate_id: aggregate_id, event_name: "flubber", event_data: {}}
12
12
  end
13
13
 
14
14
  let(:aggregate_id) { SecureRandom.uuid }
15
15
 
16
16
  it "should be able to save and retrieve events on the aggregate" do
17
17
  event_store.save_events test_events, aggregate_id, String
18
- events = event_store.find aggregate_id
18
+ events = event_store.find aggregate_id, String
19
+
19
20
  expect(events.length).to eql test_events.length
20
21
  end
21
22
 
22
23
  it "should have correct keys when asking for events" do
23
24
  event_store.save_events test_events, aggregate_id, String
24
- events = event_store.find aggregate_id
25
+ events = event_store.find aggregate_id, String
25
26
  event = events.first
26
- expect(event[:event_args]).to eql(test_events.first[:event_args])
27
+ expect(event[:event_data]).to eql(test_events.first[:event_data])
27
28
  expect(event[:event_name]).to eql("new")
28
29
  expect(event[:aggregate_id]).to eql aggregate_id
29
30
  expect(event[:aggregate_version]).to eql 1
@@ -28,6 +28,6 @@ def event_store_driver
28
28
  end
29
29
 
30
30
  def event_store
31
- @event_store ||= SandthornDriverEventStore.driver host: "localhost", port: 2113, page_size: 20
31
+ @event_store ||= SandthornDriverEventStore.driver host: "db", port: 2113, page_size: 20
32
32
  return @event_store
33
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sandthorn_driver_event_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morgan Hallgren
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-25 00:00:00.000000000 Z
11
+ date: 2018-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -192,7 +192,7 @@ dependencies:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
- description: Event Store driver for Sandthorn
195
+ description: Event Store driver
196
196
  email:
197
197
  - morgan.hallgren@gmail.com
198
198
  executables: []
@@ -205,11 +205,13 @@ files:
205
205
  - ".ruby-gemset"
206
206
  - ".ruby-version"
207
207
  - ".travis.yml"
208
+ - Dockerfile
208
209
  - Gemfile
209
210
  - Guardfile
210
211
  - LICENSE.txt
211
212
  - README.md
212
213
  - Rakefile
214
+ - docker-compose.yml
213
215
  - lib/sandthorn_driver_event_store.rb
214
216
  - lib/sandthorn_driver_event_store/access.rb
215
217
  - lib/sandthorn_driver_event_store/access/event_access.rb
@@ -230,7 +232,7 @@ files:
230
232
  - spec/in_memory_event_store_driver.rb
231
233
  - spec/saving_events_spec.rb
232
234
  - spec/spec_helper.rb
233
- homepage: ''
235
+ homepage: https://github.com/Sandthorn/sandthorn_driver_event_store
234
236
  licenses:
235
237
  - MIT
236
238
  metadata: {}
@@ -250,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
252
  version: '0'
251
253
  requirements: []
252
254
  rubyforge_project:
253
- rubygems_version: 2.4.3
255
+ rubygems_version: 2.5.2.1
254
256
  signing_key:
255
257
  specification_version: 4
256
258
  summary: Event Store driver for Sandthorn
@@ -262,4 +264,3 @@ test_files:
262
264
  - spec/in_memory_event_store_driver.rb
263
265
  - spec/saving_events_spec.rb
264
266
  - spec/spec_helper.rb
265
- has_rdoc: