service_test.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. var modelSetup = require('test/init_model_test');
  20. require('models/service');
  21. var service,
  22. serviceData = {
  23. id: 'service'
  24. },
  25. healthCases = [
  26. {
  27. status: 'STARTED',
  28. health: 'green'
  29. },
  30. {
  31. status: 'STARTING',
  32. health: 'green-blinking'
  33. },
  34. {
  35. status: 'INSTALLED',
  36. health: 'red'
  37. },
  38. {
  39. status: 'STOPPING',
  40. health: 'red-blinking'
  41. },
  42. {
  43. status: 'UNKNOWN',
  44. health: 'yellow'
  45. },
  46. {
  47. status: 'ANOTHER',
  48. health: 'yellow'
  49. }
  50. ],
  51. statusPropertiesCases = [
  52. {
  53. status: 'INSTALLED',
  54. property: 'isStopped'
  55. },
  56. {
  57. status: 'STARTED',
  58. property: 'isStarted'
  59. }
  60. ],
  61. hostComponentsDataFalse = [
  62. [],
  63. [
  64. {
  65. staleConfigs: false
  66. }
  67. ],
  68. [
  69. {
  70. service: {
  71. serviceName: 'HIVE'
  72. },
  73. staleConfigs: false
  74. }
  75. ]
  76. ],
  77. hostComponentsDataTrue = [
  78. [
  79. Em.Object.create({
  80. service: {
  81. serviceName: 'HDFS'
  82. },
  83. staleConfigs: true,
  84. displayName: 'service0'
  85. })
  86. ],
  87. [
  88. Em.Object.create({
  89. host: {
  90. publicHostName: 'host0'
  91. },
  92. service: {
  93. serviceName: 'HDFS'
  94. },
  95. staleConfigs: true,
  96. displayName: 'service1'
  97. })
  98. ]
  99. ],
  100. restartData = {
  101. host0: ['service0', 'service1']
  102. };
  103. describe('App.Service', function () {
  104. beforeEach(function () {
  105. service = App.Service.createRecord(serviceData);
  106. });
  107. afterEach(function () {
  108. modelSetup.deleteRecord(service);
  109. });
  110. describe('#isInPassive', function () {
  111. it('should be true', function () {
  112. service.set('passiveState', 'ON');
  113. expect(service.get('isInPassive')).to.be.true;
  114. });
  115. it('should be false', function () {
  116. service.set('passiveState', 'OFF');
  117. expect(service.get('isInPassive')).to.be.false;
  118. });
  119. });
  120. describe('#healthStatus', function () {
  121. healthCases.forEach(function (item) {
  122. it('should be ' + item.health, function () {
  123. service.set('workStatus', item.status);
  124. expect(service.get('healthStatus')).to.equal(item.health);
  125. });
  126. });
  127. });
  128. statusPropertiesCases.forEach(function (item) {
  129. var status = item.status,
  130. property = item.property;
  131. describe('#' + property, function () {
  132. it('status ' + status + ' is for ' + property, function () {
  133. service.set('workStatus', status);
  134. expect(service.get(property)).to.be.true;
  135. var falseStates = statusPropertiesCases.mapProperty('property').without(property);
  136. var falseStatuses = [];
  137. falseStates.forEach(function (state) {
  138. falseStatuses.push(service.get(state));
  139. });
  140. expect(falseStatuses).to.eql([false]);
  141. });
  142. });
  143. });
  144. describe('#isRestartRequired', function () {
  145. beforeEach(function () {
  146. service.reopen({
  147. serviceName: 'HDFS',
  148. hostComponents: []
  149. });
  150. });
  151. hostComponentsDataFalse.forEach(function (item) {
  152. it('should be false', function () {
  153. service.set('hostComponents', item);
  154. expect(service.get('isRestartRequired')).to.be.false;
  155. });
  156. });
  157. hostComponentsDataTrue.forEach(function (item) {
  158. it('should be true', function () {
  159. service.set('hostComponents', item);
  160. expect(service.get('isRestartRequired')).to.be.true;
  161. });
  162. });
  163. });
  164. describe('#restartRequiredMessage', function () {
  165. it('should form message for 2 services on 1 host', function () {
  166. service.set('restartRequiredHostsAndComponents', restartData);
  167. expect(service.get('restartRequiredMessage')).to.contain('host0');
  168. expect(service.get('restartRequiredMessage')).to.contain('service0');
  169. expect(service.get('restartRequiredMessage')).to.contain('service1');
  170. });
  171. });
  172. describe('#serviceTypes', function () {
  173. var testCases = [
  174. {
  175. serviceName: 'PIG',
  176. result: []
  177. },
  178. {
  179. serviceName: 'GANGLIA',
  180. result: ['MONITORING']
  181. },
  182. {
  183. serviceName: 'HDFS',
  184. result: ['HA_MODE']
  185. },
  186. {
  187. serviceName: 'YARN',
  188. result: ['HA_MODE']
  189. }
  190. ];
  191. testCases.forEach(function (test) {
  192. it('service name - ' + test.serviceName, function () {
  193. service.set('serviceName', test.serviceName);
  194. service.propertyDidChange('serviceTypes');
  195. expect(service.get('serviceTypes')).to.eql(test.result);
  196. });
  197. });
  198. });
  199. });