0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-24 00:17:37 +01:00
mongodb/jstests/sharding/flushRoutingTableCacheUpdates_enforced_on_collections.js
Matt Broadstone 771dabd098 SERVER-81339 Convert ReplSetTest and ShardingTest to modules (#26332)
GitOrigin-RevId: 744aa110a53786b23c62ff53f87a1418b5991e8d
2024-08-20 22:00:49 +00:00

34 lines
1.3 KiB
JavaScript

// Ensure that a call to _flushRoutingTableCacheUpdates in a sharded cluster will return error if
// attempted on a database instead of a collection.
import {ShardingTest} from "jstests/libs/shardingtest.js";
let st = new ShardingTest({});
const testDBName = jsTestName();
const collName = 'coll';
const testDB = st.s.getDB(testDBName);
assert.commandWorked(testDB.adminCommand({enableSharding: testDBName}));
assert.commandWorked(
testDB.adminCommand({shardCollection: testDB[collName].getFullName(), key: {x: 1}}));
// On a collection, the command works
assert.commandWorked(
st.shard0.adminCommand({_flushRoutingTableCacheUpdates: testDB[collName].getFullName()}));
// But on a database, the command fails with error "IllegalOperation"
assert.commandFailedWithCode(st.shard0.adminCommand({_flushRoutingTableCacheUpdates: testDBName}),
ErrorCodes.IllegalOperation);
// Test also variant _flushRoutingTableCacheUpdatesWithWriteConcern
assert.commandWorked(st.shard0.adminCommand({
_flushRoutingTableCacheUpdatesWithWriteConcern: testDB[collName].getFullName(),
writeConcern: {w: "majority"}
}));
assert.commandFailedWithCode(st.shard0.adminCommand({
_flushRoutingTableCacheUpdatesWithWriteConcern: testDBName,
writeConcern: {w: "majority"}
}),
ErrorCodes.IllegalOperation);
st.stop();