yarn_test.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 modelSetup = require('test/init_model_test');
  20. require('models/service/yarn');
  21. var yarnService,
  22. yarnServiceData = {
  23. id: 'yarn'
  24. },
  25. hostComponentsData = [
  26. {
  27. id: 'ats',
  28. componentName: 'APP_TIMELINE_SERVER',
  29. host: {
  30. id: 'host'
  31. }
  32. },
  33. {
  34. id: 'nodemanager',
  35. componentName: 'NODEMANAGER',
  36. host: {
  37. id: 'host'
  38. }
  39. },
  40. {
  41. id: 'yarnclient',
  42. componentName: 'YARN_CLIENT',
  43. host: {
  44. id: 'host'
  45. }
  46. }
  47. ],
  48. configs = [
  49. {
  50. properties: {
  51. 'yarn.timeline-service.webapp.address': '0.0.0.0:0000'
  52. },
  53. tag: 'version2',
  54. type: 'yarn-site'
  55. }
  56. ],
  57. nodeCountCases = [
  58. {
  59. assets: {
  60. nodeManagersStarted: 0,
  61. nodeManagersInstalled: 1,
  62. nodeManagersTotal: 1,
  63. nodeManagersCountActive: 0,
  64. nodeManagersCountRebooted: 0,
  65. nodeManagersCountUnhealthy: 0,
  66. nodeManagersCountDecommissioned: 0
  67. },
  68. nodeManagersCountLost: 1
  69. },
  70. {
  71. assets: {
  72. nodeManagersStarted: 1,
  73. nodeManagersInstalled: 1,
  74. nodeManagersTotal: 1,
  75. nodeManagersCountActive: 1,
  76. nodeManagersCountRebooted: 1,
  77. nodeManagersCountUnhealthy: 0,
  78. nodeManagersCountDecommissioned: 0
  79. },
  80. nodeManagersCountLost: 0
  81. }
  82. ],
  83. setHostComponents = function () {
  84. yarnService.reopen({
  85. hostComponents: hostComponentsData
  86. });
  87. };
  88. describe('App.YARNService', function () {
  89. beforeEach(function () {
  90. yarnService = App.YARNService.createRecord(yarnServiceData);
  91. });
  92. afterEach(function () {
  93. modelSetup.deleteRecord(yarnService);
  94. });
  95. describe('#ahsWebPort', function () {
  96. afterEach(function () {
  97. App.db.setConfigs([]);
  98. });
  99. it('should be 8188 as default', function () {
  100. App.db.setConfigs([]);
  101. expect(yarnService.get('ahsWebPort')).to.equal('8188');
  102. });
  103. it('should get value from configs', function () {
  104. App.db.setConfigs(configs);
  105. expect(yarnService.get('ahsWebPort')).to.equal('0000');
  106. });
  107. });
  108. describe('#queueFormatted', function () {
  109. it('should return formatted string', function () {
  110. yarnService.set('queue', '{"root":{"default":{}}}');
  111. expect(yarnService.get('queueFormatted')).to.equal('default (/root)<br/>');
  112. });
  113. });
  114. describe('#queuesCount', function () {
  115. it('should be 1', function () {
  116. yarnService.set('queue', '{"root":{"default":{}}}');
  117. expect(yarnService.get('queuesCount')).to.equal(1);
  118. });
  119. });
  120. describe('#maxMemory', function () {
  121. it('should add availableMemory to allocatedMemory', function () {
  122. yarnService.set('allocatedMemory', 1024);
  123. yarnService.set('availableMemory', 2048);
  124. expect(yarnService.get('maxMemory')).to.equal(3072);
  125. });
  126. });
  127. describe('#allQueueNames', function () {
  128. it('should list all queue names as array', function () {
  129. yarnService.set('queue', '{"root":{"default":{}}}');
  130. expect(yarnService.get('allQueueNames')).to.eql(['root', 'root/default']);
  131. });
  132. });
  133. describe('#childQueueNames', function () {
  134. it('should list child queue names as array', function () {
  135. yarnService.set('queue', '{"root":{"default":{}}}');
  136. expect(yarnService.get('childQueueNames')).to.eql(['root/default']);
  137. });
  138. });
  139. describe('#nodeManagersCountLost', function () {
  140. nodeCountCases.forEach(function (item) {
  141. it('should be ' + item.nodeManagersCountLost, function () {
  142. setHostComponents();
  143. for (var prop in item.assets) {
  144. yarnService.set(prop, item.assets[prop]);
  145. };
  146. expect(yarnService.get('nodeManagersCountLost')).to.equal(item.nodeManagersCountLost);
  147. });
  148. });
  149. });
  150. });