Search in sources :

Example 11 with Duration

use of org.joda.time.Duration in project druid by druid-io.

the class LoadQueuePeonTest method testFailAssign.

@Test
public void testFailAssign() throws Exception {
    final DataSegment segment = dataSegmentWithInterval("2014-10-22T00:00:00Z/P1D");
    final CountDownLatch loadRequestSignal = new CountDownLatch(1);
    final CountDownLatch segmentLoadedSignal = new CountDownLatch(1);
    loadQueuePeon = new LoadQueuePeon(curator, LOAD_QUEUE_PATH, jsonMapper, Execs.scheduledSingleThreaded("test_load_queue_peon_scheduled-%d"), Execs.singleThreaded("test_load_queue_peon-%d"), // set time-out to 1 ms so that LoadQueuePeon will fail the assignment quickly
    new TestDruidCoordinatorConfig(null, null, null, new Duration(1), null, null, 10, null, false, false, new Duration("PT1s")));
    loadQueuePeon.start();
    loadQueueCache.getListenable().addListener(new PathChildrenCacheListener() {

        @Override
        public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
            if (event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED) {
                loadRequestSignal.countDown();
            }
        }
    });
    loadQueueCache.start();
    loadQueuePeon.loadSegment(segment, new LoadPeonCallback() {

        @Override
        public void execute() {
            segmentLoadedSignal.countDown();
        }
    });
    String loadRequestPath = ZKPaths.makePath(LOAD_QUEUE_PATH, segment.getIdentifier());
    Assert.assertTrue(timing.forWaiting().awaitLatch(loadRequestSignal));
    Assert.assertNotNull(curator.checkExists().forPath(loadRequestPath));
    Assert.assertEquals(segment, ((SegmentChangeRequestLoad) jsonMapper.readValue(curator.getData().decompressed().forPath(loadRequestPath), DataSegmentChangeRequest.class)).getSegment());
    // don't simulate completion of load request here
    Assert.assertTrue(timing.forWaiting().awaitLatch(segmentLoadedSignal));
    Assert.assertEquals(0, loadQueuePeon.getSegmentsToLoad().size());
    Assert.assertEquals(0L, loadQueuePeon.getLoadQueueSize());
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) PathChildrenCacheEvent(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent) Duration(org.joda.time.Duration) CountDownLatch(java.util.concurrent.CountDownLatch) DataSegment(io.druid.timeline.DataSegment) Test(org.junit.Test)

Example 12 with Duration

use of org.joda.time.Duration in project druid by druid-io.

the class DruidCoordinatorSegmentKillerTest method testFindIntervalForKillTask.

private void testFindIntervalForKillTask(List<Interval> segmentManagerResult, Interval expected) {
    MetadataSegmentManager segmentManager = EasyMock.createMock(MetadataSegmentManager.class);
    EasyMock.expect(segmentManager.getUnusedSegmentIntervals(EasyMock.anyString(), EasyMock.anyObject(Interval.class), EasyMock.anyInt())).andReturn(segmentManagerResult);
    EasyMock.replay(segmentManager);
    IndexingServiceClient indexingServiceClient = EasyMock.createMock(IndexingServiceClient.class);
    DruidCoordinatorSegmentKiller coordinatorSegmentKiller = new DruidCoordinatorSegmentKiller(segmentManager, indexingServiceClient, new TestDruidCoordinatorConfig(null, null, Duration.parse("PT76400S"), new Duration(1), Duration.parse("PT86400S"), Duration.parse("PT86400S"), 1000, null, false, false, Duration.ZERO));
    Assert.assertEquals(expected, coordinatorSegmentKiller.findIntervalForKillTask("test", 10000));
}
Also used : IndexingServiceClient(io.druid.client.indexing.IndexingServiceClient) MetadataSegmentManager(io.druid.metadata.MetadataSegmentManager) TestDruidCoordinatorConfig(io.druid.server.coordinator.TestDruidCoordinatorConfig) Duration(org.joda.time.Duration) Interval(org.joda.time.Interval)

Example 13 with Duration

use of org.joda.time.Duration in project druid by druid-io.

the class LookupCoordinatorManagerConfigTest method testConfigsTakeOverrides.

@Test
public void testConfigsTakeOverrides() {
    final Duration funnyDuration = Duration.standardDays(100);
    final LookupCoordinatorManagerConfig config = new LookupCoordinatorManagerConfig();
    config.setDeleteAllTimeout(funnyDuration);
    config.setHostDeleteTimeout(funnyDuration);
    config.setHostUpdateTimeout(funnyDuration);
    config.setUpdateAllTimeout(funnyDuration);
    config.setPeriod(funnyDuration.getMillis());
    config.setThreadPoolSize(1200);
    Assert.assertEquals(funnyDuration, config.getDeleteAllTimeout());
    Assert.assertEquals(funnyDuration, config.getHostDeleteTimeout());
    Assert.assertEquals(funnyDuration, config.getHostUpdateTimeout());
    Assert.assertEquals(funnyDuration, config.getUpdateAllTimeout());
    Assert.assertEquals(funnyDuration.getMillis(), config.getPeriod());
    Assert.assertEquals(1200, config.getThreadPoolSize());
}
Also used : Duration(org.joda.time.Duration) Test(org.junit.Test)

Example 14 with Duration

use of org.joda.time.Duration in project druid by druid-io.

the class LookupCoordinatorManagerTest method testUpdateAllOnHostException.

@Test
public void testUpdateAllOnHostException() throws Exception {
    final HttpResponseHandler<InputStream, InputStream> responseHandler = EasyMock.createStrictMock(HttpResponseHandler.class);
    final URL url = LookupCoordinatorManager.getLookupsURL(HostAndPort.fromString("localhost"));
    final SettableFuture<InputStream> future = SettableFuture.create();
    future.set(new ByteArrayInputStream(new byte[0]));
    EasyMock.expect(client.go(EasyMock.<Request>anyObject(), EasyMock.<SequenceInputStreamResponseHandler>anyObject(), EasyMock.<Duration>anyObject())).andReturn(future).once();
    EasyMock.replay(client, responseHandler);
    final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {

        @Override
        HttpResponseHandler<InputStream, InputStream> makeResponseHandler(final AtomicInteger returnCode, final AtomicReference<String> reasonString) {
            returnCode.set(500);
            reasonString.set("");
            return responseHandler;
        }
    };
    expectedException.expect(new BaseMatcher<Throwable>() {

        @Override
        public boolean matches(Object o) {
            return o instanceof IOException && ((IOException) o).getMessage().startsWith("Bad update request");
        }

        @Override
        public void describeTo(Description description) {
        }
    });
    try {
        manager.updateAllOnHost(url, SINGLE_LOOKUP_MAP);
    } finally {
        EasyMock.verify(client, responseHandler);
    }
}
Also used : Description(org.hamcrest.Description) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(com.metamx.http.client.Request) Duration(org.joda.time.Duration) AtomicReference(java.util.concurrent.atomic.AtomicReference) SequenceInputStreamResponseHandler(com.metamx.http.client.response.SequenceInputStreamResponseHandler) IOException(java.io.IOException) URL(java.net.URL) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 15 with Duration

use of org.joda.time.Duration in project druid by druid-io.

the class LookupCoordinatorManagerTest method testUpdateAllOnHostFailsWithFailedThings.

@Test
public void testUpdateAllOnHostFailsWithFailedThings() throws Exception {
    final HttpResponseHandler<InputStream, InputStream> responseHandler = EasyMock.createStrictMock(HttpResponseHandler.class);
    final String failedLookup = "failedLookup";
    final URL url = LookupCoordinatorManager.getLookupsURL(HostAndPort.fromString("localhost"));
    final SettableFuture<InputStream> future = SettableFuture.create();
    future.set(new ByteArrayInputStream(StringUtils.toUtf8(mapper.writeValueAsString(ImmutableMap.of("status", "accepted", LookupModule.FAILED_UPDATES_KEY, ImmutableMap.of(failedLookup, ImmutableMap.of()))))));
    EasyMock.expect(client.go(EasyMock.<Request>anyObject(), EasyMock.<SequenceInputStreamResponseHandler>anyObject(), EasyMock.<Duration>anyObject())).andReturn(future).once();
    EasyMock.replay(client, responseHandler);
    final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {

        @Override
        HttpResponseHandler<InputStream, InputStream> makeResponseHandler(final AtomicInteger returnCode, final AtomicReference<String> reasonString) {
            returnCode.set(200);
            reasonString.set("");
            return responseHandler;
        }
    };
    expectedException.expectMessage("Lookups failed to update: [\"" + failedLookup + "\"]");
    try {
        manager.updateAllOnHost(url, SINGLE_LOOKUP_MAP);
    } finally {
        EasyMock.verify(client, responseHandler);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(com.metamx.http.client.Request) Duration(org.joda.time.Duration) AtomicReference(java.util.concurrent.atomic.AtomicReference) SequenceInputStreamResponseHandler(com.metamx.http.client.response.SequenceInputStreamResponseHandler) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Duration (org.joda.time.Duration)272 Test (org.junit.Test)148 Instant (org.joda.time.Instant)66 DateTime (org.joda.time.DateTime)32 Period (org.joda.time.Period)27 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)24 TestDruidCoordinatorConfig (org.apache.druid.server.coordinator.TestDruidCoordinatorConfig)22 HashMap (java.util.HashMap)18 IOException (java.io.IOException)17 Category (org.junit.experimental.categories.Category)16 ArrayList (java.util.ArrayList)15 Map (java.util.Map)15 KV (org.apache.beam.sdk.values.KV)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 IndexSpec (org.apache.druid.segment.IndexSpec)12 Set (java.util.Set)10 GlobalWindows (org.apache.beam.sdk.transforms.windowing.GlobalWindows)10 DynamicPartitionsSpec (org.apache.druid.indexer.partitions.DynamicPartitionsSpec)10 Interval (org.joda.time.Interval)10 Request (com.metamx.http.client.Request)9