use of io.airlift.testing.TestingTicker in project presto by prestodb.
the class TestTaskExecutor method test.
@Test(invocationCount = 100)
public void test() throws Exception {
TestingTicker ticker = new TestingTicker();
TaskExecutor taskExecutor = new TaskExecutor(4, 8, ticker);
taskExecutor.start();
ticker.increment(20, MILLISECONDS);
try {
TaskId taskId = new TaskId("test", 0, 0);
TaskHandle taskHandle = taskExecutor.addTask(taskId, () -> 0, 10, new Duration(1, MILLISECONDS));
Phaser beginPhase = new Phaser();
beginPhase.register();
Phaser verificationComplete = new Phaser();
verificationComplete.register();
// add two jobs
TestingJob driver1 = new TestingJob(beginPhase, verificationComplete, 10);
ListenableFuture<?> future1 = getOnlyElement(taskExecutor.enqueueSplits(taskHandle, true, ImmutableList.of(driver1)));
TestingJob driver2 = new TestingJob(beginPhase, verificationComplete, 10);
ListenableFuture<?> future2 = getOnlyElement(taskExecutor.enqueueSplits(taskHandle, true, ImmutableList.of(driver2)));
assertEquals(driver1.getCompletedPhases(), 0);
assertEquals(driver2.getCompletedPhases(), 0);
// verify worker have arrived but haven't processed yet
beginPhase.arriveAndAwaitAdvance();
assertEquals(driver1.getCompletedPhases(), 0);
assertEquals(driver2.getCompletedPhases(), 0);
ticker.increment(10, MILLISECONDS);
assertEquals(taskExecutor.getMaxActiveSplitTime(), 10);
verificationComplete.arriveAndAwaitAdvance();
// advance one phase and verify
beginPhase.arriveAndAwaitAdvance();
assertEquals(driver1.getCompletedPhases(), 1);
assertEquals(driver2.getCompletedPhases(), 1);
verificationComplete.arriveAndAwaitAdvance();
// add one more job
TestingJob driver3 = new TestingJob(beginPhase, verificationComplete, 10);
ListenableFuture<?> future3 = getOnlyElement(taskExecutor.enqueueSplits(taskHandle, false, ImmutableList.of(driver3)));
// advance one phase and verify
beginPhase.arriveAndAwaitAdvance();
assertEquals(driver1.getCompletedPhases(), 2);
assertEquals(driver2.getCompletedPhases(), 2);
assertEquals(driver3.getCompletedPhases(), 0);
verificationComplete.arriveAndAwaitAdvance();
// advance to the end of the first two task and verify
beginPhase.arriveAndAwaitAdvance();
for (int i = 0; i < 7; i++) {
verificationComplete.arriveAndAwaitAdvance();
beginPhase.arriveAndAwaitAdvance();
assertEquals(beginPhase.getPhase(), verificationComplete.getPhase() + 1);
}
assertEquals(driver1.getCompletedPhases(), 10);
assertEquals(driver2.getCompletedPhases(), 10);
assertEquals(driver3.getCompletedPhases(), 8);
future1.get(1, TimeUnit.SECONDS);
future2.get(1, TimeUnit.SECONDS);
verificationComplete.arriveAndAwaitAdvance();
// advance two more times and verify
beginPhase.arriveAndAwaitAdvance();
verificationComplete.arriveAndAwaitAdvance();
beginPhase.arriveAndAwaitAdvance();
assertEquals(driver1.getCompletedPhases(), 10);
assertEquals(driver2.getCompletedPhases(), 10);
assertEquals(driver3.getCompletedPhases(), 10);
future3.get(1, TimeUnit.SECONDS);
verificationComplete.arriveAndAwaitAdvance();
assertEquals(driver1.getFirstPhase(), 0);
assertEquals(driver2.getFirstPhase(), 0);
assertEquals(driver3.getFirstPhase(), 2);
assertEquals(driver1.getLastPhase(), 10);
assertEquals(driver2.getLastPhase(), 10);
assertEquals(driver3.getLastPhase(), 12);
// no splits remaining
ticker.increment(30, MILLISECONDS);
assertEquals(taskExecutor.getMaxActiveSplitTime(), 0);
} finally {
taskExecutor.stop();
}
}
use of io.airlift.testing.TestingTicker in project presto by prestodb.
the class TestHttpPageBufferClient method testExceptionFromResponseHandler.
@Test
public void testExceptionFromResponseHandler() throws Exception {
TestingTicker ticker = new TestingTicker();
AtomicReference<Duration> tickerIncrement = new AtomicReference<>(new Duration(0, TimeUnit.SECONDS));
TestingHttpClient.Processor processor = (input) -> {
Duration delta = tickerIncrement.get();
ticker.increment(delta.toMillis(), TimeUnit.MILLISECONDS);
throw new RuntimeException("Foo");
};
CyclicBarrier requestComplete = new CyclicBarrier(2);
TestingClientCallback callback = new TestingClientCallback(requestComplete);
URI location = URI.create("http://localhost:8080");
HttpPageBufferClient client = new HttpPageBufferClient(new TestingHttpClient(processor, executor), new DataSize(10, Unit.MEGABYTE), new Duration(1, TimeUnit.MINUTES), new Duration(1, TimeUnit.MINUTES), location, callback, executor, ticker);
assertStatus(client, location, "queued", 0, 0, 0, 0, "not scheduled");
// request processor will throw exception, verify the request is marked a completed
// this starts the error stopwatch
client.scheduleRequest();
requestComplete.await(10, TimeUnit.SECONDS);
assertEquals(callback.getPages().size(), 0);
assertEquals(callback.getCompletedRequests(), 1);
assertEquals(callback.getFinishedBuffers(), 0);
assertEquals(callback.getFailedBuffers(), 0);
assertStatus(client, location, "queued", 0, 1, 1, 1, "not scheduled");
// advance time forward, but not enough to fail the client
tickerIncrement.set(new Duration(30, TimeUnit.SECONDS));
// verify that the client has not failed
client.scheduleRequest();
requestComplete.await(10, TimeUnit.SECONDS);
assertEquals(callback.getPages().size(), 0);
assertEquals(callback.getCompletedRequests(), 2);
assertEquals(callback.getFinishedBuffers(), 0);
assertEquals(callback.getFailedBuffers(), 0);
assertStatus(client, location, "queued", 0, 2, 2, 2, "not scheduled");
// advance time forward beyond the minimum error duration
tickerIncrement.set(new Duration(31, TimeUnit.SECONDS));
// verify that the client has failed
client.scheduleRequest();
requestComplete.await(10, TimeUnit.SECONDS);
assertEquals(callback.getPages().size(), 0);
assertEquals(callback.getCompletedRequests(), 3);
assertEquals(callback.getFinishedBuffers(), 0);
assertEquals(callback.getFailedBuffers(), 1);
assertInstanceOf(callback.getFailure(), PageTransportTimeoutException.class);
assertContains(callback.getFailure().getMessage(), WORKER_NODE_ERROR + " (http://localhost:8080/0 - 3 failures, time since last success 61.00s)");
assertStatus(client, location, "queued", 0, 3, 3, 3, "not scheduled");
}
use of io.airlift.testing.TestingTicker in project airlift by airlift.
the class TestDecayTDigest method testDecayBeyondRescaleThreshold.
@Test
public void testDecayBeyondRescaleThreshold() {
TestingTicker ticker = new TestingTicker();
double decayFactor = 0.1;
DecayTDigest digest = new DecayTDigest(100, decayFactor, ticker);
// the weight of this value should decay to 1 after time advances by deltaTime
digest.add(1, Math.exp(decayFactor * RESCALE_THRESHOLD_SECONDS));
// advancing the time by this amount will trigger a rescale
ticker.increment(RESCALE_THRESHOLD_SECONDS, TimeUnit.SECONDS);
assertThat(digest.getCount()).isCloseTo(1.0, Offset.offset(ZERO_WEIGHT_THRESHOLD));
digest.add(2);
assertThat(digest.getCount()).isCloseTo(2.0, Offset.offset(ZERO_WEIGHT_THRESHOLD));
}
use of io.airlift.testing.TestingTicker in project airlift by airlift.
the class TestQuantileDigest method testMinMax.
@Test
public void testMinMax() throws Exception {
QuantileDigest digest = new QuantileDigest(0.01, 0, new TestingTicker());
int from = 500;
int to = 700;
addRange(digest, from, to + 1);
assertEquals(digest.getMin(), from);
assertEquals(digest.getMax(), to);
}
use of io.airlift.testing.TestingTicker in project airlift by airlift.
the class TestQuantileDigest method testCompression.
@Test
public void testCompression() throws Exception {
QuantileDigest digest = new QuantileDigest(1, 0, new TestingTicker());
for (int loop = 0; loop < 2; ++loop) {
addRange(digest, 0, 15);
digest.compress();
digest.validate();
}
}
Aggregations