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));
}
}
}
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));
}
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());
}
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());
}
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());
}
Aggregations