|
| 1 | +# encoding: utf-8 |
| 2 | + |
| 3 | +#-- |
| 4 | +# Copyright DataStax, Inc. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# 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 | +#++ |
| 18 | + |
| 19 | +require 'spec_helper' |
| 20 | + |
| 21 | +module Cassandra |
| 22 | + class Cluster |
| 23 | + class Schema |
| 24 | + module ReplicationStrategies |
| 25 | + describe(Simple) do |
| 26 | + subject { Simple.new } |
| 27 | + |
| 28 | + describe('#replication_map') do |
| 29 | + let(:hosts) { |
| 30 | + [ |
| 31 | + Host.new('127.0.0.1', 111, 'rack1', 'dc1'), |
| 32 | + Host.new('127.0.0.2', 112, 'rack1', 'dc1'), |
| 33 | + Host.new('127.0.0.3', 113, 'rack1', 'dc1'), |
| 34 | + ] |
| 35 | + } |
| 36 | + |
| 37 | + let(:token_hosts) { |
| 38 | + { |
| 39 | + -9000000000000000000 => hosts[0], |
| 40 | + -8000000000000000000 => hosts[0], |
| 41 | + -7000000000000000000 => hosts[1], |
| 42 | + -6000000000000000000 => hosts[1], |
| 43 | + -5000000000000000000 => hosts[2], |
| 44 | + -4000000000000000000 => hosts[2], |
| 45 | + -3000000000000000000 => hosts[0], |
| 46 | + -2000000000000000000 => hosts[0], |
| 47 | + -1000000000000000000 => hosts[1], |
| 48 | + +0000000000000000000 => hosts[1], |
| 49 | + +1000000000000000000 => hosts[2], |
| 50 | + +2000000000000000000 => hosts[2], |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + let(:token_ring) { |
| 55 | + token_hosts.keys |
| 56 | + } |
| 57 | + |
| 58 | + let(:replication_options) { |
| 59 | + { |
| 60 | + 'replication_factor' => 3, |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + it do |
| 65 | + replication_map = subject.replication_map(token_hosts, token_ring, replication_options) |
| 66 | + expect(replication_map[token_ring[0]].sort_by(&:ip).map do |host| |
| 67 | + [host.ip] |
| 68 | + end).to eq([ |
| 69 | + ['127.0.0.1'], |
| 70 | + ['127.0.0.2'], |
| 71 | + ['127.0.0.3'], |
| 72 | + ]) |
| 73 | + end |
| 74 | + end |
| 75 | + end |
| 76 | + end |
| 77 | + end |
| 78 | + end |
| 79 | +end |
0 commit comments