use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Stopwatch in project beam by apache.
the class ShardReadersPoolTest method shouldInterruptKinesisReadingAndStopShortly.
@Test
public void shouldInterruptKinesisReadingAndStopShortly() throws Exception {
when(firstIterator.readNextBatch()).thenAnswer((Answer<List<KinesisRecord>>) invocation -> {
Thread.sleep(TIMEOUT_IN_MILLIS / 2);
return Collections.emptyList();
});
shardReadersPool.start();
Stopwatch stopwatch = Stopwatch.createStarted();
shardReadersPool.stop();
assertThat(stopwatch.elapsed(TimeUnit.MILLISECONDS)).isLessThan(TIMEOUT_IN_MILLIS);
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Stopwatch in project beam by apache.
the class ShardReadersPoolTest method shouldInterruptKinesisReadingAndStopShortly.
@Test
public void shouldInterruptKinesisReadingAndStopShortly() throws TransientKinesisException, KinesisShardClosedException {
when(firstIterator.readNextBatch()).thenAnswer((Answer<List<KinesisRecord>>) invocation -> {
Thread.sleep(TIMEOUT_IN_MILLIS / 2);
return Collections.emptyList();
});
shardReadersPool.start();
Stopwatch stopwatch = Stopwatch.createStarted();
shardReadersPool.stop();
assertThat(stopwatch.elapsed(TimeUnit.MILLISECONDS)).isLessThan(TIMEOUT_IN_MILLIS);
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Stopwatch in project beam by apache.
the class ShardReadersPoolTest method shouldInterruptPuttingRecordsToQueueAndStopShortly.
@Test
public void shouldInterruptPuttingRecordsToQueueAndStopShortly() throws TransientKinesisException, KinesisShardClosedException {
when(firstIterator.readNextBatch()).thenReturn(ImmutableList.of(a, b, c));
KinesisReaderCheckpoint checkpoint = new KinesisReaderCheckpoint(ImmutableList.of(firstCheckpoint, secondCheckpoint));
WatermarkPolicyFactory watermarkPolicyFactory = WatermarkPolicyFactory.withArrivalTimePolicy();
RateLimitPolicyFactory rateLimitPolicyFactory = RateLimitPolicyFactory.withoutLimiter();
ShardReadersPool shardReadersPool = new ShardReadersPool(kinesis, checkpoint, watermarkPolicyFactory, rateLimitPolicyFactory, 2);
shardReadersPool.start();
Stopwatch stopwatch = Stopwatch.createStarted();
shardReadersPool.stop();
assertThat(stopwatch.elapsed(TimeUnit.MILLISECONDS)).isLessThan(TIMEOUT_IN_MILLIS);
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Stopwatch in project beam by apache.
the class ReaderCacheTest method testReaderCacheExpiration.
@Test
public void testReaderCacheExpiration() throws IOException, InterruptedException {
// Make sure cache closes the reader soon after expiry (as long as readerCache is accessed).
Duration cacheDuration = Duration.millis(10);
// Create a cache with short expiry period.
ReaderCache readerCache = new ReaderCache(cacheDuration, Runnable::run);
readerCache.cacheReader(WindmillComputationKey.create(C_ID, KEY_1, SHARDING_KEY), 1, 0, reader1);
readerCache.cacheReader(WindmillComputationKey.create(C_ID, KEY_2, SHARDING_KEY), 2, 0, reader2);
Stopwatch stopwatch = Stopwatch.createStarted();
while (stopwatch.elapsed(TimeUnit.MILLISECONDS) < 2 * cacheDuration.getMillis()) {
Thread.sleep(1);
}
// Trigger clean up with a lookup, non-existing key is ok.
readerCache.acquireReader(WindmillComputationKey.create(C_ID, KEY_3, SHARDING_KEY), 3, 0);
verify(reader1).close();
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Stopwatch in project beam by apache.
the class GcsFileSystem method rename.
@Override
protected void rename(List<GcsResourceId> srcResourceIds, List<GcsResourceId> destResourceIds, MoveOptions... moveOptions) throws IOException {
Stopwatch stopwatch = Stopwatch.createStarted();
options.getGcsUtil().rename(toFilenames(srcResourceIds), toFilenames(destResourceIds), moveOptions);
stopwatch.stop();
if (options.getGcsPerformanceMetrics()) {
numRenames.inc(srcResourceIds.size());
renameTimeMsec.inc(stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
}
Aggregations