Search in sources :

Example 51 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project incubator-gobblin by apache.

the class ValidationJob method processPartitionedTable.

/**
 * Validate all {@link Partition}s for a {@link Table} if it was updated recently by checking if its update time
 * lies between between maxLookBackTime and skipRecentThanTime window.
 * @param hiveDataset {@link HiveDataset} containing {@link Table} and {@link Partition} info.
 * @param client {@link IMetaStoreClient} to query Hive.
 * @throws IOException Issue in validating {@link HiveDataset}
 */
private void processPartitionedTable(ConvertibleHiveDataset hiveDataset, AutoReturnableObject<IMetaStoreClient> client) throws IOException {
    // Get partitions for the table
    List<Partition> sourcePartitions = HiveUtils.getPartitions(client.get(), hiveDataset.getTable(), Optional.<String>absent());
    for (final String format : hiveDataset.getDestFormats()) {
        Optional<ConvertibleHiveDataset.ConversionConfig> conversionConfigOptional = hiveDataset.getConversionConfigForFormat(format);
        if (conversionConfigOptional.isPresent()) {
            // Get conversion config
            ConvertibleHiveDataset.ConversionConfig conversionConfig = conversionConfigOptional.get();
            String orcTableName = conversionConfig.getDestinationTableName();
            String orcTableDatabase = conversionConfig.getDestinationDbName();
            Pair<Optional<org.apache.hadoop.hive.metastore.api.Table>, Optional<List<Partition>>> destinationMeta = HiveConverterUtils.getDestinationTableMeta(orcTableDatabase, orcTableName, this.props);
            // Validate each partition
            for (final Partition sourcePartition : sourcePartitions) {
                try {
                    final long updateTime = this.updateProvider.getUpdateTime(sourcePartition);
                    if (shouldValidate(sourcePartition)) {
                        log.info(String.format("Validating partition: %s", sourcePartition.getCompleteName()));
                        // Generate validation queries
                        final List<String> countValidationQueries = HiveValidationQueryGenerator.generateCountValidationQueries(hiveDataset, Optional.of(sourcePartition), conversionConfig);
                        final List<String> dataValidationQueries = Lists.newArrayList(HiveValidationQueryGenerator.generateDataValidationQuery(hiveDataset.getTable().getTableName(), hiveDataset.getTable().getDbName(), destinationMeta.getKey().get(), Optional.of(sourcePartition), this.isNestedORC));
                        this.futures.add(this.exec.submit(new Callable<Void>() {

                            @Override
                            public Void call() throws Exception {
                                // Execute validation queries
                                log.debug(String.format("Going to execute count validation queries queries: %s for format: %s " + "and partition %s", countValidationQueries, format, sourcePartition.getCompleteName()));
                                List<Long> rowCounts = ValidationJob.this.getValidationOutputFromHive(countValidationQueries);
                                log.debug(String.format("Going to execute data validation queries: %s for format: %s and partition %s", dataValidationQueries, format, sourcePartition.getCompleteName()));
                                List<Long> rowDataValidatedCount = ValidationJob.this.getValidationOutputFromHive(dataValidationQueries);
                                // Validate and populate report
                                validateAndPopulateReport(sourcePartition.getCompleteName(), updateTime, rowCounts, rowDataValidatedCount);
                                return null;
                            }
                        }));
                    } else {
                        log.debug(String.format("Not validating partition: %s as updateTime: %s is not in range of max look back: %s " + "and skip recent than: %s", sourcePartition.getCompleteName(), updateTime, this.maxLookBackTime, this.skipRecentThanTime));
                    }
                } catch (UncheckedExecutionException e) {
                    log.warn(String.format("Not validating partition: %s %s", sourcePartition.getCompleteName(), e.getMessage()));
                } catch (UpdateNotFoundException e) {
                    log.warn(String.format("Not validating partition: %s as update time was not found. %s", sourcePartition.getCompleteName(), e.getMessage()));
                }
            }
        } else {
            log.info(String.format("No conversion config found for format %s. Ignoring data validation", format));
        }
    }
}
Also used : UpdateNotFoundException(org.apache.gobblin.data.management.conversion.hive.provider.UpdateNotFoundException) Partition(org.apache.hadoop.hive.ql.metadata.Partition) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Optional(com.google.common.base.Optional) ConvertibleHiveDataset(org.apache.gobblin.data.management.conversion.hive.dataset.ConvertibleHiveDataset) Callable(java.util.concurrent.Callable)

Example 52 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project crate by crate.

the class SQLExceptionsTest method testUnwrap.

@Test
public void testUnwrap() {
    String msg = "cannot cast";
    Throwable t = new UncheckedExecutionException(new ExecutionException(new ClassCastException(msg)));
    Throwable unwrapped = SQLExceptions.unwrap(t);
    assertThat(unwrapped, instanceOf(ClassCastException.class));
    assertThat(unwrapped.getMessage(), is(msg));
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Test(org.junit.Test)

Example 53 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project caffeine by ben-manes.

the class CacheLoadingTest method testLoadUncheckedException.

public void testLoadUncheckedException() throws ExecutionException {
    Exception e = new RuntimeException();
    CacheLoader<Object, Object> loader = exceptionLoader(e);
    LoadingCache<Object, Object> cache = CaffeinatedGuava.build(Caffeine.newBuilder().recordStats().executor(MoreExecutors.directExecutor()), loader);
    CacheStats stats = cache.stats();
    assertEquals(0, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(0, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
    try {
        cache.get(new Object());
        fail();
    } catch (UncheckedExecutionException expected) {
        assertSame(e, expected.getCause());
    }
    stats = cache.stats();
    assertEquals(1, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(1, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
    try {
        cache.getUnchecked(new Object());
        fail();
    } catch (UncheckedExecutionException expected) {
        assertSame(e, expected.getCause());
    }
    stats = cache.stats();
    assertEquals(2, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(2, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
    cache.refresh(new Object());
    checkLoggedCause(e);
    stats = cache.stats();
    assertEquals(2, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(3, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
    Exception callableException = new RuntimeException();
    try {
        cache.get(new Object(), throwing(callableException));
        fail();
    } catch (UncheckedExecutionException expected) {
        assertSame(callableException, expected.getCause());
    }
    stats = cache.stats();
    assertEquals(3, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(4, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
    try {
        cache.getAll(asList(new Object()));
        fail();
    } catch (UncheckedExecutionException expected) {
        assertSame(e, expected.getCause());
    }
    stats = cache.stats();
    assertEquals(4, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(5, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) InvalidCacheLoadException(com.google.common.cache.CacheLoader.InvalidCacheLoadException) ExecutionException(java.util.concurrent.ExecutionException)

Example 54 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project caffeine by ben-manes.

the class CacheLoadingTest method testBulkLoadUncheckedException.

public void testBulkLoadUncheckedException() throws ExecutionException {
    Exception e = new RuntimeException();
    CacheLoader<Object, Object> loader = exceptionLoader(e);
    LoadingCache<Object, Object> cache = CaffeinatedGuava.build(Caffeine.newBuilder().recordStats(), bulkLoader(loader));
    CacheStats stats = cache.stats();
    assertEquals(0, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(0, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
    try {
        cache.getAll(asList(new Object()));
        fail();
    } catch (UncheckedExecutionException expected) {
        assertSame(e, expected.getCause());
    }
    stats = cache.stats();
    assertEquals(1, stats.missCount());
    assertEquals(0, stats.loadSuccessCount());
    assertEquals(1, stats.loadExceptionCount());
    assertEquals(0, stats.hitCount());
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) InvalidCacheLoadException(com.google.common.cache.CacheLoader.InvalidCacheLoadException) ExecutionException(java.util.concurrent.ExecutionException)

Example 55 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project caffeine by ben-manes.

the class CacheLoadingTest method testConcurrentLoadingUncheckedException.

/**
   * On a concurrent computation that throws an unchecked exception, all threads should get the
   * (wrapped) exception, with the loader called only once. The result should not be cached (a later
   * request should call the loader again).
   */
private static void testConcurrentLoadingUncheckedException(Caffeine<Object, Object> builder) throws InterruptedException {
    int count = 10;
    final AtomicInteger callCount = new AtomicInteger();
    final CountDownLatch startSignal = new CountDownLatch(count + 1);
    final RuntimeException e = new RuntimeException();
    LoadingCache<String, String> cache = CaffeinatedGuava.build(builder, new CacheLoader<String, String>() {

        @Override
        public String load(String key) {
            callCount.incrementAndGet();
            Uninterruptibles.awaitUninterruptibly(startSignal);
            throw e;
        }
    });
    List<Object> result = doConcurrentGet(cache, "bar", count, startSignal);
    assertEquals(count, callCount.get());
    for (int i = 0; i < count; i++) {
        // doConcurrentGet alternates between calling getUnchecked and calling get, but an unchecked
        // exception thrown by the loader is always wrapped as an UncheckedExecutionException.
        assertTrue(result.get(i) instanceof UncheckedExecutionException);
        assertSame(e, ((UncheckedExecutionException) result.get(i)).getCause());
    }
    // subsequent calls should call the loader again, not get the old exception
    try {
        cache.getUnchecked("bar");
        fail();
    } catch (UncheckedExecutionException expected) {
    }
    assertEquals(count + 1, callCount.get());
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)101 ExecutionException (java.util.concurrent.ExecutionException)60 IOException (java.io.IOException)31 InvalidCacheLoadException (com.google.common.cache.CacheLoader.InvalidCacheLoadException)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 Test (org.junit.Test)9 Map (java.util.Map)8 ArrayList (java.util.ArrayList)7 File (java.io.File)6 TimeoutException (java.util.concurrent.TimeoutException)6 Stopwatch (com.google.common.base.Stopwatch)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 HashMap (java.util.HashMap)5 List (java.util.List)5 NoSuchElementException (java.util.NoSuchElementException)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 InputStream (java.io.InputStream)4 Callable (java.util.concurrent.Callable)4 SirixIOException (org.sirix.exception.SirixIOException)4 TypeSignature (com.facebook.presto.common.type.TypeSignature)3