Skip to content

Commit a2f6761

Browse files
feat: improve test
1 parent dc29704 commit a2f6761

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

src/main/java/com/influxdb/v3/client/internal/GrpcCallOption.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.List;
2626
import java.util.Objects;
2727
import java.util.concurrent.Executor;
28-
import java.util.concurrent.TimeUnit;
2928
import javax.annotation.Nonnull;
3029
import javax.annotation.Nullable;
3130

@@ -40,7 +39,7 @@
4039
*/
4140
public final class GrpcCallOption {
4241

43-
private final Deadline deadLineAfter;
42+
private final Deadline deadline;
4443
private final Executor executor;
4544
private final String compressorName;
4645
private final Boolean waitForReady;
@@ -49,7 +48,7 @@ public final class GrpcCallOption {
4948
private final CallOption[] callOptionCallback;
5049

5150
private GrpcCallOption(@Nonnull final Builder builder) {
52-
this.deadLineAfter = builder.deadLineAfter;
51+
this.deadline = builder.deadline;
5352
this.executor = builder.executor;
5453
this.compressorName = builder.compressorName;
5554
this.waitForReady = builder.waitForReady;
@@ -59,13 +58,13 @@ private GrpcCallOption(@Nonnull final Builder builder) {
5958
}
6059

6160
/**
62-
* Returns the deadline that is after the given duration from now.
61+
* Returns the absolute deadline for a call.
6362
*
6463
* @return the Deadline object
6564
*/
6665
@Nullable
67-
public Deadline getDeadlineAfter() {
68-
return deadLineAfter;
66+
public Deadline getDeadline() {
67+
return deadline;
6968
}
7069

7170
/**
@@ -135,7 +134,7 @@ public boolean equals(final Object o) {
135134
return false;
136135
}
137136
GrpcCallOption that = (GrpcCallOption) o;
138-
return Objects.equals(deadLineAfter, that.deadLineAfter)
137+
return Objects.equals(deadline, that.deadline)
139138
&& Objects.equals(executor, that.executor)
140139
&& Objects.equals(compressorName, that.compressorName)
141140
&& Objects.equals(waitForReady, that.waitForReady)
@@ -145,7 +144,7 @@ public boolean equals(final Object o) {
145144

146145
@Override
147146
public int hashCode() {
148-
return Objects.hash(deadLineAfter,
147+
return Objects.hash(deadline,
149148
executor,
150149
compressorName,
151150
waitForReady,
@@ -157,7 +156,7 @@ public int hashCode() {
157156
@Override
158157
public String toString() {
159158
return "GrpcCallOption{"
160-
+ "deadLineAfter=" + deadLineAfter
159+
+ "deadline=" + deadline
161160
+ ", executor=" + executor
162161
+ ", compressorName='" + compressorName
163162
+ '\''
@@ -168,7 +167,7 @@ public String toString() {
168167
}
169168

170169
public static final class Builder {
171-
private Deadline deadLineAfter;
170+
private Deadline deadline;
172171
private Executor executor;
173172
private String compressorName;
174173
private Boolean waitForReady;
@@ -177,20 +176,18 @@ public static final class Builder {
177176
private final List<CallOption> callOptions = new ArrayList<>();
178177

179178
/**
180-
* Sets a deadline that is after the given {@code duration} from
181-
* now.
182-
* @param duration The duration
183-
* @param timeUnit The time unit
179+
* Sets the absolute deadline for a rpc call.
180+
* @param deadline The deadline
184181
* @return this
185182
*/
186-
public Builder withDeadlineAfter(final long duration, @Nonnull final TimeUnit timeUnit) {
183+
public Builder withDeadline(final @Nonnull Deadline deadline) {
187184
var callOption = new org.apache.arrow.flight.CallOptions.GrpcCallOption() {
188185
@Override
189186
public <T extends AbstractStub<T>> T wrapStub(final T stub) {
190-
return stub.withDeadlineAfter(duration, timeUnit);
187+
return stub.withDeadline(deadline);
191188
}
192189
};
193-
this.deadLineAfter = Deadline.after(duration, timeUnit);
190+
this.deadline = deadline;
194191
callOptions.add(callOption);
195192
return this;
196193
}

src/test/java/com/influxdb/v3/client/query/QueryOptionsTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525
import java.nio.charset.StandardCharsets;
2626
import java.util.ArrayList;
2727
import java.util.List;
28+
import java.util.concurrent.Executor;
29+
import java.util.concurrent.Executors;
30+
import java.util.concurrent.TimeUnit;
2831
import java.util.stream.Stream;
2932
import javax.annotation.Nonnull;
3033

34+
import io.grpc.Deadline;
3135
import io.grpc.ManagedChannel;
3236
import io.grpc.ManagedChannelBuilder;
3337
import org.apache.arrow.flight.CallOption;
@@ -178,11 +182,15 @@ void setInboundMessageSizeLarge() throws Exception {
178182

179183
@Test
180184
void grpcCallOption() {
185+
Executor executor = Executors.newSingleThreadExecutor();
186+
Deadline deadline = Deadline.after(2, TimeUnit.SECONDS);
181187
GrpcCallOption grpcCallOption = new GrpcCallOption.Builder()
182188
.withMaxInboundMessageSize(1024)
183189
.withMaxOutboundMessageSize(1024)
184190
.withCompressorName("my-compressor")
185191
.withWaitForReady()
192+
.withExecutor(executor)
193+
.withDeadline(deadline)
186194
.build();
187195
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 3333)
188196
.usePlaintext()
@@ -193,10 +201,14 @@ void grpcCallOption() {
193201
}
194202

195203
io.grpc.CallOptions stubCallOptions = stub.getCallOptions();
196-
Assertions.assertThat(stubCallOptions.getMaxInboundMessageSize()).isEqualTo(grpcCallOption.getMaxInboundMessageSize());
197-
Assertions.assertThat(stubCallOptions.getMaxOutboundMessageSize()).isEqualTo(grpcCallOption.getMaxOutboundMessageSize());
204+
Assertions.assertThat(stubCallOptions.getMaxInboundMessageSize())
205+
.isEqualTo(grpcCallOption.getMaxInboundMessageSize());
206+
Assertions.assertThat(stubCallOptions.getMaxOutboundMessageSize())
207+
.isEqualTo(grpcCallOption.getMaxOutboundMessageSize());
198208
Assertions.assertThat(stubCallOptions.getCompressor()).isEqualTo(grpcCallOption.getCompressorName());
199209
Assertions.assertThat(stubCallOptions.isWaitForReady()).isEqualTo(grpcCallOption.getWaitForReady());
210+
Assertions.assertThat(stubCallOptions.getExecutor()).isEqualTo(grpcCallOption.getExecutor());
211+
Assertions.assertThat(stubCallOptions.getDeadline()).isEqualTo(grpcCallOption.getDeadline());
200212
}
201213

202214
private FlightServer simpleFlightServer(@Nonnull final URI uri,

0 commit comments

Comments
 (0)