highAvailability_controller_test.js 4.9 KB

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