run_test.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. var modelSetup = require('test/init_model_test');
  20. require('models/run');
  21. var run,
  22. job,
  23. runData = {
  24. id: 'run'
  25. },
  26. jobData = {
  27. id: 'job'
  28. },
  29. cases = [
  30. {
  31. id: 'pig_run',
  32. type: 'Pig'
  33. },
  34. {
  35. id: 'hive_run',
  36. type: 'Hive'
  37. },
  38. {
  39. id: 'mr_run',
  40. type: 'MapReduce'
  41. },
  42. {
  43. id: 'run_pig_hive_mr_id',
  44. type: ''
  45. }
  46. ];
  47. describe('App.Run', function () {
  48. beforeEach(function () {
  49. run = App.Run.createRecord(runData);
  50. });
  51. afterEach(function () {
  52. modelSetup.deleteRecord(run);
  53. });
  54. describe('#idFormatted', function () {
  55. it('should shorten id to 20 characters', function () {
  56. for (var i = 21, name = ''; i--; ) {
  57. name += 'n';
  58. }
  59. run.set('id', name);
  60. expect(run.get('idFormatted')).to.have.length(20);
  61. });
  62. });
  63. describe('#jobs', function () {
  64. beforeEach(function () {
  65. job = App.Job.createRecord(jobData);
  66. job.reopen({
  67. run: runData
  68. });
  69. });
  70. afterEach(function () {
  71. modelSetup.deleteRecord(job);
  72. });
  73. it('should load corresponding jobs from the store', function () {
  74. run.set('loadAllJobs', true);
  75. expect(run.get('jobs')).to.have.length(1);
  76. expect(run.get('jobs').objectAt(0).get('run.id')).to.equal('run');
  77. });
  78. });
  79. describe('#duration', function () {
  80. it('should convert elapsedTime into time format', function () {
  81. run.set('elapsedTime', 1000);
  82. expect(run.get('duration')).to.equal('1.00 secs');
  83. });
  84. });
  85. describe('#isRunning', function () {
  86. it('should be true', function () {
  87. run.setProperties({
  88. numJobsTotal: 5,
  89. numJobsCompleted: 0
  90. });
  91. expect(run.get('isRunning')).to.be.true;
  92. });
  93. it('should be false', function () {
  94. run.setProperties({
  95. numJobsTotal: 5,
  96. numJobsCompleted: 5
  97. });
  98. expect(run.get('isRunning')).to.be.false;
  99. });
  100. });
  101. describe('#inputFormatted', function () {
  102. it('should convert input into bandwidth format', function () {
  103. run.set('input', 1024);
  104. expect(run.get('inputFormatted')).to.equal('1.0KB');
  105. });
  106. });
  107. describe('#outputFormatted', function () {
  108. it('should convert output into bandwidth format', function () {
  109. run.set('output', 1024);
  110. expect(run.get('outputFormatted')).to.equal('1.0KB');
  111. });
  112. });
  113. describe('#lastUpdateTime', function () {
  114. it('should sum elapsedTime and startTime', function () {
  115. run.setProperties({
  116. elapsedTime: 1000,
  117. startTime: 2000
  118. });
  119. expect(run.get('lastUpdateTime')).to.equal(3000);
  120. });
  121. });
  122. describe('#lastUpdateTimeFormattedShort', function () {
  123. it('should form date and time from lastUpdateTime', function () {
  124. run.setProperties({
  125. elapsedTime: 1000,
  126. startTime: 100000000000
  127. });
  128. expect(run.get('lastUpdateTimeFormattedShort')).to.equal('Sat Mar 03 1973');
  129. });
  130. });
  131. describe('#type', function () {
  132. cases.forEach(function (item) {
  133. it('should be ' + (item.type ? item.type : 'empty'), function () {
  134. run.set('id', item.id);
  135. expect(run.get('type')).to.equal(item.type);
  136. });
  137. });
  138. });
  139. });