Search in sources :

Example 1 with CacheTestSegmentLoader

use of org.apache.druid.segment.loading.CacheTestSegmentLoader in project druid by druid-io.

the class SegmentLoadDropHandlerTest method setUp.

@Before
public void setUp() throws IOException {
    try {
        testStorageLocation = new TestStorageLocation(temporaryFolder);
        infoDir = testStorageLocation.getInfoDir();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    locations = Collections.singletonList(testStorageLocation.toStorageLocationConfig());
    scheduledRunnable = new ArrayList<>();
    segmentCacheManager = new CacheTestSegmentCacheManager();
    segmentLoader = new CacheTestSegmentLoader();
    segmentManager = new SegmentManager(segmentLoader);
    segmentsAnnouncedByMe = new ConcurrentSkipListSet<>();
    announceCount = new AtomicInteger(0);
    announcer = new DataSegmentAnnouncer() {

        @Override
        public void announceSegment(DataSegment segment) {
            segmentsAnnouncedByMe.add(segment);
            announceCount.incrementAndGet();
        }

        @Override
        public void unannounceSegment(DataSegment segment) {
            segmentsAnnouncedByMe.remove(segment);
            announceCount.decrementAndGet();
        }

        @Override
        public void announceSegments(Iterable<DataSegment> segments) {
            for (DataSegment segment : segments) {
                segmentsAnnouncedByMe.add(segment);
            }
            announceCount.addAndGet(Iterables.size(segments));
        }

        @Override
        public void unannounceSegments(Iterable<DataSegment> segments) {
            for (DataSegment segment : segments) {
                segmentsAnnouncedByMe.remove(segment);
            }
            announceCount.addAndGet(-Iterables.size(segments));
        }
    };
    segmentLoaderConfig = new SegmentLoaderConfig() {

        @Override
        public File getInfoDir() {
            return testStorageLocation.getInfoDir();
        }

        @Override
        public int getNumLoadingThreads() {
            return 5;
        }

        @Override
        public int getAnnounceIntervalMillis() {
            return 50;
        }

        @Override
        public List<StorageLocationConfig> getLocations() {
            return locations;
        }

        @Override
        public int getDropSegmentDelayMillis() {
            return 0;
        }
    };
    noAnnouncerSegmentLoaderConfig = new SegmentLoaderConfig() {

        @Override
        public File getInfoDir() {
            return testStorageLocation.getInfoDir();
        }

        @Override
        public int getNumLoadingThreads() {
            return 5;
        }

        @Override
        public int getAnnounceIntervalMillis() {
            return 0;
        }

        @Override
        public List<StorageLocationConfig> getLocations() {
            return locations;
        }

        @Override
        public int getDropSegmentDelayMillis() {
            return 0;
        }
    };
    segmentLoaderConfigNoLocations = new SegmentLoaderConfig() {

        @Override
        public int getNumLoadingThreads() {
            return 5;
        }

        @Override
        public int getAnnounceIntervalMillis() {
            return 50;
        }

        @Override
        public int getDropSegmentDelayMillis() {
            return 0;
        }
    };
    scheduledExecutorFactory = new ScheduledExecutorFactory() {

        @Override
        public ScheduledExecutorService create(int corePoolSize, String nameFormat) {
            /*
               Override normal behavoir by adding the runnable to a list so that you can make sure
               all the shceduled runnables are executed by explicitly calling run() on each item in the list
             */
            return new ScheduledThreadPoolExecutor(corePoolSize, Execs.makeThreadFactory(nameFormat)) {

                @Override
                public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
                    scheduledRunnable.add(command);
                    return null;
                }
            };
        }
    };
    segmentLoadDropHandler = new SegmentLoadDropHandler(jsonMapper, segmentLoaderConfig, announcer, Mockito.mock(DataSegmentServerAnnouncer.class), segmentManager, segmentCacheManager, scheduledExecutorFactory.create(5, "SegmentLoadDropHandlerTest-[%d]"), new ServerTypeConfig(ServerType.HISTORICAL));
}
Also used : SegmentManager(org.apache.druid.server.SegmentManager) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) DataSegment(org.apache.druid.timeline.DataSegment) TimeUnit(java.util.concurrent.TimeUnit) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) SegmentLoaderConfig(org.apache.druid.segment.loading.SegmentLoaderConfig) CacheTestSegmentCacheManager(org.apache.druid.segment.loading.CacheTestSegmentCacheManager) CacheTestSegmentLoader(org.apache.druid.segment.loading.CacheTestSegmentLoader) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) IOException(java.io.IOException) ScheduledFuture(java.util.concurrent.ScheduledFuture) ScheduledExecutorFactory(org.apache.druid.java.util.common.concurrent.ScheduledExecutorFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File) ServerTypeConfig(org.apache.druid.guice.ServerTypeConfig) Before(org.junit.Before)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ServerTypeConfig (org.apache.druid.guice.ServerTypeConfig)1 ScheduledExecutorFactory (org.apache.druid.java.util.common.concurrent.ScheduledExecutorFactory)1 CacheTestSegmentCacheManager (org.apache.druid.segment.loading.CacheTestSegmentCacheManager)1 CacheTestSegmentLoader (org.apache.druid.segment.loading.CacheTestSegmentLoader)1 SegmentLoaderConfig (org.apache.druid.segment.loading.SegmentLoaderConfig)1 SegmentManager (org.apache.druid.server.SegmentManager)1 DataSegment (org.apache.druid.timeline.DataSegment)1 Before (org.junit.Before)1