Repository: ambari Updated Branches: refs/heads/trunk 53eba086d -> 7b3a3e067
AMBARI-5772. Add unit tests for service models (akovalenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7b3a3e06 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7b3a3e06 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7b3a3e06 Branch: refs/heads/trunk Commit: 7b3a3e067d0134a20a3ea53fa0ca8d8dc287cf1a Parents: 53eba08 Author: Aleksandr Kovalenko <[email protected]> Authored: Thu May 15 14:01:02 2014 +0300 Committer: Aleksandr Kovalenko <[email protected]> Committed: Thu May 15 14:01:02 2014 +0300 ---------------------------------------------------------------------- ambari-web/app/assets/test/tests.js | 6 + ambari-web/test/init_model_test.js | 11 +- ambari-web/test/models/service/flume_test.js | 68 +++++++ ambari-web/test/models/service/hbase_test.js | 55 ++++++ ambari-web/test/models/service/hdfs_test.js | 72 +++++++ .../test/models/service/mapreduce2_test.js | 58 ++++++ .../test/models/service/mapreduce_test.js | 55 ++++++ ambari-web/test/models/service/yarn_test.js | 192 +++++++++++++++++++ 8 files changed, 516 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/7b3a3e06/ambari-web/app/assets/test/tests.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js index 2636f75..ce4ee38 100644 --- a/ambari-web/app/assets/test/tests.js +++ b/ambari-web/app/assets/test/tests.js @@ -166,6 +166,12 @@ require('test/views/wizard/step8_view_test'); require('test/views/wizard/step9_view_test'); require('test/views/wizard/step9/hostLogPopupBody_view_test'); require('test/views/wizard/step10_view_test'); +require('test/models/service/flume_test'); +require('test/models/service/hbase_test'); +require('test/models/service/hdfs_test'); +require('test/models/service/mapreduce_test'); +require('test/models/service/mapreduce2_test'); +require('test/models/service/yarn_test'); require('test/models/host_test'); require('test/models/host_component_test'); require('test/models/rack_test'); http://git-wip-us.apache.org/repos/asf/ambari/blob/7b3a3e06/ambari-web/test/init_model_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/init_model_test.js b/ambari-web/test/init_model_test.js index bb36034..3ed3b06 100644 --- a/ambari-web/test/init_model_test.js +++ b/ambari-web/test/init_model_test.js @@ -45,5 +45,14 @@ module.exports = { restoreStackVersion: function(context) { App.set('currentStackVersion', context.prevStackVersion); }, - configs: require('test/mock_data_setup/configs_mock_data') + configs: require('test/mock_data_setup/configs_mock_data'), + /** + * Delete record from DS.Store and set its stateManager to proper state + * @param {DS.Model} record + * @method deleteRecord + */ + deleteRecord: function (record) { + record.deleteRecord(); + record.get('stateManager').transitionTo('loading'); + } }; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/7b3a3e06/ambari-web/test/models/service/flume_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/service/flume_test.js b/ambari-web/test/models/service/flume_test.js new file mode 100644 index 0000000..3b3417f --- /dev/null +++ b/ambari-web/test/models/service/flume_test.js @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var App = require('app'); + +var modelSetup = require('test/init_model_test'); +require('models/service/flume'); + +var flumeAgent, + flumeAgentData = { + id: 'agent', + name: 'agent' + }, + cases = [ + { + status: 'RUNNING', + healthClass: App.healthIconClassGreen + }, + { + status: 'NOT_RUNNING', + healthClass: App.healthIconClassRed + }, + { + status: 'UNKNOWN', + healthClass: App.healthIconClassYellow + }, + { + status: 'ANOTHER_STATUS', + healthClass: App.healthIconClassYellow + } + ]; + +describe('App.FlumeAgent', function () { + + beforeEach(function () { + flumeAgent = App.FlumeAgent.createRecord(flumeAgentData); + }); + + afterEach(function () { + modelSetup.deleteRecord(flumeAgent); + }); + + describe('#healthClass', function () { + cases.forEach(function (item) { + var healthClass = item.healthClass; + it('should be ' + healthClass, function () { + flumeAgent.set('status', item.status); + expect(flumeAgent.get('healthClass')).to.equal(healthClass); + }); + }); + }); + +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/7b3a3e06/ambari-web/test/models/service/hbase_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/service/hbase_test.js b/ambari-web/test/models/service/hbase_test.js new file mode 100644 index 0000000..861cf03 --- /dev/null +++ b/ambari-web/test/models/service/hbase_test.js @@ -0,0 +1,55 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * License); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var App = require('app'); + +var modelSetup = require('test/init_model_test'); +require('models/service/hbase'); + +var hBaseService, + hBaseServiceData = { + id: 'hbase' + }, + hostComponentsData = [ + { + id: 'regionserver', + componentName: 'HBASE_REGIONSERVER' + } + ]; + +describe('App.HBaseService', function () { + + beforeEach(function () { + hBaseService = App.HBaseService.createRecord(hBaseServiceData); + }); + + afterEach(function () { + modelSetup.deleteRecord(hBaseService); + }); + + describe('#regionServers', function () { + it('should take one component from hostComponents', function () { + hBaseService.reopen({ + hostComponents: hostComponentsData + }); + expect(hBaseService.get('regionServers')).to.have.length(1); + expect(hBaseService.get('regionServers')[0].id).to.equal('regionserver'); + }); + }); + +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/7b3a3e06/ambari-web/test/models/service/hdfs_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/service/hdfs_test.js b/ambari-web/test/models/service/hdfs_test.js new file mode 100644 index 0000000..93c3174 --- /dev/null +++ b/ambari-web/test/models/service/hdfs_test.js @@ -0,0 +1,72 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * License); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var App = require('app'); + +var modelSetup = require('test/init_model_test'); +require('models/service/hdfs'); + +var hdfsService, + hdfsServiceData = { + id: 'hdfs' + }, + hostComponentsData = [ + { + id: 'datanode', + componentName: 'DATANODE' + }, + { + id: 'journalnode', + componentName: 'JOURNALNODE' + } + ], + cases = [ + { + propertyName: 'dataNodes', + componentId: 'datanode' + }, + { + propertyName: 'journalNodes', + componentId: 'journalnode' + } + ]; + +describe('App.HDFSService', function () { + + beforeEach(function () { + hdfsService = App.HDFSService.createRecord(hdfsServiceData); + }); + + afterEach(function () { + modelSetup.deleteRecord(hdfsService); + }); + + cases.forEach(function (item) { + var propertyName = item.propertyName; + describe('#' + propertyName, function () { + it('should take one component from hostComponents', function () { + hdfsService.reopen({ + hostComponents: hostComponentsData + }); + expect(hdfsService.get(propertyName)).to.have.length(1); + expect(hdfsService.get(propertyName)[0].id).to.equal(item.componentId); + }); + }); + }); + +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/7b3a3e06/ambari-web/test/models/service/mapreduce2_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/service/mapreduce2_test.js b/ambari-web/test/models/service/mapreduce2_test.js new file mode 100644 index 0000000..b75321a --- /dev/null +++ b/ambari-web/test/models/service/mapreduce2_test.js @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * License); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var App = require('app'); + +var modelSetup = require('test/init_model_test'); +require('models/service/mapreduce2'); + +var mapReduce2Service, + mapReduce2ServiceData = { + id: 'mr2' + }, + hostComponentsData = [ + { + id: 'mr2client', + componentName: 'MAPREDUCE2_CLIENT', + host: { + id: 'host' + } + } + ]; + +describe('App.MapReduce2Service', function () { + + beforeEach(function () { + mapReduce2Service = App.MapReduce2Service.createRecord(mapReduce2ServiceData); + }); + + afterEach(function () { + modelSetup.deleteRecord(mapReduce2Service); + }); + + describe('#mapReduce2Clients', function () { + it('should take one component from hostComponents', function () { + mapReduce2Service.reopen({ + hostComponents: hostComponentsData + }); + expect(mapReduce2Service.get('mapReduce2Clients')).to.have.length(1); + expect(mapReduce2Service.get('mapReduce2Clients')[0].id).to.equal('host'); + }); + }); + +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/7b3a3e06/ambari-web/test/models/service/mapreduce_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/service/mapreduce_test.js b/ambari-web/test/models/service/mapreduce_test.js new file mode 100644 index 0000000..e94020f --- /dev/null +++ b/ambari-web/test/models/service/mapreduce_test.js @@ -0,0 +1,55 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * License); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var App = require('app'); + +var modelSetup = require('test/init_model_test'); +require('models/service/mapreduce'); + +var mapReduceService, + mapReduceServiceData = { + id: 'mr' + }, + hostComponentsData = [ + { + id: 'tasktracker', + componentName: 'TASKTRACKER' + } + ]; + +describe('App.MapReduceService', function () { + + beforeEach(function () { + mapReduceService = App.MapReduceService.createRecord(mapReduceServiceData); + }); + + afterEach(function () { + modelSetup.deleteRecord(mapReduceService); + }); + + describe('#taskTrackers', function () { + it('should take one component from hostComponents', function () { + mapReduceService.reopen({ + hostComponents: hostComponentsData + }); + expect(mapReduceService.get('taskTrackers')).to.have.length(1); + expect(mapReduceService.get('taskTrackers')[0].id).to.equal('tasktracker'); + }); + }); + +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/7b3a3e06/ambari-web/test/models/service/yarn_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/service/yarn_test.js b/ambari-web/test/models/service/yarn_test.js new file mode 100644 index 0000000..deaf55e --- /dev/null +++ b/ambari-web/test/models/service/yarn_test.js @@ -0,0 +1,192 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * License); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var App = require('app'); + +var modelSetup = require('test/init_model_test'); +require('models/service/yarn'); + +var yarnService, + yarnServiceData = { + id: 'yarn' + }, + hostComponentsData = [ + { + id: 'ats', + componentName: 'APP_TIMELINE_SERVER', + host: { + id: 'host' + } + }, + { + id: 'nodemanager', + componentName: 'NODEMANAGER', + host: { + id: 'host' + } + }, + { + id: 'yarnclient', + componentName: 'YARN_CLIENT', + host: { + id: 'host' + } + } + ], + configs = [ + { + properties: { + 'yarn.timeline-service.webapp.address': '0.0.0.0:0000' + }, + tag: 'version2', + type: 'yarn-site' + } + ], + nodeCases = [ + { + propertyName: 'nodeManagerNodes', + componentId: 'nodemanager' + }, + { + propertyName: 'yarnClientNodes', + componentId: 'host' + } + ], + nodeCountCases = [ + { + assets: { + nodeManagersCountActive: 0, + nodeManagersCountRebooted: 0, + nodeManagersCountUnhealthy: 0, + nodeManagersCountDecommissioned: 0 + }, + nodeManagersCountLost: 1 + }, + { + assets: { + nodeManagersCountActive: 1, + nodeManagersCountRebooted: 0, + nodeManagersCountUnhealthy: 0, + nodeManagersCountDecommissioned: 0 + }, + nodeManagersCountLost: 0 + } + ], + setHostComponents = function () { + yarnService.reopen({ + hostComponents: hostComponentsData + }); + }; + +describe('App.YARNService', function () { + + beforeEach(function () { + yarnService = App.YARNService.createRecord(yarnServiceData); + }); + + afterEach(function () { + modelSetup.deleteRecord(yarnService); + }); + + describe('#appTimelineServerNode', function () { + it('should take one component from hostComponents', function () { + yarnService.reopen({ + hostComponents: hostComponentsData + }); + expect(yarnService.get('appTimelineServerNode.id')).to.equal('host'); + }); + }); + + nodeCases.forEach(function (item) { + var propertyName = item.propertyName; + describe('#' + propertyName, function () { + it('should take one component from hostComponents', function () { + setHostComponents(); + expect(yarnService.get(propertyName)).to.have.length(1); + expect(yarnService.get(propertyName)[0].id).to.equal(item.componentId); + }); + }); + }); + + describe('#ahsWebPort', function () { + + afterEach(function () { + App.db.setConfigs([]); + }); + + it('should be 8188 as default', function () { + App.db.setConfigs([]); + expect(yarnService.get('ahsWebPort')).to.equal('8188'); + }); + + it('should get value from configs', function () { + App.db.setConfigs(configs); + expect(yarnService.get('ahsWebPort')).to.equal('0000'); + }); + + }); + + describe('#queueFormatted', function () { + it('should return formatted string', function () { + yarnService.set('queue', '{"root":{"default":{}}}'); + expect(yarnService.get('queueFormatted')).to.equal('default (/root)<br/>'); + }); + }); + + describe('#queuesCount', function () { + it('should be 1', function () { + yarnService.set('queue', '{"root":{"default":{}}}'); + expect(yarnService.get('queuesCount')).to.equal(1); + }); + }); + + describe('#maxMemory', function () { + it('should add availableMemory to allocatedMemory', function () { + yarnService.set('allocatedMemory', 1024); + yarnService.set('availableMemory', 2048); + expect(yarnService.get('maxMemory')).to.equal(3072); + }); + }); + + describe('#allQueueNames', function () { + it('should list all queue names as array', function () { + yarnService.set('queue', '{"root":{"default":{}}}'); + expect(yarnService.get('allQueueNames')).to.eql(['root', 'root/default']); + }); + }); + + describe('#childQueueNames', function () { + it('should list child queue names as array', function () { + yarnService.set('queue', '{"root":{"default":{}}}'); + expect(yarnService.get('childQueueNames')).to.eql(['root/default']); + }); + }); + + describe('#nodeManagersCountLost', function () { + nodeCountCases.forEach(function (item) { + it('should be ' + item.nodeManagersCountLost, function () { + setHostComponents(); + for (var prop in item.assets) { + yarnService.set(prop, item.assets[prop]); + }; + expect(yarnService.get('nodeManagersCountLost')).to.equal(item.nodeManagersCountLost); + }); + }); + }); + +});
