host_test.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. var validator = require('utils/validator');
  20. require('utils/batch_scheduled_requests');
  21. require('controllers/main/host');
  22. require('mappers/server_data_mapper');
  23. describe('MainHostController', function () {
  24. var hostController, db;
  25. // @todo add unit tests after bulk ops reimplementing
  26. describe('#bulkOperation', function() {
  27. beforeEach(function() {
  28. hostController = App.MainHostController.create({});
  29. sinon.stub(hostController, 'bulkOperationForHostsRestart', Em.K);
  30. sinon.stub(hostController, 'bulkOperationForHosts', Em.K);
  31. sinon.stub(hostController, 'bulkOperationForHostComponentsRestart', Em.K);
  32. sinon.stub(hostController, 'bulkOperationForHostComponentsDecommission', Em.K);
  33. sinon.stub(hostController, 'bulkOperationForHostComponents', Em.K);
  34. sinon.stub(hostController, 'bulkOperationForHostsPassiveState', Em.K);
  35. });
  36. afterEach(function() {
  37. hostController.bulkOperationForHosts.restore();
  38. hostController.bulkOperationForHostsRestart.restore();
  39. hostController.bulkOperationForHostComponentsRestart.restore();
  40. hostController.bulkOperationForHostComponentsDecommission.restore();
  41. hostController.bulkOperationForHostComponents.restore();
  42. hostController.bulkOperationForHostsPassiveState.restore();
  43. });
  44. it('RESTART for hosts', function() {
  45. var operationData = {
  46. action: 'RESTART'
  47. };
  48. hostController.bulkOperation(operationData, []);
  49. expect(hostController.bulkOperationForHostsRestart.calledOnce).to.equal(true);
  50. });
  51. it('START for hosts', function() {
  52. var operationData = {
  53. action: 'STARTED'
  54. };
  55. hostController.bulkOperation(operationData, []);
  56. expect(hostController.bulkOperationForHosts.calledOnce).to.equal(true);
  57. });
  58. it('STOP for hosts', function() {
  59. var operationData = {
  60. action: 'INSTALLED'
  61. };
  62. hostController.bulkOperation(operationData, []);
  63. expect(hostController.bulkOperationForHosts.calledOnce).to.equal(true);
  64. });
  65. it('PASSIVE_STATE for hosts', function() {
  66. var operationData = {
  67. action: 'PASSIVE_STATE'
  68. };
  69. hostController.bulkOperation(operationData, []);
  70. expect(hostController.bulkOperationForHostsPassiveState.calledOnce).to.equal(true);
  71. });
  72. it('RESTART for hostComponents', function() {
  73. var operationData = {
  74. action: 'RESTART',
  75. componentNameFormatted: 'DataNodes'
  76. };
  77. hostController.bulkOperation(operationData, []);
  78. expect(hostController.bulkOperationForHostComponentsRestart.calledOnce).to.equal(true);
  79. });
  80. it('START for hostComponents', function() {
  81. var operationData = {
  82. action: 'STARTED',
  83. componentNameFormatted: 'DataNodes'
  84. };
  85. hostController.bulkOperation(operationData, []);
  86. expect(hostController.bulkOperationForHostComponents.calledOnce).to.equal(true);
  87. });
  88. it('STOP for hostComponents', function() {
  89. var operationData = {
  90. action: 'INSTALLED',
  91. componentNameFormatted: 'DataNodes'
  92. };
  93. hostController.bulkOperation(operationData, []);
  94. expect(hostController.bulkOperationForHostComponents.calledOnce).to.equal(true);
  95. });
  96. it('DECOMMISSION for hostComponents', function() {
  97. var operationData = {
  98. action: 'DECOMMISSION',
  99. componentNameFormatted: 'DataNodes'
  100. };
  101. hostController.bulkOperation(operationData, []);
  102. expect(hostController.bulkOperationForHostComponentsDecommission.calledOnce).to.equal(true);
  103. });
  104. it('RECOMMISSION for hostComponents', function() {
  105. var operationData = {
  106. action: 'DECOMMISSION_OFF',
  107. componentNameFormatted: 'DataNodes'
  108. };
  109. hostController.bulkOperation(operationData, []);
  110. expect(hostController.bulkOperationForHostComponentsDecommission.calledOnce).to.equal(true);
  111. });
  112. });
  113. describe('#getRegExp()', function() {
  114. before(function() {
  115. hostController = App.MainHostController.create({});
  116. });
  117. var message = '`{0}` should convert to `{1}`',
  118. tests = [
  119. { value: '.*', expected: '.*' },
  120. { value: '.', expected: '.*' },
  121. { value: '.*.*', expected: '.*' },
  122. { value: '*', expected: '^$' },
  123. { value: '........', expected: '.*' },
  124. { value: '........*', expected: '.*' },
  125. { value: 'a1', expected: '.*a1.*' },
  126. { value: 'a1.', expected: '.*a1.*' },
  127. { value: 'a1...', expected: '.*a1.*' },
  128. { value: 'a1.*', expected: '.*a1.*' },
  129. { value: 'a1.*.a2.a3', expected: '.*a1.*.a2.a3.*' },
  130. { value: 'a1.*.a2...a3', expected: '.*a1.*.a2...a3.*' }
  131. ];
  132. tests.forEach(function(test){
  133. it(message.format(test.value, test.expected), function() {
  134. expect(hostController.getRegExp(test.value)).to.be.equal(test.expected);
  135. });
  136. });
  137. });
  138. describe('#warnBeforeDecommissionSuccess()', function () {
  139. var mock = {
  140. showHbaseActiveWarning: Em.K,
  141. checkRegionServerState: Em.K
  142. };
  143. beforeEach(function () {
  144. hostController = App.MainHostController.create({});
  145. sinon.stub(App.router, 'get', function () {
  146. return mock;
  147. });
  148. sinon.spy(mock, 'showHbaseActiveWarning');
  149. sinon.spy(mock, 'checkRegionServerState');
  150. });
  151. afterEach(function () {
  152. App.router.get.restore();
  153. mock.showHbaseActiveWarning.restore();
  154. mock.checkRegionServerState.restore();
  155. });
  156. it('items length more than 0', function () {
  157. hostController.warnBeforeDecommissionSuccess({items: [1]}, {}, {});
  158. expect(mock.showHbaseActiveWarning.calledOnce).to.be.true;
  159. });
  160. it('items length equal 0', function () {
  161. hostController.warnBeforeDecommissionSuccess({items: []}, {}, {hostNames: 'host1'});
  162. expect(mock.checkRegionServerState.calledWith('host1')).to.be.true;
  163. });
  164. });
  165. describe('#getQueryParameters', function() {
  166. beforeEach(function() {
  167. hostController = App.MainHostController.create({});
  168. sinon.spy(hostController, 'getRegExp');
  169. sinon.stub(App.db, 'getFilterConditions', function() {
  170. return [{
  171. iColumn: 1,
  172. skipFilter: false,
  173. type: "string",
  174. value: "someval"
  175. }];
  176. });
  177. });
  178. afterEach(function() {
  179. App.db.getFilterConditions.restore();
  180. hostController.getRegExp.restore();
  181. });
  182. it('should call #getRegExp with value `someval` on host name filter', function() {
  183. hostController.getQueryParameters();
  184. expect(hostController.getRegExp.calledWith('someval')).to.ok;
  185. });
  186. it('result should include host name filter converted value', function() {
  187. expect(hostController.getQueryParameters().findProperty('key', 'Hosts/host_name').value).to.equal('.*someval.*');
  188. });
  189. });
  190. describe('#getSortProps', function () {
  191. beforeEach(function () {
  192. db = {mainHostController: [
  193. {name: 'hostName', status: 'sorting'}
  194. ]};
  195. hostController = App.MainHostController.create({});
  196. sinon.stub(App.db, 'getSortingStatuses', function (k) {
  197. return db[k];
  198. });
  199. sinon.stub(App.db, 'setSortingStatuses', function (k, v) {
  200. db[k] = Em.typeOf(v) === 'array' ? v : [v];
  201. });
  202. });
  203. afterEach(function () {
  204. App.db.getSortingStatuses.restore();
  205. App.db.setSortingStatuses.restore();
  206. });
  207. it('should set default sorting condition', function () {
  208. hostController.getSortProps();
  209. expect(db.mainHostController).to.eql([{name: 'hostName', status: 'sorting_asc'}]);
  210. });
  211. });
  212. });