step5_test.js 5.6 KB

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