yarn-rm-node-test.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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-rm-node', 'Unit | Serializer | RMNode', {
  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-rm-node"
  32. },
  33. payload = {
  34. nodes: {
  35. node: [{
  36. rack: "/default-rack", state: "RUNNING", id: "192.168.1.1:64318",
  37. nodeHostName: "192.168.1.1", nodeHTTPAddress: "192.168.1.1:8042",
  38. lastHealthUpdate: 1456251290905, version: "3.0.0-SNAPSHOT",
  39. healthReport: "", numContainers: 0, usedMemoryMB: 2048,
  40. availMemoryMB: 161792, usedVirtualCores: 2,
  41. availableVirtualCores: 158, nodeLabels: ["x"],
  42. resourceUtilization: {
  43. nodePhysicalMemoryMB: 4549, nodeVirtualMemoryMB: 4549,
  44. nodeCPUUsage: 0.14995001256465912,
  45. aggregatedContainersPhysicalMemoryMB: 0,
  46. aggregatedContainersVirtualMemoryMB: 0,
  47. containersCPUUsage: 0
  48. }
  49. },{
  50. rack: "/default-rack", state: "RUNNING", id: "192.168.1.2:64318",
  51. nodeHostName: "192.168.1.2", nodeHTTPAddress: "192.168.1.2:8042",
  52. lastHealthUpdate: 1456251290905, version: "3.0.0-SNAPSHOT",
  53. healthReport: "", numContainers: 0, usedMemoryMB: 0,
  54. availMemoryMB: 163840, usedVirtualCores: 0,
  55. availableVirtualCores: 160, nodeLabels: ["y"],
  56. resourceUtilization: {
  57. nodePhysicalMemoryMB: 4549, nodeVirtualMemoryMB: 4549,
  58. nodeCPUUsage: 0.14995001256465912,
  59. aggregatedContainersPhysicalMemoryMB: 0,
  60. aggregatedContainersVirtualMemoryMB: 0,
  61. containersCPUUsage: 0
  62. }
  63. }]
  64. }
  65. };
  66. assert.expect(12);
  67. var response =
  68. serializer.normalizeArrayResponse({}, modelClass, payload, null, null);
  69. assert.ok(response.data);
  70. assert.equal(response.data.length, 2);
  71. assert.equal(response.data[0].id, "192.168.1.1:64318");
  72. assert.equal(response.data[1].id, "192.168.1.2:64318");
  73. for (var i = 0; i < 2; i++) {
  74. assert.equal(response.data[i].type, modelClass.modelName);
  75. assert.equal(response.data[i].attributes.nodeHostName,
  76. payload.nodes.node[i].nodeHostName);
  77. assert.equal(response.data[i].attributes.nodeHTTPAddress,
  78. payload.nodes.node[i].nodeHTTPAddress);
  79. assert.deepEqual(response.data[i].attributes.nodeLabels,
  80. payload.nodes.node[i].nodeLabels);
  81. }
  82. });
  83. test('normalizeArrayResponse no nodes test', function(assert) {
  84. let serializer = this.subject(),
  85. modelClass = {
  86. modelName: "yarn-rm-node"
  87. },
  88. payload = { nodes: null };
  89. assert.expect(5);
  90. var response =
  91. serializer.normalizeArrayResponse({}, modelClass, payload, null, null);
  92. console.log(response);
  93. assert.ok(response.data);
  94. assert.equal(response.data.length, 1);
  95. assert.equal(response.data[0].type, modelClass.modelName);
  96. assert.equal(response.data[0].id, "dummy");
  97. assert.equal(response.data[0].attributes.nodeHostName, undefined);
  98. });
  99. test('normalizeSingleResponse test', function(assert) {
  100. let serializer = this.subject(),
  101. modelClass = {
  102. modelName: "yarn-rm-node"
  103. },
  104. payload = {
  105. node: {
  106. rack: "/default-rack", state: "RUNNING", id: "192.168.1.1:64318",
  107. nodeHostName: "192.168.1.1", nodeHTTPAddress: "192.168.1.1:8042",
  108. lastHealthUpdate: 1456251290905, version: "3.0.0-SNAPSHOT",
  109. healthReport: "", numContainers: 0, usedMemoryMB: 2048,
  110. availMemoryMB: 161792, usedVirtualCores: 2,
  111. availableVirtualCores: 158, nodeLabels: ["x"],
  112. resourceUtilization: {
  113. nodePhysicalMemoryMB: 4549, nodeVirtualMemoryMB: 4549,
  114. nodeCPUUsage: 0.14995001256465912,
  115. aggregatedContainersPhysicalMemoryMB: 0,
  116. aggregatedContainersVirtualMemoryMB: 0,
  117. containersCPUUsage: 0
  118. }
  119. }
  120. };
  121. assert.expect(13);
  122. var id = "localhost:64318";
  123. var response =
  124. serializer.normalizeSingleResponse({}, modelClass, payload, id, null);
  125. assert.ok(response.data);
  126. assert.equal(response.data.id, id);
  127. assert.equal(response.data.type, modelClass.modelName);
  128. assert.equal(response.data.attributes.rack, payload.node.rack);
  129. assert.equal(response.data.attributes.state, payload.node.state);
  130. assert.equal(response.data.attributes.nodeHostName,
  131. payload.node.nodeHostName);
  132. assert.equal(response.data.attributes.nodeHTTPAddress,
  133. payload.node.nodeHTTPAddress);
  134. assert.equal(response.data.attributes.version, payload.node.version);
  135. assert.equal(response.data.attributes.availMemoryMB,
  136. payload.node.availMemoryMB);
  137. assert.equal(response.data.attributes.usedMemoryMB,
  138. payload.node.usedMemoryMB);
  139. assert.equal(response.data.attributes.availableVirtualCores,
  140. payload.node.availableVirtualCores);
  141. assert.equal(response.data.attributes.usedVirtualCores,
  142. payload.node.usedVirtualCores);
  143. assert.deepEqual(response.data.attributes.nodeLabels,
  144. payload.node.nodeLabels);
  145. });