step5_test.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 Ember = require('ember');
  19. var App = require('app');
  20. require('controllers/wizard/step5_controller');
  21. var components = require('data/service_components');
  22. describe('App.WizardStep5Controller', function () {
  23. var controller = App.WizardStep5Controller.create();
  24. controller.set('content', {});
  25. var cpu = 2, memory = 4;
  26. var schemes = [
  27. {'description': 'empty condition'},
  28. {
  29. 'description': 'second host if amount more than 1',
  30. "else": 1
  31. },
  32. {
  33. 'description': 'first host if amount less than 3, third host if amount less than 6, fourth host if amount more than 5',
  34. "3": 0,
  35. "6": 2,
  36. "else": 3
  37. },
  38. {
  39. 'description': 'second host if amount less than 3, second host if amount less than 6, third host if amount less than 31, sixth host if amount more than 30',
  40. "3": 1,
  41. "6": 1,
  42. "31": 2,
  43. "else": 5
  44. }
  45. ];
  46. var test_config = [
  47. {
  48. title: '1 host',
  49. hosts: ['host0'],
  50. equals: [0, 0, 0, 0]
  51. },
  52. {
  53. title: '2 hosts',
  54. hosts: ['host0', 'host1'],
  55. equals: [0, 1, 0, 1]
  56. },
  57. {
  58. title: '3 hosts',
  59. hosts: ['host0', 'host1', 'host2'],
  60. equals: [0, 1, 2, 1]
  61. },
  62. {
  63. title: '5 hosts',
  64. hosts: ['host0', 'host1', 'host2', 'host3', 'host4'],
  65. equals: [0, 1, 2, 1]
  66. },
  67. {
  68. title: '6 hosts',
  69. hosts: ['host0', 'host1', 'host2', 'host3', 'host4', 'host6'],
  70. equals: [0, 1, 3, 2]
  71. },
  72. {
  73. title: '10 hosts',
  74. hosts: ['host0', 'host1', 'host2', 'host3', 'host4', 'host5', 'host6', 'host7', 'host8', 'host9'],
  75. equals: [0, 1, 3, 2]
  76. },
  77. {
  78. title: '31 hosts',
  79. hosts: ['host0', 'host1', 'host2', 'host3', 'host4', 'host5', 'host6', 'host7', 'host8', 'host9', 'host10', 'host11', 'host12', 'host13', 'host14', 'host15', 'host16', 'host17', 'host18', 'host19', 'host20', 'host21', 'host22', 'host23', 'host24', 'host25', 'host26', 'host27', 'host28', 'host29', 'host30'],
  80. equals: [0, 1, 3, 5]
  81. }
  82. ];
  83. schemes.forEach(function(scheme, index) {
  84. describe('#getHostForComponent() condition: ' + scheme.description, function() {
  85. delete scheme['description'];
  86. test_config.forEach(function(test) {
  87. it(test.title, function () {
  88. controller.get('hosts').clear();
  89. test.hosts.forEach(function(_host) {
  90. controller.get('hosts').pushObject(Em.Object.create({
  91. host_name: _host,
  92. cpu: cpu,
  93. memory: memory
  94. }));
  95. });
  96. expect(controller.getHostForComponent(test.hosts.length, scheme).host_name).to.equal(test.hosts[test.equals[index]]);
  97. });
  98. });
  99. });
  100. });
  101. describe('#getZooKeeperServer', function() {
  102. it('should be array with three host names if hosts number more than three', function() {
  103. var hosts = [
  104. {host_name: 'host1'},
  105. {host_name: 'host2'},
  106. {host_name: 'host3'}
  107. ];
  108. controller.set('hosts', hosts);
  109. expect(controller.getZooKeeperServer(hosts.length)).to.eql(['host1', 'host2', 'host3']);
  110. });
  111. it('should be array with one host names if hosts number less than three', function() {
  112. var hosts = [
  113. {host_name: 'host1'},
  114. {host_name: 'host2'}
  115. ];
  116. controller.set('hosts', hosts);
  117. expect(controller.getZooKeeperServer(hosts.length)).to.eql(['host1']);
  118. });
  119. });
  120. describe('#getGangliaServer', function() {
  121. it('should be host name if one host ', function() {
  122. var hosts = [
  123. {host_name: 'host1'}
  124. ];
  125. controller.set('hosts', hosts);
  126. expect(controller.getGangliaServer(hosts.length)).to.eql('host1');
  127. });
  128. it('should be host name if hosts number more than one', function() {
  129. var hosts = [
  130. {host_name: 'host1'},
  131. {host_name: 'host2'}
  132. ];
  133. controller.set('hosts', hosts);
  134. expect(controller.getGangliaServer(hosts.length)).to.eql('host1');
  135. });
  136. it('should be host name different from localhost if hosts number more than one', function() {
  137. var hosts = [
  138. {host_name: ''},
  139. {host_name: 'host2'}
  140. ];
  141. //first host_name is empty string, because of location.hostname = "" in console,
  142. //to implement current test case
  143. controller.set('hosts', hosts);
  144. expect(controller.getGangliaServer(hosts.length)).to.eql('host2');
  145. });
  146. });
  147. controller.set('content', {});
  148. describe('#isReassignWizard', function() {
  149. it('true if content.controllerName is reassignMasterController', function() {
  150. controller.set('content.controllerName', 'reassignMasterController');
  151. expect(controller.get('isReassignWizard')).to.equal(true);
  152. });
  153. it('false if content.controllerName is not reassignMasterController', function() {
  154. controller.set('content.controllerName', 'mainController');
  155. expect(controller.get('isReassignWizard')).to.equal(false);
  156. });
  157. });
  158. });