Skip to content

Commit

Permalink
Merge 9a7fdac into 59e9c85
Browse files Browse the repository at this point in the history
  • Loading branch information
xhronos committed May 8, 2017
2 parents 59e9c85 + 9a7fdac commit 0281988
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 9 deletions.
65 changes: 56 additions & 9 deletions lib/client/client_session.js
Expand Up @@ -182,17 +182,65 @@ ClientSession.prototype.browse = function (nodes, callback) {
r = response.results[i];
r.references = r.references || [];
}
// detect unsupported case :
// todo implement proper support for r.continuationPoint
for (i = 0; i < response.results.length; i++) {
r = response.results[i];
callback(null, response.results, response.diagnosticInfos);
});
}
catch (err) {
/* istanbul ignore next */
callback(err);
}
};

ClientSession.prototype.browseNext = function (continuationPoints, callback) {

var self = this;

try {

self.requestedMaxReferencesPerNode = self.requestedMaxReferencesPerNode || 10000;
assert(_.isFinite(self.requestedMaxReferencesPerNode));
assert(_.isFunction(callback));

if (!_.isArray(continuationPoints)) {
continuationPoints = [continuationPoints];
}

var request = new browse_service.BrowseNextRequest({
releaseContinuationPoints : false,
continuationPoints: continuationPoints,
requestedMaxReferencesPerNode: self.requestedMaxReferencesPerNode
});

self.performMessageTransaction(request, function (err, response) {

if (r.continuationPoint !== null) {
console.log(" warning:".yellow, " BrowseResponse : server didn't send all references and has provided a continuationPoint. Unfortunately we do not support this yet");
console.log(" self.requestedMaxReferencesPerNode = ", self.requestedMaxReferencesPerNode);
console.log(" continuationPoint ", r.continuationPoint);
var i, r;


/* istanbul ignore next */
if (err) {
return callback(err, null, response);
}

assert(response instanceof browse_service.BrowseNextResponse);

if (self.requestedMaxReferencesPerNode > 0) {

for (i = 0; i < response.results.length; i++) {
r = response.results[i];

/* istanbul ignore next */
if (r.references && r.references.length > self.requestedMaxReferencesPerNode) {
console.log("warning".yellow + " BrowseNextResponse : server didn't take into account our requestedMaxReferencesPerNode ");
console.log(" self.requestedMaxReferencesPerNode= " + self.requestedMaxReferencesPerNode);
console.log(" got " + r.references.length + "for " + nodesToBrowse[i].nodeId.toString());
console.log(" continuationPoint ", r.continuationPoint);
}
}
}
for (i = 0; i < response.results.length; i++) {
r = response.results[i];
r.references = r.references || [];
}
callback(null, response.results, response.diagnosticInfos);
});
}
Expand All @@ -202,7 +250,6 @@ ClientSession.prototype.browse = function (nodes, callback) {
}
};


/**
* @method readVariableValue
* @async
Expand Down
89 changes: 89 additions & 0 deletions test/end_to_end/test_e2e_browse_next.js
@@ -0,0 +1,89 @@
require("requirish")._(module);
var assert = require("better-assert");
//var async = require("async");
var should = require("should");


var opcua = require("index");

var OPCUAClient = opcua.OPCUAClient;
var AttributeIds = opcua.AttributeIds;
var coerceNodeId = opcua.coerceNodeId;
var StatusCodes = opcua.StatusCodes;
var DataType = opcua.DataType;


var build_server_with_temperature_device = require("test/helpers/build_server_with_temperature_device").build_server_with_temperature_device;
var perform_operation_on_client_session = require("test/helpers/perform_operation_on_client_session").perform_operation_on_client_session;
var redirectToFile = require("lib/misc/utils").redirectToFile;

describe("Testing Server and Client browse and browse next using continuation points", function () {

var server, client, temperatureVariableId, endpointUrl;

var port = 2001;
before(function (done) {
// we use a different port for each tests to make sure that there is
// no left over in the tcp pipe that could generate an error
port += 1;
server = build_server_with_temperature_device({port: port}, function (err) {
endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl;
temperatureVariableId = server.temperatureVariableId;
done(err);
});
});

beforeEach(function (done) {
client = new OPCUAClient();
done();
});

afterEach(function (done) {
client = null;
done();
});

after(function (done) {
server.shutdown(done);
});

function extract_server_channel() {
var cp = server.endpoints[0];
var ckey = Object.keys(cp._channels);
assert(ckey.length === 1);
var channel = cp._channels[ckey[0]];
//assert(channel instanceof ServerSecureChannelLayer);
return channel;
}

it("Server should browse Types using continuation point", function (done) {
var results;
perform_operation_on_client_session(client, endpointUrl, function (session, done) {
session.requestedMaxReferencesPerNode = 4;

session.browse("ns=0;i=86", function (err, browseResults, diagnosticInfos) {
should(err).eql(null);

browseResults.length.should.equal(1);

var r = browseResults[0];
results = r.references;
should.exist(r.continuationPoint);

session.browseNext(r.continuationPoint, function(err, browseResults){
should.not.exist(err);

browseResults.length.should.equal(1);

var r = browseResults[0];
results = results.concat(r.references);
results.length.should.equal(7);
should.not.exist(r.continuationPoint);

done();
});
});

}, done);
});
});

0 comments on commit 0281988

Please sign in to comment.