alert_test.js 6.5 KB

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