jstests/libs/cluster_server_parameter_utils.js
// Tests that invalid uses of set/getClusterParameter fail with the appropriate errors.
Tests that invalid uses of set/getClusterParameter fail with the appropriate errors.
Tests that invalid uses of set / getClusterParameter fail with the appropriate errors .
function testInvalidClusterParameterCommands(conn) {
    if (conn instanceof ReplSetTest) {
        const adminDB = conn.getPrimary().getDB('admin');
        testInvalidGetClusterParameter(conn.getPrimary());
        assert.commandFailedWithCode(
            adminDB.runCommand({setClusterParameter: {nonexistentParam: {intData: 5}}}),
            ErrorCodes.IllegalOperation);
        assert.commandFailedWithCode(
            adminDB.runCommand({setClusterParameter: {testIntClusterParameter: 5}}),
            ErrorCodes.IllegalOperation);
        conn.getSecondaries().forEach(function(secondary) {
            const secondaryAdminDB = secondary.getDB('admin');
            assert.commandFailedWithCode(
                secondaryAdminDB.runCommand(
                    {setClusterParameter: {testIntClusterParameter: {intData: 5}}}),
                ErrorCodes.NotWritablePrimary);
            testInvalidGetClusterParameter(secondary);
        });
    } else {
        const adminDB = conn.s0.getDB('admin');
        testInvalidGetClusterParameter(conn.s0);
        assert.commandFailedWithCode(
            adminDB.runCommand({setClusterParameter: {nonexistentParam: {intData: 5}}}),
            ErrorCodes.IllegalOperation);
        assert.commandFailedWithCode(
            adminDB.runCommand({setClusterParameter: {testIntClusterParameter: 5}}),
            ErrorCodes.IllegalOperation);
        const shards = [conn.rs0, conn.rs1, conn.rs2];
        shards.forEach(function(shard) {
            const shardPrimaryAdmin = shard.getPrimary().getDB('admin');
            assert.commandFailedWithCode(
                shardPrimaryAdmin.runCommand(
                    {setClusterParameter: {testIntClusterParameter: {intData: 5}}}),
                ErrorCodes.NotImplemented);
            testInvalidGetClusterParameter(shard.getPrimary());
            shard.getSecondaries().forEach(function(secondary) {
                const shardSecondaryAdmin = secondary.getDB('admin');
                assert.commandFailedWithCode(
                    shardSecondaryAdmin.runCommand(
                        {setClusterParameter: {testIntClusterParameter: {intData: 5}}}),
                    ErrorCodes.NotWritablePrimary);
                testInvalidGetClusterParameter(secondary);
            });
        });
        const configRS = conn.configRS;
        const configPrimaryAdmin = configRS.getPrimary().getDB('admin');
        assert.commandFailedWithCode(
            configPrimaryAdmin.runCommand(
                {setClusterParameter: {testIntClusterParameter: {intData: 5}}}),
            ErrorCodes.NotImplemented);
        testInvalidGetClusterParameter(configRS.getPrimary());
        configRS.getSecondaries().forEach(function(secondary) {
            const configSecondaryAdmin = secondary.getDB('admin');
            assert.commandFailedWithCode(
                configSecondaryAdmin.runCommand(
                    {setClusterParameter: {testIntClusterParameter: {intData: 5}}}),
                ErrorCodes.NotWritablePrimary);
            testInvalidGetClusterParameter(secondary);
        });
    }
}
function testInvalidClusterParameterCommands ( conn ) { if ( conn instanceof ReplSetTest ) { const adminDB = conn . getPrimary ( ) . getDB ( 'admin' ) ; testInvalidGetClusterParameter ( conn . getPrimary ( ) ) ; assert . commandFailedWithCode ( adminDB . runCommand ( { setClusterParameter : { nonexistentParam : { intData : 5 } } } ) , ErrorCodes . IllegalOperation ) ; assert . commandFailedWithCode ( adminDB . runCommand ( { setClusterParameter : { testIntClusterParameter : 5 } } ) , ErrorCodes . IllegalOperation ) ; conn . getSecondaries ( ) . forEach ( function ( secondary ) { const secondaryAdminDB = secondary . getDB ( 'admin' ) ; assert . commandFailedWithCode ( secondaryAdminDB . runCommand ( { setClusterParameter : { testIntClusterParameter : { intData : 5 } } } ) , ErrorCodes . NotWritablePrimary ) ; testInvalidGetClusterParameter ( secondary ) ; } ) ; } else { const adminDB = conn . s0 . getDB ( 'admin' ) ; testInvalidGetClusterParameter ( conn . s0 ) ; assert . commandFailedWithCode ( adminDB . runCommand ( { setClusterParameter : { nonexistentParam : { intData : 5 } } } ) , ErrorCodes . IllegalOperation ) ; assert . commandFailedWithCode ( adminDB . runCommand ( { setClusterParameter : { testIntClusterParameter : 5 } } ) , ErrorCodes . IllegalOperation ) ; const shards = [ conn . rs0 , conn . rs1 , conn . rs2 ] ; shards . forEach ( function ( shard ) { const shardPrimaryAdmin = shard . getPrimary ( ) . getDB ( 'admin' ) ; assert . commandFailedWithCode ( shardPrimaryAdmin . runCommand ( { setClusterParameter : { testIntClusterParameter : { intData : 5 } } } ) , ErrorCodes . NotImplemented ) ; testInvalidGetClusterParameter ( shard . getPrimary ( ) ) ; shard . getSecondaries ( ) . forEach ( function ( secondary ) { const shardSecondaryAdmin = secondary . getDB ( 'admin' ) ; assert . commandFailedWithCode ( shardSecondaryAdmin . runCommand ( { setClusterParameter : { testIntClusterParameter : { intData : 5 } } } ) , ErrorCodes . NotWritablePrimary ) ; testInvalidGetClusterParameter ( secondary ) ; } ) ; } ) ; const configRS = conn . configRS ; const configPrimaryAdmin = configRS . getPrimary ( ) . getDB ( 'admin' ) ; assert . commandFailedWithCode ( configPrimaryAdmin . runCommand ( { setClusterParameter : { testIntClusterParameter : { intData : 5 } } } ) , ErrorCodes . NotImplemented ) ; testInvalidGetClusterParameter ( configRS . getPrimary ( ) ) ; configRS . getSecondaries ( ) . forEach ( function ( secondary ) { const configSecondaryAdmin = secondary . getDB ( 'admin' ) ; assert . commandFailedWithCode ( configSecondaryAdmin . runCommand ( { setClusterParameter : { testIntClusterParameter : { intData : 5 } } } ) , ErrorCodes . NotWritablePrimary ) ; testInvalidGetClusterParameter ( secondary ) ; } ) ; } }
Tests that invalid uses of set/getClusterParameter fail with the appropriate errors.
Tests that invalid uses of set / getClusterParameter fail with the appropriate errors .
// Assert that invalid uses of getClusterParameter fail on the primary. // Assert that setting a nonexistent parameter on the primary returns an error. // Assert that running setClusterParameter with a scalar value fails. // Assert that setClusterParameter cannot be run on a secondary. // Assert that invalid uses of getClusterParameter fail on secondaries. // Assert that invalid uses of getClusterParameter fail on mongos. // Assert that setting a nonexistent parameter on the mongos returns an error. // Assert that running setClusterParameter with a scalar value fails. // Assert that setClusterParameter cannot be run directly on a shard primary. // Assert that invalid forms of getClusterParameter fail on the shard primary. // Assert that setClusterParameter cannot be run on a shard secondary. // Assert that invalid forms of getClusterParameter fail on shard secondaries. // Assert that setClusterParameter cannot be run directly on the configsvr primary. // Assert that invalid forms of getClusterParameter fail on the configsvr primary. // Assert that setClusterParameter cannot be run on a configsvr secondary. // Assert that invalid forms of getClusterParameter fail on configsvr secondaries.