Search in sources :

Example 1 with DataSegmentChangeRequestAndStatus

use of org.apache.druid.server.coordination.SegmentLoadDropHandler.DataSegmentChangeRequestAndStatus in project druid by druid-io.

the class SegmentLoadDropHandlerTest method testProcessBatchDuplicateLoadRequestsWhenFirstRequestFailsSecondRequestShouldSucceed.

@Test(timeout = 60_000L)
public void testProcessBatchDuplicateLoadRequestsWhenFirstRequestFailsSecondRequestShouldSucceed() throws Exception {
    final SegmentManager segmentManager = Mockito.mock(SegmentManager.class);
    Mockito.when(segmentManager.loadSegment(ArgumentMatchers.any(), ArgumentMatchers.anyBoolean(), ArgumentMatchers.any())).thenThrow(new RuntimeException("segment loading failure test")).thenReturn(true);
    final SegmentLoadDropHandler segmentLoadDropHandler = new SegmentLoadDropHandler(jsonMapper, segmentLoaderConfig, announcer, Mockito.mock(DataSegmentServerAnnouncer.class), segmentManager, segmentCacheManager, scheduledExecutorFactory.create(5, "SegmentLoadDropHandlerTest-[%d]"), new ServerTypeConfig(ServerType.HISTORICAL));
    segmentLoadDropHandler.start();
    DataSegment segment1 = makeSegment("batchtest1", "1", Intervals.of("P1d/2011-04-01"));
    List<DataSegmentChangeRequest> batch = ImmutableList.of(new SegmentChangeRequestLoad(segment1));
    ListenableFuture<List<DataSegmentChangeRequestAndStatus>> future = segmentLoadDropHandler.processBatch(batch);
    for (Runnable runnable : scheduledRunnable) {
        runnable.run();
    }
    List<DataSegmentChangeRequestAndStatus> result = future.get();
    Assert.assertEquals(STATE.FAILED, result.get(0).getStatus().getState());
    future = segmentLoadDropHandler.processBatch(batch);
    for (Runnable runnable : scheduledRunnable) {
        runnable.run();
    }
    result = future.get();
    Assert.assertEquals(STATE.SUCCESS, result.get(0).getStatus().getState());
    segmentLoadDropHandler.stop();
}
Also used : SegmentManager(org.apache.druid.server.SegmentManager) DataSegment(org.apache.druid.timeline.DataSegment) DataSegmentChangeRequestAndStatus(org.apache.druid.server.coordination.SegmentLoadDropHandler.DataSegmentChangeRequestAndStatus) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ServerTypeConfig(org.apache.druid.guice.ServerTypeConfig) Test(org.junit.Test)

Example 2 with DataSegmentChangeRequestAndStatus

use of org.apache.druid.server.coordination.SegmentLoadDropHandler.DataSegmentChangeRequestAndStatus in project druid by druid-io.

the class SegmentLoadDropHandlerTest method testProcessBatchLoadDropLoadSequenceForSameSegment.

@Test(timeout = 60_000L)
public void testProcessBatchLoadDropLoadSequenceForSameSegment() throws Exception {
    final SegmentManager segmentManager = Mockito.mock(SegmentManager.class);
    Mockito.when(segmentManager.loadSegment(ArgumentMatchers.any(), ArgumentMatchers.anyBoolean(), ArgumentMatchers.any())).thenReturn(true);
    Mockito.doNothing().when(segmentManager).dropSegment(ArgumentMatchers.any());
    final SegmentLoadDropHandler segmentLoadDropHandler = new SegmentLoadDropHandler(jsonMapper, noAnnouncerSegmentLoaderConfig, announcer, Mockito.mock(DataSegmentServerAnnouncer.class), segmentManager, segmentCacheManager, scheduledExecutorFactory.create(5, "SegmentLoadDropHandlerTest-[%d]"), new ServerTypeConfig(ServerType.HISTORICAL));
    segmentLoadDropHandler.start();
    DataSegment segment1 = makeSegment("batchtest1", "1", Intervals.of("P1d/2011-04-01"));
    List<DataSegmentChangeRequest> batch = ImmutableList.of(new SegmentChangeRequestLoad(segment1));
    // load the segment
    ListenableFuture<List<DataSegmentChangeRequestAndStatus>> future = segmentLoadDropHandler.processBatch(batch);
    for (Runnable runnable : scheduledRunnable) {
        runnable.run();
    }
    List<DataSegmentChangeRequestAndStatus> result = future.get();
    Assert.assertEquals(STATE.SUCCESS, result.get(0).getStatus().getState());
    scheduledRunnable.clear();
    // drop the segment
    batch = ImmutableList.of(new SegmentChangeRequestDrop(segment1));
    future = segmentLoadDropHandler.processBatch(batch);
    for (Runnable runnable : scheduledRunnable) {
        runnable.run();
    }
    result = future.get();
    Assert.assertEquals(STATE.SUCCESS, result.get(0).getStatus().getState());
    scheduledRunnable.clear();
    // check invocations after a load-drop sequence
    Mockito.verify(segmentManager, Mockito.times(1)).loadSegment(ArgumentMatchers.any(), ArgumentMatchers.anyBoolean(), ArgumentMatchers.any());
    Mockito.verify(segmentManager, Mockito.times(1)).dropSegment(ArgumentMatchers.any());
    // try to reload the segment - this should be a no-op since it might be the case that this is the first load client
    // with this request, we'll forget about the success of the load request
    batch = ImmutableList.of(new SegmentChangeRequestLoad(segment1));
    future = segmentLoadDropHandler.processBatch(batch);
    Assert.assertEquals(scheduledRunnable.size(), 0);
    result = future.get();
    Assert.assertEquals(STATE.SUCCESS, result.get(0).getStatus().getState());
    // check invocations - should stay the same
    Mockito.verify(segmentManager, Mockito.times(1)).loadSegment(ArgumentMatchers.any(), ArgumentMatchers.anyBoolean(), ArgumentMatchers.any());
    Mockito.verify(segmentManager, Mockito.times(1)).dropSegment(ArgumentMatchers.any());
    // try to reload the segment - this time the loader will know that is a fresh request to load
    // so, the segment manager will be asked to load
    batch = ImmutableList.of(new SegmentChangeRequestLoad(segment1));
    future = segmentLoadDropHandler.processBatch(batch);
    for (Runnable runnable : scheduledRunnable) {
        runnable.run();
    }
    result = future.get();
    Assert.assertEquals(STATE.SUCCESS, result.get(0).getStatus().getState());
    scheduledRunnable.clear();
    // check invocations - the load segment counter should bump up
    Mockito.verify(segmentManager, Mockito.times(2)).loadSegment(ArgumentMatchers.any(), ArgumentMatchers.anyBoolean(), ArgumentMatchers.any());
    Mockito.verify(segmentManager, Mockito.times(1)).dropSegment(ArgumentMatchers.any());
    segmentLoadDropHandler.stop();
}
Also used : SegmentManager(org.apache.druid.server.SegmentManager) DataSegment(org.apache.druid.timeline.DataSegment) DataSegmentChangeRequestAndStatus(org.apache.druid.server.coordination.SegmentLoadDropHandler.DataSegmentChangeRequestAndStatus) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ServerTypeConfig(org.apache.druid.guice.ServerTypeConfig) Test(org.junit.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ServerTypeConfig (org.apache.druid.guice.ServerTypeConfig)2 SegmentManager (org.apache.druid.server.SegmentManager)2 DataSegmentChangeRequestAndStatus (org.apache.druid.server.coordination.SegmentLoadDropHandler.DataSegmentChangeRequestAndStatus)2 DataSegment (org.apache.druid.timeline.DataSegment)2 Test (org.junit.Test)2