batch_scheduled_requests_test.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. require('utils/helper');
  19. var batchUtils = require('utils/batch_scheduled_requests');
  20. describe('batch_scheduled_requests', function() {
  21. describe('#getRollingRestartComponentName', function() {
  22. var tests = [
  23. {serviceName: 'HDFS', componentName: 'DATANODE'},
  24. {serviceName: 'YARN', componentName: 'NODEMANAGER'},
  25. {serviceName: 'MAPREDUCE', componentName: 'TASKTRACKER'},
  26. {serviceName: 'HBASE', componentName: 'HBASE_REGIONSERVER'},
  27. {serviceName: 'STORM', componentName: 'SUPERVISOR'},
  28. {serviceName: 'SOME_INVALID_SERVICE', componentName: null}
  29. ];
  30. tests.forEach(function(test) {
  31. it(test.serviceName + ' - ' + test.componentName, function() {
  32. expect(batchUtils.getRollingRestartComponentName(test.serviceName)).to.equal(test.componentName);
  33. });
  34. });
  35. });
  36. describe('#getBatchesForRollingRestartRequest', function() {
  37. var tests = [
  38. {
  39. hostComponents: Em.A([
  40. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host1'}}),
  41. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host2'}}),
  42. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host3'}})
  43. ]),
  44. batchSize: 2,
  45. m: 'DATANODES on three hosts, batchSize = 2',
  46. e: {
  47. batchCount: 2
  48. }
  49. },
  50. {
  51. hostComponents: Em.A([
  52. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host1'}}),
  53. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host2'}}),
  54. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host3'}})
  55. ]),
  56. batchSize: 3,
  57. m: 'DATANODES on 3 hosts, batchSize = 3',
  58. e: {
  59. batchCount: 1
  60. }
  61. },
  62. {
  63. hostComponents: Em.A([
  64. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host1'}}),
  65. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host2'}}),
  66. Em.Object.create({componentName:'DATANODE', service:{serviceName:'HDFS'}, host:{hostName:'host3'}})
  67. ]),
  68. batchSize: 1,
  69. m: 'DATANODES on 3 hosts, batchSize = 1',
  70. e: {
  71. batchCount: 3
  72. }
  73. }
  74. ];
  75. tests.forEach(function(test) {
  76. it(test.m, function() {
  77. expect(batchUtils.getBatchesForRollingRestartRequest(test.hostComponents, test.batchSize).length).to.equal(test.e.batchCount);
  78. });
  79. });
  80. });
  81. });