1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
# frozen_string_literal: true
# rubocop:todo all
require 'lite_spec_helper'
describe Mongo::Cluster::Topology do
let(:monitoring) do
Mongo::Monitoring.new(monitoring: false)
end
let(:cluster) { Mongo::Cluster.new(['a'], Mongo::Monitoring.new, monitoring_io: false) }
describe '.initial' do
context 'when provided a replica set option' do
let(:topology) do
described_class.initial(cluster, monitoring, connect: :replica_set, replica_set_name: 'foo')
end
it 'returns a replica set topology' do
expect(topology).to be_a(Mongo::Cluster::Topology::ReplicaSetNoPrimary)
end
context 'when the option is a String (due to YAML parsing)' do
let(:topology) do
described_class.initial(cluster, monitoring, connect: 'replica_set', replica_set_name: 'foo')
end
it 'returns a replica set topology' do
expect(topology).to be_a(Mongo::Cluster::Topology::ReplicaSetNoPrimary)
end
end
end
context 'when provided a single option' do
let(:topology) do
described_class.initial(cluster, monitoring, connect: :direct)
end
it 'returns a single topology' do
expect(topology).to be_a(Mongo::Cluster::Topology::Single)
end
it 'sets the seed on the topology' do
expect(topology.addresses).to eq(['a'])
end
context 'when the option is a String (due to YAML parsing)' do
let(:topology) do
described_class.initial(cluster, monitoring, connect: 'direct')
end
it 'returns a single topology' do
expect(topology).to be_a(Mongo::Cluster::Topology::Single)
end
it 'sets the seed on the topology' do
expect(topology.addresses).to eq(['a'])
end
end
end
context 'when provided a sharded option' do
let(:topology) do
described_class.initial(cluster, monitoring, connect: :sharded)
end
it 'returns a sharded topology' do
expect(topology).to be_a(Mongo::Cluster::Topology::Sharded)
end
context 'when the option is a String (due to YAML parsing)' do
let(:topology) do
described_class.initial(cluster, monitoring, connect: 'sharded')
end
it 'returns a sharded topology' do
expect(topology).to be_a(Mongo::Cluster::Topology::Sharded)
end
end
end
context 'when provided no option' do
context 'when a set name is in the options' do
let(:topology) do
described_class.initial(cluster, monitoring, replica_set_name: 'testing')
end
it 'returns a replica set topology' do
expect(topology).to be_a(Mongo::Cluster::Topology::ReplicaSetNoPrimary)
end
end
context 'when no set name is in the options' do
let(:topology) do
described_class.initial(cluster, monitoring, {})
end
it 'returns an unknown topology' do
expect(topology).to be_a(Mongo::Cluster::Topology::Unknown)
end
end
end
end
describe '#logical_session_timeout' do
require_no_linting
let(:listeners) do
Mongo::Event::Listeners.new
end
let(:monitoring) do
Mongo::Monitoring.new(monitoring: false)
end
let(:server_one) do
Mongo::Server.new(Mongo::Address.new('a:27017'),
cluster, monitoring, listeners, monitoring_io: false)
end
let(:server_two) do
Mongo::Server.new(Mongo::Address.new('b:27017'),
cluster, monitoring, listeners, monitoring_io: false)
end
let(:servers) do
[ server_one, server_two ]
end
let(:topology) do
Mongo::Cluster::Topology::Sharded.new({}, monitoring, cluster)
end
before do
expect(cluster).to receive(:servers_list).and_return(servers)
end
context 'when servers are data bearing' do
before do
expect(server_one.description).to receive(:primary?).and_return(true)
allow(server_two.description).to receive(:primary?).and_return(true)
end
context 'when one server has a nil logical session timeout value' do
before do
expect(server_one.description).to receive(:logical_session_timeout).and_return(7)
expect(server_two.description).to receive(:logical_session_timeout).and_return(nil)
end
it 'returns nil' do
expect(topology.logical_session_timeout).to be(nil)
end
end
context 'when all servers have a logical session timeout value' do
before do
expect(server_one.description).to receive(:logical_session_timeout).and_return(7)
expect(server_two.description).to receive(:logical_session_timeout).and_return(3)
end
it 'returns the minimum' do
expect(topology.logical_session_timeout).to be(3)
end
end
context 'when no servers have a logical session timeout value' do
before do
expect(server_one.description).to receive(:logical_session_timeout).and_return(nil)
allow(server_two.description).to receive(:logical_session_timeout).and_return(nil)
end
it 'returns nil' do
expect(topology.logical_session_timeout).to be(nil)
end
end
end
context 'when servers are not data bearing' do
before do
expect(server_one).to be_unknown
expect(server_two).to be_unknown
end
context 'when all servers have a logical session timeout value' do
before do
expect(server_one).not_to receive(:logical_session_timeout)
expect(server_two).not_to receive(:logical_session_timeout)
end
it 'returns nil' do
expect(topology.logical_session_timeout).to be nil
end
end
end
end
end
|