Skip to content

Commit

Permalink
Rename Dispatcher to SyncScheduler
Browse files Browse the repository at this point in the history
Co-authored-by: Paweł Pacana <[email protected]>
Co-authored-by: Szymon Fiedler <[email protected]>
  • Loading branch information
3 people committed Feb 10, 2023
1 parent 5e97818 commit 0f8aef1
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion contrib/ruby_event_store-profiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion contrib/ruby_event_store-profiler/examples/demo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contrib/ruby_event_store-profiler/spec/profiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion rails_event_store/lib/rails_event_store/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion rails_event_store/lib/rails_event_store/json_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion ruby_event_store/lib/ruby_event_store.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ruby_event_store/lib/ruby_event_store/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ruby_event_store/lib/ruby_event_store/spec/broker_lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module RubyEventStore
class Dispatcher
class SyncScheduler
def call(subscriber, event, _)
subscriber.call(event)
end
Expand Down
4 changes: 2 additions & 2 deletions ruby_event_store/spec/instrumented_dispatcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0f8aef1

Please sign in to comment.