Skip to content

Commit a2c80a6

Browse files
refactor: not use stream
1 parent 76964cf commit a2c80a6

File tree

4 files changed

+93
-11
lines changed

4 files changed

+93
-11
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@
2222
package com.influxdb.v3.client.internal;
2323

2424
import java.util.ArrayList;
25-
import java.util.Arrays;
2625
import java.util.List;
2726
import java.util.Objects;
28-
import java.util.Optional;
2927
import java.util.concurrent.Executor;
30-
import java.util.stream.Stream;
3128
import javax.annotation.Nonnull;
3229
import javax.annotation.Nullable;
3330

@@ -72,9 +69,9 @@ private GrpcCallOptions(@Nonnull final Builder builder) {
7269
*
7370
* @return the default configuration of {@link GrpcCallOptions}.
7471
*/
72+
@Nonnull
7573
public static GrpcCallOptions getDefaultOptions() {
7674
GrpcCallOptions.Builder builder = new GrpcCallOptions.Builder();
77-
builder.withMaxInboundMessageSize(Integer.MAX_VALUE);
7875
return builder.build();
7976
}
8077

@@ -89,10 +86,12 @@ public static GrpcCallOptions getDefaultOptions() {
8986
*/
9087
public static CallOption[] mergeCallOptions(@Nullable final CallOption[] baseCallOptions,
9188
final CallOption... callOptions) {
92-
return Stream.concat(
93-
Arrays.stream(Optional.ofNullable(baseCallOptions).orElse(new CallOption[0])),
94-
Arrays.stream(Optional.ofNullable(callOptions).orElse(new CallOption[0]))
95-
).toArray(CallOption[]::new);
89+
CallOption[] base = baseCallOptions != null ? baseCallOptions : new CallOption[0];
90+
CallOption[] additional = callOptions != null ? callOptions : new CallOption[0];
91+
CallOption[] merged = new CallOption[base.length + additional.length];
92+
System.arraycopy(base, 0, merged, 0, base.length);
93+
System.arraycopy(additional, 0, merged, base.length, additional.length);
94+
return merged;
9695
}
9796

9897
/**

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ private Stream<VectorSchemaRoot> queryData(@Nonnull final String query,
342342
}
343343
});
344344

345-
CallOption[] callOptions = options.grpcCallOptions() != null
346-
? options.grpcCallOptions().getCallOptions() : null;
345+
CallOption[] callOptions = options.grpcCallOptions().getCallOptions();
347346
return flightSqlClient.execute(
348347
query,
349348
database,

src/main/java/com/influxdb/v3/client/query/QueryOptions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,14 @@ public Map<String, String> headersSafe() {
151151
* @param grpcCallOptions the grpcCallOptions
152152
*/
153153
public void setGrpcCallOptions(@Nonnull final GrpcCallOptions grpcCallOptions) {
154+
Arguments.checkNotNull(grpcCallOptions, "grpcCallOptions");
154155
this.grpcCallOptions = grpcCallOptions;
155156
}
156157

157158
/**
158159
* @return the GrpcCallOptions object.
159160
*/
160-
@Nullable
161+
@Nonnull
161162
public GrpcCallOptions grpcCallOptions() {
162163
return grpcCallOptions;
163164
}

src/test/java/com/influxdb/v3/client/internal/GrpcCallOptionsTest.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.junit.jupiter.api.Test;
2828

2929
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
3031
import static org.junit.jupiter.api.Assertions.assertNotNull;
3132

3233
class GrpcCallOptionsTest {
@@ -118,4 +119,86 @@ public <T extends AbstractStub<T>> T wrapStub(final T stub) {
118119
};
119120
}
120121

122+
@Test
123+
void testEqualsWithEqualObjects() {
124+
GrpcCallOptions options1 = new GrpcCallOptions.Builder()
125+
.withMaxInboundMessageSize(2000)
126+
.withCompressorName("gzip")
127+
.build();
128+
GrpcCallOptions options2 = new GrpcCallOptions.Builder()
129+
.withMaxInboundMessageSize(2000)
130+
.withCompressorName("gzip")
131+
.build();
132+
133+
assertEquals(options1, options2);
134+
}
135+
136+
@Test
137+
void testEqualsWithDifferentObjects() {
138+
GrpcCallOptions options1 = new GrpcCallOptions.Builder()
139+
.withMaxInboundMessageSize(2000)
140+
.withCompressorName("gzip")
141+
.build();
142+
GrpcCallOptions options2 = new GrpcCallOptions.Builder()
143+
.withMaxInboundMessageSize(1000)
144+
.withCompressorName("deflate")
145+
.build();
146+
147+
assertNotEquals(options1, options2);
148+
}
149+
150+
@Test
151+
void testEqualsWithNullAndDifferentClass() {
152+
GrpcCallOptions options = new GrpcCallOptions.Builder()
153+
.withMaxInboundMessageSize(2000)
154+
.build();
155+
156+
assertNotEquals(null, options);
157+
assertNotEquals(1, options);
158+
}
159+
160+
@Test
161+
void testHashCodeWithEqualObjects() {
162+
GrpcCallOptions options1 = new GrpcCallOptions.Builder()
163+
.withMaxInboundMessageSize(2000)
164+
.withCompressorName("gzip")
165+
.build();
166+
GrpcCallOptions options2 = new GrpcCallOptions.Builder()
167+
.withMaxInboundMessageSize(2000)
168+
.withCompressorName("gzip")
169+
.build();
170+
171+
assertEquals(options1.hashCode(), options2.hashCode());
172+
}
173+
174+
@Test
175+
void testHashCodeWithDifferentObjects() {
176+
GrpcCallOptions options1 = new GrpcCallOptions.Builder()
177+
.withMaxInboundMessageSize(2000)
178+
.withCompressorName("gzip")
179+
.build();
180+
GrpcCallOptions options2 = new GrpcCallOptions.Builder()
181+
.withMaxInboundMessageSize(1000)
182+
.withCompressorName("deflate")
183+
.build();
184+
185+
assertNotEquals(options1.hashCode(), options2.hashCode());
186+
}
187+
188+
@Test
189+
void testToString() {
190+
GrpcCallOptions options = new GrpcCallOptions.Builder()
191+
.withMaxInboundMessageSize(2000)
192+
.withMaxOutboundMessageSize(5000)
193+
.withCompressorName("gzip")
194+
.build();
195+
196+
String expected = "GrpcCallOptions{deadline=null, "
197+
+ "executor=null, "
198+
+ "compressorName='gzip', "
199+
+ "waitForReady=null, "
200+
+ "maxInboundMessageSize=2000, "
201+
+ "maxOutboundMessageSize=5000}";
202+
assertEquals(expected, options.toString());
203+
}
121204
}

0 commit comments

Comments
 (0)