From 0f8aef1bfb8fe02591bf4936d479a32f59dd57f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 8 Feb 2023 15:42:02 +0100 Subject: [PATCH] Rename Dispatcher to SyncScheduler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Paweł Pacana Co-authored-by: Szymon Fiedler --- contrib/ruby_event_store-profiler/README.md | 2 +- .../ruby_event_store-profiler/examples/demo | 2 +- .../spec/profiler_spec.rb | 2 +- .../spec/protobuf_integration_spec.rb | 2 +- .../lib/rails_event_store/client.rb | 2 +- .../lib/rails_event_store/json_client.rb | 2 +- ruby_event_store/lib/ruby_event_store.rb | 2 +- .../lib/ruby_event_store/client.rb | 2 +- .../lib/ruby_event_store/spec/broker_lint.rb | 4 ++-- .../{dispatcher.rb => sync_scheduler.rb} | 2 +- .../spec/instrumented_dispatcher_spec.rb | 4 ++-- ...patcher_spec.rb => sync_scheduler_spec.rb} | 22 +++++++++---------- 12 files changed, 24 insertions(+), 24 deletions(-) rename ruby_event_store/lib/ruby_event_store/{dispatcher.rb => sync_scheduler.rb} (90%) rename ruby_event_store/spec/{dispatcher_spec.rb => sync_scheduler_spec.rb} (62%) diff --git a/contrib/ruby_event_store-profiler/README.md b/contrib/ruby_event_store-profiler/README.md index 19d5988b67..d3de56b190 100644 --- a/contrib/ruby_event_store-profiler/README.md +++ b/contrib/ruby_event_store-profiler/README.md @@ -10,7 +10,7 @@ event_store = RubyEventStore::Client.new( repository: RubyEventStore::InstrumentedRepository.new(RubyEventStore::InMemoryRepository.new, instrumenter), mapper: RubyEventStore::Mappers::InstrumentedMapper.new(RubyEventStore::Mappers::Default.new, instrumenter), - dispatcher: RubyEventStore::InstrumentedDispatcher.new(RubyEventStore::Dispatcher.new, instrumenter), + dispatcher: RubyEventStore::InstrumentedDispatcher.new(RubyEventStore::SyncScheduler.new, instrumenter), ) repository = AggregateRoot::InstrumentedRepository.new(AggregateRoot::Repository.new(event_store), instrumenter) diff --git a/contrib/ruby_event_store-profiler/examples/demo b/contrib/ruby_event_store-profiler/examples/demo index bf6cb97f30..57d14d0653 100755 --- a/contrib/ruby_event_store-profiler/examples/demo +++ b/contrib/ruby_event_store-profiler/examples/demo @@ -10,7 +10,7 @@ asn = ActiveSupport::Notifications event_store = RubyEventStore::Client.new( repository: RubyEventStore::InstrumentedRepository.new(RubyEventStore::InMemoryRepository.new, asn), mapper: RubyEventStore::Mappers::InstrumentedMapper.new(RubyEventStore::Mappers::Default.new, asn), - dispatcher: RubyEventStore::InstrumentedDispatcher.new(RubyEventStore::Dispatcher.new, asn) + dispatcher: RubyEventStore::InstrumentedDispatcher.new(RubyEventStore::SyncScheduler.new, asn) ) DummyEvent = Class.new(RubyEventStore::Event) dummy = DummyEvent.new diff --git a/contrib/ruby_event_store-profiler/spec/profiler_spec.rb b/contrib/ruby_event_store-profiler/spec/profiler_spec.rb index bdaeb6efa0..eae3402750 100644 --- a/contrib/ruby_event_store-profiler/spec/profiler_spec.rb +++ b/contrib/ruby_event_store-profiler/spec/profiler_spec.rb @@ -7,7 +7,7 @@ module RubyEventStore Client.new( repository: InstrumentedRepository.new(InMemoryRepository.new, instrumenter), mapper: Mappers::InstrumentedMapper.new(Mappers::Default.new, instrumenter), - dispatcher: InstrumentedDispatcher.new(Dispatcher.new, instrumenter) + dispatcher: InstrumentedDispatcher.new(SyncScheduler.new, instrumenter) ) end diff --git a/contrib/ruby_event_store-protobuf/spec/protobuf_integration_spec.rb b/contrib/ruby_event_store-protobuf/spec/protobuf_integration_spec.rb index 4121d3d03d..0bb04c2068 100644 --- a/contrib/ruby_event_store-protobuf/spec/protobuf_integration_spec.rb +++ b/contrib/ruby_event_store-protobuf/spec/protobuf_integration_spec.rb @@ -28,7 +28,7 @@ module RubyEventStore dispatcher: ComposedDispatcher.new( ImmediateDispatcher.new(scheduler: RailsEventStore::ActiveJobScheduler.new(serializer: NULL)), - Dispatcher.new + SyncScheduler.new ) ) client.subscribe(->(ev) { @ev = ev }, to: [ResTesting::OrderCreated.descriptor.name]) diff --git a/rails_event_store/lib/rails_event_store/client.rb b/rails_event_store/lib/rails_event_store/client.rb index acdd5cd424..efcc338612 100644 --- a/rails_event_store/lib/rails_event_store/client.rb +++ b/rails_event_store/lib/rails_event_store/client.rb @@ -12,7 +12,7 @@ def initialize( RailsEventStore::AfterCommitDispatcher.new( scheduler: ActiveJobScheduler.new(serializer: RubyEventStore::Serializers::YAML) ), - RubyEventStore::Dispatcher.new + RubyEventStore::SyncScheduler.new ), clock: default_clock, correlation_id_generator: default_correlation_id_generator, diff --git a/rails_event_store/lib/rails_event_store/json_client.rb b/rails_event_store/lib/rails_event_store/json_client.rb index 632a816c91..4857e99862 100644 --- a/rails_event_store/lib/rails_event_store/json_client.rb +++ b/rails_event_store/lib/rails_event_store/json_client.rb @@ -32,7 +32,7 @@ def initialize( RailsEventStore::AfterCommitDispatcher.new( scheduler: ActiveJobScheduler.new(serializer: RubyEventStore::Serializers::YAML) ), - RubyEventStore::Dispatcher.new + RubyEventStore::SyncScheduler.new ), clock: default_clock, correlation_id_generator: default_correlation_id_generator, diff --git a/ruby_event_store/lib/ruby_event_store.rb b/ruby_event_store/lib/ruby_event_store.rb index aa2293059a..7b0a5f3fa0 100644 --- a/ruby_event_store/lib/ruby_event_store.rb +++ b/ruby_event_store/lib/ruby_event_store.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "ruby_event_store/dispatcher" +require_relative "ruby_event_store/sync_scheduler" require_relative "ruby_event_store/subscriptions" require_relative "ruby_event_store/broker" require_relative "ruby_event_store/in_memory_repository" diff --git a/ruby_event_store/lib/ruby_event_store/client.rb b/ruby_event_store/lib/ruby_event_store/client.rb index 354c3ea7cc..e0444099e3 100644 --- a/ruby_event_store/lib/ruby_event_store/client.rb +++ b/ruby_event_store/lib/ruby_event_store/client.rb @@ -8,7 +8,7 @@ def initialize( repository: InMemoryRepository.new, mapper: Mappers::Default.new, subscriptions: Subscriptions.new, - dispatcher: Dispatcher.new, + dispatcher: SyncScheduler.new, clock: default_clock, correlation_id_generator: default_correlation_id_generator, event_type_resolver: EventTypeResolver.new diff --git a/ruby_event_store/lib/ruby_event_store/spec/broker_lint.rb b/ruby_event_store/lib/ruby_event_store/spec/broker_lint.rb index 07f6538c21..0c338d68e9 100644 --- a/ruby_event_store/lib/ruby_event_store/spec/broker_lint.rb +++ b/ruby_event_store/lib/ruby_event_store/spec/broker_lint.rb @@ -3,7 +3,7 @@ let(:record) { instance_double(::RubyEventStore::Record) } let(:handler) { HandlerClass.new } let(:subscriptions) { ::RubyEventStore::Subscriptions.new } - let(:dispatcher) { ::RubyEventStore::Dispatcher.new } + let(:dispatcher) { ::RubyEventStore::SyncScheduler.new } let(:broker) { broker_klass.new(subscriptions: subscriptions, dispatcher: dispatcher) } specify "no dispatch when no subscriptions" do @@ -48,7 +48,7 @@ allow(dispatcher).to receive(:verify).and_return(false) expect { broker.add_subscription(HandlerClass, []) }.to raise_error( RubyEventStore::InvalidHandler, - /Handler HandlerClass is invalid for dispatcher .*Dispatcher/ + /Handler HandlerClass is invalid for dispatcher .*SyncScheduler/ ) expect { broker.add_global_subscription(HandlerClass) }.to raise_error( RubyEventStore::InvalidHandler, diff --git a/ruby_event_store/lib/ruby_event_store/dispatcher.rb b/ruby_event_store/lib/ruby_event_store/sync_scheduler.rb similarity index 90% rename from ruby_event_store/lib/ruby_event_store/dispatcher.rb rename to ruby_event_store/lib/ruby_event_store/sync_scheduler.rb index 6736e379ba..d9cf2b75b6 100644 --- a/ruby_event_store/lib/ruby_event_store/dispatcher.rb +++ b/ruby_event_store/lib/ruby_event_store/sync_scheduler.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module RubyEventStore - class Dispatcher + class SyncScheduler def call(subscriber, event, _) subscriber.call(event) end diff --git a/ruby_event_store/spec/instrumented_dispatcher_spec.rb b/ruby_event_store/spec/instrumented_dispatcher_spec.rb index c54f051e6a..b56060d27d 100644 --- a/ruby_event_store/spec/instrumented_dispatcher_spec.rb +++ b/ruby_event_store/spec/instrumented_dispatcher_spec.rb @@ -6,7 +6,7 @@ module RubyEventStore ::RSpec.describe InstrumentedDispatcher do - it_behaves_like :dispatcher, InstrumentedDispatcher.new(Dispatcher.new, ActiveSupport::Notifications) + it_behaves_like :dispatcher, InstrumentedDispatcher.new(SyncScheduler.new, ActiveSupport::Notifications) describe "#call" do specify "wraps around original implementation" do @@ -60,7 +60,7 @@ module RubyEventStore end specify "method unknown by instrumentation and unknown by dispatcher" do - some_dispatcher = Dispatcher.new + some_dispatcher = SyncScheduler.new instrumented_dispatcher = InstrumentedDispatcher.new(some_dispatcher, ActiveSupport::Notifications) expect(instrumented_dispatcher).not_to respond_to(:arbitrary_method_name) diff --git a/ruby_event_store/spec/dispatcher_spec.rb b/ruby_event_store/spec/sync_scheduler_spec.rb similarity index 62% rename from ruby_event_store/spec/dispatcher_spec.rb rename to ruby_event_store/spec/sync_scheduler_spec.rb index 3b0c966112..1996e0cd19 100644 --- a/ruby_event_store/spec/dispatcher_spec.rb +++ b/ruby_event_store/spec/sync_scheduler_spec.rb @@ -2,20 +2,20 @@ require "ruby_event_store/spec/dispatcher_lint" module RubyEventStore - ::RSpec.describe Dispatcher do - it_behaves_like :dispatcher, Dispatcher.new + ::RSpec.describe SyncScheduler do + it_behaves_like :dispatcher, SyncScheduler.new let(:event) { instance_double(Event) } let(:record) { instance_double(Record) } let(:handler) { HandlerClass.new } specify "does not allow silly subscribers" do - expect(Dispatcher.new.verify(:symbol)).to eq(false) - expect(Dispatcher.new.verify(Object.new)).to eq(false) + expect(SyncScheduler.new.verify(:symbol)).to eq(false) + expect(SyncScheduler.new.verify(Object.new)).to eq(false) end specify "does not allow class without instance method #call" do klass = Class.new - expect(Dispatcher.new.verify(klass)).to eq(false) + expect(SyncScheduler.new.verify(klass)).to eq(false) end specify "does not allow class without constructor requiring arguments" do @@ -27,24 +27,24 @@ def initialize(something) def call; end end - expect(Dispatcher.new.verify(klass)).to eq(false) + expect(SyncScheduler.new.verify(klass)).to eq(false) end specify "calls subscribed instance" do expect(handler).to receive(:call).with(event) - Dispatcher.new.call(handler, event, record) + SyncScheduler.new.call(handler, event, record) end specify "calls subscribed class" do expect(HandlerClass).to receive(:new).and_return(handler) expect(handler).to receive(:call).with(event) - Dispatcher.new.call(-> (event) { HandlerClass.new.call(event) }, event, record) + SyncScheduler.new.call(-> (event) { HandlerClass.new.call(event) }, event, record) end specify "allows callable classes and instances" do - expect(Dispatcher.new.verify(-> { HandlerClass.new })).to eq(true) - expect(Dispatcher.new.verify(HandlerClass.new)).to eq(true) - expect(Dispatcher.new.verify(Proc.new { "yo" })).to eq(true) + expect(SyncScheduler.new.verify(-> { HandlerClass.new })).to eq(true) + expect(SyncScheduler.new.verify(HandlerClass.new)).to eq(true) + expect(SyncScheduler.new.verify(Proc.new { "yo" })).to eq(true) end private