update_controller_test.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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('controllers/global/update_controller');
  20. describe('App.UpdateController', function () {
  21. var controller = App.UpdateController.create({
  22. clusterName: '',
  23. location: '',
  24. updateServiceMetric: function(){}
  25. });
  26. describe('#getUrl()', function () {
  27. it('testMode = true', function () {
  28. App.set('testMode', true);
  29. expect(controller.getUrl('test', '/real')).to.equal('test');
  30. });
  31. it('testMode = false', function () {
  32. App.set('testMode', false);
  33. expect(controller.getUrl('test', '/real')).to.equal('/api/v1/clusters//real');
  34. });
  35. it('testMode = false', function () {
  36. App.set('testMode', false);
  37. controller.set('clusterName', 'mycluster');
  38. expect(controller.getUrl('test', '/real')).to.equal('/api/v1/clusters/mycluster/real');
  39. });
  40. });
  41. describe('#updateAll()', function () {
  42. beforeEach(function () {
  43. sinon.stub(App.updater, 'run', Em.K);
  44. });
  45. afterEach(function () {
  46. App.updater.run.restore();
  47. });
  48. it('isWorking = false', function () {
  49. controller.set('isWorking', false);
  50. expect(App.updater.run.called).to.equal(false);
  51. });
  52. it('isWorking = true, App.supports.hostOverrides = false', function () {
  53. App.supports.hostOverrides = false;
  54. controller.set('isWorking', true);
  55. expect(App.updater.run.callCount).to.equal(5);
  56. controller.set('isWorking', false);
  57. });
  58. it('isWorking = true, App.supports.hostOverrides = true', function () {
  59. App.supports.hostOverrides = true;
  60. controller.set('isWorking', true);
  61. expect(App.updater.run.callCount).to.equal(6);
  62. });
  63. });
  64. describe('#updateHostConditionally()', function () {
  65. var context = {
  66. callback: function(){}
  67. };
  68. beforeEach(function () {
  69. sinon.stub(controller, 'updateHost', Em.K);
  70. sinon.spy(context, 'callback');
  71. });
  72. afterEach(function () {
  73. controller.updateHost.restore();
  74. context.callback.restore();
  75. });
  76. it('location is empty', function () {
  77. controller.set('location', '');
  78. controller.updateHostConditionally(context.callback);
  79. expect(controller.updateHost.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.updateHostConditionally(context.callback);
  85. expect(controller.updateHost.called).to.equal(false);
  86. expect(context.callback.called).to.equal(true);
  87. });
  88. it('location is "/main/hosts"', function () {
  89. controller.set('location', '/main/hosts');
  90. controller.updateHostConditionally(context.callback);
  91. expect(controller.updateHost.called).to.equal(true);
  92. expect(context.callback.called).to.equal(false);
  93. });
  94. it('location is "/main/charts/heatmap"', function () {
  95. controller.set('location', '/main/charts/heatmap');
  96. controller.updateHostConditionally(context.callback);
  97. expect(controller.updateHost.called).to.equal(true);
  98. expect(context.callback.called).to.equal(false);
  99. });
  100. it('location is "/main/hosts/host1"', function () {
  101. controller.set('location', '/main/hosts/host1');
  102. controller.updateHostConditionally(context.callback);
  103. expect(controller.updateHost.called).to.equal(true);
  104. expect(context.callback.called).to.equal(false);
  105. });
  106. });
  107. describe('#updateServiceMetricConditionally()', function () {
  108. var context = {
  109. callback: function(){}
  110. };
  111. beforeEach(function () {
  112. sinon.spy(controller, 'updateServiceMetric');
  113. sinon.spy(context, 'callback');
  114. });
  115. afterEach(function () {
  116. controller.updateServiceMetric.restore();
  117. context.callback.restore();
  118. });
  119. it('location is empty', function () {
  120. controller.set('location', '');
  121. controller.updateServiceMetricConditionally(context.callback);
  122. expect(controller.updateServiceMetric.called).to.equal(false);
  123. expect(context.callback.called).to.equal(true);
  124. });
  125. it('location is "/main/hosts"', function () {
  126. controller.set('location', '/main/hosts');
  127. controller.updateServiceMetricConditionally(context.callback);
  128. expect(controller.updateServiceMetric.called).to.equal(false);
  129. expect(context.callback.called).to.equal(true);
  130. });
  131. it('location is "/main/dashboard"', function () {
  132. controller.set('location', '/main/dashboard');
  133. controller.updateServiceMetricConditionally(context.callback);
  134. expect(controller.updateServiceMetric.called).to.equal(true);
  135. expect(context.callback.called).to.equal(false);
  136. });
  137. it('location is "/main/services/HDFS"', function () {
  138. controller.set('location', '/main/services/HDFS');
  139. controller.updateServiceMetricConditionally(context.callback);
  140. expect(controller.updateServiceMetric.called).to.equal(true);
  141. expect(context.callback.called).to.equal(false);
  142. });
  143. });
  144. describe('#getConditionalFields()', function () {
  145. var testCases = [
  146. {
  147. title: 'No services exist',
  148. services: [],
  149. result: []
  150. },
  151. {
  152. title: 'HDFS service',
  153. services: [
  154. {
  155. ServiceInfo: {
  156. service_name: 'HDFS'
  157. }
  158. }
  159. ],
  160. result: []
  161. },
  162. {
  163. title: 'FLUME service',
  164. services: [
  165. {
  166. ServiceInfo: {
  167. service_name: 'FLUME'
  168. }
  169. }
  170. ],
  171. result: ["host_components/metrics/flume/flume,"+
  172. "host_components/processes/HostComponentProcess"]
  173. },
  174. {
  175. title: 'YARN service',
  176. services: [
  177. {
  178. ServiceInfo: {
  179. service_name: 'YARN'
  180. }
  181. }
  182. ],
  183. result: ["host_components/metrics/yarn/Queue," +
  184. "ServiceComponentInfo/rm_metrics/cluster/activeNMcount," +
  185. "ServiceComponentInfo/rm_metrics/cluster/unhealthyNMcount," +
  186. "ServiceComponentInfo/rm_metrics/cluster/rebootedNMcount," +
  187. "ServiceComponentInfo/rm_metrics/cluster/decommissionedNMcount"]
  188. },
  189. {
  190. title: 'HBASE service',
  191. services: [
  192. {
  193. ServiceInfo: {
  194. service_name: 'HBASE'
  195. }
  196. }
  197. ],
  198. result: ["host_components/metrics/hbase/master/IsActiveMaster," +
  199. "ServiceComponentInfo/MasterStartTime," +
  200. "ServiceComponentInfo/MasterActiveTime," +
  201. "ServiceComponentInfo/AverageLoad," +
  202. "ServiceComponentInfo/Revision," +
  203. "ServiceComponentInfo/RegionsInTransition"]
  204. },
  205. {
  206. title: 'MAPREDUCE service',
  207. services: [
  208. {
  209. ServiceInfo: {
  210. service_name: 'MAPREDUCE'
  211. }
  212. }
  213. ],
  214. result: ["ServiceComponentInfo/AliveNodes," +
  215. "ServiceComponentInfo/GrayListedNodes," +
  216. "ServiceComponentInfo/BlackListedNodes," +
  217. "ServiceComponentInfo/jobtracker/*,"]
  218. },
  219. {
  220. title: 'STORM service',
  221. services: [
  222. {
  223. ServiceInfo: {
  224. service_name: 'STORM'
  225. }
  226. }
  227. ],
  228. result: ["metrics/api/cluster/summary,"]
  229. }
  230. ];
  231. testCases.forEach(function(test){
  232. it(test.title, function () {
  233. App.cache['services'] = test.services;
  234. expect(controller.getConditionalFields()).to.eql(test.result);
  235. });
  236. });
  237. });
  238. });