move hermann_lib -> hermann_rdkafka / Hermann::Provider::RDKafka

This commit is contained in:
Ben Osheroff 2015-06-23 09:01:31 -07:00
parent a9d80242dd
commit 9edc4b9301
8 changed files with 24 additions and 23 deletions

View File

@ -6,7 +6,7 @@ require 'rake/extensiontask'
Rake::ExtensionTask.new do |t| Rake::ExtensionTask.new do |t|
t.name = 'hermann_lib' t.name = 'hermann_rdkafka'
t.ext_dir = 'ext/hermann' t.ext_dir = 'ext/hermann'
t.gem_spec = Gem::Specification.load('hermann.gemspec') t.gem_spec = Gem::Specification.load('hermann.gemspec')
end end

View File

@ -1,5 +1,5 @@
/* /*
* hermann_lib.c - Ruby wrapper for the librdkafka library * hermann_rdkafka.c - Ruby wrapper for the librdkafka library
* *
* Copyright (c) 2014 Stan Campbell * Copyright (c) 2014 Stan Campbell
* Copyright (c) 2014 Lookout, Inc. * Copyright (c) 2014 Lookout, Inc.
@ -31,7 +31,7 @@
/* Much of the librdkafka library calls were lifted from rdkafka_example.c */ /* Much of the librdkafka library calls were lifted from rdkafka_example.c */
#include "hermann_lib.h" #include "hermann_rdkafka.h"
#ifdef HAVE_RUBY_VERSION_H #ifdef HAVE_RUBY_VERSION_H
#include <ruby/version.h> #include <ruby/version.h>
@ -444,7 +444,7 @@ static VALUE consumer_consume_loop_stop(VALUE self) {
} }
/** /**
* Hermann::Lib::Consumer.consume * Hermann::Provider::RDKafka::Consumer.consume
* *
* @param VALUE self the Ruby object for this consumer * @param VALUE self the Ruby object for this consumer
* @param VALUE topic the Ruby string representing a topic to consume * @param VALUE topic the Ruby string representing a topic to consume
@ -1190,21 +1190,21 @@ static VALUE producer_init_copy(VALUE copy,
} }
/** /**
* Init_hermann_lib * Init_hermann_rdkafka
* *
* Called by Ruby when the Hermann gem is loaded. * Called by Ruby when the Hermann gem is loaded.
* Defines the Hermann module. * Defines the Hermann module.
* Defines the Producer and Consumer classes. * Defines the Producer and Consumer classes.
*/ */
void Init_hermann_lib() { void Init_hermann_rdkafka() {
VALUE lib_module, c_consumer, c_producer; VALUE lib_module, provider_module, c_consumer, c_producer;
TRACER("setting up Hermann::Lib\n"); TRACER("setting up Hermann::Provider::RDKafka\n");
/* Define the module */ /* Define the module */
hermann_module = rb_define_module("Hermann"); hermann_module = rb_define_module("Hermann");
lib_module = rb_define_module_under(hermann_module, "Lib"); provider_module = rb_define_module_under(hermann_module, "Provider");
lib_module = rb_define_module_under(provider_module, "RDKafka");
/* ---- Define the consumer class ---- */ /* ---- Define the consumer class ---- */
c_consumer = rb_define_class_under(lib_module, "Consumer", rb_cObject); c_consumer = rb_define_class_under(lib_module, "Consumer", rb_cObject);

View File

@ -1,5 +1,5 @@
/* /*
* hermann_lib.h - Ruby wrapper for the librdkafka library * hermann_rdkafka.h - Ruby wrapper for the librdkafka library
* *
* Copyright (c) 2014 Stan Campbell * Copyright (c) 2014 Stan Campbell
* Copyright (c) 2014 Lookout, Inc. * Copyright (c) 2014 Lookout, Inc.
@ -107,7 +107,7 @@ typedef struct HermannInstanceConfig {
typedef HermannInstanceConfig hermann_conf_t; typedef HermannInstanceConfig hermann_conf_t;
typedef struct { typedef struct {
/* Hermann::Lib::Producer */ /* Hermann::Provider::RDKafka::Producer */
hermann_conf_t *producer; hermann_conf_t *producer;
/* Hermann::Result */ /* Hermann::Result */
VALUE result; VALUE result;

View File

@ -4,7 +4,7 @@ require 'hermann/errors'
if Hermann.jruby? if Hermann.jruby?
require 'hermann/provider/java_simple_consumer' require 'hermann/provider/java_simple_consumer'
else else
require 'hermann_lib' require 'hermann_rdkafka'
end end
module Hermann module Hermann
@ -37,7 +37,7 @@ module Hermann
else else
brokers, partition = require_values_at(opts, :brokers, :partition) brokers, partition = require_values_at(opts, :brokers, :partition)
@internal = Hermann::Lib::Consumer.new(topic, brokers, partition, offset) @internal = Hermann::Provider::RDKafka::Consumer.new(topic, brokers, partition, offset)
end end
end end

View File

@ -1,4 +1,4 @@
require 'hermann_lib' require 'hermann_rdkafka'
require 'hermann/consumer' require 'hermann/consumer'
module Hermann module Hermann
@ -20,7 +20,7 @@ module Hermann
DEFAULT_TIMEOUT_MS = 2_000 DEFAULT_TIMEOUT_MS = 2_000
def initialize(brokers, options = {}) def initialize(brokers, options = {})
raise "this is an MRI api only!" if Hermann.jruby? raise "this is an MRI api only!" if Hermann.jruby?
@internal = Hermann::Lib::Producer.new(brokers) @internal = Hermann::Provider::RDKafka::Producer.new(brokers)
@timeout = options[:timeout] || DEFAULT_TIMEOUT_MS @timeout = options[:timeout] || DEFAULT_TIMEOUT_MS
end end

View File

@ -6,7 +6,7 @@ require 'hermann/result'
if RUBY_PLATFORM == "java" if RUBY_PLATFORM == "java"
require 'hermann/provider/java_producer' require 'hermann/provider/java_producer'
else else
require 'hermann_lib' require 'hermann_rdkafka'
end end
module Hermann module Hermann
@ -23,7 +23,7 @@ module Hermann
if Hermann.jruby? if Hermann.jruby?
@internal = Hermann::Provider::JavaProducer.new(brokers.join(','), opts) @internal = Hermann::Provider::JavaProducer.new(brokers.join(','), opts)
else else
@internal = Hermann::Lib::Producer.new(brokers.join(',')) @internal = Hermann::Provider::RDKafka::Producer.new(brokers.join(','))
end end
# We're tracking children so we can make sure that at Producer exit we # We're tracking children so we can make sure that at Producer exit we
# make a reasonable attempt to clean up outstanding result objects # make a reasonable attempt to clean up outstanding result objects

View File

@ -1,13 +1,13 @@
require 'spec_helper' require 'spec_helper'
describe 'Hermann::Lib::Producer', :platform => :mri do describe 'Hermann::Provider::RDKafka::Producer', :platform => :mri do
before :all do before :all do
require 'hermann_lib' require 'hermann_rdkafka'
end end
let(:topic) { 'rspec' } let(:topic) { 'rspec' }
let(:brokers) { 'localhost:1337' } let(:brokers) { 'localhost:1337' }
subject(:producer) { Hermann::Lib::Producer.new(brokers) } subject(:producer) { Hermann::Provider::RDKafka::Producer.new(brokers) }
let(:timeout) { 3000 } let(:timeout) { 3000 }
it { should respond_to :push_single } it { should respond_to :push_single }

View File

@ -11,10 +11,11 @@ describe Hermann::Producer do
describe '#initialize' do describe '#initialize' do
context 'with C ruby', :platform => :mri do context 'with C ruby', :platform => :mri do
it 'joins broker array' do it 'joins broker array' do
expect(Hermann::Lib::Producer).to receive(:new).with(brokers.first) expect(Hermann::Provider::RDKafka::Producer).to receive(:new).with(brokers.first)
expect(producer).to be_a Hermann::Producer expect(producer).to be_a Hermann::Producer
end end
end end
context 'with Java', :platform => :java do context 'with Java', :platform => :java do
it 'joins broker array' do it 'joins broker array' do
expect(Hermann::Provider::JavaProducer).to receive(:new).with(brokers.first, opts) expect(Hermann::Provider::JavaProducer).to receive(:new).with(brokers.first, opts)
@ -190,7 +191,7 @@ describe Hermann::Producer do
describe '#tick_reactor' do describe '#tick_reactor' do
let(:timeout) { 0 } let(:timeout) { 0 }
let(:internal) { double('Hermann::Lib::Producer mock') } let(:internal) { double('Hermann::Provider::RDKafka::Producer mock') }
subject(:tick) { producer.tick_reactor(timeout) } subject(:tick) { producer.tick_reactor(timeout) }
before :each do before :each do