mirror of https://github.com/grpc/grpc-java.git
core,stub: remove deprecated deadline methods
This commit is contained in:
parent
d17a7b5bd4
commit
8e463ce1a8
|
|
@ -136,25 +136,6 @@ public final class CallOptions {
|
|||
return newOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@code CallOptions} with the given absolute deadline in nanoseconds in the clock
|
||||
* as per {@link System#nanoTime()}.
|
||||
*
|
||||
* <p>This is mostly used for propagating an existing deadline. {@link #withDeadlineAfter} is the
|
||||
* recommended way of setting a new deadline,
|
||||
*
|
||||
* @param deadlineNanoTime the deadline in the clock as per {@link System#nanoTime()}.
|
||||
* {@code null} for unsetting the deadline.
|
||||
* @deprecated Use {@link #withDeadline(Deadline)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public CallOptions withDeadlineNanoTime(@Nullable Long deadlineNanoTime) {
|
||||
Deadline deadline = deadlineNanoTime != null
|
||||
? Deadline.after(deadlineNanoTime - System.nanoTime(), TimeUnit.NANOSECONDS)
|
||||
: null;
|
||||
return withDeadline(deadline);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@code CallOptions} with a deadline that is after the given {@code duration} from
|
||||
* now.
|
||||
|
|
@ -163,20 +144,6 @@ public final class CallOptions {
|
|||
return withDeadline(Deadline.after(duration, unit));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the deadline in nanoseconds in the clock as per {@link System#nanoTime()}. {@code null}
|
||||
* if the deadline is not set.
|
||||
*
|
||||
* @deprecated Use {@link #getDeadline()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public Long getDeadlineNanoTime() {
|
||||
if (getDeadline() == null) {
|
||||
return null;
|
||||
}
|
||||
return System.nanoTime() + getDeadline().timeRemaining(TimeUnit.NANOSECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the deadline or {@code null} if the deadline is not set.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -191,22 +191,6 @@ public class CallOptionsTest {
|
|||
assertThat(allSet.toString()).contains("1 ns from now");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void withDeadlineNanoTime() {
|
||||
// Create Deadline near calling System.nanoTime to reduce clock differences
|
||||
Deadline reference = Deadline.after(-1, NANOSECONDS);
|
||||
long rawDeadline = System.nanoTime() - 1;
|
||||
CallOptions opts = CallOptions.DEFAULT.withDeadlineNanoTime(rawDeadline);
|
||||
assertThat(opts.getDeadlineNanoTime()).isNotNull();
|
||||
// This is not technically correct, since nanoTime is permitted to overflow, but the chances of
|
||||
// that impacting this test are very remote.
|
||||
assertThat(opts.getDeadlineNanoTime()).isAtMost(System.nanoTime());
|
||||
assertThat(opts.getDeadline().isExpired()).isTrue();
|
||||
|
||||
assertAbout(deadline()).that(opts.getDeadline()).isWithin(50, MILLISECONDS).of(reference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withCustomOptionDefault() {
|
||||
CallOptions opts = CallOptions.DEFAULT;
|
||||
|
|
|
|||
|
|
@ -31,14 +31,10 @@
|
|||
|
||||
package io.grpc.stub;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.same;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
|
@ -100,26 +96,6 @@ public class StubConfigTest {
|
|||
assertNull(stub.getCallOptions().getDeadline());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
public void testConfigureDeadlineNanoTime() {
|
||||
long deadline = System.nanoTime() + SECONDS.toNanos(1);
|
||||
// Create a default stub
|
||||
TestServiceGrpc.TestServiceBlockingStub stub = TestServiceGrpc.newBlockingStub(channel);
|
||||
assertNull(stub.getCallOptions().getDeadlineNanoTime());
|
||||
// Warm up JVM
|
||||
stub.withDeadlineNanoTime(deadline);
|
||||
// Reconfigure it
|
||||
TestServiceGrpc.TestServiceBlockingStub reconfiguredStub = stub.withDeadlineNanoTime(deadline);
|
||||
// New altered config
|
||||
assertNotNull(reconfiguredStub.getCallOptions().getDeadlineNanoTime());
|
||||
long maxDelta = MILLISECONDS.toNanos(10);
|
||||
long actualDelta = Math.abs(reconfiguredStub.getCallOptions().getDeadlineNanoTime() - deadline);
|
||||
assertTrue(maxDelta + " < " + actualDelta, maxDelta >= actualDelta);
|
||||
// Default config unchanged
|
||||
assertNull(stub.getCallOptions().getDeadlineNanoTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStubCallOptionsPopulatedToNewCall() {
|
||||
TestServiceGrpc.TestServiceStub stub = TestServiceGrpc.newStub(channel);
|
||||
|
|
|
|||
|
|
@ -112,21 +112,6 @@ public abstract class AbstractStub<S extends AbstractStub<S>> {
|
|||
return build(channel, callOptions.withDeadline(deadline));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new stub with an absolute deadline in nanoseconds in the clock as per {@link
|
||||
* System#nanoTime()}.
|
||||
*
|
||||
* <p>This is mostly used for propagating an existing deadline. {@link #withDeadlineAfter} is the
|
||||
* recommended way of setting a new deadline,
|
||||
*
|
||||
* @param deadlineNanoTime nanoseconds in the clock as per {@link System#nanoTime()}
|
||||
* @deprecated Use {@link #withDeadline(Deadline)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public final S withDeadlineNanoTime(@Nullable Long deadlineNanoTime) {
|
||||
return build(channel, callOptions.withDeadlineNanoTime(deadlineNanoTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new stub with a deadline that is after the given {@code duration} from now.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue