浏览代码

AMBARI-5772. Add unit tests for service models (akovalenko)

Aleksandr Kovalenko 11 年之前
父节点
当前提交
7b3a3e067d

+ 6 - 0
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');

+ 10 - 1
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');
+  }
 };

+ 68 - 0
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);
+      });
+    });
+  });
+
+});

+ 55 - 0
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');
+    });
+  });
+
+});

+ 72 - 0
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);
+      });
+    });
+  });
+
+});

+ 58 - 0
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');
+    });
+  });
+
+});

+ 55 - 0
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');
+    });
+  });
+
+});

+ 192 - 0
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);
+      });
+    });
+  });
+
+});