use of io.airlift.testing.TestingTicker in project presto by prestodb.
the class TestShardCleaner method setup.
@BeforeMethod
public void setup() throws Exception {
dbi = new DBI("jdbc:h2:mem:test" + System.nanoTime());
dummyHandle = dbi.open();
createTablesWithRetry(dbi);
temporary = createTempDir();
File directory = new File(temporary, "data");
storageService = new FileStorageService(directory);
storageService.start();
File backupDirectory = new File(temporary, "backup");
backupStore = new FileBackupStore(backupDirectory);
((FileBackupStore) backupStore).start();
ticker = new TestingTicker();
ShardCleanerConfig config = new ShardCleanerConfig();
cleaner = new ShardCleaner(new DaoSupplier<>(dbi, H2ShardDao.class), "node1", true, ticker, storageService, Optional.of(backupStore), config.getMaxTransactionAge(), config.getTransactionCleanerInterval(), config.getLocalCleanerInterval(), config.getLocalCleanTime(), config.getBackupCleanerInterval(), config.getBackupCleanTime(), config.getBackupDeletionThreads(), config.getMaxCompletedTransactionAge());
}
use of io.airlift.testing.TestingTicker in project presto by prestodb.
the class TestAssignmentLimiter method testLimiter.
@Test
public void testLimiter() {
TestingTicker ticker = new TestingTicker();
AssignmentLimiter limiter = new AssignmentLimiter(ImmutableSet::of, ticker, new Duration(5, MINUTES), new Duration(10, MINUTES));
// 4:00
assertCheckFails(limiter, "A", RAPTOR_REASSIGNMENT_DELAY);
// 4:01
ticker.increment(1, MINUTES);
assertCheckFails(limiter, "A", RAPTOR_REASSIGNMENT_DELAY);
assertCheckFails(limiter, "B", RAPTOR_REASSIGNMENT_DELAY);
// 4:05
ticker.increment(4, MINUTES);
limiter.checkAssignFrom("A");
assertCheckFails(limiter, "B", RAPTOR_REASSIGNMENT_DELAY);
// 4:06
ticker.increment(1, MINUTES);
assertCheckFails(limiter, "B", RAPTOR_REASSIGNMENT_THROTTLE);
assertCheckFails(limiter, "C", RAPTOR_REASSIGNMENT_DELAY);
// 4:14
ticker.increment(8, MINUTES);
assertCheckFails(limiter, "B", RAPTOR_REASSIGNMENT_THROTTLE);
assertCheckFails(limiter, "C", RAPTOR_REASSIGNMENT_THROTTLE);
// 4:15
ticker.increment(1, MINUTES);
limiter.checkAssignFrom("B");
assertCheckFails(limiter, "C", RAPTOR_REASSIGNMENT_THROTTLE);
// 4:24
ticker.increment(9, MINUTES);
assertCheckFails(limiter, "C", RAPTOR_REASSIGNMENT_THROTTLE);
// 4:25
ticker.increment(1, MINUTES);
limiter.checkAssignFrom("A");
// 4:30
ticker.increment(5, MINUTES);
limiter.checkAssignFrom("A");
limiter.checkAssignFrom("B");
limiter.checkAssignFrom("C");
}
use of io.airlift.testing.TestingTicker in project presto by prestodb.
the class TestDatabaseShardManager method testBucketAssignments.
@Test
public void testBucketAssignments() {
Node node1 = createTestingNode();
Node node2 = createTestingNode();
Node node3 = createTestingNode();
TestingTicker ticker = new TestingTicker();
MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
int bucketCount = 13;
long distributionId = metadataDao.insertDistribution(null, "test", bucketCount);
Set<Node> originalNodes = ImmutableSet.of(node1, node2);
ShardManager shardManager = createShardManager(dbi, () -> originalNodes, ticker);
shardManager.createBuckets(distributionId, bucketCount);
Map<Integer, String> assignments = shardManager.getBucketAssignments(distributionId);
assertEquals(assignments.size(), bucketCount);
assertEquals(ImmutableSet.copyOf(assignments.values()), nodeIds(originalNodes));
Set<Node> newNodes = ImmutableSet.of(node1, node3);
shardManager = createShardManager(dbi, () -> newNodes, ticker);
try {
shardManager.getBucketAssignments(distributionId);
fail("expected exception");
} catch (PrestoException e) {
assertEquals(e.getErrorCode(), SERVER_STARTING_UP.toErrorCode());
}
ticker.increment(2, DAYS);
assignments = shardManager.getBucketAssignments(distributionId);
assertEquals(assignments.size(), bucketCount);
assertEquals(ImmutableSet.copyOf(assignments.values()), nodeIds(newNodes));
}
use of io.airlift.testing.TestingTicker in project presto by prestodb.
the class TestBackoff method testMaxFailureInterval.
@Test
public void testMaxFailureInterval() {
TestingTicker ticker = new TestingTicker();
Backoff backoff = new Backoff(new Duration(5, SECONDS), new Duration(15, SECONDS), ticker, new Duration(10, MILLISECONDS));
ticker.increment(10, MICROSECONDS);
ticker.increment(6, SECONDS);
assertTrue(backoff.failure());
assertEquals(backoff.getFailureCount(), 1);
assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 6);
backoff.success();
// Check that we will tolerate failures for longer than the min, if the query has been running that long
ticker.increment(6, SECONDS);
assertFalse(backoff.failure());
assertEquals(backoff.getFailureCount(), 1);
assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 6);
ticker.increment(1, SECONDS);
// Check that we won't tolerate failures for longer than the query has been running
assertTrue(backoff.failure());
assertEquals(backoff.getFailureCount(), 2);
assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 7);
ticker.increment(20, SECONDS);
backoff.success();
ticker.increment(20, SECONDS);
// Check that we won't tolerate failures for longer than the max, even if the query has been running for a long time
assertTrue(backoff.failure());
assertEquals(backoff.getFailureCount(), 1);
assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 20);
}
use of io.airlift.testing.TestingTicker in project presto by prestodb.
the class TestBackoff method testStartRequest.
@Test
public void testStartRequest() {
TestingTicker ticker = new TestingTicker();
Backoff backoff = new Backoff(new Duration(15, SECONDS), new Duration(15, SECONDS), ticker, new Duration(10, MILLISECONDS));
ticker.increment(10, MICROSECONDS);
assertEquals(backoff.getFailureCount(), 0);
assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 0);
ticker.increment(14, SECONDS);
backoff.startRequest();
ticker.increment(14, SECONDS);
assertFalse(backoff.failure());
assertEquals(backoff.getFailureCount(), 1);
assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 28);
ticker.increment(1, SECONDS);
assertTrue(backoff.failure());
assertEquals(backoff.getFailureCount(), 2);
assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 29);
}
Aggregations