Skip to content

Latest commit

 

History

History
60 lines (44 loc) · 1.55 KB

2.0-Upgrade.md

File metadata and controls

60 lines (44 loc) · 1.55 KB

Welcome to Karafka-Testing 2.0!

Karafka-Testing 2.0 some breaking changes in the way consumer builder and message publishing is done.

Upgrade

Please upgrade your application to Karafka 2.0 first.

  • Replace #karafka_consumer_for in your specs with #karafka.consumer_for
  • Replace #publish_for_karafka in your specs with #karafka.produce

And that's all!

Below you can find same example written for Karafka 2.0 and 1.4.

Karafka 2.0

RSpec.describe CountersConsumer do
  subject(:consumer) { karafka.consumer_for(:counters) }

  let(:nr1_value) { rand }
  let(:nr2_value) { rand }
  let(:sum) { nr1_value + nr2_value }

  before do
    karafka.produce({ 'number' => nr1_value }.to_json)
    karafka.produce({ 'number' => nr2_value }.to_json, partition: 2)
    allow(Karafka.logger).to receive(:info)
  end

  it 'expects to log a proper message' do
    expect(Karafka.logger).to receive(:info).with("Sum of 2 elements equals to: #{sum}")
    consumer.consume
  end
end

Karafka 1.4

RSpec.describe InlineBatchConsumer do
  subject(:consumer) { karafka_consumer_for(:counters) }

  let(:nr1_value) { rand }
  let(:nr2_value) { rand }
  let(:sum) { nr1_value + nr2_value }

  before do
    publish_for_karafka({ 'number' => nr1_value }.to_json)
    publish_for_karafka({ 'number' => nr2_value }.to_json, partition: 2)
    allow(Karafka.logger).to receive(:info)
  end

  it 'expects to log a proper message' do
    expect(Karafka.logger).to receive(:info).with("Sum of 2 elements equals to: #{sum}")
    consumer.consume
  end
end