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
|
# frozen_string_literal: true
# rubocop:todo all
require 'spec_helper'
describe 'Map-reduce operations' do
let(:client) { authorized_client }
let(:collection) { client['mr_integration'] }
let(:subscriber) { Mrss::EventSubscriber.new }
let(:find_options) { {} }
let(:operation) do
collection.find({}, find_options).map_reduce('function(){}', 'function(){}')
end
before do
collection.insert_one(test: 1)
# Ensure all mongoses are aware of the collection.
maybe_run_mongos_distincts(collection.database.name, collection.name)
client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
end
let(:event) { subscriber.single_command_started_event('mapReduce') }
context 'read preference' do
require_topology :sharded
context 'specified on client' do
let(:client) { authorized_client.with(read: {mode: :secondary_preferred }) }
# RUBY-2706: read preference is not sent on pre-3.6 servers
min_server_fcv '3.6'
it 'is sent' do
operation.to_a
event.command['$readPreference'].should == {'mode' => 'secondaryPreferred'}
end
end
context 'specified on collection' do
let(:collection) { client['mr_integration', read: {mode: :secondary_preferred }] }
# RUBY-2706: read preference is not sent on pre-3.6 servers
min_server_fcv '3.6'
it 'is sent' do
operation.to_a
event.command['$readPreference'].should == {'mode' => 'secondaryPreferred'}
end
end
context 'specified on operation' do
let(:find_options) { {read: {mode: :secondary_preferred }} }
# RUBY-2706: read preference is not sent on pre-3.6 servers
min_server_fcv '3.6'
it 'is sent' do
operation.to_a
event.command['$readPreference'].should == {'mode' => 'secondaryPreferred'}
end
end
end
context 'session' do
min_server_fcv '3.6'
it 'is sent' do
operation.to_a
event.command['lsid'].should_not be nil
end
end
end
|