-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Inference API time to reserve tokens for rate limiter (#107571)
* Refactoring tests * Adding time to reserve tests
- Loading branch information
1 parent
cc75338
commit 1aa182a
Showing
5 changed files
with
307 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...rence/src/test/java/org/elasticsearch/xpack/inference/common/RateLimiterAcquireTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.inference.common; | ||
|
||
import org.elasticsearch.core.TimeValue; | ||
|
||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class RateLimiterAcquireTests extends BaseRateLimiterTests { | ||
|
||
@Override | ||
protected TimeValue tokenMethod(RateLimiter limiter, int tokens) throws InterruptedException { | ||
limiter.acquire(tokens); | ||
return null; | ||
} | ||
|
||
@Override | ||
protected void sleepValidationMethod( | ||
TimeValue result, | ||
RateLimiter.Sleeper mockSleeper, | ||
int numberOfClassToExpect, | ||
long expectedMicrosecondsToSleep | ||
) throws InterruptedException { | ||
verify(mockSleeper, times(numberOfClassToExpect)).sleep(expectedMicrosecondsToSleep); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...rence/src/test/java/org/elasticsearch/xpack/inference/common/RateLimiterReserveTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.inference.common; | ||
|
||
import org.elasticsearch.core.TimeValue; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
public class RateLimiterReserveTests extends BaseRateLimiterTests { | ||
|
||
@Override | ||
protected TimeValue tokenMethod(RateLimiter limiter, int tokens) { | ||
return limiter.reserve(tokens); | ||
} | ||
|
||
@Override | ||
protected void sleepValidationMethod( | ||
TimeValue result, | ||
RateLimiter.Sleeper mockSleeper, | ||
int numberOfClassToExpect, | ||
long expectedMicrosecondsToSleep | ||
) { | ||
assertThat(result.getMicros(), is(expectedMicrosecondsToSleep)); | ||
} | ||
} |
Oops, something went wrong.