host_component_test.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('models/host_component');
  20. describe('App.HostComponent', function() {
  21. App.store.load(App.HostComponent, {
  22. id: 'COMP_host',
  23. component_name: 'COMP1'
  24. });
  25. var hc = App.HostComponent.find('COMP_host');
  26. describe('#getStatusesList', function() {
  27. it('allowed statuses', function() {
  28. var statuses = ["STARTED","STARTING","INSTALLED","STOPPING","INSTALL_FAILED","INSTALLING","UPGRADE_FAILED","UNKNOWN","DISABLED","INIT"];
  29. expect(App.HostComponentStatus.getStatusesList()).to.include.members(statuses);
  30. expect(statuses).to.include.members(App.HostComponentStatus.getStatusesList());
  31. });
  32. });
  33. describe('#isClient', function() {
  34. beforeEach(function () {
  35. sinon.stub(App.get('components.clients'), 'contains', Em.K);
  36. hc.propertyDidChange('isClient');
  37. hc.get('isClient');
  38. });
  39. afterEach(function () {
  40. App.get('components.clients').contains.restore();
  41. });
  42. it('components.clients is called with correct data', function() {
  43. expect(App.get('components.clients').contains.calledWith('COMP1')).to.be.true;
  44. });
  45. });
  46. describe('#isMaster', function() {
  47. beforeEach(function () {
  48. sinon.stub(App.get('components.masters'), 'contains', Em.K);
  49. hc.propertyDidChange('isMaster');
  50. hc.get('isMaster');
  51. });
  52. afterEach(function () {
  53. App.get('components.masters').contains.restore();
  54. });
  55. it('components.masters is called with correct data', function() {
  56. expect(App.get('components.masters').contains.calledWith('COMP1')).to.be.true;
  57. });
  58. });
  59. describe('#isSlave', function() {
  60. beforeEach(function () {
  61. sinon.stub(App.get('components.slaves'), 'contains', Em.K);
  62. hc.propertyDidChange('isSlave');
  63. hc.get('isSlave');
  64. });
  65. afterEach(function () {
  66. App.get('components.slaves').contains.restore();
  67. });
  68. it('components.slaves is called with correct data', function() {
  69. expect(App.get('components.slaves').contains.calledWith('COMP1')).to.be.true;
  70. });
  71. });
  72. describe('#isDeletable', function() {
  73. beforeEach(function () {
  74. sinon.stub(App.get('components.deletable'), 'contains', Em.K);
  75. hc.propertyDidChange('isDeletable');
  76. hc.get('isDeletable');
  77. });
  78. afterEach(function () {
  79. App.get('components.deletable').contains.restore();
  80. });
  81. it('components.deletable is called with correct data', function() {
  82. expect(App.get('components.deletable').contains.calledWith('COMP1')).to.be.true;
  83. });
  84. });
  85. App.TestAliases.testAsComputedIfThenElse(hc, 'passiveTooltip', 'isActive', '', Em.I18n.t('hosts.component.passive.mode'));
  86. App.TestAliases.testAsComputedExistsIn(hc, 'isRunning', 'workStatus', ['STARTED', 'STARTING']);
  87. describe('#isDecommissioning', function() {
  88. var mock = [];
  89. beforeEach(function () {
  90. sinon.stub(App.HDFSService, 'find', function () {
  91. return mock;
  92. })
  93. });
  94. afterEach(function () {
  95. App.HDFSService.find.restore();
  96. });
  97. it('component name is not DATANODE', function() {
  98. hc.propertyDidChange('isDecommissioning');
  99. expect(hc.get('isDecommissioning')).to.be.false;
  100. });
  101. it('component name is DATANODE but no HDFS service', function() {
  102. hc.set('componentName', 'DATANODE');
  103. hc.propertyDidChange('isDecommissioning');
  104. expect(hc.get('isDecommissioning')).to.be.false;
  105. });
  106. it('HDFS has no decommission DataNodes', function() {
  107. hc.set('componentName', 'DATANODE');
  108. mock.push(Em.Object.create({
  109. decommissionDataNodes: []
  110. }));
  111. hc.propertyDidChange('isDecommissioning');
  112. expect(hc.get('isDecommissioning')).to.be.false;
  113. });
  114. it('HDFS has decommission DataNodes', function() {
  115. hc.set('componentName', 'DATANODE');
  116. hc.set('hostName', 'host1');
  117. mock.clear();
  118. mock.push(Em.Object.create({
  119. decommissionDataNodes: [{hostName: 'host1'}]
  120. }));
  121. hc.propertyDidChange('isDecommissioning');
  122. expect(hc.get('isDecommissioning')).to.be.true;
  123. });
  124. });
  125. App.TestAliases.testAsComputedEqual(hc, 'isActive', 'passiveState', 'OFF');
  126. App.TestAliases.testAsComputedIfThenElse(hc, 'passiveTooltip', 'isActive', '', Em.I18n.t('hosts.component.passive.mode'));
  127. describe('#isActive', function() {
  128. it('passiveState is ON', function() {
  129. hc.set('passiveState', "ON");
  130. hc.propertyDidChange('isActive');
  131. expect(hc.get('isActive')).to.be.false;
  132. });
  133. it('passiveState is OFF', function() {
  134. hc.set('passiveState', "OFF");
  135. hc.propertyDidChange('isActive');
  136. expect(hc.get('isActive')).to.be.true;
  137. });
  138. });
  139. describe('#statusClass', function() {
  140. it('isActive is false', function() {
  141. hc.reopen({
  142. isActive: false
  143. });
  144. hc.propertyDidChange('statusClass');
  145. expect(hc.get('statusClass')).to.equal('icon-medkit');
  146. });
  147. it('isActive is true', function() {
  148. var status = 'INSTALLED';
  149. hc.set('isActive', true);
  150. hc.set('workStatus', status);
  151. hc.propertyDidChange('statusClass');
  152. expect(hc.get('statusClass')).to.equal(status);
  153. });
  154. });
  155. describe('#statusIconClass', function () {
  156. var testCases = [
  157. {
  158. statusClass: 'STARTED',
  159. result: 'icon-ok-sign'
  160. },
  161. {
  162. statusClass: 'STARTING',
  163. result: 'icon-ok-sign'
  164. },
  165. {
  166. statusClass: 'INSTALLED',
  167. result: 'icon-warning-sign'
  168. },
  169. {
  170. statusClass: 'STOPPING',
  171. result: 'icon-warning-sign'
  172. },
  173. {
  174. statusClass: 'UNKNOWN',
  175. result: 'icon-question-sign'
  176. },
  177. {
  178. statusClass: '',
  179. result: ''
  180. }
  181. ];
  182. beforeEach(function () {
  183. hc.reopen({
  184. statusClass: ''
  185. });
  186. });
  187. testCases.forEach(function (test) {
  188. it('statusClass - ' + test.statusClass, function () {
  189. hc.set('statusClass', test.statusClass);
  190. hc.propertyDidChange('statusIconClass');
  191. expect(hc.get('statusIconClass')).to.equal(test.result);
  192. });
  193. });
  194. });
  195. describe('#componentTextStatus', function () {
  196. before(function () {
  197. sinon.stub(App.HostComponentStatus, 'getTextStatus', Em.K);
  198. });
  199. after(function () {
  200. App.HostComponentStatus.getTextStatus.restore();
  201. });
  202. it('componentTextStatus should be changed', function () {
  203. var status = 'INSTALLED';
  204. hc.set('workStatus', status);
  205. hc.propertyDidChange('componentTextStatus');
  206. hc.get('componentTextStatus');
  207. expect(App.HostComponentStatus.getTextStatus.calledWith(status)).to.be.true;
  208. });
  209. });
  210. describe("#getCount", function () {
  211. var testCases = [
  212. {
  213. t: 'unknown component',
  214. data: {
  215. componentName: 'CC',
  216. type: 'totalCount',
  217. stackComponent: Em.Object.create()
  218. },
  219. result: 0
  220. },
  221. {
  222. t: 'master component',
  223. data: {
  224. componentName: 'C1',
  225. type: 'totalCount',
  226. stackComponent: Em.Object.create({componentCategory: 'MASTER'})
  227. },
  228. result: 3
  229. },
  230. {
  231. t: 'slave component',
  232. data: {
  233. componentName: 'C1',
  234. type: 'installedCount',
  235. stackComponent: Em.Object.create({componentCategory: 'SLAVE'})
  236. },
  237. result: 4
  238. },
  239. {
  240. t: 'client component',
  241. data: {
  242. componentName: 'C1',
  243. type: 'startedCount',
  244. stackComponent: Em.Object.create({componentCategory: 'CLIENT'})
  245. },
  246. result: 5
  247. },
  248. {
  249. t: 'client component, unknown type',
  250. data: {
  251. componentName: 'C1',
  252. type: 'unknownCount',
  253. stackComponent: Em.Object.create({componentCategory: 'CLIENT'})
  254. },
  255. result: 0
  256. }
  257. ];
  258. beforeEach(function () {
  259. this.mock = sinon.stub(App.StackServiceComponent, 'find');
  260. sinon.stub(App.MasterComponent, 'find').returns(Em.Object.create({totalCount: 3}));
  261. sinon.stub(App.SlaveComponent, 'find').returns(Em.Object.create({installedCount: 4}));
  262. sinon.stub(App.ClientComponent, 'find').returns(Em.Object.create({startedCount: 5, unknownCount: null}));
  263. });
  264. afterEach(function () {
  265. this.mock.restore();
  266. App.MasterComponent.find.restore();
  267. App.SlaveComponent.find.restore();
  268. App.ClientComponent.find.restore();
  269. });
  270. testCases.forEach(function (test) {
  271. it(test.t, function () {
  272. this.mock.returns(test.data.stackComponent);
  273. expect(App.HostComponent.getCount(test.data.componentName, test.data.type)).to.equal(test.result);
  274. });
  275. });
  276. });
  277. App.TestAliases.testAsComputedExistsIn(hc, 'isNotInstalled', 'workStatus', ['INIT', 'INSTALL_FAILED']);
  278. });