bulk_operations_controller_test.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. describe('BulkOperationsController', function () {
  20. var hostController;
  21. describe('#bulkOperation', function() {
  22. beforeEach(function() {
  23. hostController = App.BulkOperationsController.create({});
  24. sinon.stub(hostController, 'bulkOperationForHostsRestart', Em.K);
  25. sinon.stub(hostController, 'bulkOperationForHosts', Em.K);
  26. sinon.stub(hostController, 'bulkOperationForHostsReinstall', Em.K);
  27. sinon.stub(hostController, 'bulkOperationForHostComponentsRestart', Em.K);
  28. sinon.stub(hostController, 'bulkOperationForHostComponentsDecommission', Em.K);
  29. sinon.stub(hostController, 'bulkOperationForHostComponents', Em.K);
  30. sinon.stub(hostController, 'bulkOperationForHostsPassiveState', Em.K);
  31. });
  32. afterEach(function() {
  33. hostController.bulkOperationForHosts.restore();
  34. hostController.bulkOperationForHostsRestart.restore();
  35. hostController.bulkOperationForHostsReinstall.restore();
  36. hostController.bulkOperationForHostComponentsRestart.restore();
  37. hostController.bulkOperationForHostComponentsDecommission.restore();
  38. hostController.bulkOperationForHostComponents.restore();
  39. hostController.bulkOperationForHostsPassiveState.restore();
  40. });
  41. it('RESTART for hosts', function() {
  42. var operationData = {
  43. action: 'RESTART'
  44. };
  45. hostController.bulkOperation(operationData, []);
  46. expect(hostController.bulkOperationForHostsRestart.calledOnce).to.equal(true);
  47. });
  48. it('START for hosts', function() {
  49. var operationData = {
  50. action: 'STARTED'
  51. };
  52. hostController.bulkOperation(operationData, []);
  53. expect(hostController.bulkOperationForHosts.calledOnce).to.equal(true);
  54. });
  55. it('STOP for hosts', function() {
  56. var operationData = {
  57. action: 'INSTALLED'
  58. };
  59. hostController.bulkOperation(operationData, []);
  60. expect(hostController.bulkOperationForHosts.calledOnce).to.equal(true);
  61. });
  62. it('REINSTALL for hosts', function() {
  63. var operationData = {
  64. action: 'REINSTALL'
  65. };
  66. hostController.bulkOperation(operationData, []);
  67. expect(hostController.bulkOperationForHostsReinstall.calledOnce).to.equal(true);
  68. });
  69. it('PASSIVE_STATE for hosts', function() {
  70. var operationData = {
  71. action: 'PASSIVE_STATE'
  72. };
  73. hostController.bulkOperation(operationData, []);
  74. expect(hostController.bulkOperationForHostsPassiveState.calledOnce).to.equal(true);
  75. });
  76. it('RESTART for hostComponents', function() {
  77. var operationData = {
  78. action: 'RESTART',
  79. componentNameFormatted: 'DataNodes'
  80. };
  81. hostController.bulkOperation(operationData, []);
  82. expect(hostController.bulkOperationForHostComponentsRestart.calledOnce).to.equal(true);
  83. });
  84. it('START for hostComponents', function() {
  85. var operationData = {
  86. action: 'STARTED',
  87. componentNameFormatted: 'DataNodes'
  88. };
  89. hostController.bulkOperation(operationData, []);
  90. expect(hostController.bulkOperationForHostComponents.calledOnce).to.equal(true);
  91. });
  92. it('STOP for hostComponents', function() {
  93. var operationData = {
  94. action: 'INSTALLED',
  95. componentNameFormatted: 'DataNodes'
  96. };
  97. hostController.bulkOperation(operationData, []);
  98. expect(hostController.bulkOperationForHostComponents.calledOnce).to.equal(true);
  99. });
  100. it('DECOMMISSION for hostComponents', function() {
  101. var operationData = {
  102. action: 'DECOMMISSION',
  103. componentNameFormatted: 'DataNodes'
  104. };
  105. hostController.bulkOperation(operationData, []);
  106. expect(hostController.bulkOperationForHostComponentsDecommission.calledOnce).to.equal(true);
  107. });
  108. it('RECOMMISSION for hostComponents', function() {
  109. var operationData = {
  110. action: 'DECOMMISSION_OFF',
  111. componentNameFormatted: 'DataNodes'
  112. };
  113. hostController.bulkOperation(operationData, []);
  114. expect(hostController.bulkOperationForHostComponentsDecommission.calledOnce).to.equal(true);
  115. });
  116. });
  117. describe('#warnBeforeDecommissionSuccess()', function () {
  118. var mock = {
  119. showHbaseActiveWarning: Em.K,
  120. checkRegionServerState: Em.K
  121. };
  122. beforeEach(function () {
  123. hostController = App.BulkOperationsController.create({});
  124. sinon.stub(App.router, 'get', function () {
  125. return mock;
  126. });
  127. sinon.spy(mock, 'showHbaseActiveWarning');
  128. sinon.spy(mock, 'checkRegionServerState');
  129. });
  130. afterEach(function () {
  131. App.router.get.restore();
  132. mock.showHbaseActiveWarning.restore();
  133. mock.checkRegionServerState.restore();
  134. });
  135. it('items length more than 0', function () {
  136. hostController.warnBeforeDecommissionSuccess({items: [1]}, {}, {});
  137. expect(mock.showHbaseActiveWarning.calledOnce).to.be.true;
  138. });
  139. it('items length equal 0', function () {
  140. hostController.warnBeforeDecommissionSuccess({items: []}, {}, {hostNames: 'host1'});
  141. expect(mock.checkRegionServerState.calledWith('host1')).to.be.true;
  142. });
  143. });
  144. });