Esempio n. 1
0
  private <T> void assertQueryable(
      QueryGranularity granularity,
      String dataSource,
      Interval interval,
      List<Pair<String, Interval>> expected) {
    Iterator<Pair<String, Interval>> expectedIter = expected.iterator();
    final List<Interval> intervals = Arrays.asList(interval);
    final SearchQuery query =
        Druids.newSearchQueryBuilder()
            .dataSource(dataSource)
            .intervals(intervals)
            .granularity(granularity)
            .limit(10000)
            .query("wow")
            .build();
    QueryRunner<Result<SearchResultValue>> runner =
        serverManager.getQueryRunnerForIntervals(query, intervals);
    final Sequence<Result<SearchResultValue>> seq = runner.run(query);
    Sequences.toList(seq, Lists.<Result<SearchResultValue>>newArrayList());
    Iterator<SegmentForTesting> adaptersIter = factory.getAdapters().iterator();

    while (expectedIter.hasNext() && adaptersIter.hasNext()) {
      Pair<String, Interval> expectedVals = expectedIter.next();
      SegmentForTesting value = adaptersIter.next();

      Assert.assertEquals(expectedVals.lhs, value.getVersion());
      Assert.assertEquals(expectedVals.rhs, value.getInterval());
    }

    Assert.assertFalse(expectedIter.hasNext());
    Assert.assertFalse(adaptersIter.hasNext());

    factory.clearAdapters();
  }
Esempio n. 2
0
 private void waitForTestVerificationAndCleanup(Future future) {
   try {
     queryNotifyLatch.await(25, TimeUnit.MILLISECONDS);
     queryWaitYieldLatch.countDown();
     queryWaitLatch.countDown();
     future.get();
     factory.clearAdapters();
   } catch (Exception e) {
     throw Throwables.propagate(e);
   }
 }
Esempio n. 3
0
  @Test
  public void testReferenceCounting() throws Exception {
    loadQueryable("test", "3", new Interval("2011-04-04/2011-04-05"));

    Future future =
        assertQueryable(
            QueryGranularity.DAY,
            "test",
            new Interval("2011-04-04/2011-04-06"),
            ImmutableList.<Pair<String, Interval>>of(
                new Pair<String, Interval>("3", new Interval("2011-04-04/2011-04-05"))));

    queryNotifyLatch.await(25, TimeUnit.MILLISECONDS);

    Assert.assertEquals(1, factory.getSegmentReferences().size());

    for (ReferenceCountingSegment referenceCountingSegment : factory.getSegmentReferences()) {
      Assert.assertEquals(1, referenceCountingSegment.getNumReferences());
    }

    queryWaitYieldLatch.countDown();

    Assert.assertTrue(factory.getAdapters().size() == 1);

    for (SegmentForTesting segmentForTesting : factory.getAdapters()) {
      Assert.assertFalse(segmentForTesting.isClosed());
    }

    queryWaitLatch.countDown();
    future.get();

    dropQueryable("test", "3", new Interval("2011-04-04/2011-04-05"));

    for (SegmentForTesting segmentForTesting : factory.getAdapters()) {
      Assert.assertTrue(segmentForTesting.isClosed());
    }
  }