3535import org .apache .druid .query .expression .TestExprMacroTable ;
3636import org .apache .druid .segment .IndexIO ;
3737import org .apache .druid .segment .IndexSpec ;
38+ import org .apache .druid .segment .ReferenceCountedSegmentProvider ;
3839import org .apache .druid .segment .SegmentLazyLoadFailCallback ;
3940import org .apache .druid .segment .SegmentMapFunction ;
4041import org .apache .druid .segment .TestHelper ;
4546import org .apache .druid .segment .loading .LeastBytesUsedStorageLocationSelectorStrategy ;
4647import org .apache .druid .segment .loading .LocalDataSegmentPuller ;
4748import org .apache .druid .segment .loading .LocalLoadSpec ;
48- import org .apache .druid .segment .loading .SegmentCacheManager ;
4949import org .apache .druid .segment .loading .SegmentLoaderConfig ;
5050import org .apache .druid .segment .loading .SegmentLoadingException ;
5151import org .apache .druid .segment .loading .SegmentLocalCacheManager ;
@@ -90,7 +90,9 @@ public class SegmentManagerTest extends InitializedNullHandlingTest
9090 );
9191
9292 private ExecutorService executor ;
93+ private SegmentLocalCacheManager cacheManager ;
9394 private SegmentManager segmentManager ;
95+ private SegmentLocalCacheManager virtualCacheManager ;
9496 private SegmentManager virtualSegmentManager ;
9597
9698 @ Rule
@@ -160,7 +162,7 @@ public boolean isVirtualStorage()
160162 );
161163
162164 final List <StorageLocation > storageLocations = loaderConfig .toStorageLocations ();
163- final SegmentLocalCacheManager cacheManager = new SegmentLocalCacheManager (
165+ cacheManager = new SegmentLocalCacheManager (
164166 storageLocations ,
165167 loaderConfig ,
166168 new LeastBytesUsedStorageLocationSelectorStrategy (storageLocations ),
@@ -170,7 +172,7 @@ public boolean isVirtualStorage()
170172 segmentManager = new SegmentManager (cacheManager );
171173
172174 final List <StorageLocation > virtualStorageLocations = virtualLoaderConfig .toStorageLocations ();
173- final SegmentCacheManager virtualCacheManager = new SegmentLocalCacheManager (
175+ virtualCacheManager = new SegmentLocalCacheManager (
174176 virtualStorageLocations ,
175177 virtualLoaderConfig ,
176178 new LeastBytesUsedStorageLocationSelectorStrategy (virtualStorageLocations ),
@@ -238,8 +240,12 @@ public void testLoadBootstrapSegment() throws ExecutionException, InterruptedExc
238240 @ Test
239241 public void testDropSegment () throws SegmentLoadingException , ExecutionException , InterruptedException , IOException
240242 {
243+ List <ReferenceCountedSegmentProvider > referenceProviders = new ArrayList <>();
241244 for (DataSegment eachSegment : SEGMENTS ) {
242245 segmentManager .loadSegment (eachSegment );
246+ ReferenceCountedSegmentProvider refProvider = cacheManager .getSegmentReferenceProvider (eachSegment );
247+ referenceProviders .add (refProvider );
248+ Assert .assertFalse (refProvider .isClosed ());
243249 }
244250
245251 final List <Future <Void >> futures = ImmutableList .of (SEGMENTS .get (0 ), SEGMENTS .get (2 )).stream ()
@@ -260,6 +266,14 @@ public void testDropSegment() throws SegmentLoadingException, ExecutionException
260266 assertResult (
261267 ImmutableList .of (SEGMENTS .get (1 ), SEGMENTS .get (3 ), SEGMENTS .get (4 ))
262268 );
269+ for (int i = 0 ; i < SEGMENTS .size (); i ++) {
270+ Assert .assertEquals (0 , referenceProviders .get (i ).getNumReferences ());
271+ if (i == 0 || i == 2 ) {
272+ Assert .assertTrue (referenceProviders .get (i ).isClosed ());
273+ } else {
274+ Assert .assertFalse (referenceProviders .get (i ).isClosed ());
275+ }
276+ }
263277 }
264278
265279 private Void loadSegmentOrFail (DataSegment segment )
0 commit comments