step4_controller_test.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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('controllers/main/admin/highAvailability/journalNode/step1_controller');
  20. var testHelpers = require('test/helpers');
  21. describe('App.ManageJournalNodeWizardStep4Controller', function () {
  22. var controller;
  23. beforeEach(function () {
  24. controller = App.ManageJournalNodeWizardStep4Controller.create({
  25. content: Em.Object.create()
  26. });
  27. });
  28. describe('#stopStandbyNameNode', function() {
  29. beforeEach(function() {
  30. sinon.stub(controller, 'updateComponent');
  31. });
  32. afterEach(function() {
  33. controller.updateComponent.restore();
  34. });
  35. it('updateComponent should be called', function() {
  36. controller.set('content.standByNN', {
  37. host_name: 'host1'
  38. });
  39. controller.stopStandbyNameNode();
  40. expect(controller.updateComponent.calledWith('NAMENODE', 'host1', 'HDFS', 'INSTALLED')).to.be.true;
  41. });
  42. });
  43. describe('#stopAllServices', function() {
  44. beforeEach(function() {
  45. sinon.stub(controller, 'stopServices');
  46. });
  47. afterEach(function() {
  48. controller.stopServices.restore();
  49. });
  50. it('stopAllServices should be called', function() {
  51. controller.stopAllServices();
  52. expect(controller.stopServices.calledWith([], true, true)).to.be.true;
  53. });
  54. });
  55. describe('#installJournalNodes', function() {
  56. var wizardController = {
  57. getJournalNodesToAdd: Em.K
  58. };
  59. beforeEach(function() {
  60. this.mock = sinon.stub(wizardController, 'getJournalNodesToAdd');
  61. sinon.stub(App.router, 'get').returns(wizardController);
  62. sinon.stub(controller, 'createInstallComponentTask');
  63. sinon.stub(controller, 'onTaskCompleted');
  64. });
  65. afterEach(function() {
  66. App.router.get.restore();
  67. this.mock.restore();
  68. controller.createInstallComponentTask.restore();
  69. controller.onTaskCompleted.restore();
  70. });
  71. it('onTaskCompleted should be called when no journalnodes to add', function() {
  72. this.mock.returns([]);
  73. controller.installJournalNodes();
  74. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  75. expect(controller.createInstallComponentTask.called).to.be.false;
  76. });
  77. it('createInstallComponentTask should be called when there are journalnodes to add', function() {
  78. this.mock.returns(['host1']);
  79. controller.installJournalNodes();
  80. expect(controller.onTaskCompleted.called).to.be.false;
  81. expect(controller.createInstallComponentTask.calledWith('JOURNALNODE', ['host1'], "HDFS")).to.be.true;
  82. });
  83. });
  84. describe('#deleteJournalNodes', function() {
  85. var wizardController = {
  86. getJournalNodesToDelete: Em.K
  87. };
  88. beforeEach(function() {
  89. this.mock = sinon.stub(wizardController, 'getJournalNodesToDelete');
  90. sinon.stub(App.router, 'get').returns(wizardController);
  91. sinon.stub(controller, 'deleteComponent');
  92. sinon.stub(controller, 'onTaskCompleted');
  93. });
  94. afterEach(function() {
  95. App.router.get.restore();
  96. this.mock.restore();
  97. controller.deleteComponent.restore();
  98. controller.onTaskCompleted.restore();
  99. });
  100. it('onTaskCompleted should be called when no journalnodes to delete', function() {
  101. this.mock.returns([]);
  102. controller.deleteJournalNodes();
  103. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  104. expect(controller.deleteComponent.called).to.be.false;
  105. });
  106. it('deleteComponent should be called when there are journalnodes to delete', function() {
  107. this.mock.returns(['host1']);
  108. controller.deleteJournalNodes();
  109. expect(controller.onTaskCompleted.called).to.be.false;
  110. expect(controller.deleteComponent.calledWith('JOURNALNODE', 'host1')).to.be.true;
  111. });
  112. });
  113. describe('#reconfigureHDFS', function() {
  114. beforeEach(function() {
  115. sinon.stub(controller, 'updateConfigProperties');
  116. });
  117. afterEach(function() {
  118. controller.updateConfigProperties.restore();
  119. });
  120. it('updateConfigProperties should be called', function() {
  121. controller.set('content.serviceConfigProperties', [
  122. {}
  123. ]);
  124. controller.reconfigureHDFS();
  125. expect(controller.updateConfigProperties.calledWith([{}])).to.be.true;
  126. });
  127. });
  128. describe('#updateConfigProperties', function() {
  129. beforeEach(function() {
  130. sinon.stub(controller, 'reconfigureSites').returns({});
  131. });
  132. afterEach(function() {
  133. controller.reconfigureSites.restore();
  134. });
  135. it('App.ajax.send should be called', function() {
  136. controller.updateConfigProperties();
  137. var args = testHelpers.findAjaxRequest('name', 'common.service.configurations');
  138. expect(args[0]).to.be.eql({
  139. name: 'common.service.configurations',
  140. sender: controller,
  141. data: {
  142. desired_config: {}
  143. },
  144. success: 'installHDFSClients',
  145. error: 'onTaskError'
  146. });
  147. });
  148. });
  149. describe('#installHDFSClients', function() {
  150. beforeEach(function() {
  151. sinon.stub(controller, 'createInstallComponentTask');
  152. sinon.stub(App.clusterStatus, 'setClusterStatus');
  153. controller.set('content.masterComponentHosts', [
  154. {
  155. component: 'NAMENODE',
  156. hostName: 'host1'
  157. },
  158. {
  159. component: 'JOURNALNODE',
  160. hostName: 'host2'
  161. }
  162. ]);
  163. });
  164. afterEach(function() {
  165. controller.createInstallComponentTask.restore();
  166. App.clusterStatus.setClusterStatus.restore();
  167. });
  168. it('App.clusterStatus.setClusterStatus should be called', function() {
  169. controller.installHDFSClients();
  170. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  171. });
  172. it('createInstallComponentTask should be called', function() {
  173. controller.installHDFSClients();
  174. expect(controller.createInstallComponentTask.calledWith('HDFS_CLIENT', ['host1', 'host2'], 'HDFS')).to.be.true;
  175. });
  176. });
  177. });