highAvailability_controller_test.js 5.8 KB

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