From 4858b04a453b75f9ee566c548757ade9065c177b Mon Sep 17 00:00:00 2001 From: Morgan Hallgren Date: Tue, 14 Apr 2015 20:28:18 +0200 Subject: [PATCH 1/2] added snapshoting --- .../access/snapshot_access.rb | 49 ++-- lib/sandthorn_driver_sequel_2/errors.rb | 3 +- lib/sandthorn_driver_sequel_2/event_store.rb | 11 +- .../wrappers/snapshot_wrapper.rb | 4 + .../asking_for_aggregates_to_snapshot_spec.rb | 64 ----- spec/event_access_spec.rb | 13 -- spec/saving_snapshot_spec.rb | 137 +++++------ spec/snapshot_access_spec.rb | 221 +++++++++--------- 8 files changed, 190 insertions(+), 312 deletions(-) delete mode 100644 spec/asking_for_aggregates_to_snapshot_spec.rb diff --git a/lib/sandthorn_driver_sequel_2/access/snapshot_access.rb b/lib/sandthorn_driver_sequel_2/access/snapshot_access.rb index 9b2993c..df43345 100644 --- a/lib/sandthorn_driver_sequel_2/access/snapshot_access.rb +++ b/lib/sandthorn_driver_sequel_2/access/snapshot_access.rb @@ -2,7 +2,6 @@ module SandthornDriverSequel2 class SnapshotAccess < Access::Base def find_by_aggregate_id(aggregate_id) - #aggregate = aggregates.find_by_aggregate_id(aggregate_id) storage.snapshots.first(aggregate_id: aggregate_id) end @@ -11,42 +10,26 @@ def find(snapshot_id) end def record_snapshot(aggregate_id, snapshot_data) - #aggregate = aggregates.find_by_aggregate_id!(aggregate_id) + raise SandthornDriverSequel2::Errors::SnapshotDataError unless perform_snapshot?(snapshot_data) + previous_snapshot = find_by_aggregate_id(aggregate_id) - #if perform_snapshot?(aggregate, previous_snapshot) - perform_snapshot(aggregate_id, previous_snapshot, snapshot_data) - #end - end - - def obsolete(aggregate_types: [], max_event_distance: 100) - aggregate_types.map!(&:to_s) - snapshot_version = Sequel.qualify(storage.snapshots_table_name, :aggregate_version) - aggregate_version = Sequel.qualify(storage.aggregates_table_name, :aggregate_version) - aggregate_id = Sequel.qualify(storage.aggregates_table_name, :aggregate_id) - query = storage.aggregates.left_outer_join(storage.snapshots, aggregate_id: :aggregate_id) - query = query.select { (aggregate_version - snapshot_version).as(distance) } - query = query.select_append(aggregate_id, :aggregate_type) - query = query.where { (aggregate_version - coalesce(snapshot_version, 0)) > max_event_distance } - if aggregate_types.any? - query = query.where(aggregate_type: aggregate_types) + if previous_snapshot + return if previous_snapshot[:aggregate_version] == snapshot_data[:aggregate_version] end - query.all + perform_snapshot(aggregate_id, previous_snapshot, snapshot_data) end private - def aggregates - @aggregates ||= AggregateAccess.new(storage) - end - - def perform_snapshot?(aggregate, snapshot) - return true if snapshot.nil? - snapshot = SnapshotWrapper.new(snapshot) - aggregate.aggregate_version > snapshot.aggregate_version + def perform_snapshot?(snapshot_data) + return false if snapshot_data.nil? + return false unless snapshot_data.class == Hash + return false if snapshot_data[:aggregate_version].nil? + return false if snapshot_data[:event_data].nil? + return true end def perform_snapshot(aggregate_id, previous_snapshot, snapshot_data) - #check_snapshot_version!(aggregate, snapshot_data) if valid_snapshot?(previous_snapshot) update_snapshot(previous_snapshot, snapshot_data) else @@ -65,6 +48,7 @@ def build_snapshot(snapshot_data) { snapshot_data: snapshot_data.data, aggregate_version: snapshot_data.aggregate_version + # aggregate_type: snapshot_data.aggregate_version } end @@ -74,14 +58,7 @@ def valid_snapshot?(snapshot) def update_snapshot(snapshot, snapshot_data) data = build_snapshot(snapshot_data) - storage.snapshots.where(aggregate_id: snapshot.id).update(data) - end - - def check_snapshot_version!(aggregate, snapshot_data) - snapshot = SnapshotWrapper.new(snapshot_data) - if aggregate.aggregate_version < snapshot.aggregate_version - raise Errors::WrongSnapshotVersionError.new(aggregate, snapshot.aggregate_version) - end + storage.snapshots.where(id: snapshot.id).update(data) end end diff --git a/lib/sandthorn_driver_sequel_2/errors.rb b/lib/sandthorn_driver_sequel_2/errors.rb index 86b5092..761f715 100644 --- a/lib/sandthorn_driver_sequel_2/errors.rb +++ b/lib/sandthorn_driver_sequel_2/errors.rb @@ -3,7 +3,8 @@ module SandthornDriverSequel2::Errors InternalError = Class.new(Error) NoAggregateError = Class.new(Error) EventFormatError = Class.new(Error) - + SnapshotDataError = Class.new(Error) + class ConcurrencyError < Error attr_reader :event, :aggregate def initialize(event, aggregate) diff --git a/lib/sandthorn_driver_sequel_2/event_store.rb b/lib/sandthorn_driver_sequel_2/event_store.rb index 29bdb23..90b1f1c 100644 --- a/lib/sandthorn_driver_sequel_2/event_store.rb +++ b/lib/sandthorn_driver_sequel_2/event_store.rb @@ -41,9 +41,9 @@ def save_snapshot aggregate_snapshot, aggregate_id # TODO: needs a better name def get_aggregate_events_from_snapshot(aggregate_id) driver.execute do |db| - #snapshots = get_snapshot_access(db) + snapshots = get_snapshot_access(db) event_access = get_event_access(db) - snapshot = false#snapshots.find_by_aggregate_id(aggregate_id) + snapshot = snapshots.find_by_aggregate_id(aggregate_id) if snapshot events = event_access.after_snapshot(snapshot) snapshot_event = build_snapshot_event(snapshot) @@ -105,13 +105,6 @@ def get_new_events_after_event_id_matching_classname event_id, class_name, take: get_events(after_sequence_number: event_id, aggregate_types: Utilities.array_wrap(class_name), take: take) end - def obsolete_snapshots(*args) - driver.execute do |db| - snapshots = get_snapshot_access(db) - snapshots.obsolete(*args) - end - end - private def transform_snapshot(snapshot) diff --git a/lib/sandthorn_driver_sequel_2/wrappers/snapshot_wrapper.rb b/lib/sandthorn_driver_sequel_2/wrappers/snapshot_wrapper.rb index c39b81a..64a3a78 100644 --- a/lib/sandthorn_driver_sequel_2/wrappers/snapshot_wrapper.rb +++ b/lib/sandthorn_driver_sequel_2/wrappers/snapshot_wrapper.rb @@ -7,5 +7,9 @@ def aggregate_version def data self[:event_data] end + + # def aggregate_type + # self[:aggregate_type] + # end end end \ No newline at end of file diff --git a/spec/asking_for_aggregates_to_snapshot_spec.rb b/spec/asking_for_aggregates_to_snapshot_spec.rb deleted file mode 100644 index d5b973a..0000000 --- a/spec/asking_for_aggregates_to_snapshot_spec.rb +++ /dev/null @@ -1,64 +0,0 @@ -# require 'spec_helper' - -# class Foo; end -# class Bar; end - -# module SandthornDriverSequel2 - -# describe EventStore do -# before(:each) { prepare_for_test } -# context "when asking for aggregates to snapshot" do -# let(:aggregates) { -# [{id: "1", class_name: Foo}, {id: "2", class_name: Bar},{id: "3", class_name: Foo}]} - -# before(:each) {save_test_events} - -# context "when asking for type 'Bar' and max event count 5" do -# let(:needs_snapshot) { event_store.obsolete_snapshots aggregate_types: [Bar], max_event_distance: 5 } -# context "and no snapshots exist" do -# it "should return that id 2 with class Bar need to be snapshotted" do -# expect(needs_snapshot.length).to eql 1 -# expect(needs_snapshot.first[:aggregate_id]).to eql aggregates[1][:id] -# expect(needs_snapshot.first[:aggregate_type]).to eql "Bar" -# end -# end -# context "and a recent snapshot exists" do -# before(:each) do -# snapshot_data = { event_data: "YO MAN", aggregate_version: 11 } -# event_store.save_snapshot(snapshot_data, aggregates[1][:id]) -# end -# it "should return nil" do -# expect(needs_snapshot).to be_empty -# end -# end -# end - - -# def save_test_events -# for_1 = event_generator count: 4, start_at: 1 -# for_2 = event_generator count: 3, start_at: 1 -# for_3 = event_generator count: 6, start_at: 1 -# for_2_2 = event_generator count: 10, start_at: 4 -# for_1_2 = event_generator count: 1, start_at: 5 -# save_events for_1, 0 -# save_events for_2, 1 -# save_events for_3, 2 -# save_events for_1_2, 0 -# save_events for_2_2, 1 -# end -# def save_events events, aggregate_index -# event_store.save_events events, aggregates[aggregate_index][:id], aggregates[aggregate_index][:class_name] -# end - -# def event_generator count: 1, start_at: 1 -# events = [] -# i = 0 -# while i < count do -# events << { aggregate_version: i+start_at, event_data: nil, event_name: "event_foo_#{i}" } -# i += 1 -# end -# events -# end -# end -# end -# end \ No newline at end of file diff --git a/spec/event_access_spec.rb b/spec/event_access_spec.rb index 67d0ac7..29bc83e 100644 --- a/spec/event_access_spec.rb +++ b/spec/event_access_spec.rb @@ -11,11 +11,7 @@ module SandthornDriverSequel2 let(:context) { :test } let(:db) { Sequel.connect(event_store_url)} let(:aggregate_id) { SecureRandom.uuid } - let(:aggregate) do - aggregate_access.register_aggregate(aggregate_id, "foo") - end let(:storage) { Storage.new(db, :test, {}) } - let(:aggregate_access) { AggregateAccess.new(storage) } let(:snapshot_access) { SnapshotAccess.new(storage)} let(:access) { EventAccess.new(storage) } @@ -51,15 +47,6 @@ module SandthornDriverSequel2 expect(events.map(&:timestamp).all?).to be_truthy end - # it "updates the aggregate version" do - # access.store_events(events) - # events = access.find_events_by_aggregate_id(aggregate_id) - # version = events.map(&:aggregate_version).max - - # reloaded_aggregate = aggregate_access.find(aggregate.id) - # expect(reloaded_aggregate.aggregate_version).to eq(version) - # end - context "when the aggregate version of an event is incorrect" do it "throws an error" do event = { aggregate_version: 100, aggregate_id: aggregate_id, aggregate_type: "Foo", event_name: "new", event_data: "noop" } diff --git a/spec/saving_snapshot_spec.rb b/spec/saving_snapshot_spec.rb index b32d752..43da90e 100644 --- a/spec/saving_snapshot_spec.rb +++ b/spec/saving_snapshot_spec.rb @@ -1,77 +1,66 @@ -# require 'spec_helper' -# require 'yaml' +require 'spec_helper' +require 'yaml' -# module SandthornDriverSequel2 -# describe EventStore do -# before(:each) { prepare_for_test } -# let(:aggregate_id) { @id ||= UUIDTools::UUID.random_create.to_s } -# let(:test_events) { [{aggregate_version: 1, event_data: nil, event_name: "new"},{aggregate_version: 2, event_data: nil, event_name: "foo"}] } -# let(:additional_events) { [{aggregate_version: 3, event_data: nil, event_name: "klopp"},{aggregate_version: 4, event_data: nil, event_name: "flipp"}] } -# let(:snapshot_data) { { event_data: YAML.dump(Object.new), aggregate_version: 2 } } -# let(:save_snapshot) { event_store.save_snapshot snapshot_data, aggregate_id } -# let(:save_events) { event_store.save_events test_events, aggregate_id, SandthornDriverSequel2::EventStore } -# let(:save_additional_events) { event_store.save_events additional_events, aggregate_id, SandthornDriverSequel2::EventStore } -# context "when loading an aggregate using get_aggregate" do -# context "and it has a snapshot" do -# before(:each) do -# save_events -# save_snapshot -# save_additional_events -# end -# let(:events) { event_store.get_aggregate aggregate_id, SandthornDriverSequel2::EventStore } -# it "should have the first event as :aggregate_set_from_snapshot" do -# expect(events.first[:event_name]).to eql "aggregate_set_from_snapshot" -# end -# it "should have additional events after first snapshot-event" do -# expect(events.length).to eql 1+additional_events.length -# expect(events[1][:aggregate_version]).to eql additional_events[0][:aggregate_version] -# expect(events.last[:aggregate_version]).to eql additional_events.last[:aggregate_version] -# end -# end +module SandthornDriverSequel2 + describe EventStore do + before(:each) { prepare_for_test } + let(:aggregate_id) { @id ||= UUIDTools::UUID.random_create.to_s } + let(:test_events) { [{aggregate_version: 1, event_data: nil, event_name: "new"},{aggregate_version: 2, event_data: nil, event_name: "foo"}] } + let(:additional_events) { [{aggregate_version: 3, event_data: nil, event_name: "klopp"},{aggregate_version: 4, event_data: nil, event_name: "flipp"}] } + let(:snapshot_data) { { event_data: YAML.dump(Object.new), aggregate_version: 2 } } + let(:save_snapshot) { event_store.save_snapshot snapshot_data, aggregate_id } + let(:save_events) { event_store.save_events test_events, aggregate_id, SandthornDriverSequel2::EventStore } + let(:save_additional_events) { event_store.save_events additional_events, aggregate_id, SandthornDriverSequel2::EventStore } + context "when loading an aggregate using get_aggregate" do + context "and it has a snapshot" do + before(:each) do + save_events + save_snapshot + save_additional_events + end + let(:events) { event_store.get_aggregate aggregate_id, SandthornDriverSequel2::EventStore } + it "should have the first event as :aggregate_set_from_snapshot" do + expect(events.first[:event_name]).to eql "aggregate_set_from_snapshot" + end + it "should have additional events after first snapshot-event" do + expect(events.length).to eql 1+additional_events.length + expect(events[1][:aggregate_version]).to eql additional_events[0][:aggregate_version] + expect(events.last[:aggregate_version]).to eql additional_events.last[:aggregate_version] + end + end -# end -# context "when saving a snapshot" do + end + context "when saving a snapshot" do -# context "and events are saved beforehand" do -# before(:each) { save_events } -# it "should be able to save snapshot" do -# expect { save_snapshot }.to_not raise_error -# end -# it "should be able to save and get snapshot" do -# save_snapshot -# snap = event_store.get_snapshot(aggregate_id) -# expect(snap).to eql snapshot_data -# end -# end -# context "when trying to save a snapshot on a non-existing aggregate" do -# it "should raise a NonAggregateError" do -# expect { save_snapshot }.to raise_error SandthornDriverSequel2::Errors::NoAggregateError -# end -# end -# context "when trying to save a snapshot with a non-existing aggregate_version" do -# before(:each) { save_events } -# it "should raise a WrongAggregateVersion error" do -# data = snapshot_data -# data[:aggregate_version] = 100 -# expect { event_store.save_snapshot data, aggregate_id }.to raise_error SandthornDriverSequel2::Errors::WrongSnapshotVersionError -# end -# end -# context "when saving a snapshot twice" do -# before(:each) { save_events; save_snapshot } -# it "should not raise error" do -# expect { save_snapshot }.to_not raise_error -# end -# end -# context "when saving a snapshot on a version less than current version" do -# before(:each) { save_events; } -# it "should save without protesting" do -# data = snapshot_data -# data[:aggregate_version] = 1 -# event_store.save_snapshot(data, aggregate_id) -# snap = event_store.get_snapshot(aggregate_id) -# expect(snap).to eql data -# end -# end -# end -# end -# end \ No newline at end of file + context "and events are saved beforehand" do + before(:each) { save_events } + it "should be able to save snapshot" do + expect { save_snapshot }.to_not raise_error + end + it "should be able to save and get snapshot" do + save_snapshot + snap = event_store.get_snapshot(aggregate_id) + expect(snap).to eql snapshot_data + end + end + + + context "when saving a snapshot twice" do + before(:each) { save_events; save_snapshot } + it "should not raise error" do + expect { save_snapshot }.to_not raise_error + end + end + context "when saving a snapshot on a version less than current version" do + before(:each) { save_events; } + it "should save without protesting" do + data = snapshot_data + data[:aggregate_version] = 1 + event_store.save_snapshot(data, aggregate_id) + snap = event_store.get_snapshot(aggregate_id) + expect(snap).to eql data + end + end + end + end +end \ No newline at end of file diff --git a/spec/snapshot_access_spec.rb b/spec/snapshot_access_spec.rb index 5c6ad25..a7592dc 100644 --- a/spec/snapshot_access_spec.rb +++ b/spec/snapshot_access_spec.rb @@ -1,125 +1,116 @@ -# require 'spec_helper' +require 'spec_helper' -# module SandthornDriverSequel2 -# describe SnapshotAccess do -# include EventStoreContext +module SandthornDriverSequel2 + describe SnapshotAccess do + include EventStoreContext -# before do -# prepare_for_test -# end + before do + prepare_for_test + end -# let(:context) { :test } -# let(:db) { Sequel.connect(event_store_url)} -# let(:aggregate_id) { generate_uuid } -# let(:storage) { Storage.new(db, :test) } -# let(:aggregate_access) { AggregateAccess.new(storage) } -# let(:event_access) { EventAccess.new(storage) } -# let(:aggregate) { aggregate_access.register_aggregate(aggregate_id, "foo") } -# let(:access) { SnapshotAccess.new(storage) } -# let(:events) do -# [ -# { -# aggregate_id: aggregate_id, -# aggregate_type: "Foo", -# aggregate_version: 1, -# event_name: "new", -# event_data: "new_data" -# },{ -# aggregate_id: aggregate_id, -# aggregate_type: "Foo", -# aggregate_version: 2, -# event_name: "foo", -# event_data: "foo_data" -# } -# ] -# end + let(:context) { :test } + let(:db) { Sequel.connect(event_store_url)} + let(:aggregate_id) { generate_uuid } + let(:storage) { Storage.new(db, :test, {}) } + let(:event_access) { EventAccess.new(storage) } + let(:access) { SnapshotAccess.new(storage) } + let(:events) do + [ + { + sequence_number: 1, + aggregate_id: aggregate_id, + aggregate_type: "Foo", + aggregate_version: 1, + event_name: "new", + event_data: "new_data" + },{ + sequence_number: 2, + aggregate_id: aggregate_id, + aggregate_type: "Foo", + aggregate_version: 2, + event_name: "foo", + event_data: "foo_data" + } + ] + end -# describe "#find_by_aggregate_id" do -# it "returns the correct data" do -# aggregate = aggregate_access.register_aggregate(aggregate_id, "foo") -# access.record_snapshot(aggregate.aggregate_id, { aggregate_version: 0, event_data: "data" }) -# aggregate.update(aggregate_version: 1) -# snapshot = access.find_by_aggregate_id(aggregate.aggregate_id) -# expected = { -# # aggregate_table_id: aggregate.id, -# aggregate_id: aggregate.aggregate_id, -# aggregate_type: "Foo", -# aggregate_version: 0, -# snapshot_data: "data", -# id: snapshot.id -# } -# expect(snapshot.values).to eq(expected) -# end -# end + describe "#find_by_aggregate_id" do + it "returns the correct data" do + event_access.store_events(events[0]) + events = event_access.find_events_by_aggregate_id(aggregate_id) + access.record_snapshot(aggregate_id, { aggregate_version: 1, event_data: "data" }) + snapshot = access.find_by_aggregate_id(aggregate_id) + expected = { + aggregate_id: aggregate_id, + aggregate_version: 1, + snapshot_data: "data", + id: snapshot.id + } + expect(snapshot.values).to eq(expected) + end + end -# describe "#record" do -# context "when the aggregate doesn't exist" do -# it "raises an error" do -# expect { access.record_snapshot("qux", "data") }.to raise_error(Errors::NoAggregateError) -# end -# end -# context "when the aggregate exists" do -# context "when no previous snapshot exists" do -# it "records the snapshot" do -# #aggregate_table_id = aggregate_access.register_aggregate(aggregate_id, "foo").id -# expect(access.find_by_aggregate_id(aggregate_id)).to be_nil -# access.record_snapshot(aggregate_id, { aggregate_version: 0, event_data: "data"}) + describe "#record" do + context "when the aggregate doesn't exist" do + it "raises an error" do + expect { access.record_snapshot("qux", "data") }.to raise_error(Errors::SnapshotDataError) + end + end + context "when the aggregate exists" do + context "when no previous snapshot exists" do + it "records the snapshot" do + expect(access.find_by_aggregate_id(aggregate_id)).to be_nil + access.record_snapshot(aggregate_id, { aggregate_version: 0, event_data: "data"}) -# snapshot = access.find_by_aggregate_id(aggregate_id) -# expect(snapshot).to_not be_nil -# expect(snapshot.aggregate_id).to eq(aggregate_id) -# expect(snapshot.snapshot_data).to eq("data") -# expect(snapshot.aggregate_version).to eq(0) -# end -# end -# context "when the snapshot isn't fresh" do -# context "when the versions match" do -# it "records a new snapshot" do -# #aggregate = aggregate_access.register_aggregate(aggregate_id, "foo") -# expect(access.find_by_aggregate_id(aggregate_id)).to be_nil -# access.record_snapshot(aggregate_id, { aggregate_version: 0, aggregate_type: "Foo", event_data: "data"}) -# event_access.store_events(events) -# access.record_snapshot(aggregate_id, { aggregate_version: 2, aggregate_type: "Foo", event_data: "other_data"}) + snapshot = access.find_by_aggregate_id(aggregate_id) + expect(snapshot).to_not be_nil + expect(snapshot.aggregate_id).to eq(aggregate_id) + expect(snapshot.snapshot_data).to eq("data") + expect(snapshot.aggregate_version).to eq(0) + end + end + context "when the snapshot isn't fresh" do + context "when the versions match" do + it "records a new snapshot" do + event_access.store_events(events[0]) + expect(access.find_by_aggregate_id(aggregate_id)).to be_nil + access.record_snapshot(aggregate_id, { aggregate_version: 1, event_data: "data"}) + event_access.store_events(events[1]) + access.record_snapshot(aggregate_id, { aggregate_version: 2, event_data: "other_data"}) -# snapshot = access.find_by_aggregate_id(aggregate_id) -# expect(snapshot).to_not be_nil -# expect(snapshot.aggregate_id).to eq(aggregate_id) -# expect(snapshot.snapshot_data).to eq("other_data") -# expect(snapshot.aggregate_version).to eq(2) -# end -# end + snapshot = access.find_by_aggregate_id(aggregate_id) + expect(snapshot).to_not be_nil + expect(snapshot.aggregate_id).to eq(aggregate_id) + expect(snapshot.snapshot_data).to eq("other_data") + expect(snapshot.aggregate_version).to eq(2) + end + end -# # context "when the versions don't match" do -# # it "raises an error" do -# # aggregate = aggregate_access.register_aggregate(aggregate_id, "foo") -# # aggregate.update(aggregate_version: 10) -# # expect { access.record_snapshot(aggregate_id, snapshot_data) }.to raise_error -# # end -# # end -# end -# context "when the snapshot is fresh" do -# it "doesn't record a snapshot" do -# aggregate = aggregate_access.register_aggregate(aggregate_id, "foo") -# expect(access.find_by_aggregate_id(aggregate_id)).to be_nil -# access.record_snapshot(aggregate_id, { aggregate_version: 0, event_data: "data"}) -# access.record_snapshot(aggregate_id, { aggregate_version: 0, event_data: "new_data"}) -# snapshot = access.find_by_aggregate_id(aggregate_id) -# expect(snapshot.snapshot_data).to eq("data") -# end -# end -# end -# end + + end + context "when the snapshot is fresh" do + it "doesn't record a snapshot" do + expect(access.find_by_aggregate_id(aggregate_id)).to be_nil + event_access.store_events(events) + access.record_snapshot(aggregate_id, { aggregate_version: 2, event_data: "data"}) + access.record_snapshot(aggregate_id, { aggregate_version: 2, event_data: "new_data"}) + snapshot = access.find_by_aggregate_id(aggregate_id) + expect(snapshot.snapshot_data).to eq("data") + end + end + end + end -# it "can write and read snapshots" do -# snapshot_id = access.record_snapshot(aggregate.aggregate_id, { aggregate_version: 0, event_data: "data" }) -# snapshot = access.find(snapshot_id) -# expect(snapshot).to_not be_nil -# expect(snapshot.snapshot_data).to eq("data") -# expect(snapshot) -# end + it "can write and read snapshots" do + snapshot_id = access.record_snapshot(aggregate_id, { aggregate_version: 0, event_data: "data" }) + snapshot = access.find(snapshot_id) + expect(snapshot).to_not be_nil + expect(snapshot.snapshot_data).to eq("data") + expect(snapshot) + end -# def generate_uuid -# SecureRandom.uuid -# end -# end -# end + def generate_uuid + SecureRandom.uuid + end + end +end From a14373973c8e89f430428a3ea8924e59f5569534 Mon Sep 17 00:00:00 2001 From: Morgan Hallgren Date: Tue, 14 Apr 2015 20:30:36 +0200 Subject: [PATCH 2/2] removed commented code --- lib/sandthorn_driver_sequel_2/wrappers/snapshot_wrapper.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/sandthorn_driver_sequel_2/wrappers/snapshot_wrapper.rb b/lib/sandthorn_driver_sequel_2/wrappers/snapshot_wrapper.rb index 64a3a78..e7f310c 100644 --- a/lib/sandthorn_driver_sequel_2/wrappers/snapshot_wrapper.rb +++ b/lib/sandthorn_driver_sequel_2/wrappers/snapshot_wrapper.rb @@ -8,8 +8,5 @@ def data self[:event_data] end - # def aggregate_type - # self[:aggregate_type] - # end end end \ No newline at end of file