use of java.util.LongSummaryStatistics in project j2objc by google.
the class LongSummaryStatisticsTest method test_empty.
public void test_empty() {
LongSummaryStatistics lss = new LongSummaryStatistics();
assertEquals(0, lss.getCount());
assertEquals(0, lss.getSum());
assertEquals(0.0d, lss.getAverage());
assertEquals(Long.MAX_VALUE, lss.getMin());
assertEquals(Long.MIN_VALUE, lss.getMax());
}
use of java.util.LongSummaryStatistics in project j2objc by google.
the class LongSummaryStatisticsTest method test_accept.
public void test_accept() {
LongSummaryStatistics lss = new LongSummaryStatistics();
// For long values
lss.accept(100L);
assertEquals(1, lss.getCount());
assertEquals(100L, lss.getSum());
lss.accept(250L);
assertEquals(2, lss.getCount());
assertEquals(350L, lss.getSum());
// for int values
lss.accept(50);
assertEquals(3, lss.getCount());
assertEquals(400L, lss.getSum());
lss.accept(200);
assertEquals(4, lss.getCount());
assertEquals(600L, lss.getSum());
}
use of java.util.LongSummaryStatistics in project j2objc by google.
the class LongSummaryStatisticsTest method test_getSum.
public void test_getSum() {
LongSummaryStatistics lss1 = getLongSummaryStatisticsData1();
assertEquals(104L, lss1.getSum());
}
use of java.util.LongSummaryStatistics in project j2objc by google.
the class LongSummaryStatisticsTest method test_getAverage.
public void test_getAverage() {
LongSummaryStatistics lss1 = getLongSummaryStatisticsData1();
assertEquals(14.857142, lss1.getAverage(), 1E-6);
}
use of java.util.LongSummaryStatistics in project hive by apache.
the class Initiator method foundCurrentOrFailedCompactions.
private boolean foundCurrentOrFailedCompactions(ShowCompactResponse compactions, CompactionInfo ci) throws MetaException {
if (compactions.getCompacts() == null) {
return false;
}
List<ShowCompactResponseElement> filteredElements = compactions.getCompacts().stream().filter(e -> e.getDbname().equals(ci.dbname) && e.getTablename().equals(ci.tableName) && (e.getPartitionname() == null && ci.partName == null || e.getPartitionname().equals(ci.partName))).collect(Collectors.toList());
// Figure out if there are any currently running compactions on the same table or partition.
if (filteredElements.stream().anyMatch(e -> TxnStore.WORKING_RESPONSE.equals(e.getState()) || TxnStore.INITIATED_RESPONSE.equals(e.getState()))) {
LOG.info("Found currently initiated or working compaction for " + ci.getFullPartitionName() + " so we will not initiate another compaction");
return true;
}
// Check if there is already sufficient number of consecutive failures for this table/partition
// so that no new automatic compactions needs to be scheduled.
int failedThreshold = MetastoreConf.getIntVar(conf, MetastoreConf.ConfVars.COMPACTOR_INITIATOR_FAILED_THRESHOLD);
LongSummaryStatistics failedStats = filteredElements.stream().filter(e -> TxnStore.SUCCEEDED_RESPONSE.equals(e.getState()) || TxnStore.FAILED_RESPONSE.equals(e.getState())).sorted(Comparator.comparingLong(ShowCompactResponseElement::getId).reversed()).limit(failedThreshold).filter(e -> TxnStore.FAILED_RESPONSE.equals(e.getState())).collect(Collectors.summarizingLong(ShowCompactResponseElement::getEnqueueTime));
// If the last attempt was too long ago, ignore the failed threshold and try compaction again
long retryTime = MetastoreConf.getTimeVar(conf, MetastoreConf.ConfVars.COMPACTOR_INITIATOR_FAILED_RETRY_TIME, TimeUnit.MILLISECONDS);
boolean needsRetry = (retryTime > 0) && (failedStats.getMax() + retryTime < System.currentTimeMillis());
if (failedStats.getCount() == failedThreshold && !needsRetry) {
LOG.warn("Will not initiate compaction for " + ci.getFullPartitionName() + " since last " + MetastoreConf.ConfVars.COMPACTOR_INITIATOR_FAILED_THRESHOLD + " attempts to compact it failed.");
ci.errorMessage = "Compaction is not initiated since last " + MetastoreConf.ConfVars.COMPACTOR_INITIATOR_FAILED_THRESHOLD + " consecutive compaction attempts failed)";
txnHandler.markFailed(ci);
return true;
}
return false;
}
Aggregations