alert_test.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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('models/alert');
  20. var alert,
  21. sampleTime = 1399312800,
  22. statusCases = [
  23. {
  24. status: 0,
  25. property: 'isOk',
  26. format: 'OK'
  27. },
  28. {
  29. status: 1,
  30. property: 'isWarning',
  31. format: 'WARN'
  32. },
  33. {
  34. status: 2,
  35. property: 'isCritical',
  36. format: 'CRIT'
  37. },
  38. {
  39. status: 3,
  40. property: 'isPassive',
  41. format: 'MAINT'
  42. },
  43. {
  44. status: 4,
  45. property: '',
  46. format: 'UNKNOWN'
  47. }
  48. ],
  49. ignoredCases = [
  50. {
  51. title: 'title',
  52. result: false
  53. },
  54. {
  55. title: 'Percent',
  56. result: true
  57. }
  58. ],
  59. serviceTypeCases = [
  60. {
  61. type: 'MAPREDUCE',
  62. name: 'MapReduce',
  63. link: '#/main/services/MAPREDUCE/summary'
  64. },
  65. {
  66. type: 'HDFS',
  67. name: 'HDFS',
  68. link: '#/main/services/HDFS/summary'
  69. },
  70. {
  71. type: 'HBASE',
  72. name: 'HBase',
  73. link: '#/main/services/HBASE/summary'
  74. },
  75. {
  76. type: 'ZOOKEEPER',
  77. name: 'Zookeeper',
  78. link: '#/main/services/ZOOKEEPER/summary'
  79. },
  80. {
  81. type: 'OOZIE',
  82. name: 'Oozie',
  83. link: '#/main/services/OOZIE/summary'
  84. },
  85. {
  86. type: 'HIVE',
  87. name: 'Hive',
  88. link: '#/main/services/HIVE/summary'
  89. },
  90. {
  91. type: 'service',
  92. name: null,
  93. link: null
  94. },
  95. {
  96. type: null,
  97. name: null,
  98. link: null
  99. }
  100. ],
  101. titles = ['NodeManager health', 'NodeManager process', 'TaskTracker process', 'RegionServer process', 'DataNode process', 'DataNode space', 'ZooKeeper Server process', 'Supervisors process'];
  102. describe('App.Alert', function () {
  103. beforeEach(function() {
  104. alert = App.Alert.create();
  105. });
  106. describe('#date', function () {
  107. it('is Mon May 05 2014', function () {
  108. alert.set('lastTime', sampleTime);
  109. expect(alert.get('date').toDateString()).to.equal('Mon May 05 2014');
  110. });
  111. });
  112. statusCases.forEach(function (item) {
  113. var status = item.status,
  114. property = item.property;
  115. if (property) {
  116. describe('#' + property, function () {
  117. it('status ' + status + ' is for ' + property, function () {
  118. alert.set('status', status);
  119. expect(alert.get(property)).to.be.true;
  120. var falseStates = statusCases.mapProperty('property').without(property).without('');
  121. var falseStatuses = [];
  122. falseStates.forEach(function (state) {
  123. falseStatuses.push(alert.get(state));
  124. });
  125. expect(falseStatuses).to.eql([false, false, false]);
  126. });
  127. });
  128. }
  129. });
  130. describe('#ignoredForServices', function () {
  131. titles.forEach(function (item) {
  132. it('should be true for ' + item, function () {
  133. alert.set('title', item);
  134. expect(alert.get('ignoredForServices')).to.be.true;
  135. });
  136. });
  137. it('should be false', function () {
  138. alert.set('title', 'title');
  139. expect(alert.get('ignoredForServices')).to.be.false;
  140. });
  141. });
  142. describe('#ignoredForHosts', function () {
  143. ignoredCases.forEach(function (item) {
  144. it('should be ' + item.result, function () {
  145. alert.set('title', item.title);
  146. expect(alert.get('ignoredForHosts')).to.equal(item.result);
  147. });
  148. });
  149. });
  150. describe('#timeSinceAlert', function () {
  151. statusCases.forEach(function (item) {
  152. var format = item.format;
  153. it('should indicate ' + format + ' status duration', function () {
  154. alert.setProperties({
  155. lastTime: sampleTime,
  156. status: item.status.toString()
  157. });
  158. expect(alert.get('timeSinceAlert')).to.have.string(format);
  159. expect(alert.get('timeSinceAlert.length')).to.be.above(format.length);
  160. alert.set('lastTime', 0);
  161. expect(alert.get('timeSinceAlert')).to.equal(format);
  162. });
  163. });
  164. it('should be empty', function () {
  165. alert.set('lastTime', undefined);
  166. expect(alert.get('timeSinceAlert')).to.be.empty;
  167. });
  168. });
  169. describe('#makeTimeAtleastMinuteAgo', function () {
  170. it('should set the minute-ago time', function () {
  171. var time = App.dateTime() - 50000,
  172. date = new Date(time - 10000);
  173. alert.set('lastTime', time);
  174. expect(alert.makeTimeAtleastMinuteAgo(alert.get('date'))).to.be.at.least(date);
  175. });
  176. it('should return the actual time', function () {
  177. var time = App.dateTime() - 70000;
  178. alert.set('lastTime', time);
  179. expect(alert.makeTimeAtleastMinuteAgo(alert.get('date'))).to.eql(alert.get('date'));
  180. });
  181. });
  182. describe('#timeSinceAlertDetails', function () {
  183. it ('should return the appropriate string', function () {
  184. alert.set('lastTime', sampleTime);
  185. var occurred = Em.I18n.t('services.alerts.occurredOn').format('May 05 2014', alert.get('date').toLocaleTimeString());
  186. var brChecked = Em.I18n.t('services.alerts.brLastCheck').format($.timeago(sampleTime));
  187. var checked = Em.I18n.t('services.alerts.lastCheck').format($.timeago(sampleTime));
  188. expect(alert.get('timeSinceAlertDetails')).to.equal(occurred);
  189. alert.set('lastCheck', sampleTime / 1000);
  190. expect(alert.get('timeSinceAlertDetails')).to.equal(occurred + brChecked);
  191. alert.set('lastTime', undefined);
  192. expect(alert.get('timeSinceAlertDetails')).to.equal(checked);
  193. });
  194. it ('should be empty', function () {
  195. alert.set('lastCheck', undefined);
  196. expect(alert.get('timeSinceAlertDetails')).to.be.empty;
  197. });
  198. });
  199. describe('#serviceName', function () {
  200. serviceTypeCases.forEach(function (item) {
  201. it('should be ' + item.name, function () {
  202. alert.set('serviceType', item.type);
  203. expect(alert.get('serviceName')).to.equal(item.name);
  204. });
  205. });
  206. });
  207. describe('#serviceLink', function () {
  208. serviceTypeCases.forEach(function (item) {
  209. it('should be ' + item.link, function () {
  210. alert.set('serviceType', item.type);
  211. expect(alert.get('serviceLink')).to.equal(item.link);
  212. });
  213. });
  214. });
  215. });