Sha256: f376a5e3f5e76d0bcb6c07329373fcaceaca57e354cc03f2addc315171051106
Contents?: true
Size: 1.85 KB
Versions: 1
Compression:
Stored size: 1.85 KB
Contents
require "spec_helper" describe Rdkafka::Consumer::Message do let(:native_topic) do Rdkafka::FFI.rd_kafka_topic_new( native_client, "topic_name", nil ) end let(:payload) { nil } let(:key) { nil } let(:native_message) do Rdkafka::FFI::Message.new.tap do |message| message[:rkt] = native_topic message[:partition] = 3 message[:offset] = 100 if payload ptr = ::FFI::MemoryPointer.new(:char, payload.bytesize) ptr.put_bytes(0, payload) message[:payload] = ptr message[:len] = payload.bytesize end if key ptr = ::FFI::MemoryPointer.new(:char, key.bytesize) ptr.put_bytes(0, key) message[:key] = ptr message[:key_len] = key.bytesize end end end subject { Rdkafka::Consumer::Message.new(native_message) } it "should have a topic" do expect(subject.topic).to eq "topic_name" end it "should have a partition" do expect(subject.partition).to eq 3 end context "payload" do it "should have a nil payload when none is present" do expect(subject.payload).to be_nil end context "present payload" do let(:payload) { "payload content" } it "should have a payload" do expect(subject.payload).to eq "payload content" end end end context "key" do it "should have a nil key when none is present" do expect(subject.key).to be_nil end context "present key" do let(:key) { "key content" } it "should have a key" do expect(subject.key).to eq "key content" end end end it "should have an offset" do expect(subject.offset).to eq 100 end it "should have a timestamp" do # There is no effective way to mock this this, just # make sure it doesn't crash. expect { subject.timestamp }.not_to raise_error end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rdkafka-0.2.0 | spec/rdkafka/consumer/message_spec.rb |