host_component_test.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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('#getStatusesList', function() {
  34. it('allowed statuses', function() {
  35. var statuses = ["STARTED","STARTING","INSTALLED","STOPPING","INSTALL_FAILED","INSTALLING","UPGRADE_FAILED","UNKNOWN","DISABLED","INIT"];
  36. expect(App.HostComponentStatus.getStatusesList()).to.include.members(statuses);
  37. expect(statuses).to.include.members(App.HostComponentStatus.getStatusesList());
  38. });
  39. });
  40. describe('#isClient', function() {
  41. it('', function() {
  42. sinon.stub(App.get('components.clients'), 'contains', Em.K);
  43. hc.propertyDidChange('isClient');
  44. hc.get('isClient');
  45. expect(App.get('components.clients').contains.calledWith('COMP1')).to.be.true;
  46. App.get('components.clients').contains.restore();
  47. });
  48. });
  49. describe('#displayName', function() {
  50. it('', function() {
  51. sinon.stub(App.format, 'role', Em.K);
  52. hc.propertyDidChange('displayName');
  53. hc.get('displayName');
  54. expect(App.format.role.calledWith('COMP1')).to.be.true;
  55. App.format.role.restore();
  56. });
  57. });
  58. describe('#isMaster', function() {
  59. it('', function() {
  60. sinon.stub(App.get('components.masters'), 'contains', Em.K);
  61. hc.propertyDidChange('isMaster');
  62. hc.get('isMaster');
  63. expect(App.get('components.masters').contains.calledWith('COMP1')).to.be.true;
  64. App.get('components.masters').contains.restore();
  65. });
  66. });
  67. describe('#isSlave', function() {
  68. it('', function() {
  69. sinon.stub(App.get('components.slaves'), 'contains', Em.K);
  70. hc.propertyDidChange('isSlave');
  71. hc.get('isSlave');
  72. expect(App.get('components.slaves').contains.calledWith('COMP1')).to.be.true;
  73. App.get('components.slaves').contains.restore();
  74. });
  75. });
  76. describe('#isDeletable', function() {
  77. it('', function() {
  78. sinon.stub(App.get('components.deletable'), 'contains', Em.K);
  79. hc.propertyDidChange('isDeletable');
  80. hc.get('isDeletable');
  81. expect(App.get('components.deletable').contains.calledWith('COMP1')).to.be.true;
  82. App.get('components.deletable').contains.restore();
  83. });
  84. });
  85. describe('#isRunning', function() {
  86. var testCases = [
  87. {
  88. workStatus: 'INSTALLED',
  89. result: false
  90. },
  91. {
  92. workStatus: 'STARTING',
  93. result: true
  94. },
  95. {
  96. workStatus: 'STARTED',
  97. result: true
  98. }
  99. ];
  100. testCases.forEach(function(test){
  101. it('workStatus - ' + test.workStatus, function() {
  102. hc.set('workStatus', test.workStatus);
  103. hc.propertyDidChange('isRunning');
  104. expect(hc.get('isRunning')).to.equal(test.result);
  105. });
  106. });
  107. });
  108. describe('#isDecommissioning', function() {
  109. var mock = [];
  110. beforeEach(function () {
  111. sinon.stub(App.HDFSService, 'find', function () {
  112. return mock;
  113. })
  114. });
  115. afterEach(function () {
  116. App.HDFSService.find.restore();
  117. });
  118. it('component name is not DATANODE', function() {
  119. hc.propertyDidChange('isDecommissioning');
  120. expect(hc.get('isDecommissioning')).to.be.false;
  121. });
  122. it('component name is DATANODE but no HDFS service', function() {
  123. hc.set('componentName', 'DATANODE');
  124. hc.propertyDidChange('isDecommissioning');
  125. expect(hc.get('isDecommissioning')).to.be.false;
  126. });
  127. it('HDFS has no decommission DataNodes', function() {
  128. hc.set('componentName', 'DATANODE');
  129. mock.push(Em.Object.create({
  130. decommissionDataNodes: []
  131. }));
  132. hc.propertyDidChange('isDecommissioning');
  133. expect(hc.get('isDecommissioning')).to.be.false;
  134. });
  135. it('HDFS has decommission DataNodes', function() {
  136. hc.set('componentName', 'DATANODE');
  137. hc.set('hostName', 'host1');
  138. mock.clear();
  139. mock.push(Em.Object.create({
  140. decommissionDataNodes: [{hostName: 'host1'}]
  141. }));
  142. hc.propertyDidChange('isDecommissioning');
  143. expect(hc.get('isDecommissioning')).to.be.true;
  144. });
  145. });
  146. describe('#isActive', function() {
  147. it('passiveState is ON', function() {
  148. hc.set('passiveState', "ON");
  149. hc.propertyDidChange('isActive');
  150. expect(hc.get('isActive')).to.be.false;
  151. });
  152. it('passiveState is OFF', function() {
  153. hc.set('passiveState', "OFF");
  154. hc.propertyDidChange('isActive');
  155. expect(hc.get('isActive')).to.be.true;
  156. });
  157. });
  158. describe('#statusClass', function() {
  159. it('isActive is false', function() {
  160. hc.reopen({
  161. isActive: false
  162. });
  163. hc.propertyDidChange('statusClass');
  164. expect(hc.get('statusClass')).to.equal('icon-medkit');
  165. });
  166. it('isActive is true', function() {
  167. var status = 'INSTALLED';
  168. hc.set('isActive', true);
  169. hc.set('workStatus', status);
  170. hc.propertyDidChange('statusClass');
  171. expect(hc.get('statusClass')).to.equal(status);
  172. });
  173. });
  174. describe('#statusIconClass', function () {
  175. var testCases = [
  176. {
  177. statusClass: 'STARTED',
  178. result: 'icon-ok-sign'
  179. },
  180. {
  181. statusClass: 'STARTING',
  182. result: 'icon-ok-sign'
  183. },
  184. {
  185. statusClass: 'INSTALLED',
  186. result: 'icon-warning-sign'
  187. },
  188. {
  189. statusClass: 'STOPPING',
  190. result: 'icon-warning-sign'
  191. },
  192. {
  193. statusClass: 'UNKNOWN',
  194. result: 'icon-question-sign'
  195. },
  196. {
  197. statusClass: '',
  198. result: ''
  199. }
  200. ];
  201. it('reset statusClass to plain property', function () {
  202. hc.reopen({
  203. statusClass: ''
  204. })
  205. });
  206. testCases.forEach(function (test) {
  207. it('statusClass - ' + test.statusClass, function () {
  208. hc.set('statusClass', test.statusClass);
  209. hc.propertyDidChange('statusIconClass');
  210. expect(hc.get('statusIconClass')).to.equal(test.result);
  211. });
  212. });
  213. });
  214. describe('#componentTextStatus', function() {
  215. it('', function() {
  216. var status = 'INSTALLED';
  217. sinon.stub(App.HostComponentStatus, 'getTextStatus', Em.K);
  218. hc.set('workStatus', status);
  219. hc.propertyDidChange('componentTextStatus');
  220. hc.get('componentTextStatus');
  221. expect(App.HostComponentStatus.getTextStatus.calledWith(status)).to.be.true;
  222. App.HostComponentStatus.getTextStatus.restore();
  223. });
  224. });
  225. });