Skip to content

Commit

Permalink
[FABN-1155] Include missed connection setting
Browse files Browse the repository at this point in the history
Added settings from fabric-client/default.json
Updated unit-tests

Change-Id: Ibc1cdd7a571a7555c498489ca6024d144ded75aa
Signed-off-by: Leo Le <leo2le@protonmail.com>
  • Loading branch information
LeoLe authored and harrisob committed Mar 25, 2019
1 parent ecaedf0 commit 4daba1f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 18 deletions.
31 changes: 30 additions & 1 deletion fabric-client/lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ const Client = class extends BaseClient {
const method = 'getConnectionOptions';
logger.debug('%s - start', method);
let return_options = Object.assign({}, Client.getConfigSetting('connection-options'));
return_options = Object.assign({}, this._connection_options);
return_options = Object.assign(return_options, this._connection_options);
return_options = Object.assign(return_options, this._getLegacyOptions()); // keep for a while legacy options
return_options = Object.assign(return_options, options);

if (!return_options.clientCert) {
Expand All @@ -214,6 +215,34 @@ const Client = class extends BaseClient {
return return_options;
}

// @deprecated
// Deprecated, but keep for a while for backward compatibility. Code is moved here from Remote.js;
_getLegacyOptions() {
const MAX_SEND = 'grpc.max_send_message_length';
const MAX_RECEIVE = 'grpc.max_receive_message_length';
const MAX_SEND_V10 = 'grpc-max-send-message-length';
const MAX_RECEIVE_V10 = 'grpc-max-receive-message-length';
const LEGACY_WARN_MESSAGE = 'Setting grpc options by utils.setConfigSetting() is deprecated. Use utils.g(s)etConfigSetting("connection-options")';
const result = {};

if (typeof sdkUtils.getConfigSetting(MAX_RECEIVE) !== 'undefined') {
Object.assign(result, {[MAX_RECEIVE]: sdkUtils.getConfigSetting(MAX_RECEIVE)});
}
if (typeof sdkUtils.getConfigSetting(MAX_RECEIVE_V10) !== 'undefined') {
Object.assign(result, {[MAX_RECEIVE]: sdkUtils.getConfigSetting(MAX_RECEIVE_V10)});
}
if (typeof sdkUtils.getConfigSetting(MAX_SEND) !== 'undefined') {
Object.assign(result, {[MAX_SEND]: sdkUtils.getConfigSetting(MAX_SEND)});
}
if (typeof sdkUtils.getConfigSetting(MAX_SEND_V10) !== 'undefined') {
Object.assign(result, {[MAX_SEND]: sdkUtils.getConfigSetting(MAX_SEND_V10)});
}
if (Object.keys(result).length > 0) {
logger.warn(LEGACY_WARN_MESSAGE);
}
return result;
}

/**
* Add a set of connection options to this client. These will be
* available to be merged into an application's options when new
Expand Down
6 changes: 4 additions & 2 deletions fabric-client/lib/Remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ class Remote {
if (typeof grpc_receive_max === 'undefined') {
grpc_receive_max = -1; // default is unlimited
}
this._options[MAX_RECEIVE] = grpc_receive_max;
// keep this for backward compatibility until remove probably deprecated code (lines 83-115)
this._options[MAX_RECEIVE] = (this._options[MAX_RECEIVE] && (this._options[MAX_RECEIVE] !== -1))
? this._options[MAX_RECEIVE] : grpc_receive_max;

let grpc_send_max;
if (opts[MAX_SEND_V10]) {
Expand All @@ -110,7 +112,7 @@ class Remote {
if (typeof grpc_send_max === 'undefined') {
grpc_send_max = -1; // default is unlimited
}
this._options[MAX_SEND] = grpc_send_max;
this._options[MAX_SEND] = (this._options[MAX_SEND] && (this._options[MAX_SEND] !== -1)) ? this._options[MAX_SEND] : grpc_send_max;

// service connection
this._url = url;
Expand Down
4 changes: 2 additions & 2 deletions fabric-client/test/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2974,10 +2974,10 @@ describe('Client', () => {
newOpts.hope.should.equal('found');
});

it('should call _buildConnectionOptions and return opts', () => {
it('should call _buildConnectionOptions and return default opts', () => {
const client = new Client();
const opts = client.getConfigSetting('connection-options');
const newOpts = client._buildConnectionOptions(opts);
const newOpts = client._buildConnectionOptions();
newOpts.should.deep.equal(opts);
});
});
Expand Down
39 changes: 26 additions & 13 deletions test/integration/grpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test('\n\n*** GRPC message size tests ***\n\n', async (t) => {
}
};

// setup reusable artificates
// setup reusable certificates
const opts = {
pem: Buffer.from(data).toString(),
clientCert: tlsInfo.certificate,
Expand All @@ -97,6 +97,11 @@ test('\n\n*** GRPC message size tests ***\n\n', async (t) => {

t.pass('Successfully setup grpc testing environment');

// check default connection settings are loaded from the config/default.json
const defaultConnectionOptions = Client.getConfigSetting('connection-options');
const clientOptionsSubset = getClientOptionsDefinedInDefault(client, defaultConnectionOptions);
t.deepEqual(defaultConnectionOptions, clientOptionsSubset, 'Test default connection settings are applied');

// use the connection profile defined peer which includes a GRPC max setting
response = await sendToConnectionProfile(client, channel, connection_profile, go_cc, 1);
checkResponse(t, response, 'Test golang cc able to use connection profile set with grpc max receive', 'Received|max|1024');
Expand Down Expand Up @@ -160,18 +165,11 @@ test('\n\n*** GRPC message size tests ***\n\n', async (t) => {
});

async function send(client, channel, url, cc, opts, megs, grpc_send_max, grpc_receive_max, sdk_send_max, sdk_receive_max) {
if (grpc_send_max !== null) {
utils.setConfigSetting('grpc.max_send_message_length', grpc_send_max);
}
if (grpc_receive_max !== null) {
utils.setConfigSetting('grpc.max_receive_message_length', grpc_receive_max);
}
if (sdk_send_max !== null) {
utils.setConfigSetting('grpc-max-send-message-length', sdk_send_max);
}
if (sdk_receive_max !== null) {
utils.setConfigSetting('grpc-max-receive-message-length', sdk_receive_max);
}

sentConnectionOptionsIfDefined('grpc.max_send_message_length', grpc_send_max);
sentConnectionOptionsIfDefined('grpc.max_receive_message_length', grpc_receive_max);
sentConnectionOptionsIfDefined('grpc-max-send-message-length', sdk_send_max);
sentConnectionOptionsIfDefined('grpc-max-receive-message-length', sdk_receive_max);

// replace the default loading
client._connection_options = {};
Expand Down Expand Up @@ -223,3 +221,18 @@ function checkResponse(t, response, message, error_message) {
t.fail('Failed to get an error message for ' + message);
}
}

function sentConnectionOptionsIfDefined(optionName, optionValue) {
if (optionValue !== null) {
let connectionOptions = utils.getConfigSetting('connection-options');
connectionOptions = Object.assign(connectionOptions, {[optionName]:optionValue});
utils.setConfigSetting('connection-options', connectionOptions);
}
}

function getClientOptionsDefinedInDefault(client, defaultConnectionOptions) {
const clientConnectionOptions = client._buildConnectionOptions();
const clientOptionsSubset = {};
Object.keys(defaultConnectionOptions).forEach(key => clientOptionsSubset[key] = clientConnectionOptions[key]);
return clientOptionsSubset;
}

0 comments on commit 4daba1f

Please sign in to comment.