Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,12 @@ public void testRandomChoosingPolicy() throws IOException {
containerSet = new ContainerSet();

int numContainers = 10;
Random random = new Random();
for (int i = 0; i < numContainers; i++) {
KeyValueContainerData data = new KeyValueContainerData(i,
layout,
ContainerTestHelper.CONTAINER_MAX_SIZE, UUID.randomUUID().toString(),
UUID.randomUUID().toString());
data.incrPendingDeletionBlocks(random.nextInt(numContainers) + 1);
data.incrPendingDeletionBlocks(20);
data.closeContainer();
KeyValueContainer container = new KeyValueContainer(data, conf);
containerSet.addContainer(container);
Expand All @@ -125,22 +124,22 @@ public void testRandomChoosingPolicy() throws IOException {
}
Assert.assertTrue(totPendingBlocks >= blockLimitPerInterval);


// test random choosing
List<ContainerBlockInfo> result1 = blockDeletingService
.chooseContainerForBlockDeletion(numContainers, deletionPolicy);
List<ContainerBlockInfo> result2 = blockDeletingService
.chooseContainerForBlockDeletion(numContainers, deletionPolicy);

boolean hasShuffled = false;
for (int i = 0; i < numContainers; i++) {
if (result1.get(i).getContainerData().getContainerID() != result2.get(i)
.getContainerData().getContainerID()) {
hasShuffled = true;
break;
// test random choosing. We choose 100 times the 3 datanodes twice.
//We expect different order at least once.
for (int j = 0; j < 100; j++) {
List<ContainerBlockInfo> result1 = blockDeletingService
.chooseContainerForBlockDeletion(50, deletionPolicy);
List<ContainerBlockInfo> result2 = blockDeletingService
.chooseContainerForBlockDeletion(50, deletionPolicy);
boolean hasShuffled = false;
for (int i = 0; i < result1.size(); i++) {
if (result1.get(i).getContainerData().getContainerID() != result2.get(i)
.getContainerData().getContainerID()) {
return;
}
}
}
Assert.assertTrue("Chosen container results were same", hasShuffled);
Assert.fail("Chosen container results were same 100 times");

}

Expand Down