host_component_test.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. App.TestAliases.testAsComputedGetByKey(hc, 'statusIconClass', 'statusIconClassMap', 'statusClass', {defaultValue: '', map: {
  156. STARTED: App.healthIconClassGreen,
  157. STARTING: App.healthIconClassGreen,
  158. INSTALLED: App.healthIconClassRed,
  159. STOPPING: App.healthIconClassRed,
  160. UNKNOWN: App.healthIconClassYellow
  161. }});
  162. describe('#componentTextStatus', function () {
  163. before(function () {
  164. sinon.stub(App.HostComponentStatus, 'getTextStatus', Em.K);
  165. });
  166. after(function () {
  167. App.HostComponentStatus.getTextStatus.restore();
  168. });
  169. it('componentTextStatus should be changed', function () {
  170. var status = 'INSTALLED';
  171. hc.set('workStatus', status);
  172. hc.propertyDidChange('componentTextStatus');
  173. hc.get('componentTextStatus');
  174. expect(App.HostComponentStatus.getTextStatus.calledWith(status)).to.be.true;
  175. });
  176. });
  177. describe("#getCount", function () {
  178. var testCases = [
  179. {
  180. t: 'unknown component',
  181. data: {
  182. componentName: 'CC',
  183. type: 'totalCount',
  184. stackComponent: Em.Object.create()
  185. },
  186. result: 0
  187. },
  188. {
  189. t: 'master component',
  190. data: {
  191. componentName: 'C1',
  192. type: 'totalCount',
  193. stackComponent: Em.Object.create({componentCategory: 'MASTER'})
  194. },
  195. result: 3
  196. },
  197. {
  198. t: 'slave component',
  199. data: {
  200. componentName: 'C1',
  201. type: 'installedCount',
  202. stackComponent: Em.Object.create({componentCategory: 'SLAVE'})
  203. },
  204. result: 4
  205. },
  206. {
  207. t: 'client component',
  208. data: {
  209. componentName: 'C1',
  210. type: 'startedCount',
  211. stackComponent: Em.Object.create({componentCategory: 'CLIENT'})
  212. },
  213. result: 5
  214. },
  215. {
  216. t: 'client component, unknown type',
  217. data: {
  218. componentName: 'C1',
  219. type: 'unknownCount',
  220. stackComponent: Em.Object.create({componentCategory: 'CLIENT'})
  221. },
  222. result: 0
  223. }
  224. ];
  225. beforeEach(function () {
  226. this.mock = sinon.stub(App.StackServiceComponent, 'find');
  227. sinon.stub(App.MasterComponent, 'find').returns(Em.Object.create({totalCount: 3}));
  228. sinon.stub(App.SlaveComponent, 'find').returns(Em.Object.create({installedCount: 4}));
  229. sinon.stub(App.ClientComponent, 'find').returns(Em.Object.create({startedCount: 5, unknownCount: null}));
  230. });
  231. afterEach(function () {
  232. this.mock.restore();
  233. App.MasterComponent.find.restore();
  234. App.SlaveComponent.find.restore();
  235. App.ClientComponent.find.restore();
  236. });
  237. testCases.forEach(function (test) {
  238. it(test.t, function () {
  239. this.mock.returns(test.data.stackComponent);
  240. expect(App.HostComponent.getCount(test.data.componentName, test.data.type)).to.equal(test.result);
  241. });
  242. });
  243. });
  244. App.TestAliases.testAsComputedExistsIn(hc, 'isNotInstalled', 'workStatus', ['INIT', 'INSTALL_FAILED']);
  245. describe("#getDisplayName",function(){
  246. var testCases = [
  247. {
  248. testName: 'for displayName of length < 19',
  249. displayName: 'abc',
  250. result: 'abc'
  251. },
  252. {
  253. testName:'for displayName of length = 19',
  254. displayName: '1234567890123456789',
  255. result: '1234567890123456789'
  256. },
  257. {
  258. testName:'for displayName of length > 19',
  259. displayName: '12345678901234567890',
  260. result: '1234567890123456...'
  261. }
  262. ];
  263. testCases.forEach(function(test){
  264. it(test.testName, function(){
  265. hc.set('displayName',test.displayName);
  266. expect(hc.get('getDisplayName')).to.equal(test.result);
  267. });
  268. });
  269. });
  270. describe("#getDisplayNameAdvanced",function(){
  271. var testCases = [
  272. {
  273. testName: 'for displayNameAdvanced of length < 19',
  274. displayNameAdvanced: 'abc',
  275. result: 'abc'
  276. },
  277. {
  278. testName:'for displayNameAdvanced of length = 19',
  279. displayNameAdvanced: '1234567890123456789',
  280. result: '1234567890123456789'
  281. },
  282. {
  283. testName:'for displayNameAdvanced of length > 19',
  284. displayNameAdvanced: '12345678901234567890',
  285. result: '1234567890123456...'
  286. }
  287. ];
  288. testCases.forEach(function(test){
  289. it(test.testName, function(){
  290. hc.set('displayNameAdvanced',test.displayNameAdvanced);
  291. expect(hc.get('getDisplayNameAdvanced')).to.equal(test.result);
  292. });
  293. });
  294. });
  295. App.TestAliases.testAsComputedTruncate(hc, 'serviceDisplayName', 'service.displayName', 14, 11);
  296. App.TestAliases.testAsComputedTruncate(hc, 'getDisplayName', 'displayName', 19, 16);
  297. App.TestAliases.testAsComputedTruncate(hc, 'getDisplayNameAdvanced', 'displayNameAdvanced', 19, 16);
  298. describe("#serviceDisplayName",function(){
  299. var testCases = [
  300. {
  301. testName: 'for service.displayName of length < 14',
  302. serviceDisplayName: 'abc',
  303. result: 'abc'
  304. },
  305. {
  306. testName:'for service.displayName of length = 14',
  307. serviceDisplayName: '12345678901234',
  308. result: '12345678901234'
  309. },
  310. {
  311. testName:'for service.displayName of length > 14',
  312. serviceDisplayName: '123456789012345',
  313. result: '12345678901...'
  314. }
  315. ];
  316. testCases.forEach(function(test){
  317. it(test.testName, function(){
  318. hc.set('service',Em.Object.create({displayName:test.serviceDisplayName}));
  319. expect(hc.get('serviceDisplayName')).to.equal(test.result);
  320. });
  321. });
  322. });
  323. });