@@ -0,0 +1,2992 @@
+package tachyon.worker.block;%0A%0Aimport org.junit.Assert;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport tachyon.worker.BlockStoreLocation;%0A%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Apublic class BlockHeartbeatReporterTest %7B%0A  private static final int USER_ID = 1;%0A  private static final BlockStoreLocation MEM_LOC = new BlockStoreLocation(1, 0);%0A  private static final BlockStoreLocation SSD_LOC = new BlockStoreLocation(2, 0);%0A  private static final BlockStoreLocation HDD_LOC = new BlockStoreLocation(3, 0);%0A  BlockHeartbeatReporter mReporter;%0A%0A  @Before%0A  public final void before() %7B%0A    mReporter = new BlockHeartbeatReporter();%0A  %7D%0A%0A  private void moveBlock(long blockId, BlockStoreLocation loc) %7B%0A    mReporter.postMoveBlock(USER_ID, blockId, loc);%0A  %7D%0A%0A  // Tests Empty Report%0A  @Test%0A  public void generateReportEmptyTest() %7B%0A    BlockHeartbeatReport report = mReporter.generateReport();%0A    Assert.assertTrue(report.getAddedBlocks().isEmpty());%0A    Assert.assertTrue(report.getRemovedBlocks().isEmpty());%0A  %7D%0A%0A  // Tests a report is correctly generated after moving blocks%0A  @Test%0A  public void generateReportSimpleMoveTest() %7B%0A    Long block1 = 1L;%0A    Long block2 = 2L;%0A    Long block3 = 3L;%0A    moveBlock(block1, MEM_LOC);%0A    moveBlock(block2, SSD_LOC);%0A    moveBlock(block3, HDD_LOC);%0A    BlockHeartbeatReport report = mReporter.generateReport();%0A    Map%3CLong, List%3CLong%3E%3E addedBlocks = report.getAddedBlocks();%0A%0A    // Block1 moved to memory%0A    List%3CLong%3E addedBlocksMem = addedBlocks.get(MEM_LOC.getStorageDirId());%0A    Assert.assertEquals(addedBlocksMem.size(), 1);%0A    Assert.assertEquals(addedBlocksMem.get(0), block1);%0A%0A    // Block2 moved to ssd%0A    List%3CLong%3E addedBlocksSsd = addedBlocks.get(SSD_LOC.getStorageDirId());%0A    Assert.assertEquals(addedBlocksSsd.size(), 1);%0A    Assert.assertEquals(addedBlocksSsd.get(0), block2);%0A%0A    // Block3 moved to hdd%0A    List%3CLong%3E addedBlocksHdd = addedBlocks.get(HDD_LOC.getStorageDirId());%0A    Assert.assertEquals(addedBlocksHdd.size(), 1);%0A    Assert.assertEquals(addedBlocksHdd.get(0), block3);%0A%0A    // All blocks should be %22removed%22 to force an update of their location in master%0A    List%3CLong%3E removedBlocks = report.getRemovedBlocks();%0A    Assert.assertEquals(removedBlocks.size(), 3);%0A    Assert.assertTrue(removedBlocks.contains(block1));%0A    Assert.assertTrue(removedBlocks.contains(block2));%0A    Assert.assertTrue(removedBlocks.contains(block3));%0A  %7D%0A%0A  // Tests generating a report clears the state of the reporter%0A  @Test%0A  public void generateReportStateClearTest() %7B%0A    Long block1 = 1L;%0A    moveBlock(block1, MEM_LOC);%0A    BlockHeartbeatReport report = mReporter.generateReport();%0A    Assert.assertFalse(report.getAddedBlocks().isEmpty());%0A    Assert.assertFalse(report.getRemovedBlocks().isEmpty());%0A%0A    BlockHeartbeatReport nextReport = mReporter.generateReport();%0A    Assert.assertTrue(nextReport.getAddedBlocks().isEmpty());%0A    Assert.assertTrue(nextReport.getRemovedBlocks().isEmpty());%0A  %7D%0A%7D%0A

Add unit tests for block heartbeat reporter.