step6_controller_test.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. describe('App.ReassignMasterWizardStep6Controller', function () {
  21. var controller = App.ReassignMasterWizardStep6Controller.create({
  22. content: Em.Object.create({
  23. reassign: Em.Object.create(),
  24. reassignHosts: Em.Object.create()
  25. })
  26. });
  27. beforeEach(function () {
  28. sinon.stub(App.ajax, 'send', Em.K);
  29. });
  30. afterEach(function () {
  31. App.ajax.send.restore();
  32. });
  33. describe('#initializeTasks()', function () {
  34. it('No commands', function () {
  35. controller.set('commands', []);
  36. controller.set('hostComponents', []);
  37. controller.initializeTasks();
  38. expect(controller.get('tasks')).to.be.empty;
  39. });
  40. it('One command', function () {
  41. controller.set('commands', ['COMMAND1']);
  42. controller.initializeTasks();
  43. expect(controller.get('tasks')[0].get('id')).to.equal(0);
  44. expect(controller.get('tasks')[0].get('command')).to.equal('COMMAND1');
  45. });
  46. });
  47. describe('#hideRollbackButton()', function () {
  48. it('No showRollback command', function () {
  49. controller.set('tasks', [Em.Object.create({
  50. showRollback: false
  51. })]);
  52. controller.hideRollbackButton();
  53. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  54. });
  55. it('showRollback command is present', function () {
  56. controller.set('tasks', [Em.Object.create({
  57. showRollback: true
  58. })]);
  59. controller.hideRollbackButton();
  60. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  61. });
  62. });
  63. describe('#onComponentsTasksSuccess()', function () {
  64. beforeEach(function () {
  65. sinon.stub(controller, 'onTaskCompleted', Em.K);
  66. });
  67. afterEach(function () {
  68. controller.onTaskCompleted.restore();
  69. });
  70. it('No host-components', function () {
  71. controller.set('multiTaskCounter', 0);
  72. controller.set('hostComponents', []);
  73. controller.onComponentsTasksSuccess();
  74. expect(controller.get('multiTaskCounter')).to.equal(1);
  75. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  76. });
  77. it('One host-component', function () {
  78. controller.set('multiTaskCounter', 0);
  79. controller.set('hostComponents', [
  80. {}
  81. ]);
  82. controller.onComponentsTasksSuccess();
  83. expect(controller.get('multiTaskCounter')).to.equal(1);
  84. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  85. });
  86. it('two host-components', function () {
  87. controller.set('multiTaskCounter', 0);
  88. controller.set('hostComponents', [
  89. {},
  90. {}
  91. ]);
  92. controller.onComponentsTasksSuccess();
  93. expect(controller.get('multiTaskCounter')).to.equal(1);
  94. expect(controller.onTaskCompleted.called).to.be.false;
  95. });
  96. });
  97. describe('#loadStep()', function () {
  98. var isHaEnabled = true;
  99. beforeEach(function () {
  100. controller.set('content.reassign.service_id', 'service1');
  101. sinon.stub(controller, 'onTaskStatusChange', Em.K);
  102. sinon.stub(controller, 'initializeTasks', Em.K);
  103. sinon.stub(App, 'get', function () {
  104. return isHaEnabled;
  105. });
  106. });
  107. afterEach(function () {
  108. controller.onTaskStatusChange.restore();
  109. controller.initializeTasks.restore();
  110. App.get.restore();
  111. });
  112. it('reassign component is NameNode and HA enabled', function () {
  113. isHaEnabled = true;
  114. controller.set('content.reassign.component_name', 'NAMENODE');
  115. controller.loadStep();
  116. expect(controller.get('hostComponents')).to.eql(['NAMENODE', 'ZKFC']);
  117. });
  118. it('reassign component is NameNode and HA disabled', function () {
  119. isHaEnabled = false;
  120. controller.set('content.reassign.component_name', 'NAMENODE');
  121. controller.loadStep();
  122. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  123. });
  124. it('reassign component is RESOURCEMANAGER', function () {
  125. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  126. controller.loadStep();
  127. expect(controller.get('hostComponents')).to.eql(['RESOURCEMANAGER']);
  128. });
  129. });
  130. describe('#startServices()', function () {
  131. it('', function () {
  132. controller.startServices();
  133. expect(App.ajax.send.calledOnce).to.be.true;
  134. });
  135. });
  136. describe('#deleteHostComponents()', function () {
  137. it('No host components', function () {
  138. controller.set('hostComponents', []);
  139. controller.set('content.reassignHosts.source', 'host1');
  140. controller.deleteHostComponents();
  141. expect(App.ajax.send.called).to.be.false;
  142. });
  143. it('delete two components', function () {
  144. controller.set('hostComponents', [1, 2]);
  145. controller.set('content.reassignHosts.source', 'host1');
  146. controller.deleteHostComponents();
  147. expect(App.ajax.send.getCall(0).args[0].data).to.eql({
  148. "hostName": "host1",
  149. "componentName": 1
  150. });
  151. expect(App.ajax.send.getCall(1).args[0].data).to.eql({
  152. "hostName": "host1",
  153. "componentName": 2
  154. });
  155. });
  156. });
  157. describe('#onDeleteHostComponentsError()', function () {
  158. beforeEach(function () {
  159. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  160. sinon.stub(controller, 'onTaskError', Em.K);
  161. });
  162. afterEach(function () {
  163. controller.onComponentsTasksSuccess.restore();
  164. controller.onTaskError.restore();
  165. });
  166. it('task success', function () {
  167. var error = {
  168. responseText: 'org.apache.ambari.server.controller.spi.NoSuchResourceException'
  169. }
  170. controller.onDeleteHostComponentsError(error);
  171. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  172. });
  173. it('unknown error', function () {
  174. var error = {
  175. responseText: ''
  176. }
  177. controller.onDeleteHostComponentsError(error);
  178. expect(controller.onTaskError.calledOnce).to.be.true;
  179. });
  180. });
  181. });