hdfs_test.js 11 KB

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