update_controller_test.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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(7);
  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/metrics/flume/flume,"+
  123. "host_components/processes/HostComponentProcess"]
  124. },
  125. {
  126. title: 'YARN service',
  127. services: [
  128. {
  129. ServiceInfo: {
  130. service_name: 'YARN'
  131. }
  132. }
  133. ],
  134. result: ["host_components/metrics/yarn/Queue," +
  135. "ServiceComponentInfo/rm_metrics/cluster/activeNMcount," +
  136. "ServiceComponentInfo/rm_metrics/cluster/unhealthyNMcount," +
  137. "ServiceComponentInfo/rm_metrics/cluster/rebootedNMcount," +
  138. "ServiceComponentInfo/rm_metrics/cluster/decommissionedNMcount"]
  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. "ServiceComponentInfo/MasterStartTime," +
  151. "ServiceComponentInfo/MasterActiveTime," +
  152. "ServiceComponentInfo/AverageLoad," +
  153. "ServiceComponentInfo/Revision," +
  154. "ServiceComponentInfo/RegionsInTransition"]
  155. },
  156. {
  157. title: 'MAPREDUCE service',
  158. services: [
  159. {
  160. ServiceInfo: {
  161. service_name: 'MAPREDUCE'
  162. }
  163. }
  164. ],
  165. result: ["ServiceComponentInfo/AliveNodes," +
  166. "ServiceComponentInfo/GrayListedNodes," +
  167. "ServiceComponentInfo/BlackListedNodes," +
  168. "ServiceComponentInfo/jobtracker/*,"]
  169. },
  170. {
  171. title: 'STORM service',
  172. services: [
  173. {
  174. ServiceInfo: {
  175. service_name: 'STORM'
  176. }
  177. }
  178. ],
  179. result: ["metrics/api/v1/cluster/summary," +
  180. "metrics/api/v1/topology/summary"]
  181. }
  182. ];
  183. var testCasesByStackVersion = [
  184. {
  185. title: 'STORM service stack 2.1',
  186. services: [
  187. {
  188. ServiceInfo: {
  189. service_name: 'STORM'
  190. }
  191. }
  192. ],
  193. stackVersionNumber: '2.1',
  194. result: ["metrics/api/cluster/summary"]
  195. },
  196. {
  197. title: 'STORM service stack 2.2',
  198. services: [
  199. {
  200. ServiceInfo: {
  201. service_name: 'STORM'
  202. }
  203. }
  204. ],
  205. stackVersionNumber: '2.2',
  206. result: ["metrics/api/v1/cluster/summary,metrics/api/v1/topology/summary"]
  207. }
  208. ];
  209. testCases.forEach(function(test){
  210. it(test.title, function () {
  211. App.cache['services'] = test.services;
  212. expect(controller.getConditionalFields()).to.eql(test.result);
  213. });
  214. });
  215. testCasesByStackVersion.forEach(function(test) {
  216. it(test.title, function() {
  217. App.cache['services'] = test.services;
  218. sinon.stub(App, 'get', function(key) {
  219. if (key == 'currentStackVersionNumber') {
  220. return test.stackVersionNumber;
  221. }
  222. });
  223. expect(controller.getConditionalFields()).to.eql(test.result);
  224. App.get.restore();
  225. });
  226. });
  227. });
  228. });