update_controller_test.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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('utils/updater');
  20. require('controllers/global/update_controller');
  21. describe('App.UpdateController', function () {
  22. var controller = App.UpdateController.create({
  23. clusterName: '',
  24. location: '',
  25. updateServiceMetric: function(){}
  26. });
  27. describe('#getUrl()', function () {
  28. it('testMode = true', function () {
  29. App.set('testMode', true);
  30. expect(controller.getUrl('test', '/real')).to.equal('test');
  31. });
  32. it('testMode = false', function () {
  33. App.set('testMode', false);
  34. expect(controller.getUrl('test', '/real')).to.equal('/api/v1/clusters//real');
  35. });
  36. it('testMode = false', function () {
  37. App.set('testMode', false);
  38. controller.set('clusterName', 'mycluster');
  39. expect(controller.getUrl('test', '/real')).to.equal('/api/v1/clusters/mycluster/real');
  40. });
  41. });
  42. describe('#updateAll()', function () {
  43. beforeEach(function () {
  44. sinon.stub(App.updater, 'run', Em.K);
  45. });
  46. afterEach(function () {
  47. App.updater.run.restore();
  48. });
  49. it('isWorking = false', function () {
  50. controller.set('isWorking', false);
  51. expect(App.updater.run.called).to.equal(false);
  52. });
  53. it('isWorking = true', function () {
  54. controller.set('isWorking', true);
  55. expect(App.updater.run.callCount).to.equal(10);
  56. });
  57. });
  58. describe('#updateServiceMetricConditionally()', function () {
  59. var context = {
  60. callback: function(){}
  61. };
  62. beforeEach(function () {
  63. sinon.spy(controller, 'updateServiceMetric');
  64. sinon.spy(context, 'callback');
  65. });
  66. afterEach(function () {
  67. controller.updateServiceMetric.restore();
  68. context.callback.restore();
  69. });
  70. it('location is empty', function () {
  71. controller.set('location', '');
  72. controller.updateServiceMetricConditionally(context.callback);
  73. expect(controller.updateServiceMetric.called).to.equal(false);
  74. expect(context.callback.called).to.equal(true);
  75. });
  76. it('location is "/main/hosts"', function () {
  77. controller.set('location', '/main/hosts');
  78. controller.updateServiceMetricConditionally(context.callback);
  79. expect(controller.updateServiceMetric.called).to.equal(false);
  80. expect(context.callback.called).to.equal(true);
  81. });
  82. it('location is "/main/dashboard"', function () {
  83. controller.set('location', '/main/dashboard');
  84. controller.updateServiceMetricConditionally(context.callback);
  85. expect(controller.updateServiceMetric.called).to.equal(true);
  86. expect(context.callback.called).to.equal(false);
  87. });
  88. it('location is "/main/services/HDFS"', function () {
  89. controller.set('location', '/main/services/HDFS');
  90. controller.updateServiceMetricConditionally(context.callback);
  91. expect(controller.updateServiceMetric.called).to.equal(true);
  92. expect(context.callback.called).to.equal(false);
  93. });
  94. });
  95. describe('#getConditionalFields()', function () {
  96. var testCases = [
  97. {
  98. title: 'No services exist',
  99. services: [],
  100. result: []
  101. },
  102. {
  103. title: 'HDFS service',
  104. services: [
  105. {
  106. ServiceInfo: {
  107. service_name: 'HDFS'
  108. }
  109. }
  110. ],
  111. result: []
  112. },
  113. {
  114. title: 'FLUME service',
  115. services: [
  116. {
  117. ServiceInfo: {
  118. service_name: 'FLUME'
  119. }
  120. }
  121. ],
  122. result: ["host_components/processes/HostComponentProcess"]
  123. },
  124. {
  125. title: 'YARN service',
  126. services: [
  127. {
  128. ServiceInfo: {
  129. service_name: 'YARN'
  130. }
  131. }
  132. ],
  133. result: ["host_components/metrics/yarn/Queue," +
  134. "host_components/metrics/yarn/ClusterMetrics/NumActiveNMs," +
  135. "host_components/metrics/yarn/ClusterMetrics/NumLostNMs," +
  136. "host_components/metrics/yarn/ClusterMetrics/NumUnhealthyNMs," +
  137. "host_components/metrics/yarn/ClusterMetrics/NumRebootedNMs," +
  138. "host_components/metrics/yarn/ClusterMetrics/NumDecommissionedNMs"]
  139. },
  140. {
  141. title: 'HBASE service',
  142. services: [
  143. {
  144. ServiceInfo: {
  145. service_name: 'HBASE'
  146. }
  147. }
  148. ],
  149. result: ["host_components/metrics/hbase/master/IsActiveMaster," +
  150. "host_components/metrics/hbase/master/MasterStartTime," +
  151. "host_components/metrics/hbase/master/MasterActiveTime," +
  152. "host_components/metrics/hbase/master/AverageLoad," +
  153. "host_components/metrics/master/AssignmentManger/ritCount"]
  154. },
  155. {
  156. title: 'STORM service',
  157. services: [
  158. {
  159. ServiceInfo: {
  160. service_name: 'STORM'
  161. }
  162. }
  163. ],
  164. result: ["metrics/api/v1/cluster/summary," +
  165. "metrics/api/v1/topology/summary"]
  166. }
  167. ];
  168. var testCasesByStackVersion = [
  169. {
  170. title: 'STORM service stack 2.1',
  171. services: [
  172. {
  173. ServiceInfo: {
  174. service_name: 'STORM'
  175. }
  176. }
  177. ],
  178. stackVersionNumber: '2.1',
  179. result: ["metrics/api/cluster/summary"]
  180. },
  181. {
  182. title: 'STORM service stack 2.2',
  183. services: [
  184. {
  185. ServiceInfo: {
  186. service_name: 'STORM'
  187. }
  188. }
  189. ],
  190. stackVersionNumber: '2.2',
  191. result: ["metrics/api/v1/cluster/summary,metrics/api/v1/topology/summary"]
  192. }
  193. ];
  194. testCases.forEach(function(test){
  195. it(test.title, function () {
  196. App.cache['services'] = test.services;
  197. expect(controller.getConditionalFields()).to.eql(test.result);
  198. });
  199. });
  200. testCasesByStackVersion.forEach(function(test) {
  201. it(test.title, function() {
  202. App.cache['services'] = test.services;
  203. sinon.stub(App, 'get', function(key) {
  204. if (key == 'currentStackVersionNumber') {
  205. return test.stackVersionNumber;
  206. }
  207. });
  208. expect(controller.getConditionalFields()).to.eql(test.result);
  209. App.get.restore();
  210. });
  211. });
  212. });
  213. });