UNPKG

@mindconnect/mindconnect-nodejs

Version:

MindConnect Library for NodeJS (community based)

240 lines 11.3 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); // Copyright (C), Siemens AG 2017 const chai = require("chai"); const console_1 = require("console"); const fs = require("fs"); const os = require("os"); require("url-search-params-polyfill"); const src_1 = require("../src"); const sdk_1 = require("../src/api/sdk"); const utils_1 = require("../src/api/utils"); const test_agent_setup_utils_1 = require("./test-agent-setup-utils"); chai.should(); describe("MindConnectApi RSA_3072 Agent performance test", () => { const auth = utils_1.loadAuth(); const sdk = new sdk_1.MindSphereSdk({ gateway: auth.gateway, basicAuth: utils_1.decrypt(auth, "passkey.4.unit.test"), tenant: auth.tenant }); let rsaConfig = {}; let unitTestConfiguration = {}; before(() => __awaiter(void 0, void 0, void 0, function* () { unitTestConfiguration = yield test_agent_setup_utils_1.unitTestSetup(sdk, sdk_1.AgentManagementModels.AgentUpdate.SecurityProfileEnum.RSA3072); rsaConfig = unitTestConfiguration.agentConfig; })); after(() => __awaiter(void 0, void 0, void 0, function* () { yield test_agent_setup_utils_1.tearDownAgents(sdk, unitTestConfiguration); })); it("should instantiate RSA_3072 agent.", () => { const agent = new src_1.MindConnectAgent(rsaConfig); agent.should.not.be.null; agent._configuration.should.not.be.null; agent._configuration.content.clientCredentialProfile[0].should.be.equal("RSA_3072"); agent._storage.should.not.be.null; }); it("should be able to put the datasource configuration.", () => __awaiter(void 0, void 0, void 0, function* () { const agent = new src_1.MindConnectAgent(rsaConfig); agent.SetupAgentCertificate(fs.readFileSync("private.key")); if (!agent.IsOnBoarded()) { yield agent.OnBoard(); } yield agent.GetDataSourceConfiguration(); if (agent.HasDataSourceConfiguration()) { console_1.log("The agent is already configured"); return; } const dataSourceConfig = { configurationId: "Configuration01", dataSources: [ { name: "EnvironmentData", description: "EnvironmentData (from environment sensors)", dataPoints: [ { id: "DP-Temperature", name: "Temperature", description: "Temperature", type: src_1.DataPoint.TypeEnum.DOUBLE, unit: "°C" }, { id: "DP-Humidity", name: "Humidity", description: "Humidity", type: src_1.DataPoint.TypeEnum.INT, unit: "%" }, { id: "DP-Pressure", name: "Pressure", description: "Pressure", type: src_1.DataPoint.TypeEnum.DOUBLE, unit: "kPa" } ], customData: { ostype: os.type(), osHostname: os.hostname() } }, { name: "VibrationData", description: "Vibration (from vibration sensors)", dataPoints: [ { id: "DP-Displacement", name: "Displacement", description: "Displacement", type: src_1.DataPoint.TypeEnum.DOUBLE, unit: "mm" }, { id: "DP-Velocity", name: "Velocity", description: "Velocity", type: src_1.DataPoint.TypeEnum.DOUBLE, unit: "mm/s" }, { id: "DP-Acceleration", name: "Acceleration", description: "Acceleration", type: src_1.DataPoint.TypeEnum.DOUBLE, unit: "mm/s^2" }, { id: "DP-Frequency", name: "Frequency", description: "Frequency", type: src_1.DataPoint.TypeEnum.DOUBLE, unit: "Hz" } ], customData: { ostype: os.type(), osHostname: os.hostname() } } ] }; if (!agent.HasDataSourceConfiguration()) { const result = yield agent.PutDataSourceConfiguration(dataSourceConfig); result.should.not.be.undefined; } })); it("should be able to get the datasource configuration.", () => __awaiter(void 0, void 0, void 0, function* () { const agent = new src_1.MindConnectAgent(rsaConfig); agent.SetupAgentCertificate(fs.readFileSync("private.key")); if (!agent.IsOnBoarded()) { yield agent.OnBoard(); } const result = yield agent.GetDataSourceConfiguration(); result.should.not.be.null; })); it("should be able to put the mappings configuration.", () => __awaiter(void 0, void 0, void 0, function* () { const agent = new src_1.MindConnectAgent(rsaConfig); agent.SetupAgentCertificate(fs.readFileSync("private.key")); if (!agent.IsOnBoarded()) { yield agent.OnBoard(); } const dataSourceConfig = yield agent.GetDataSourceConfiguration(); dataSourceConfig.should.not.be.null; const mappings = []; const aspects = unitTestConfiguration.targetAsset.aspects || []; const variables = []; for (const aspect of aspects) { for (const variable of aspect.variables || []) { variables.push(variable); } } const agentId = agent.ClientId(); const targetAssetId = unitTestConfiguration.targetAsset.assetId || utils_1.throwError("invalid asset"); for (const dataSource of dataSourceConfig.dataSources) { for (const datapoint of dataSource.dataPoints) { mappings.push({ agentId: agentId, dataPointId: datapoint.id, entityId: targetAssetId, propertyName: datapoint.name.replace("DP-", ""), propertySetName: dataSource.name, keepMapping: true }); } } const result = yield agent.PutDataMappings(mappings); result.should.not.be.undefined; })); it("should be able to get the data mappings.", () => __awaiter(void 0, void 0, void 0, function* () { const agent = new src_1.MindConnectAgent(rsaConfig); agent.SetupAgentCertificate(fs.readFileSync("private.key")); if (!agent.IsOnBoarded()) { yield agent.OnBoard(); } const result = yield agent.GetDataMappings(); result.should.not.be.null; result.should.not.be.equal([]); })); it("should function under heavy load", () => __awaiter(void 0, void 0, void 0, function* () { if (!process.env.CI) return; const agent = new src_1.MindConnectAgent(rsaConfig); agent.SetupAgentCertificate(fs.readFileSync("private.key")); if (!agent.IsOnBoarded()) { yield agent.OnBoard(); } if (!agent.HasDataSourceConfiguration()) { yield src_1.retry(5, () => agent.GetDataSourceConfiguration()); } const promises = []; for (let index = 0; index < 10; index++) { const now = Math.floor(Date.now() / 1000); agent._configuration.response.client_secret_expires_at = now; promises.push(yield agent.RenewToken()); } yield Promise.all(promises); for (let index = 0; index < 100; index++) { const values = [ { dataPointId: "DP-Temperature", qualityCode: "0", value: (Math.sin(index) * (20 + (index % 2)) + 25).toString() }, { dataPointId: "DP-Pressure", qualityCode: "0", value: (Math.cos(index) * (20 + (index % 25)) + 25).toString() }, { dataPointId: "DP-Humidity", qualityCode: "0", value: ((index + 30) % 100).toString() }, { dataPointId: "DP-Acceleration", qualityCode: "0", value: (1000.0 + index).toString() }, { dataPointId: "DP-Frequency", qualityCode: "0", value: (60.0 + index * 0.1).toString() }, { dataPointId: "DP-Displacement", qualityCode: "0", value: (index % 10).toString() }, { dataPointId: "DP-Velocity", qualityCode: "0", value: (50.0 + index).toString() } ]; if (Date.now() % 3 === 0) { const now = Math.floor(Date.now() / 1000); agent._configuration.response.client_secret_expires_at = now; } const validator = agent.GetValidator(); const isValid = yield validator(values); if (isValid) { } else { throw new Error("invalid configuration!"); } yield src_1.retry(3, () => agent.Upload(`images/mappings.png`, "", "desc", true, undefined, undefined, undefined, `${new Date().getTime()}/mappings.png`)); yield src_1.retry(3, () => agent.Upload(`images/mc4.png`, "", "desc", true, undefined, undefined, undefined, `${new Date().getTime()}/mappings.png`)); } })); }); //# sourceMappingURL=mindconnect-agent-performance-test.spec.js.map