leffen-kafka-rb 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,74 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require File.dirname(__FILE__) + '/spec_helper'
17
+
18
+ describe MultiProducer do
19
+ before(:each) do
20
+ @mocked_socket = mock(TCPSocket)
21
+ TCPSocket.stub!(:new).and_return(@mocked_socket) # don't use a real socket
22
+ end
23
+
24
+ describe "Kafka Producer" do
25
+ it "should set default host and port if none is specified" do
26
+ subject.host.should eql("localhost")
27
+ subject.port.should eql(9092)
28
+ end
29
+
30
+ it "should have compression" do
31
+ subject.should respond_to :compression
32
+ described_class.new(:compression => Kafka::Message::SNAPPY_COMPRESSION).compression.should == Kafka::Message::SNAPPY_COMPRESSION
33
+ described_class.new.compression.should == Kafka::Message::NO_COMPRESSION
34
+ end
35
+
36
+ it "sends single messages" do
37
+ message = Kafka::Message.new("ale")
38
+ encoded = Kafka::Encoder.produce("test", 0, message)
39
+
40
+ subject.should_receive(:write).with(encoded).and_return(encoded.length)
41
+ subject.push("test", message, :partition => 0).should == encoded.length
42
+ end
43
+
44
+ it "sends multiple messages" do
45
+ messages = [Kafka::Message.new("ale"), Kafka::Message.new("beer")]
46
+ reqs = [
47
+ Kafka::ProducerRequest.new("topic", messages[0]),
48
+ Kafka::ProducerRequest.new("topic", messages[1]),
49
+ ]
50
+ encoded = Encoder.multiproduce(reqs)
51
+
52
+ subject.should_receive(:write).with(encoded).and_return(encoded.length)
53
+ subject.multi_push(reqs).should == encoded.length
54
+ end
55
+
56
+ it "should compress messages" do
57
+ subject.compression = Kafka::Message::SNAPPY_COMPRESSION
58
+ @mocked_socket.stub! :write => 0
59
+ messages = [Kafka::Message.new("ale"), Kafka::Message.new("beer")]
60
+
61
+ encoded = Encoder.produce("test", 0, messages[0])
62
+ Encoder.should_receive(:produce).with("test", 0, messages[0], subject.compression).and_return encoded
63
+ subject.push("test", messages[0], :partition => 0)
64
+
65
+ reqs = [
66
+ Kafka::ProducerRequest.new("topic", messages[0]),
67
+ Kafka::ProducerRequest.new("topic", messages[1]),
68
+ ]
69
+ encoded = Encoder.multiproduce(reqs)
70
+ Encoder.should_receive(:multiproduce).with(reqs, subject.compression)
71
+ subject.multi_push(reqs)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,38 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require File.dirname(__FILE__) + '/spec_helper'
17
+
18
+ describe ProducerRequest do
19
+ let(:message) { Kafka::Message.new }
20
+ let(:req) { described_class.new("topic", message) }
21
+
22
+ it "has a topic" do
23
+ req.topic = "topic"
24
+ end
25
+
26
+ it "has a set of messages" do
27
+ req.messages.should == [message]
28
+ end
29
+
30
+ it "has a default partition" do
31
+ req.partition.should == 0
32
+ end
33
+
34
+ it "can use a user-specified partition" do
35
+ req = described_class.new("topic", message, :partition => 42)
36
+ req.partition.should == 42
37
+ end
38
+ end
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+
3
+ # Licensed to the Apache Software Foundation (ASF) under one or more
4
+ # contributor license agreements. See the NOTICE file distributed with
5
+ # this work for additional information regarding copyright ownership.
6
+ # The ASF licenses this file to You under the Apache License, Version 2.0
7
+ # (the "License"); you may not use this file except in compliance with
8
+ # the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ require File.dirname(__FILE__) + '/spec_helper'
18
+
19
+ describe Producer do
20
+
21
+ before(:each) do
22
+ @mocked_socket = mock(TCPSocket)
23
+ TCPSocket.stub!(:new).and_return(@mocked_socket) # don't use a real socket
24
+ @producer = Producer.new
25
+ end
26
+
27
+ describe "Kafka Producer" do
28
+ it "should have a topic and a partition" do
29
+ @producer.should respond_to(:topic)
30
+ @producer.should respond_to(:partition)
31
+ end
32
+
33
+ it "should have compression" do
34
+ @producer.should respond_to :compression
35
+ Producer.new(:compression => 1).compression.should == 1
36
+ Producer.new.compression.should == 0
37
+ end
38
+
39
+ it "should set a topic and partition on initialize" do
40
+ @producer = Producer.new({ :host => "localhost", :port => 9092, :topic => "testing" })
41
+ @producer.topic.should eql("testing")
42
+ @producer.partition.should eql(0)
43
+ @producer = Producer.new({ :topic => "testing", :partition => 3 })
44
+ @producer.partition.should eql(3)
45
+ end
46
+
47
+ it "should set default host and port if none is specified" do
48
+ @producer = Producer.new
49
+ @producer.host.should eql("localhost")
50
+ @producer.port.should eql(9092)
51
+ end
52
+ end
53
+
54
+ it "should send messages" do
55
+ @producer.should_receive(:write).and_return(32)
56
+ message = Kafka::Message.new("ale")
57
+ @producer.push(message).should eql(32)
58
+ end
59
+
60
+ describe "Message Batching" do
61
+ it "should batch messages and send them at once" do
62
+ message1 = Kafka::Message.new("one")
63
+ message2 = Kafka::Message.new("two")
64
+ @producer.should_receive(:push).with([message1, message2]).exactly(:once).and_return(nil)
65
+ @producer.batch do |messages|
66
+ messages << message1
67
+ messages << message2
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,18 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ require 'rubygems'
16
+ require 'kafka'
17
+
18
+ include Kafka
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: leffen-kafka-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.15
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alejandro Crosa
9
+ - Stefan Mees
10
+ - Tim Lossen
11
+ - Liam Stewart
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2013-04-10 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rspec
19
+ requirement: !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ type: :development
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ description: kafka-rb allows you to produce and consume messages using the Kafka distributed
34
+ publish/subscribe messaging service.
35
+ email: leffen@gmail.com
36
+ executables:
37
+ - leffen-kafka-consumer
38
+ - leffen-kafka-publish
39
+ extensions: []
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ files:
43
+ - LICENSE
44
+ - README.md
45
+ - Rakefile
46
+ - lib/kafka/batch.rb
47
+ - lib/kafka/cli.rb
48
+ - lib/kafka/consumer.rb
49
+ - lib/kafka/encoder.rb
50
+ - lib/kafka/error_codes.rb
51
+ - lib/kafka/io.rb
52
+ - lib/kafka/message.rb
53
+ - lib/kafka/multi_producer.rb
54
+ - lib/kafka/producer.rb
55
+ - lib/kafka/producer_request.rb
56
+ - lib/kafka/request_type.rb
57
+ - lib/kafka.rb
58
+ - lib/leffen-kafka.rb
59
+ - spec/batch_spec.rb
60
+ - spec/cli_spec.rb
61
+ - spec/consumer_spec.rb
62
+ - spec/encoder_spec.rb
63
+ - spec/io_spec.rb
64
+ - spec/kafka_spec.rb
65
+ - spec/message_spec.rb
66
+ - spec/multi_producer_spec.rb
67
+ - spec/producer_request_spec.rb
68
+ - spec/producer_spec.rb
69
+ - spec/spec_helper.rb
70
+ - bin/leffen-kafka-consumer
71
+ - bin/leffen-kafka-publish
72
+ homepage: http://github.com/acrosa/kafka-rb
73
+ licenses: []
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.25
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: A Ruby client for the Kafka distributed publish/subscribe messaging service
96
+ test_files:
97
+ - spec/batch_spec.rb
98
+ - spec/cli_spec.rb
99
+ - spec/consumer_spec.rb
100
+ - spec/encoder_spec.rb
101
+ - spec/io_spec.rb
102
+ - spec/kafka_spec.rb
103
+ - spec/message_spec.rb
104
+ - spec/multi_producer_spec.rb
105
+ - spec/producer_request_spec.rb
106
+ - spec/producer_spec.rb
107
+ - spec/spec_helper.rb