step4_controller_test.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. describe('App.HighAvailabilityWizardStep4Controller', function() {
  20. describe('#checkNnCheckPointStatus', function() {
  21. beforeEach(function() {
  22. this.controller = App.HighAvailabilityWizardStep4Controller.create();
  23. this.clock = sinon.useFakeTimers();
  24. sinon.stub(this.controller, 'pullCheckPointStatus');
  25. });
  26. afterEach(function() {
  27. this.clock.restore();
  28. this.controller.pullCheckPointStatus.restore();
  29. });
  30. var tests = [
  31. {
  32. responseData: {
  33. HostRoles: { desired_state: 'STARTED' }
  34. },
  35. m: 'NameNode started, Safemode off, no journal node transaction. Polling should be performed and isNameNodeStarted should be true',
  36. e: {
  37. isPollingCalled: true,
  38. isNameNodeStarted: true,
  39. isNextEnabled: false
  40. }
  41. },
  42. {
  43. responseData: {
  44. HostRoles: { desired_state: 'STARTED' },
  45. metrics: { dfs: { namenode: {
  46. Safemode: 'ON',
  47. JournalNodeTransactionInfo: "{\"LastAppliedOrWrittenTxId\":\"4\",\"MostRecentCheckpointTxId\":\"2\"}"
  48. }}}
  49. },
  50. m: 'NameNode started, Safemode on, journal node transaction invalid. Polling should be performed and isNameNodeStarted should be true',
  51. e: {
  52. isPollingCalled: true,
  53. isNameNodeStarted: true,
  54. isNextEnabled: false
  55. }
  56. },
  57. {
  58. responseData: {
  59. HostRoles: { desired_state: 'INSTALLED' },
  60. metrics: { dfs: { namenode: {
  61. Safemode: 'ON',
  62. JournalNodeTransactionInfo: "{\"LastAppliedOrWrittenTxId\":\"15\",\"MostRecentCheckpointTxId\":\"14\"}"
  63. }}}
  64. },
  65. m: 'NameNode not started, Safemode on, journal node transaction present. Polling should not be performed and isNameNodeStarted should be false',
  66. e: {
  67. isPollingCalled: false,
  68. isNameNodeStarted: false,
  69. isNextEnabled: true
  70. }
  71. },
  72. {
  73. responseData: {
  74. HostRoles: { desired_state: 'STARTED' },
  75. metrics: { dfs: { namenode: {
  76. Safemode: "",
  77. JournalNodeTransactionInfo: "{\"LastAppliedOrWrittenTxId\":\"15\",\"MostRecentCheckpointTxId\":\"14\"}"
  78. }}}
  79. },
  80. m: 'NameNode started, Safemode off, journal node transaction present. Polling should not be performed and isNameNodeStarted should be true',
  81. e: {
  82. isPollingCalled: true,
  83. isNameNodeStarted: true,
  84. isNextEnabled: false
  85. }
  86. }
  87. ];
  88. tests.forEach(function(test) {
  89. it(test.m, function() {
  90. this.controller.set('isNameNodeStarted', !test.e.isNameNodeStarted);
  91. this.controller.checkNnCheckPointStatus(test.responseData);
  92. this.clock.tick(this.controller.get('POLL_INTERVAL'));
  93. expect(this.controller.get('isNameNodeStarted')).to.be.eql(test.e.isNameNodeStarted);
  94. expect(this.controller.get('isNextEnabled')).to.be.eql(test.e.isNextEnabled);
  95. expect(this.controller.pullCheckPointStatus.called).to.be.eql(test.e.isPollingCalled);
  96. });
  97. });
  98. });
  99. });