Skip to content

Commit

Permalink
[RUBY-35] make sure host tokens are not nil
Browse files Browse the repository at this point in the history
  • Loading branch information
Bulat Shakirzyanov committed Oct 4, 2014
1 parent f2af2c4 commit d472834
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cassandra/cluster/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def host_lost(address)
private

def create_host(ip, data)
Host.new(ip, data['host_id'], data['rack'], data['data_center'], data['release_version'], data['tokens'].freeze, :up)
Host.new(ip, data['host_id'], data['rack'], data['data_center'], data['release_version'], Array(data['tokens']).freeze, :up)
end

def toggle_up(host)
Expand Down
55 changes: 55 additions & 0 deletions spec/cassandra/cluster/registry_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# encoding: utf-8

#--
# Copyright 2013-2014 DataStax, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#++

require 'spec_helper'

module Cassandra
class Cluster
describe(Registry) do
let(:logger) { double('logger').as_null_object }

subject { Registry.new(logger) }

describe('#host_found') do
let(:listener) { double('listener') }

before do
subject.add_listener(listener)
end

context('when host is unknown') do
it 'notifies listeners' do
expect(listener).to receive(:host_found).once do |host|
expect(host.ip).to eq(IPAddr.new('127.0.0.1'))
expect(host.tokens).to eq([])
expect(host).to be_up
end

expect(listener).to receive(:host_up).once do |host|
expect(host.ip).to eq(IPAddr.new('127.0.0.1'))
expect(host.tokens).to eq([])
expect(host).to be_up
end

subject.host_found(IPAddr.new('127.0.0.1'), {})
end
end
end
end
end
end

0 comments on commit d472834

Please sign in to comment.