use of io.airlift.units.Duration in project presto by prestodb.
the class TestStartTransactionTask method testStartTransactionIdleExpiration.
@Test
public void testStartTransactionIdleExpiration() throws Exception {
Session session = sessionBuilder().setClientTransactionSupport().build();
TransactionManager transactionManager = TransactionManager.create(new TransactionManagerConfig().setIdleTimeout(// Fast idle timeout
new Duration(1, TimeUnit.MICROSECONDS)).setIdleCheckInterval(new Duration(10, TimeUnit.MILLISECONDS)), scheduledExecutor, new CatalogManager(), executor);
AccessControl accessControl = new AccessControlManager(transactionManager);
QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "START TRANSACTION", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
assertFalse(stateMachine.getSession().getTransactionId().isPresent());
getFutureValue(new StartTransactionTask().execute(new StartTransaction(ImmutableList.of()), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
assertFalse(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
assertTrue(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
long start = System.nanoTime();
while (!transactionManager.getAllTransactionInfos().isEmpty()) {
if (Duration.nanosSince(start).toMillis() > 10_000) {
fail("Transaction did not expire in the allotted time");
}
TimeUnit.MILLISECONDS.sleep(10);
}
}
use of io.airlift.units.Duration in project presto by prestodb.
the class TestStateMachine method assertNoStateChange.
private void assertNoStateChange(StateMachine<State> stateMachine, StateChanger stateChange) throws Exception {
State initialState = stateMachine.get();
ListenableFuture<State> futureChange = stateMachine.getStateChange(initialState);
SettableFuture<State> listenerChange = SettableFuture.create();
stateMachine.addStateChangeListener(listenerChange::set);
Future<State> waitChange = executor.submit(() -> {
try {
stateMachine.waitForStateChange(initialState, new Duration(10, SECONDS));
return stateMachine.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Throwables.propagate(e);
}
});
// listeners should not be added if we are in a terminal state
boolean isTerminalState = stateMachine.isTerminalState(initialState);
if (isTerminalState) {
assertEquals(stateMachine.getStateChangeListeners(), ImmutableSet.of());
}
stateChange.run();
assertEquals(stateMachine.get(), initialState);
try {
// none of the futures should finish, but there is no way to prove that
// the state change is not happening (the changes happen in another thread),
// so we wait a short time for nothing to happen.
waitChange.get(50, MILLISECONDS);
} catch (InterruptedException e) {
throw e;
} catch (Exception ignored) {
}
// the state change listeners will trigger if the state machine is in a terminal state
// this is to prevent waiting for state changes that will never occur
assertEquals(futureChange.isDone(), isTerminalState);
futureChange.cancel(true);
assertEquals(listenerChange.isDone(), isTerminalState);
listenerChange.cancel(true);
if (isTerminalState) {
// in low CPU test environments it can take longer than 50ms for the waitChange future to complete
tryGetFutureValue(waitChange, 1, SECONDS);
}
assertEquals(waitChange.isDone(), isTerminalState);
waitChange.cancel(true);
}
use of io.airlift.units.Duration in project presto by prestodb.
the class TestTaskManagerConfig method testExplicitPropertyMappings.
@Test
public void testExplicitPropertyMappings() {
Map<String, String> properties = new ImmutableMap.Builder<String, String>().put("task.initial-splits-per-node", "1").put("task.split-concurrency-adjustment-interval", "1s").put("task.status-refresh-max-wait", "2s").put("task.info-update-interval", "2s").put("task.verbose-stats", "true").put("task.cpu-timer-enabled", "false").put("task.max-index-memory", "512MB").put("task.share-index-loading", "true").put("task.max-partial-aggregation-memory", "32MB").put("task.max-worker-threads", "3").put("task.min-drivers", "2").put("task.info.max-age", "22m").put("task.client.timeout", "10s").put("sink.max-buffer-size", "42MB").put("driver.max-page-partitioning-buffer-size", "40MB").put("task.writer-count", "4").put("task.concurrency", "8").put("task.http-response-threads", "4").put("task.http-timeout-threads", "10").put("task.task-notification-threads", "13").build();
TaskManagerConfig expected = new TaskManagerConfig().setInitialSplitsPerNode(1).setSplitConcurrencyAdjustmentInterval(new Duration(1, TimeUnit.SECONDS)).setStatusRefreshMaxWait(new Duration(2, TimeUnit.SECONDS)).setInfoUpdateInterval(new Duration(2, TimeUnit.SECONDS)).setVerboseStats(true).setTaskCpuTimerEnabled(false).setMaxIndexMemoryUsage(new DataSize(512, Unit.MEGABYTE)).setShareIndexLoading(true).setMaxPartialAggregationMemoryUsage(new DataSize(32, Unit.MEGABYTE)).setMaxWorkerThreads(3).setMinDrivers(2).setInfoMaxAge(new Duration(22, TimeUnit.MINUTES)).setClientTimeout(new Duration(10, TimeUnit.SECONDS)).setSinkMaxBufferSize(new DataSize(42, Unit.MEGABYTE)).setMaxPagePartitioningBufferSize(new DataSize(40, Unit.MEGABYTE)).setWriterCount(4).setTaskConcurrency(8).setHttpResponseThreads(4).setHttpTimeoutThreads(10).setTaskNotificationThreads(13);
assertFullMapping(properties, expected);
}
use of io.airlift.units.Duration in project presto by prestodb.
the class TestResourceGroups method testHardCpuLimit.
@Test(timeOut = 10_000)
public void testHardCpuLimit() {
RootInternalResourceGroup root = new RootInternalResourceGroup("root", (group, export) -> {
}, directExecutor());
root.setSoftMemoryLimit(new DataSize(1, BYTE));
root.setHardCpuLimit(new Duration(1, SECONDS));
root.setCpuQuotaGenerationMillisPerSecond(2000);
root.setMaxQueuedQueries(1);
root.setMaxRunningQueries(1);
MockQueryExecution query1 = new MockQueryExecution(1, "query_id", 1, new Duration(2, SECONDS));
root.run(query1);
assertEquals(query1.getState(), RUNNING);
MockQueryExecution query2 = new MockQueryExecution(0);
root.run(query2);
assertEquals(query2.getState(), QUEUED);
query1.complete();
root.processQueuedQueries();
assertEquals(query2.getState(), QUEUED);
root.generateCpuQuota(2);
root.processQueuedQueries();
assertEquals(query2.getState(), RUNNING);
}
use of io.airlift.units.Duration in project presto by prestodb.
the class TestTransactionManager method testExpiration.
@Test
public void testExpiration() throws Exception {
try (IdleCheckExecutor executor = new IdleCheckExecutor()) {
TransactionManager transactionManager = TransactionManager.create(new TransactionManagerConfig().setIdleTimeout(new Duration(1, TimeUnit.MILLISECONDS)).setIdleCheckInterval(new Duration(5, TimeUnit.MILLISECONDS)), executor.getExecutor(), new CatalogManager(), finishingExecutor);
TransactionId transactionId = transactionManager.beginTransaction(false);
assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
TransactionInfo transactionInfo = transactionManager.getTransactionInfo(transactionId);
assertFalse(transactionInfo.isAutoCommitContext());
assertTrue(transactionInfo.getConnectorIds().isEmpty());
assertFalse(transactionInfo.getWrittenConnectorId().isPresent());
transactionManager.trySetInactive(transactionId);
TimeUnit.MILLISECONDS.sleep(100);
assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
}
Aggregations