Search in sources :

Example 21 with ISE

use of io.druid.java.util.common.ISE in project druid by druid-io.

the class ServiceAnnouncerTest method testServiceAnnouncement.

@Test
public void testServiceAnnouncement() throws Exception {
    curator.start();
    curator.blockUntilConnected();
    List<String> serviceNames = ImmutableList.of("druid/overlord", "druid/coordinator", "druid/firehose/tranquility_test-50-0000-0000");
    final ServiceDiscovery serviceDiscovery = createAndAnnounceServices(serviceNames);
    Assert.assertTrue(Iterators.all(serviceNames.iterator(), new Predicate<String>() {

        @Override
        public boolean apply(String input) {
            try {
                return serviceDiscovery.queryForInstances(input.replaceAll("/", ":")).size() == 1;
            } catch (Exception e) {
                throw new ISE("Something went wrong while finding instance with name [%s] in Service Discovery", input);
            }
        }
    }));
}
Also used : ISE(io.druid.java.util.common.ISE) ServiceDiscovery(org.apache.curator.x.discovery.ServiceDiscovery) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Example 22 with ISE

use of io.druid.java.util.common.ISE in project druid by druid-io.

the class BatchServerInventoryViewTest method waitForUpdateEvents.

private void waitForUpdateEvents(int count) throws Exception {
    final Timing forWaitingTiming = timing.forWaiting();
    Stopwatch stopwatch = Stopwatch.createStarted();
    while (inventoryUpdateCounter.get() != count) {
        Thread.sleep(100);
        if (stopwatch.elapsed(TimeUnit.MILLISECONDS) > forWaitingTiming.milliseconds()) {
            throw new ISE("BatchServerInventoryView is not updating counter expected[%d] value[%d]", count, inventoryUpdateCounter.get());
        }
    }
}
Also used : Stopwatch(com.google.common.base.Stopwatch) ISE(io.druid.java.util.common.ISE) Timing(org.apache.curator.test.Timing)

Example 23 with ISE

use of io.druid.java.util.common.ISE in project druid by druid-io.

the class NamedIntrospectionHandler method testConcurrencyStartStopChaos.

@Test(timeout = 10000L)
public void testConcurrencyStartStopChaos() throws Exception {
    // Don't want to exercise snapshot here
    final LookupReferencesManager manager = new LookupReferencesManager(new LookupConfig(null), mapper);
    final Runnable chaosStart = new Runnable() {

        @Override
        public void run() {
            manager.start();
        }
    };
    final Runnable chaosStop = new Runnable() {

        @Override
        public void run() {
            manager.stop();
        }
    };
    final CountDownLatch runnableStartBarrier = new CountDownLatch(1);
    final Random random = new Random(478137498L);
    final int numUpdates = 100000;
    final int numNamespaces = 100;
    final CountDownLatch runnablesFinishedBarrier = new CountDownLatch(numUpdates);
    final List<Runnable> runnables = new ArrayList<>(numUpdates);
    final Map<String, Integer> maxNumber = new HashMap<>();
    for (int i = 1; i <= numUpdates; ++i) {
        final boolean shouldStart = random.nextInt(10) == 1;
        final boolean shouldClose = random.nextInt(10) == 1;
        final String name = Integer.toString(random.nextInt(numNamespaces));
        final int position = i;
        final LookupExtractorFactory lookupExtractorFactory = new LookupExtractorFactory() {

            @Override
            public boolean start() {
                return shouldStart;
            }

            @Override
            public boolean close() {
                return shouldClose;
            }

            @Override
            public boolean replaces(@Nullable LookupExtractorFactory other) {
                if (other == null) {
                    return true;
                }
                final NamedIntrospectionHandler introspectionHandler = (NamedIntrospectionHandler) other.getIntrospectHandler();
                return position > introspectionHandler.position;
            }

            @Nullable
            @Override
            public LookupIntrospectHandler getIntrospectHandler() {
                return new NamedIntrospectionHandler(position);
            }

            @Override
            public String toString() {
                return String.format("TestFactroy position %d", position);
            }

            @Override
            public LookupExtractor get() {
                return null;
            }
        };
        if (random.nextFloat() < 0.001) {
            if (random.nextBoolean()) {
                runnables.add(chaosStart);
            } else {
                runnables.add(chaosStop);
            }
        } else {
            if (shouldStart && (!maxNumber.containsKey(name) || maxNumber.get(name) < position)) {
                maxNumber.put(name, position);
            }
            runnables.add(new LookupUpdatingRunnable(name, lookupExtractorFactory, runnableStartBarrier, manager));
        }
    }
    ////// Add some CHAOS!
    Collections.shuffle(runnables, random);
    final Runnable decrementFinished = new Runnable() {

        @Override
        public void run() {
            runnablesFinishedBarrier.countDown();
        }
    };
    for (Runnable runnable : runnables) {
        executorService.submit(runnable).addListener(decrementFinished, MoreExecutors.sameThreadExecutor());
    }
    runnableStartBarrier.countDown();
    do {
        for (String name : maxNumber.keySet()) {
            final LookupExtractorFactory factory;
            try {
                factory = manager.get(name);
            } catch (ISE e) {
                continue;
            }
            if (null == factory) {
                continue;
            }
            final NamedIntrospectionHandler introspectionHandler = (NamedIntrospectionHandler) factory.getIntrospectHandler();
            Assert.assertTrue(introspectionHandler.position >= 0);
        }
    } while (runnablesFinishedBarrier.getCount() > 0);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Random(java.util.Random) ISE(io.druid.java.util.common.ISE) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Example 24 with ISE

use of io.druid.java.util.common.ISE in project druid by druid-io.

the class RealtimeManagerTest method testRunV2.

@Test
public void testRunV2() throws Exception {
    realtimeManager2.start();
    Stopwatch stopwatch = Stopwatch.createStarted();
    while (realtimeManager2.getMetrics("testV2").processed() != 1) {
        Thread.sleep(100);
        if (stopwatch.elapsed(TimeUnit.MILLISECONDS) > 1000) {
            throw new ISE("Realtime manager should have completed processing 2 events!");
        }
    }
    Assert.assertEquals(1, realtimeManager2.getMetrics("testV2").processed());
    Assert.assertEquals(1, realtimeManager2.getMetrics("testV2").thrownAway());
    Assert.assertEquals(2, realtimeManager2.getMetrics("testV2").unparseable());
    Assert.assertTrue(plumber2.isStartedJob());
    Assert.assertTrue(plumber2.isFinishedJob());
    Assert.assertEquals(0, plumber2.getPersistCount());
}
Also used : Stopwatch(com.google.common.base.Stopwatch) ISE(io.druid.java.util.common.ISE) GroupByQueryRunnerTest(io.druid.query.groupby.GroupByQueryRunnerTest) Test(org.junit.Test)

Example 25 with ISE

use of io.druid.java.util.common.ISE in project druid by druid-io.

the class RowSignature method getRelDataType.

/**
   * Returns a Calcite RelDataType corresponding to this row signature.
   *
   * @param typeFactory factory for type construction
   *
   * @return Calcite row type
   */
public RelDataType getRelDataType(final RelDataTypeFactory typeFactory) {
    final RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
    for (final String columnName : columnNames) {
        final ValueType columnType = getColumnType(columnName);
        final RelDataType type;
        if (Column.TIME_COLUMN_NAME.equals(columnName)) {
            type = typeFactory.createSqlType(SqlTypeName.TIMESTAMP);
        } else {
            switch(columnType) {
                case STRING:
                    // Note that there is no attempt here to handle multi-value in any special way. Maybe one day...
                    type = typeFactory.createTypeWithCharsetAndCollation(typeFactory.createSqlType(SqlTypeName.VARCHAR), Calcites.defaultCharset(), SqlCollation.IMPLICIT);
                    break;
                case LONG:
                    type = typeFactory.createSqlType(SqlTypeName.BIGINT);
                    break;
                case FLOAT:
                    type = typeFactory.createSqlType(SqlTypeName.FLOAT);
                    break;
                case COMPLEX:
                    // Loses information about exactly what kind of complex column this is.
                    type = typeFactory.createSqlType(SqlTypeName.OTHER);
                    break;
                default:
                    throw new ISE("WTF?! valueType[%s] not translatable?", columnType);
            }
        }
        builder.add(columnName, type);
    }
    return builder.build();
}
Also used : ValueType(io.druid.segment.column.ValueType) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) ISE(io.druid.java.util.common.ISE)

Aggregations

ISE (io.druid.java.util.common.ISE)158 IOException (java.io.IOException)37 Map (java.util.Map)23 Test (org.junit.Test)21 File (java.io.File)20 List (java.util.List)19 DateTime (org.joda.time.DateTime)18 ArrayList (java.util.ArrayList)17 DataSegment (io.druid.timeline.DataSegment)15 Interval (org.joda.time.Interval)15 Function (com.google.common.base.Function)14 TimeoutException (java.util.concurrent.TimeoutException)12 IAE (io.druid.java.util.common.IAE)10 HashMap (java.util.HashMap)10 ExecutionException (java.util.concurrent.ExecutionException)10 Stopwatch (com.google.common.base.Stopwatch)9 DimensionSpec (io.druid.query.dimension.DimensionSpec)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)8 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)8