step6_controller_test.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. App = require('app');
  19. require('controllers/main/service/reassign/step6_controller');
  20. var controller;
  21. var testHelpers = require('test/helpers');
  22. describe('App.ReassignMasterWizardStep6Controller', function () {
  23. beforeEach(function () {
  24. controller = App.ReassignMasterWizardStep6Controller.create({
  25. content: Em.Object.create({
  26. reassign: Em.Object.create(),
  27. reassignHosts: Em.Object.create()
  28. }),
  29. startServices: Em.K
  30. });
  31. });
  32. describe('#initializeTasks()', function () {
  33. it('No commands', function () {
  34. controller.set('commands', []);
  35. controller.set('hostComponents', []);
  36. controller.initializeTasks();
  37. expect(controller.get('tasks')).to.be.empty;
  38. });
  39. it('One command', function () {
  40. controller.set('commands', ['COMMAND1']);
  41. controller.initializeTasks();
  42. expect(controller.get('tasks')[0].get('id')).to.equal(0);
  43. expect(controller.get('tasks')[0].get('command')).to.equal('COMMAND1');
  44. });
  45. });
  46. describe('#hideRollbackButton()', function () {
  47. it('No showRollback command', function () {
  48. controller.set('tasks', [Em.Object.create({
  49. showRollback: false
  50. })]);
  51. controller.hideRollbackButton();
  52. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  53. });
  54. it('showRollback command is present', function () {
  55. controller.set('tasks', [Em.Object.create({
  56. showRollback: true
  57. })]);
  58. controller.hideRollbackButton();
  59. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  60. });
  61. });
  62. describe('#onComponentsTasksSuccess()', function () {
  63. beforeEach(function () {
  64. sinon.stub(controller, 'onTaskCompleted', Em.K);
  65. });
  66. afterEach(function () {
  67. controller.onTaskCompleted.restore();
  68. });
  69. it('One host-component', function () {
  70. controller.set('multiTaskCounter', 1);
  71. controller.set('hostComponents', [
  72. {}
  73. ]);
  74. controller.onComponentsTasksSuccess();
  75. expect(controller.get('multiTaskCounter')).to.equal(0);
  76. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  77. });
  78. it('two host-components', function () {
  79. controller.set('multiTaskCounter', 2);
  80. controller.set('hostComponents', [
  81. {},
  82. {}
  83. ]);
  84. controller.onComponentsTasksSuccess();
  85. expect(controller.get('multiTaskCounter')).to.equal(1);
  86. expect(controller.onTaskCompleted.called).to.be.false;
  87. });
  88. });
  89. describe('#loadStep()', function () {
  90. var isHaEnabled = true;
  91. beforeEach(function () {
  92. controller.set('content.reassign.service_id', 'service1');
  93. sinon.stub(controller, 'onTaskStatusChange', Em.K);
  94. sinon.stub(controller, 'initializeTasks', Em.K);
  95. sinon.stub(App, 'get', function () {
  96. return isHaEnabled;
  97. });
  98. });
  99. afterEach(function () {
  100. controller.onTaskStatusChange.restore();
  101. controller.initializeTasks.restore();
  102. App.get.restore();
  103. });
  104. it('reassign component is NameNode and HA enabled', function () {
  105. isHaEnabled = true;
  106. controller.set('content.reassign.component_name', 'NAMENODE');
  107. controller.loadStep();
  108. expect(controller.get('hostComponents')).to.eql(['NAMENODE', 'ZKFC']);
  109. });
  110. it('reassign component is NameNode and HA disabled', function () {
  111. isHaEnabled = false;
  112. controller.set('content.reassign.component_name', 'NAMENODE');
  113. controller.loadStep();
  114. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  115. });
  116. it('reassign component is RESOURCEMANAGER', function () {
  117. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  118. controller.loadStep();
  119. expect(controller.get('hostComponents')).to.eql(['RESOURCEMANAGER']);
  120. });
  121. });
  122. describe('#deleteHostComponents()', function () {
  123. it('No host components', function () {
  124. controller.set('hostComponents', []);
  125. controller.set('content.reassignHosts.source', 'host1');
  126. controller.deleteHostComponents();
  127. var args = testHelpers.findAjaxRequest('name', 'common.delete.host_component');
  128. expect(args).not.exists;
  129. });
  130. it('delete two components', function () {
  131. controller.set('hostComponents', [1, 2]);
  132. controller.set('content.reassignHosts.source', 'host1');
  133. controller.deleteHostComponents();
  134. var args = testHelpers.filterAjaxRequests('name', 'common.delete.host_component');
  135. expect(args).to.have.property('length').equal(2);
  136. expect(args[0][0].data).to.eql({
  137. "hostName": "host1",
  138. "componentName": 1
  139. });
  140. expect(args[1][0].data).to.eql({
  141. "hostName": "host1",
  142. "componentName": 2
  143. });
  144. });
  145. });
  146. describe('#onDeleteHostComponentsError()', function () {
  147. beforeEach(function () {
  148. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  149. sinon.stub(controller, 'onTaskError', Em.K);
  150. });
  151. afterEach(function () {
  152. controller.onComponentsTasksSuccess.restore();
  153. controller.onTaskError.restore();
  154. });
  155. it('task success', function () {
  156. var error = {
  157. responseText: 'org.apache.ambari.server.controller.spi.NoSuchResourceException'
  158. };
  159. controller.onDeleteHostComponentsError(error);
  160. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  161. });
  162. it('unknown error', function () {
  163. var error = {
  164. responseText: ''
  165. };
  166. controller.onDeleteHostComponentsError(error);
  167. expect(controller.onTaskError.calledOnce).to.be.true;
  168. });
  169. });
  170. describe('#stopMysqlService()', function () {
  171. it('stopMysqlService', function () {
  172. controller.stopMysqlService();
  173. var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.update');
  174. expect(args[0]).exists;
  175. });
  176. });
  177. describe('#putHostComponentsInMaintenanceMode()', function () {
  178. beforeEach(function(){
  179. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  180. controller.set('content.reassignHosts.source', 'source');
  181. });
  182. afterEach(function(){
  183. controller.onComponentsTasksSuccess.restore();
  184. });
  185. it('No host-components', function () {
  186. controller.set('hostComponents', []);
  187. controller.putHostComponentsInMaintenanceMode();
  188. var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
  189. expect(args).not.exists;
  190. expect(controller.get('multiTaskCounter')).to.equal(0);
  191. });
  192. it('One host-components', function () {
  193. controller.set('hostComponents', [{}]);
  194. controller.putHostComponentsInMaintenanceMode();
  195. var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
  196. expect(args).exists;
  197. expect(controller.get('multiTaskCounter')).to.equal(1);
  198. });
  199. });
  200. describe("#removeTasks()", function() {
  201. it("no tasks to delete", function() {
  202. controller.set('tasks', [Em.Object.create()]);
  203. controller.removeTasks([]);
  204. expect(controller.get('tasks').length).to.equal(1);
  205. });
  206. it("one task to delete", function() {
  207. controller.set('tasks', [Em.Object.create({command: 'task1'})]);
  208. controller.removeTasks(['task1']);
  209. expect(controller.get('tasks')).to.be.empty;
  210. });
  211. });
  212. describe("#startAllServices()", function() {
  213. beforeEach(function () {
  214. sinon.stub(controller, 'startServices', Em.K);
  215. });
  216. afterEach(function () {
  217. controller.startServices.restore();
  218. });
  219. it("startServices is called with valid arguments", function () {
  220. controller.startAllServices();
  221. expect(controller.startServices.calledWith(true)).to.be.true;
  222. });
  223. });
  224. });