step5_test.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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/installer/step5_controller');
  20. describe('App.InstallerStep5Controller', function () {
  21. var controller = App.InstallerStep5Controller.create();
  22. describe('#getAvailableHosts()', function () {
  23. it('should generate available hosts for a new zookeeper service', function () {
  24. var hostsForNewZookeepers = controller.getAvailableHosts("ZooKeeper"),
  25. ok = true, i = 0, masters = null;
  26. //test that the hosts found, do not have Zookeeper master assigned to them
  27. for (i = 0; i < hostsForNewZookeepers.get("length"); i++) {
  28. masters = controller.get("selectedServicesMasters").filterProperty(hostsForNewZookeepers[i].get("host_name"));
  29. if (masters.findProperty("component_name", "ZooKeeper")) {
  30. ok = false;
  31. break;
  32. }
  33. }
  34. expect(ok).to.equal(true);
  35. })
  36. it('should return all hosts for services other than ZooKeeper', function () {
  37. var hostsForNewZookeepers = controller.getAvailableHosts("");
  38. expect(hostsForNewZookeepers.get("length")).to.equal(controller.get("hosts.length"));
  39. })
  40. })
  41. describe('#assignHostToMaster()', function () {
  42. it('should assign the selected host to the master service', function () {
  43. //test non-zookeeper master
  44. var SERVICE_MASTER = "NameNode",
  45. HOST = "host4", ZID, status;
  46. controller.assignHostToMaster(SERVICE_MASTER, HOST);
  47. expect(controller.get("selectedServicesMasters").findProperty("component_name", "NameNode").get("selectedHost")).to.equal(HOST);
  48. })
  49. it('should assign the selected host to the ZooKeeper master service', function () {
  50. //test non-zookeeper master
  51. var SERVICE_MASTER = "ZooKeeper",
  52. HOST = "host4", ZID = 2;
  53. //test zookeeper master assignment with
  54. if (controller.addZookeepers()) {
  55. controller.assignHostToMaster(SERVICE_MASTER, HOST, ZID);
  56. expect(controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").findProperty("zId", ZID).get("selectedHost")).to.equal(HOST);
  57. }
  58. })
  59. })
  60. describe('#addZookeepers()', function () {
  61. it('should add a new ZooKeeper', function () {
  62. var newLength = 0;
  63. if (controller.get("selectedServices").mapProperty("service_name").contains("ZooKeeper")
  64. && controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("length") < controller.get("hosts.length")) {
  65. newLength = controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("length");
  66. controller.addZookeepers();
  67. expect(controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("length")).to.equal(newLength + 1);
  68. }
  69. })
  70. it('should add ZooKeepers up to the number of hosts', function () {
  71. var currentZooKeepers = controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper"),
  72. success = true;
  73. //add ZooKeepers as long as possible
  74. if (currentZooKeepers) {
  75. while (success) {
  76. success = controller.addZookeepers();
  77. }
  78. expect(controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("length")).to.equal(controller.get("hosts.length"));
  79. }
  80. })
  81. })
  82. describe('#removeZookeepers()', function () {
  83. it('should remove a ZooKeeper', function () {
  84. var newLength = 0;
  85. if (controller.get("selectedServices").mapProperty("service_name").contains("ZooKeeper")) {
  86. if (controller.addZookeepers()) {
  87. newLength = controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("length");
  88. controller.removeZookeepers(2);
  89. expect(controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("length")).to.equal(newLength - 1);
  90. }
  91. }
  92. })
  93. it('should fail to remove a ZooKeeper if there is only 1', function () {
  94. var currentZooKeepers = controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper"),
  95. success = true;
  96. //remove ZooKeepers as long as possible
  97. if (currentZooKeepers) {
  98. while (success) {
  99. success = controller.removeZookeepers(controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("lastObject.zId"));
  100. }
  101. expect(controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("length")).to.equal(1);
  102. }
  103. })
  104. })
  105. describe('#rebalanceZookeeperHosts()', function () {
  106. it('should rebalance hosts for ZooKeeper', function () {
  107. //assign a host to a zookeeper and then rebalance the available hosts for the other zookeepers
  108. var zookeepers = controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper"),
  109. aZookeeper = null, aHost = null, i = 0, ok = true;
  110. if (zookeepers.get("length") > 1) {
  111. aZookeeper = controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").findProperty("zId", 1);
  112. aHost = aZookeeper.get("availableHosts")[0];
  113. aZookeeper.set("selectedHost", aHost.get("host_name"));
  114. controller.rebalanceZookeeperHosts();
  115. for (i = 0; i < zookeepers.get("length"); i++) {
  116. if (zookeepers[i].get("availableHosts").mapProperty("host_name").contains(aHost)) {
  117. ok = false;
  118. break;
  119. }
  120. }
  121. expect(ok).to.equal(true);
  122. }
  123. })
  124. })
  125. })