hdfs_test.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. var date = require('utils/date/date');
  20. require('/views/main/service/services/hdfs');
  21. function getView(options) {
  22. return App.MainDashboardServiceHdfsView.create(options || {});
  23. }
  24. describe('App.MainDashboardServiceHdfsView', function () {
  25. var view;
  26. beforeEach(function() {
  27. view = getView({service: Em.Object.create()});
  28. });
  29. App.TestAliases.testAsComputedAlias(getView(), 'dataNodesDead', 'service.dataNodesInstalled', 'boolean');
  30. App.TestAliases.testAsComputedAlias(getView(), 'journalNodesTotal', 'service.journalNodes.length', 'number');
  31. App.TestAliases.testAsComputedGt(getView(), 'showJournalNodes', 'service.journalNodes.length', 0);
  32. describe("#Chart", function() {
  33. var chartView;
  34. beforeEach(function() {
  35. chartView = view.get('Chart').create();
  36. });
  37. describe("#data", function () {
  38. it("should return data", function () {
  39. chartView.set('service', Em.Object.create({
  40. capacityTotal: 100,
  41. capacityRemaining: 1
  42. }));
  43. chartView.propertyDidChange('data');
  44. expect(chartView.get('data')).to.be.eql([99, 1]);
  45. });
  46. });
  47. });
  48. describe("#dashboardMasterComponentView", function() {
  49. var dashboardMasterComponentView;
  50. beforeEach(function() {
  51. dashboardMasterComponentView = view.get('dashboardMasterComponentView').create({
  52. parentView: Em.Object.create()
  53. });
  54. });
  55. describe("#mastersComp", function () {
  56. it("should return master components", function () {
  57. dashboardMasterComponentView.set('parentView.service', Em.Object.create({
  58. hostComponents: [
  59. Em.Object.create({
  60. componentName: 'ZKFC'
  61. }),
  62. Em.Object.create({
  63. componentName: 'JOURNALNODE'
  64. }),
  65. Em.Object.create({
  66. componentName: 'NAMENODE',
  67. isMaster: true
  68. })
  69. ]
  70. }));
  71. dashboardMasterComponentView.propertyDidChange('mastersComp');
  72. expect(dashboardMasterComponentView.get('mastersComp').mapProperty('componentName')).to.be.eql(['NAMENODE', 'ZKFC']);
  73. expect(dashboardMasterComponentView.get('mastersComp')[0].get('isMaster')).to.be.true;
  74. expect(dashboardMasterComponentView.get('mastersComp')[1].get('isSubComponent')).to.be.true;
  75. });
  76. });
  77. describe("#didInsertElement()", function() {
  78. beforeEach(function() {
  79. sinon.stub(App, 'tooltip');
  80. });
  81. afterEach(function() {
  82. App.tooltip.restore();
  83. });
  84. it("App.tooltip should be called", function() {
  85. dashboardMasterComponentView.didInsertElement();
  86. expect(App.tooltip.calledOnce).to.be.true;
  87. });
  88. });
  89. describe("#willDestroyElement()", function() {
  90. var mock = {
  91. tooltip: Em.K
  92. };
  93. beforeEach(function() {
  94. sinon.stub(mock, 'tooltip');
  95. sinon.stub(window, '$').returns(mock);
  96. });
  97. afterEach(function() {
  98. mock.tooltip.restore();
  99. window.$.restore();
  100. });
  101. it("tooltip destroy should be called", function() {
  102. dashboardMasterComponentView.willDestroyElement();
  103. expect(mock.tooltip.calledWith('destroy')).to.be.true;
  104. });
  105. });
  106. });
  107. describe("#didInsertElement()", function() {
  108. beforeEach(function() {
  109. sinon.stub(App, 'tooltip');
  110. });
  111. afterEach(function() {
  112. App.tooltip.restore();
  113. });
  114. it("App.tooltip should be called", function() {
  115. view.didInsertElement();
  116. expect(App.tooltip.calledOnce).to.be.true;
  117. });
  118. });
  119. describe("#willDestroyElement()", function() {
  120. var mock = {
  121. tooltip: Em.K
  122. };
  123. beforeEach(function() {
  124. sinon.stub(mock, 'tooltip');
  125. sinon.stub(window, '$').returns(mock);
  126. });
  127. afterEach(function() {
  128. mock.tooltip.restore();
  129. window.$.restore();
  130. });
  131. it("tooltip destroy should be called", function() {
  132. view.willDestroyElement();
  133. expect(mock.tooltip.calledWith('destroy')).to.be.true;
  134. });
  135. });
  136. describe("#journalNodesLive", function() {
  137. it("should return live journal nodes count", function() {
  138. view.set('service', Em.Object.create({
  139. journalNodes: [
  140. Em.Object.create({workStatus: 'STARTED'}),
  141. Em.Object.create()
  142. ]
  143. }));
  144. view.propertyDidChange('journalNodesLive');
  145. expect(view.get('journalNodesLive')).to.be.equal(1);
  146. });
  147. });
  148. describe("#nodeUptime", function() {
  149. beforeEach(function() {
  150. sinon.stub(App, 'dateTime').returns(10);
  151. sinon.stub(date, 'timingFormat').returns('11');
  152. });
  153. afterEach(function() {
  154. App.dateTime.restore();
  155. date.timingFormat.restore();
  156. });
  157. it("nameNodeStartTime is 0", function() {
  158. view.set('service.nameNodeStartTime', 0);
  159. view.propertyDidChange('nodeUptime');
  160. expect(view.get('nodeUptime')).to.be.equal(view.t('services.service.summary.notRunning'));
  161. });
  162. it("nameNodeStartTime is -1", function() {
  163. view.set('service.nameNodeStartTime', -1);
  164. view.propertyDidChange('nodeUptime');
  165. expect(view.get('nodeUptime')).to.be.equal(view.t('services.service.summary.notRunning'));
  166. });
  167. it("nameNodeStartTime is 1", function() {
  168. view.set('service.nameNodeStartTime', 1);
  169. view.propertyDidChange('nodeUptime');
  170. expect(view.get('nodeUptime')).to.be.equal(view.t('dashboard.services.uptime').format('11'));
  171. expect(date.timingFormat.calledWith(9)).to.be.true;
  172. });
  173. it("nameNodeStartTime is 11", function() {
  174. view.set('service.nameNodeStartTime', 11);
  175. view.propertyDidChange('nodeUptime');
  176. expect(view.get('nodeUptime')).to.be.equal(view.t('dashboard.services.uptime').format('11'));
  177. expect(date.timingFormat.calledWith(0)).to.be.true;
  178. });
  179. });
  180. describe("#nodeWebUrl", function () {
  181. it("singleNodeInstall is true", function () {
  182. App.set('singleNodeInstall', true);
  183. App.set('singleNodeAlias', 'host1');
  184. view.propertyDidChange('nodeWebUrl');
  185. expect(view.get('nodeWebUrl')).to.be.equal("http://host1:50070");
  186. });
  187. it("singleNodeInstall is false", function () {
  188. App.set('singleNodeInstall', false);
  189. view.set('service.nameNode', Em.Object.create({
  190. publicHostName: 'host2'
  191. }));
  192. view.propertyDidChange('nodeWebUrl');
  193. expect(view.get('nodeWebUrl')).to.be.equal("http://host2:50070");
  194. });
  195. });
  196. describe("#nonDfsUsed", function() {
  197. var testCases = [
  198. {
  199. input: {
  200. capacityTotal: null,
  201. capacityRemaining: 1,
  202. capacityUsed: 90
  203. },
  204. expected: null
  205. },
  206. {
  207. input: {
  208. capacityTotal: 100,
  209. capacityRemaining: null,
  210. capacityUsed: 90
  211. },
  212. expected: null
  213. },
  214. {
  215. input: {
  216. capacityTotal: 100,
  217. capacityRemaining: 1,
  218. capacityUsed: null
  219. },
  220. expected: null
  221. },
  222. {
  223. input: {
  224. capacityTotal: 100,
  225. capacityRemaining: 1,
  226. capacityUsed: 90
  227. },
  228. expected: 9
  229. }
  230. ];
  231. testCases.forEach(function(test) {
  232. it("total=" + test.input.capacityTotal + " remaining" + test.input.capacityRemaining + " used" + test.input.capacityUsed, function() {
  233. view.get('service').setProperties(test.input);
  234. view.propertyDidChange('nonDfsUsed');
  235. expect(view.get('nonDfsUsed')).to.be.equal(test.expected);
  236. });
  237. });
  238. });
  239. describe("#isNfsInStack", function() {
  240. beforeEach(function() {
  241. this.mock = sinon.stub(App.StackServiceComponent, 'find');
  242. });
  243. afterEach(function() {
  244. this.mock.restore();
  245. });
  246. it("no NFS_GATEWAY component", function() {
  247. this.mock.returns([]);
  248. view.propertyDidChange('isNfsInStack');
  249. expect(view.get('isNfsInStack')).to.be.false;
  250. });
  251. it("NFS_GATEWAY component present", function() {
  252. this.mock.returns([{componentName: 'NFS_GATEWAY'}]);
  253. view.propertyDidChange('isNfsInStack');
  254. expect(view.get('isNfsInStack')).to.be.true;
  255. });
  256. });
  257. describe("#safeModeStatus", function() {
  258. it("safeModeStatus is null", function() {
  259. view.set('service.safeModeStatus', null);
  260. view.propertyDidChange('safeModeStatus');
  261. expect(view.get('safeModeStatus')).to.be.equal(Em.I18n.t("services.service.summary.notAvailable"));
  262. });
  263. it("safeModeStatus is empty", function() {
  264. view.set('service.safeModeStatus', "");
  265. view.propertyDidChange('safeModeStatus');
  266. expect(view.get('safeModeStatus')).to.be.equal(Em.I18n.t("services.service.summary.safeModeStatus.notInSafeMode"));
  267. });
  268. it("safeModeStatus is on", function() {
  269. view.set('service.safeModeStatus', 'on');
  270. view.propertyDidChange('safeModeStatus');
  271. expect(view.get('safeModeStatus')).to.be.equal(Em.I18n.t("services.service.summary.safeModeStatus.inSafeMode"));
  272. });
  273. });
  274. describe("#upgradeStatus", function() {
  275. it("upgradeStatus is 'true'", function() {
  276. view.set('service.upgradeStatus', 'true');
  277. view.propertyDidChange('upgradeStatus');
  278. expect(view.get('upgradeStatus')).to.be.equal(Em.I18n.t('services.service.summary.pendingUpgradeStatus.notPending'));
  279. });
  280. it("upgradeStatus is 'false', healthStatus is 'green'", function() {
  281. view.set('service.upgradeStatus', 'false');
  282. view.set('service.healthStatus', 'green');
  283. view.propertyDidChange('upgradeStatus');
  284. expect(view.get('upgradeStatus')).to.be.equal(Em.I18n.t('services.service.summary.pendingUpgradeStatus.notFinalized'));
  285. });
  286. it("upgradeStatus is null", function() {
  287. view.set('service.upgradeStatus', null);
  288. view.propertyDidChange('upgradeStatus');
  289. expect(view.get('upgradeStatus')).to.be.equal(Em.I18n.t('services.service.summary.notAvailable'));
  290. });
  291. });
  292. describe("#isUpgradeStatusWarning", function() {
  293. it("upgradeStatus is 'false', healthStatus is 'green'", function() {
  294. view.set('service.upgradeStatus', 'false');
  295. view.set('service.healthStatus', 'green');
  296. view.propertyDidChange('isUpgradeStatusWarning');
  297. expect(view.get('isUpgradeStatusWarning')).to.be.true;
  298. });
  299. it("upgradeStatus is 'true', healthStatus is 'green'", function() {
  300. view.set('service.upgradeStatus', 'true');
  301. view.set('service.healthStatus', 'green');
  302. view.propertyDidChange('isUpgradeStatusWarning');
  303. expect(view.get('isUpgradeStatusWarning')).to.be.false;
  304. });
  305. it("upgradeStatus is 'false', healthStatus is 'red'", function() {
  306. view.set('service.upgradeStatus', 'false');
  307. view.set('service.healthStatus', 'red');
  308. view.propertyDidChange('isUpgradeStatusWarning');
  309. expect(view.get('isUpgradeStatusWarning')).to.be.false;
  310. });
  311. });
  312. });