highAvailability_controller_test.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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_controller');
  20. require('models/host_component');
  21. require('models/host');
  22. require('utils/ajax/ajax');
  23. describe('App.MainAdminHighAvailabilityController', function () {
  24. var controller = App.MainAdminHighAvailabilityController.create();
  25. describe('#enableHighAvailability()', function () {
  26. var hostComponents = [];
  27. beforeEach(function () {
  28. sinon.stub(App.router, 'transitionTo', Em.K);
  29. sinon.stub(App.HostComponent, 'find', function(){
  30. return hostComponents;
  31. });
  32. sinon.spy(controller, "showErrorPopup");
  33. });
  34. afterEach(function () {
  35. App.router.transitionTo.restore();
  36. controller.showErrorPopup.restore();
  37. App.HostComponent.find.restore();
  38. App.router.get.restore();
  39. });
  40. describe('NAMENODE in INSTALLED state', function () {
  41. beforeEach(function () {
  42. hostComponents = [
  43. Em.Object.create({
  44. componentName: 'NAMENODE',
  45. workStatus: 'INSTALLED'
  46. }),
  47. Em.Object.create({
  48. componentName: 'ZOOKEEPER_SERVER',
  49. workStatus: 'INSTALLED'
  50. }),
  51. Em.Object.create({
  52. componentName: 'ZOOKEEPER_SERVER',
  53. workStatus: 'INSTALLED'
  54. }),
  55. Em.Object.create({
  56. componentName: 'ZOOKEEPER_SERVER',
  57. workStatus: 'INSTALLED'
  58. })
  59. ];
  60. sinon.stub(App.router, 'get', function() {
  61. return 3;
  62. });
  63. this.result = controller.enableHighAvailability();
  64. });
  65. it('enableHighAvailability result is false', function () {
  66. expect(this.result).to.be.false;
  67. });
  68. it('showErrorPopup is called once', function () {
  69. expect(controller.showErrorPopup.calledOnce).to.be.true;
  70. });
  71. });
  72. describe('Cluster has less than 3 ZOOKEPER_SERVER components', function () {
  73. hostComponents = [
  74. Em.Object.create({
  75. componentName: 'NAMENODE',
  76. workStatus: 'STARTED'
  77. })
  78. ];
  79. beforeEach(function () {
  80. sinon.stub(App.router, 'get', function(){
  81. return 3;
  82. });
  83. this.result = controller.enableHighAvailability();
  84. });
  85. it('enableHighAvailability result is false', function () {
  86. expect(this.result).to.be.false;
  87. });
  88. it('showErrorPopup is called', function () {
  89. expect(controller.showErrorPopup.called).to.be.true;
  90. });
  91. });
  92. describe('total hosts number less than 3', function () {
  93. hostComponents = [
  94. Em.Object.create({
  95. componentName: 'NAMENODE',
  96. workStatus: 'STARTED'
  97. }),
  98. Em.Object.create({
  99. componentName: 'ZOOKEEPER_SERVER',
  100. workStatus: 'INSTALLED'
  101. }),
  102. Em.Object.create({
  103. componentName: 'ZOOKEEPER_SERVER',
  104. workStatus: 'INSTALLED'
  105. }),
  106. Em.Object.create({
  107. componentName: 'ZOOKEEPER_SERVER',
  108. workStatus: 'INSTALLED'
  109. })
  110. ];
  111. beforeEach(function () {
  112. sinon.stub(App.router, 'get', function () {
  113. return 1;
  114. });
  115. this.result = controller.enableHighAvailability();
  116. });
  117. it('enableHighAvailability result is false', function () {
  118. expect(this.result).to.be.false;
  119. });
  120. it('showErrorPopup is called once', function () {
  121. expect(controller.showErrorPopup.calledOnce).to.be.true;
  122. });
  123. });
  124. describe('All checks passed', function () {
  125. beforeEach(function () {
  126. hostComponents = [
  127. Em.Object.create({
  128. componentName: 'NAMENODE',
  129. workStatus: 'STARTED'
  130. }),
  131. Em.Object.create({
  132. componentName: 'ZOOKEEPER_SERVER',
  133. workStatus: 'INSTALLED'
  134. }),
  135. Em.Object.create({
  136. componentName: 'ZOOKEEPER_SERVER',
  137. workStatus: 'INSTALLED'
  138. }),
  139. Em.Object.create({
  140. componentName: 'ZOOKEEPER_SERVER',
  141. workStatus: 'INSTALLED'
  142. })
  143. ];
  144. sinon.stub(App.router, 'get', function() {
  145. return 3;
  146. });
  147. this.result = controller.enableHighAvailability();
  148. });
  149. it('enableHighAvailability result is true', function () {
  150. expect(this.result).to.be.true;
  151. });
  152. it('user is moved to enable HA', function () {
  153. expect(App.router.transitionTo.calledWith('main.services.enableHighAvailability')).to.be.true;
  154. });
  155. it('showErrorPopup is not called', function () {
  156. expect(controller.showErrorPopup.calledOnce).to.be.false;
  157. });
  158. });
  159. });
  160. describe('#joinMessage()', function () {
  161. it('message is empty', function () {
  162. var message = [];
  163. expect(controller.joinMessage(message)).to.be.empty;
  164. });
  165. it('message is array from two strings', function () {
  166. var message = ['yes', 'no'];
  167. expect(controller.joinMessage(message)).to.equal('yes<br/>no');
  168. });
  169. it('message is string', function () {
  170. var message = 'hello';
  171. expect(controller.joinMessage(message)).to.equal('<p>hello</p>');
  172. });
  173. });
  174. });