Search in sources :

Example 6 with Stopwatch

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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Duration(org.joda.time.Duration) RunWith(org.junit.runner.RunWith) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Mockito.timeout(org.mockito.Mockito.timeout) Answer(org.mockito.stubbing.Answer) After(org.junit.After) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) RETURNS_DEEP_STUBS(org.mockito.Answers.RETURNS_DEEP_STUBS) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) List(java.util.List) Instant(org.joda.time.Instant) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) Stopwatch(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Stopwatch) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Stopwatch(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Stopwatch) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 7 with Stopwatch

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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Duration(org.joda.time.Duration) RunWith(org.junit.runner.RunWith) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Mockito.timeout(org.mockito.Mockito.timeout) Answer(org.mockito.stubbing.Answer) After(org.junit.After) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) List(java.util.List) Instant(org.joda.time.Instant) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) Stopwatch(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Stopwatch) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Stopwatch(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Stopwatch) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 8 with Stopwatch

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);
}
Also used : Stopwatch(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Stopwatch) Test(org.junit.Test)

Example 9 with Stopwatch

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();
}
Also used : Stopwatch(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Stopwatch) Duration(org.joda.time.Duration) Test(org.junit.Test)

Example 10 with Stopwatch

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));
    }
}
Also used : Stopwatch(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Stopwatch)

Aggregations

Stopwatch (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Stopwatch)11 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)3 Duration (org.joda.time.Duration)3 Instant (org.joda.time.Instant)3 Collections (java.util.Collections)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 WindowedValue (org.apache.beam.sdk.util.WindowedValue)2 ImmutableList (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 After (org.junit.After)2 Before (org.junit.Before)2 RunWith (org.junit.runner.RunWith)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)2 ArgumentMatchers.same (org.mockito.ArgumentMatchers.same)2 Mock (org.mockito.Mock)2 Mockito (org.mockito.Mockito)2