yarn_test.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. var numberUtils = require('utils/number_utils');
  21. require('/views/main/service/services/yarn');
  22. function getView(options) {
  23. return App.MainDashboardServiceYARNView.create(options || {});
  24. }
  25. describe('App.MainDashboardServiceYARNView', function () {
  26. var view;
  27. beforeEach(function() {
  28. view = getView({service: Em.Object.create()});
  29. });
  30. App.TestAliases.testAsComputedCountBasedMessage(getView(), 'nodeManagerText', 'service.nodeManagersTotal', '', Em.I18n.t('services.service.summary.viewHost'), Em.I18n.t('services.service.summary.viewHosts'));
  31. App.TestAliases.testAsComputedGt(getView(), 'hasManyYarnClients', 'service.installedClients', 1);
  32. App.TestAliases.testAsComputedFormatNa(getView(), '_nmActive', 'service.nodeManagersCountActive');
  33. App.TestAliases.testAsComputedFormatNa(getView(), '_nmLost', 'service.nodeManagersCountLost');
  34. App.TestAliases.testAsComputedFormatNa(getView(), '_nmUnhealthy', 'service.nodeManagersCountUnhealthy');
  35. App.TestAliases.testAsComputedFormatNa(getView(), '_nmRebooted', 'service.nodeManagersCountRebooted');
  36. App.TestAliases.testAsComputedFormatNa(getView(), '_nmDecom', 'service.nodeManagersCountDecommissioned');
  37. App.TestAliases.testAsComputedFormatNa(getView(), '_allocated', 'service.containersAllocated');
  38. App.TestAliases.testAsComputedFormatNa(getView(), '_pending', 'service.containersPending');
  39. App.TestAliases.testAsComputedFormatNa(getView(), '_reserved', 'service.containersReserved');
  40. App.TestAliases.testAsComputedFormatNa(getView(), '_appsSubmitted', 'service.appsSubmitted');
  41. App.TestAliases.testAsComputedFormatNa(getView(), '_appsRunning', 'service.appsRunning');
  42. App.TestAliases.testAsComputedFormatNa(getView(), '_appsPending', 'service.appsPending');
  43. App.TestAliases.testAsComputedFormatNa(getView(), '_appsCompleted', 'service.appsCompleted');
  44. App.TestAliases.testAsComputedFormatNa(getView(), '_appsKilled', 'service.appsKilled');
  45. App.TestAliases.testAsComputedFormatNa(getView(), '_appsFailed', 'service.appsFailed');
  46. App.TestAliases.testAsComputedFormatNa(getView(), '_queuesCountFormatted', 'service.queuesCount');
  47. describe("#nodeUptime", function() {
  48. beforeEach(function() {
  49. sinon.stub(App, 'dateTime').returns(10);
  50. sinon.stub(date, 'timingFormat').returns('11');
  51. });
  52. afterEach(function() {
  53. App.dateTime.restore();
  54. date.timingFormat.restore();
  55. });
  56. it("resourceManagerStartTime is 0", function() {
  57. view.set('service.resourceManagerStartTime', 0);
  58. view.propertyDidChange('nodeUptime');
  59. expect(view.get('nodeUptime')).to.be.equal(view.t('services.service.summary.notRunning'));
  60. });
  61. it("resourceManagerStartTime is -1", function() {
  62. view.set('service.resourceManagerStartTime', -1);
  63. view.propertyDidChange('nodeUptime');
  64. expect(view.get('nodeUptime')).to.be.equal(view.t('services.service.summary.notRunning'));
  65. });
  66. it("resourceManagerStartTime is 1", function() {
  67. view.set('service.resourceManagerStartTime', 1);
  68. view.propertyDidChange('nodeUptime');
  69. expect(view.get('nodeUptime')).to.be.equal(view.t('dashboard.services.uptime').format('11'));
  70. expect(date.timingFormat.calledWith(9)).to.be.true;
  71. });
  72. it("resourceManagerStartTime is 11", function() {
  73. view.set('service.resourceManagerStartTime', 11);
  74. view.propertyDidChange('nodeUptime');
  75. expect(view.get('nodeUptime')).to.be.equal(view.t('dashboard.services.uptime').format('11'));
  76. expect(date.timingFormat.calledWith(0)).to.be.true;
  77. });
  78. });
  79. describe("#memory", function() {
  80. beforeEach(function() {
  81. sinon.stub(numberUtils, 'bytesToSize', function(arg1) {
  82. return arg1;
  83. })
  84. });
  85. afterEach(function() {
  86. numberUtils.bytesToSize.restore();
  87. });
  88. it("should return formatted memory", function() {
  89. view.set('service', Em.Object.create({
  90. allocatedMemory: 1,
  91. reservedMemory: 2,
  92. availableMemory: 3
  93. }));
  94. view.propertyDidChange('memory');
  95. expect(view.get('memory')).to.be.equal(Em.I18n.t('dashboard.services.yarn.memory.msg').format(1,2,3));
  96. });
  97. });
  98. describe("#didInsertElement()", function() {
  99. beforeEach(function() {
  100. sinon.stub(App, 'tooltip');
  101. });
  102. afterEach(function() {
  103. App.tooltip.restore();
  104. });
  105. it("App.tooltip should be called", function() {
  106. view.didInsertElement();
  107. expect(App.tooltip.calledOnce).to.be.true;
  108. });
  109. });
  110. describe("#willDestroyElement()", function() {
  111. var mock = {
  112. tooltip: Em.K
  113. };
  114. beforeEach(function() {
  115. sinon.stub(window, '$').returns(mock);
  116. sinon.stub(mock, 'tooltip');
  117. });
  118. afterEach(function() {
  119. window.$.restore();
  120. mock.tooltip.restore();
  121. });
  122. it("tooltip destroy should be called", function() {
  123. view.willDestroyElement();
  124. expect(mock.tooltip.calledWith('destroy')).to.be.true;
  125. });
  126. });
  127. });