server/src/test/java/org/apache/druid/server/coordination/SegmentLoadDropHandlerTest.java
/**
   * Steps:
   * 1. addSegment() succesfully loads the segment and annouces it
   * 2. removeSegment() unannounces the segment and schedules a delete runnable that deletes segment files
   * 3. addSegment() calls loadSegment() and annouces it again
   * 4. scheduled delete task executes and realizes it should not delete the segment files.
   */
1. addSegment() succesfully loads the segment and annouces it
2. removeSegment() unannounces the segment and schedules a delete runnable that deletes segment files
3. addSegment() calls loadSegment() and annouces it again
4. scheduled delete task executes and realizes it should not delete the segment files.
1 . addSegment () succesfully loads the segment and annouces it 2 . removeSegment () unannounces the segment and schedules a delete runnable that deletes segment files 3 . addSegment () calls loadSegment () and annouces it again 4 . scheduled delete task executes and realizes it should not delete the segment files .
@Test
  public void testSegmentLoading2() throws Exception
  {
    segmentLoadDropHandler.start();
    final DataSegment segment = makeSegment("test", "1", Intervals.of("P1d/2011-04-01"));
    segmentLoadDropHandler.addSegment(segment, DataSegmentChangeCallback.NOOP);
    Assert.assertTrue(segmentsAnnouncedByMe.contains(segment));
    segmentLoadDropHandler.removeSegment(segment, DataSegmentChangeCallback.NOOP);
    Assert.assertFalse(segmentsAnnouncedByMe.contains(segment));
    segmentLoadDropHandler.addSegment(segment, DataSegmentChangeCallback.NOOP);
    /*
       make sure the scheduled runnable that "deletes" segment files has been executed.
       Because another addSegment() call is executed, which removes the segment from segmentsToDelete field in
       ZkCoordinator, the scheduled runnable will not actually delete segment files.
     */
    for (Runnable runnable : scheduledRunnable) {
      runnable.run();
    }
    Assert.assertTrue(segmentsAnnouncedByMe.contains(segment));
    Assert.assertFalse("segment files shouldn't be deleted", segmentCacheManager.getSegmentsInTrash().contains(segment));
    segmentLoadDropHandler.stop();
  }
@ Test public void testSegmentLoading2 ( ) throws Exception { segmentLoadDropHandler . start ( ) ; final DataSegment segment = makeSegment ( "test" , "1" , Intervals . of ( "P1d/2011-04-01" ) ) ; segmentLoadDropHandler . addSegment ( segment , DataSegmentChangeCallback . NOOP ) ; Assert . assertTrue ( segmentsAnnouncedByMe . contains ( segment ) ) ; segmentLoadDropHandler . removeSegment ( segment , DataSegmentChangeCallback . NOOP ) ; Assert . assertFalse ( segmentsAnnouncedByMe . contains ( segment ) ) ; segmentLoadDropHandler . addSegment ( segment , DataSegmentChangeCallback . NOOP ) ; /*
       make sure the scheduled runnable that "deletes" segment files has been executed.
       Because another addSegment() call is executed, which removes the segment from segmentsToDelete field in
       ZkCoordinator, the scheduled runnable will not actually delete segment files.
     */ for ( Runnable runnable : scheduledRunnable ) { runnable . run ( ) ; } Assert . assertTrue ( segmentsAnnouncedByMe . contains ( segment ) ) ; Assert . assertFalse ( "segment files shouldn't be deleted" , segmentCacheManager . getSegmentsInTrash ( ) . contains ( segment ) ) ; segmentLoadDropHandler . stop ( ) ; }
Steps:
 1. addSegment() succesfully loads the segment and annouces it
 2. removeSegment() unannounces the segment and schedules a delete runnable that deletes segment files
 3. addSegment() calls loadSegment() and annouces it again
 4. scheduled delete task executes and realizes it should not delete the segment files.
Steps : 1 . addSegment () succesfully loads the segment and annouces it 2 . removeSegment () unannounces the segment and schedules a delete runnable that deletes segment files 3 . addSegment () calls loadSegment () and annouces it again 4 . scheduled delete task executes and realizes it should not delete the segment files .