MCPcopy Create free account
hub / github.com/apache/cassandra-nodejs-driver / getClient

Function getClient

test/unit/insights-client-tests.js:445–484  ·  view source on GitHub ↗

* Gets a fake client instance. * @param {{rpcCallback, errorGetter, hostVersions, clientOptions}} [options]

(options)

Source from the content-addressed store, hash-verified

443 * @param {{rpcCallback, errorGetter, hostVersions, clientOptions}} [options]
444 */
445function getClient(options) {
446 options = options || {};
447
448 const rpcCallback = options.rpcCallback || utils.noop;
449 const errorGetter = options.errorGetter || utils.noop;
450
451 const clientOptions = Object.assign(
452 { pooling: { coreConnectionsPerHost: coreConnectionsPerHostV3 }, applicationName: 'My Test Application' },
453 options.clientOptions);
454
455 const client = new Client(helper.getOptions(clientOptions));
456
457 // Provide a fake control connection
458 client.controlConnection.query = (request, w) => {
459 rpcCallback(request.params[0]);
460 const err = errorGetter();
461
462 if (err) {
463 return Promise.reject(err);
464 }
465
466 return Promise.resolve();
467 };
468 client.controlConnection.protocolVersion = 4;
469 client.controlConnection.getLocalAddress = () => '10.10.10.1:9042';
470
471 client.getState = () => new ClientState([{ address: '1.2.3.4:9042'}], { '1.2.3.4:9042': 2 }, { '1.2.3.4:9042': 123 });
472
473 const hostVersions = options.hostVersions || [ '6.7.0' ];
474
475 hostVersions.forEach((v, i) => {
476 client.hosts.set(`10.10.10.${i}`, {
477 getDseVersion: () => (v === '{empty}' ? utils.emptyArray : v.split('.')),
478 datacenter: 'dc' + (i % 2),
479 setDistance: () => {}
480 });
481 });
482
483 return client;
484}
485
486/**
487 * @param {{hostVersions, clientOptions}} [options]

Callers 2

getStartupMessageFunction · 0.70

Calls 4

setMethod · 0.80
getOptionsMethod · 0.65
forEachMethod · 0.65
splitMethod · 0.45

Tested by

no test coverage detected