Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typo fix - reduce AI generated PRs #8971

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

public class ThrottlerTest {
private final AtomicInteger resource = new AtomicInteger(0);
private final UInt64 throttingPeriod = UInt64.valueOf(10);
private final Throttler<AtomicInteger> throttler = new Throttler<>(resource, throttingPeriod);
private final UInt64 throttlingPeriod = UInt64.valueOf(10);
private final Throttler<AtomicInteger> throttler = new Throttler<>(resource, throttlingPeriod);

@Test
public void init_mustThrowWhenThrottlingPeriodIsNull() {
Expand Down Expand Up @@ -59,19 +59,19 @@ public void invoke_shouldThrottle() {
assertThat(resource.get()).isEqualTo(1);

// Repeatedly invoke at initial time
for (int i = 0; i < throttingPeriod.times(2).intValue(); i++) {
for (int i = 0; i < throttlingPeriod.times(2).intValue(); i++) {
throttler.invoke(initialTime, AtomicInteger::incrementAndGet);
assertThat(resource.get()).isEqualTo(1);
}

// Increment time and invoke up to limit
for (int i = 0; i < throttingPeriod.intValue(); i++) {
for (int i = 0; i < throttlingPeriod.intValue(); i++) {
throttler.invoke(initialTime.plus(i), AtomicInteger::incrementAndGet);
}
assertThat(resource.get()).isEqualTo(1);

// Invoke at boundary
throttler.invoke(initialTime.plus(throttingPeriod), AtomicInteger::incrementAndGet);
throttler.invoke(initialTime.plus(throttlingPeriod), AtomicInteger::incrementAndGet);
assertThat(resource.get()).isEqualTo(2);
}

Expand All @@ -81,11 +81,11 @@ public void invoke_shouldNotThrottleAcrossSparseInvocations() {
throttler.invoke(initialTime, AtomicInteger::incrementAndGet);
assertThat(resource.get()).isEqualTo(1);

throttler.invoke(initialTime.plus(throttingPeriod.times(2)), AtomicInteger::incrementAndGet);
throttler.invoke(initialTime.plus(throttlingPeriod.times(2)), AtomicInteger::incrementAndGet);
assertThat(resource.get()).isEqualTo(2);

throttler.invoke(
initialTime.plus(throttingPeriod.times(3)).plus(1), AtomicInteger::incrementAndGet);
initialTime.plus(throttlingPeriod.times(3)).plus(1), AtomicInteger::incrementAndGet);
assertThat(resource.get()).isEqualTo(3);
}

Expand All @@ -108,19 +108,21 @@ public void invoke_shouldThrottleBasedOnLastSuccessfulInvocation() {
assertThat(resource.get()).isEqualTo(1);

// Don't throttle under the next threshold
throttler.invoke(lastInvocation.plus(throttingPeriod).minus(1), AtomicInteger::incrementAndGet);
throttler.invoke(
lastInvocation.plus(throttlingPeriod).minus(1), AtomicInteger::incrementAndGet);
assertThat(resource.get()).isEqualTo(1);

// Invoke once we pass the current threshold
lastInvocation = lastInvocation.plus(throttingPeriod.times(2)).plus(1);
lastInvocation = lastInvocation.plus(throttlingPeriod.times(2)).plus(1);
throttler.invoke(lastInvocation, AtomicInteger::incrementAndGet);
assertThat(resource.get()).isEqualTo(2);

// Don't throttle under the next threshold
throttler.invoke(lastInvocation.plus(throttingPeriod).minus(1), AtomicInteger::incrementAndGet);
throttler.invoke(
lastInvocation.plus(throttlingPeriod).minus(1), AtomicInteger::incrementAndGet);
assertThat(resource.get()).isEqualTo(2);
// Invoke at next threshold
throttler.invoke(lastInvocation.plus(throttingPeriod), AtomicInteger::incrementAndGet);
throttler.invoke(lastInvocation.plus(throttlingPeriod), AtomicInteger::incrementAndGet);
assertThat(resource.get()).isEqualTo(3);
}
}
Loading