server/src/test/java/org/apache/druid/server/coordination/SegmentLoadDropHandlerTest.java
/**
   * Steps:
   * 1. removeSegment() schedules a delete runnable that deletes segment files,
   * 2. addSegment() succesfully loads the segment and annouces it
   * 3. scheduled delete task executes and realizes it should not delete the segment files.
   */
1. removeSegment() schedules a delete runnable that deletes segment files,
2. addSegment() succesfully loads the segment and annouces it
3. scheduled delete task executes and realizes it should not delete the segment files.
1 . removeSegment () schedules a delete runnable that deletes segment files 2 . addSegment () succesfully loads the segment and annouces it 3 . scheduled delete task executes and realizes it should not delete the segment files .
@Test
  public void testSegmentLoading1() throws Exception
  {
    segmentLoadDropHandler.start();
    final DataSegment segment = makeSegment("test", "1", Intervals.of("P1d/2011-04-01"));
    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 testSegmentLoading1 ( ) throws Exception { segmentLoadDropHandler . start ( ) ; final DataSegment segment = makeSegment ( "test" , "1" , Intervals . of ( "P1d/2011-04-01" ) ) ; 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. removeSegment() schedules a delete runnable that deletes segment files,
 2. addSegment() succesfully loads the segment and annouces it
 3. scheduled delete task executes and realizes it should not delete the segment files.
Steps : 1 . removeSegment () schedules a delete runnable that deletes segment files 2 . addSegment () succesfully loads the segment and annouces it 3 . scheduled delete task executes and realizes it should not delete the segment files .