service_test.js 4.9 KB

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