Skip to content

Commit

Permalink
Merge pull request apache#22 from Microsoft/qinchen/fixUT
Browse files Browse the repository at this point in the history
fix ut
  • Loading branch information
qinchen123 authored Nov 21, 2017
2 parents 44f5aaf + a048a4d commit 1534eae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public synchronized Node allocateCandidateRequestNode(ResourceDescriptor request
return candidateNode;
}

private synchronized long selectCandidateGPU(Node candidateNode, int requestGPUCount) {
public synchronized long selectCandidateGPU(Node candidateNode, int requestGPUCount) {
long candidateSelectGPU = 0;
long availableGPU = candidateNode.getNodeGpuStatus();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ public void testGpuAllocationManager() {
Node node6 = new Node("node6", tag, ResourceDescriptor.newInstance(2, 2, 4, 0xFL), ResourceDescriptor.newInstance(0, 0, 0, 0L));

GpuAllocationManager gpuMgr = new GpuAllocationManager();

long candidateGPU = gpuMgr.selectCandidateGPU(node1, 1);
Assert.assertEquals(1L, candidateGPU);
candidateGPU = gpuMgr.selectCandidateGPU(node1, 2);
Assert.assertEquals(3L, candidateGPU);

candidateGPU = gpuMgr.selectCandidateGPU(node3, 2);
Assert.assertEquals(3L, candidateGPU);
candidateGPU = gpuMgr.selectCandidateGPU(node3, 4);
Assert.assertEquals(0xFL, candidateGPU);
candidateGPU = gpuMgr.selectCandidateGPU(node3, 8);
Assert.assertEquals(0xFFL, candidateGPU);

candidateGPU = gpuMgr.selectCandidateGPU(node4, 2);
Assert.assertEquals(0x30L, candidateGPU);

Node result = gpuMgr.allocateCandidateRequestNode(ResourceDescriptor.newInstance(1, 1, 1, 0L), null);
//Empty allocation failed;
Assert.assertEquals(null, result);
Expand Down Expand Up @@ -114,28 +130,4 @@ public void testGpuAllocationManager() {
result = gpuMgr.allocateCandidateRequestNode(ResourceDescriptor.newInstance(1, 1, 1, 0L), null);
Assert.assertEquals(null, result);
}

@Test
public void testNode() {
Set<String> tag = null;

Node node1 = new Node("node1", tag, ResourceDescriptor.newInstance(2, 2, 2, 3L), ResourceDescriptor.newInstance(0, 0, 0, 0L));
Node node3 = new Node("node3", tag, ResourceDescriptor.newInstance(2, 2, 8, 0xFFL), ResourceDescriptor.newInstance(0, 0, 0, 0L));
Node node4 = new Node("node4", tag, ResourceDescriptor.newInstance(2, 2, 8, 0xFFL), ResourceDescriptor.newInstance(0, 0, 4, 0xFL));

long candidateGPU = node1.calculateCandidateGPU(1);
Assert.assertEquals(1L, candidateGPU);
candidateGPU = node1.calculateCandidateGPU(2);
Assert.assertEquals(3L, candidateGPU);

candidateGPU = node3.calculateCandidateGPU(2);
Assert.assertEquals(3L, candidateGPU);
candidateGPU = node3.calculateCandidateGPU(4);
Assert.assertEquals(0xFL, candidateGPU);
candidateGPU = node3.calculateCandidateGPU(8);
Assert.assertEquals(0xFFL, candidateGPU);

candidateGPU = node4.calculateCandidateGPU(2);
Assert.assertEquals(0x30L, candidateGPU);
}
}

0 comments on commit 1534eae

Please sign in to comment.