yarn-node-container-test.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. import { moduleFor, test } from 'ember-qunit';
  19. moduleFor('serializer:yarn-node-container', 'Unit | Serializer | NodeContainer', {
  20. });
  21. test('Basic creation test', function(assert) {
  22. let serializer = this.subject();
  23. assert.ok(serializer);
  24. assert.ok(serializer.normalizeSingleResponse);
  25. assert.ok(serializer.normalizeArrayResponse);
  26. assert.ok(serializer.internalNormalizeSingleResponse);
  27. });
  28. test('normalizeArrayResponse test', function(assert) {
  29. let serializer = this.subject(),
  30. modelClass = {
  31. modelName: "yarn-node-container"
  32. },
  33. payload = {
  34. containers: {
  35. container: [{
  36. id: "container_e32_1456000363780_0002_01_000001", state: "RUNNING",
  37. exitCode:-1000,diagnostics:"",user:"root",totalMemoryNeededMB:2048,
  38. totalVCoresNeeded:1,containerLogsLink: "http://localhost:8042/node/" +
  39. "containerlogs/container_e32_1456000363780_0002_01_000001/root",
  40. nodeId: "localhost:64318", containerLogFiles:["syslog","stderr",
  41. "stdout"]
  42. },{
  43. id:"container_e32_1456000363780_0002_01_000003", state:"RUNNING",
  44. exitCode:-1000, diagnostics:"", user:"root", totalMemoryNeededMB:1024,
  45. totalVCoresNeeded:1,containerLogsLink:"http://localhost:8042/node" +
  46. "/containerlogs/container_e32_1456000363780_0002_01_000003/root",
  47. nodeId:"localhost:64318",containerLogFiles:["syslog","stderr",
  48. "syslog.shuffle","stdout"]
  49. }]
  50. }
  51. };
  52. assert.expect(14);
  53. var response =
  54. serializer.normalizeArrayResponse({}, modelClass, payload, null, null);
  55. assert.ok(response.data);
  56. assert.equal(response.data.length, 2);
  57. assert.equal(response.data[0].id,
  58. "container_e32_1456000363780_0002_01_000001");
  59. assert.equal(response.data[1].id,
  60. "container_e32_1456000363780_0002_01_000003");
  61. assert.equal(response.data[0].attributes.containerLogFiles.length, 3);
  62. assert.equal(response.data[1].attributes.containerLogFiles.length, 4);
  63. for (var i = 0; i < 2; i++) {
  64. assert.equal(response.data[i].type, modelClass.modelName);
  65. assert.deepEqual(response.data[i].attributes.containerLogFiles,
  66. payload.containers.container[i].containerLogFiles);
  67. assert.equal(response.data[i].attributes.state,
  68. payload.containers.container[i].state);
  69. assert.equal(response.data[i].attributes.user,
  70. payload.containers.container[i].user);
  71. }
  72. });
  73. test('normalizeArrayResponse no containers test', function(assert) {
  74. let serializer = this.subject(),
  75. modelClass = {
  76. modelName: "yarn-node-container"
  77. },
  78. payload = { containers: null };
  79. assert.expect(5);
  80. var response =
  81. serializer.normalizeArrayResponse({}, modelClass, payload, null, null);
  82. assert.ok(response.data);
  83. assert.equal(response.data.length, 1);
  84. assert.equal(response.data[0].type, modelClass.modelName);
  85. assert.equal(response.data[0].id, "dummy");
  86. assert.equal(response.data[0].attributes.containerId, undefined);
  87. });
  88. test('normalizeSingleResponse test', function(assert) {
  89. let serializer = this.subject(),
  90. modelClass = {
  91. modelName: "yarn-node-container"
  92. },
  93. payload = {
  94. container: {
  95. id: "container_e32_1456000363780_0002_01_000001", state: "RUNNING",
  96. exitCode:-1000,diagnostics:"",user:"root",totalMemoryNeededMB:2048,
  97. totalVCoresNeeded:1,containerLogsLink: "http://localhost:8042/node/" +
  98. "containerlogs/container_e32_1456000363780_0002_01_000001/root",
  99. nodeId: "localhost:64318", containerLogFiles:["syslog","stderr",
  100. "stdout"]
  101. }
  102. };
  103. assert.expect(11);
  104. var response =
  105. serializer.normalizeSingleResponse({}, modelClass, payload, null, null);
  106. assert.ok(response.data);
  107. assert.equal(response.data.id, payload.container.id);
  108. assert.equal(response.data.type, modelClass.modelName);
  109. assert.equal(response.data.attributes.containerId, payload.container.id);
  110. assert.equal(response.data.attributes.state, payload.container.state);
  111. assert.equal(response.data.attributes.user, payload.container.user);
  112. assert.equal(response.data.attributes.exitCode, payload.container.exitCode);
  113. assert.equal(response.data.attributes.totalMemoryNeededMB,
  114. payload.container.totalMemoryNeeded);
  115. assert.equal(response.data.attributes.totalVCoresNeeded,
  116. payload.container.totalVCoresNeeded);
  117. assert.equal(response.data.attributes.containerLogFiles.length, 3);
  118. assert.deepEqual(response.data.attributes.containerLogFiles,
  119. payload.container.containerLogFiles);
  120. });