Skip to content

Commit 61eac1b

Browse files
committed
[#596] Setting default EMPTY value for featureStore, simplifying unit tests.
1 parent 850cc81 commit 61eac1b

File tree

3 files changed

+121
-122
lines changed

3 files changed

+121
-122
lines changed

core/src/main/java/com/datastax/oss/driver/internal/core/channel/ProtocolInitHandler.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import com.datastax.oss.driver.internal.core.protocol.SegmentToFrameDecoder;
4646
import com.datastax.oss.driver.internal.core.util.ProtocolUtils;
4747
import com.datastax.oss.driver.internal.core.util.concurrent.UncaughtExceptions;
48-
import com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting;
4948
import com.datastax.oss.protocol.internal.Message;
5049
import com.datastax.oss.protocol.internal.ProtocolConstants;
5150
import com.datastax.oss.protocol.internal.ProtocolConstants.ErrorCode;
@@ -95,7 +94,7 @@ class ProtocolInitHandler extends ConnectInitHandler {
9594
private String logPrefix;
9695
private ChannelHandlerContext ctx;
9796
private final boolean querySupportedOptions;
98-
private ProtocolFeatureStore featureStore;
97+
private ProtocolFeatureStore featureStore = ProtocolFeatureStore.EMPTY;
9998

10099
/**
101100
* @param querySupportedOptions whether to send OPTIONS as the first message, to request which
@@ -465,9 +464,4 @@ private void maybeUpdatePipeline() {
465464
private String getString(List<ByteBuffer> row, int i) {
466465
return TypeCodecs.TEXT.decode(row.get(i), DefaultProtocolVersion.DEFAULT);
467466
}
468-
469-
@VisibleForTesting
470-
void setFeatureStore(ProtocolFeatureStore featureStore) {
471-
this.featureStore = featureStore;
472-
}
473467
}

core/src/test/java/com/datastax/oss/driver/internal/core/channel/ChannelFactoryTestBase.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import com.datastax.oss.driver.internal.core.context.NettyOptions;
3535
import com.datastax.oss.driver.internal.core.metrics.NodeMetricUpdater;
3636
import com.datastax.oss.driver.internal.core.protocol.ByteBufPrimitiveCodec;
37-
import com.datastax.oss.driver.internal.core.protocol.ProtocolFeatureStore;
3837
import com.datastax.oss.protocol.internal.Compressor;
3938
import com.datastax.oss.protocol.internal.Frame;
4039
import com.datastax.oss.protocol.internal.FrameCodec;
@@ -272,7 +271,6 @@ protected void initChannel(Channel channel) throws Exception {
272271
options,
273272
heartbeatHandler,
274273
productType == null);
275-
initHandler.setFeatureStore(ProtocolFeatureStore.EMPTY);
276274
channel
277275
.pipeline()
278276
.addLast(ChannelFactory.INFLIGHT_HANDLER_NAME, inFlightHandler)

core/src/test/java/com/datastax/oss/driver/internal/core/channel/ProtocolInitHandlerTest.java

Lines changed: 120 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import com.datastax.oss.driver.internal.core.TestResponses;
4343
import com.datastax.oss.driver.internal.core.context.InternalDriverContext;
4444
import com.datastax.oss.driver.internal.core.metadata.TestNodeFactory;
45-
import com.datastax.oss.driver.internal.core.protocol.ProtocolFeatureStore;
4645
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList;
4746
import com.datastax.oss.protocol.internal.Frame;
4847
import com.datastax.oss.protocol.internal.ProtocolConstants;
@@ -120,17 +119,18 @@ public void setup() {
120119

121120
@Test
122121
public void should_initialize() {
123-
ProtocolInitHandler protocolInitHandler =
124-
new ProtocolInitHandler(
125-
internalDriverContext,
126-
DefaultProtocolVersion.V4,
127-
null,
128-
END_POINT,
129-
DriverChannelOptions.DEFAULT,
130-
heartbeatHandler,
131-
false);
132-
protocolInitHandler.setFeatureStore(ProtocolFeatureStore.EMPTY);
133-
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, protocolInitHandler);
122+
channel
123+
.pipeline()
124+
.addLast(
125+
ChannelFactory.INIT_HANDLER_NAME,
126+
new ProtocolInitHandler(
127+
internalDriverContext,
128+
DefaultProtocolVersion.V4,
129+
null,
130+
END_POINT,
131+
DriverChannelOptions.DEFAULT,
132+
heartbeatHandler,
133+
false));
134134

135135
ChannelFuture connectFuture = channel.connect(new InetSocketAddress("localhost", 9042));
136136

@@ -208,7 +208,6 @@ public void should_add_heartbeat_handler_to_pipeline_on_success() {
208208
DriverChannelOptions.DEFAULT,
209209
heartbeatHandler,
210210
false);
211-
protocolInitHandler.setFeatureStore(ProtocolFeatureStore.EMPTY);
212211

213212
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, protocolInitHandler);
214213

@@ -268,17 +267,18 @@ public void should_fail_to_initialize_if_init_query_times_out() throws Interrupt
268267

269268
@Test
270269
public void should_initialize_with_authentication() {
271-
ProtocolInitHandler protocolInitHandler =
272-
new ProtocolInitHandler(
273-
internalDriverContext,
274-
DefaultProtocolVersion.V4,
275-
null,
276-
END_POINT,
277-
DriverChannelOptions.DEFAULT,
278-
heartbeatHandler,
279-
false);
280-
protocolInitHandler.setFeatureStore(ProtocolFeatureStore.EMPTY);
281-
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, protocolInitHandler);
270+
channel
271+
.pipeline()
272+
.addLast(
273+
ChannelFactory.INIT_HANDLER_NAME,
274+
new ProtocolInitHandler(
275+
internalDriverContext,
276+
DefaultProtocolVersion.V4,
277+
null,
278+
END_POINT,
279+
DriverChannelOptions.DEFAULT,
280+
heartbeatHandler,
281+
false));
282282

283283
String serverAuthenticator = "mockServerAuthenticator";
284284
AuthProvider authProvider = mock(AuthProvider.class);
@@ -332,17 +332,18 @@ public void should_initialize_with_authentication() {
332332

333333
@Test
334334
public void should_invoke_auth_provider_when_server_does_not_send_challenge() {
335-
ProtocolInitHandler protocolInitHandler =
336-
new ProtocolInitHandler(
337-
internalDriverContext,
338-
DefaultProtocolVersion.V4,
339-
null,
340-
END_POINT,
341-
DriverChannelOptions.DEFAULT,
342-
heartbeatHandler,
343-
false);
344-
protocolInitHandler.setFeatureStore(ProtocolFeatureStore.EMPTY);
345-
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, protocolInitHandler);
335+
channel
336+
.pipeline()
337+
.addLast(
338+
ChannelFactory.INIT_HANDLER_NAME,
339+
new ProtocolInitHandler(
340+
internalDriverContext,
341+
DefaultProtocolVersion.V4,
342+
null,
343+
END_POINT,
344+
DriverChannelOptions.DEFAULT,
345+
heartbeatHandler,
346+
false));
346347

347348
AuthProvider authProvider = mock(AuthProvider.class);
348349
when(internalDriverContext.getAuthProvider()).thenReturn(Optional.of(authProvider));
@@ -365,17 +366,18 @@ public void should_invoke_auth_provider_when_server_does_not_send_challenge() {
365366

366367
@Test
367368
public void should_fail_to_initialize_if_server_sends_auth_error() {
368-
ProtocolInitHandler protocolInitHandler =
369-
new ProtocolInitHandler(
370-
internalDriverContext,
371-
DefaultProtocolVersion.V4,
372-
null,
373-
END_POINT,
374-
DriverChannelOptions.DEFAULT,
375-
heartbeatHandler,
376-
false);
377-
protocolInitHandler.setFeatureStore(ProtocolFeatureStore.EMPTY);
378-
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, protocolInitHandler);
369+
channel
370+
.pipeline()
371+
.addLast(
372+
ChannelFactory.INIT_HANDLER_NAME,
373+
new ProtocolInitHandler(
374+
internalDriverContext,
375+
DefaultProtocolVersion.V4,
376+
null,
377+
END_POINT,
378+
DriverChannelOptions.DEFAULT,
379+
heartbeatHandler,
380+
false));
379381

380382
String serverAuthenticator = "mockServerAuthenticator";
381383
AuthProvider authProvider = mock(AuthProvider.class);
@@ -411,17 +413,18 @@ public void should_fail_to_initialize_if_server_sends_auth_error() {
411413

412414
@Test
413415
public void should_check_cluster_name_if_provided() {
414-
ProtocolInitHandler protocolInitHandler =
415-
new ProtocolInitHandler(
416-
internalDriverContext,
417-
DefaultProtocolVersion.V4,
418-
"expectedClusterName",
419-
END_POINT,
420-
DriverChannelOptions.DEFAULT,
421-
heartbeatHandler,
422-
false);
423-
protocolInitHandler.setFeatureStore(ProtocolFeatureStore.EMPTY);
424-
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, protocolInitHandler);
416+
channel
417+
.pipeline()
418+
.addLast(
419+
ChannelFactory.INIT_HANDLER_NAME,
420+
new ProtocolInitHandler(
421+
internalDriverContext,
422+
DefaultProtocolVersion.V4,
423+
"expectedClusterName",
424+
END_POINT,
425+
DriverChannelOptions.DEFAULT,
426+
heartbeatHandler,
427+
false));
425428

426429
ChannelFuture connectFuture = channel.connect(new InetSocketAddress("localhost", 9042));
427430

@@ -441,18 +444,18 @@ public void should_check_cluster_name_if_provided() {
441444

442445
@Test
443446
public void should_fail_to_initialize_if_cluster_name_does_not_match() {
444-
ProtocolInitHandler protocolInitHandler =
445-
new ProtocolInitHandler(
446-
internalDriverContext,
447-
DefaultProtocolVersion.V4,
448-
"expectedClusterName",
449-
END_POINT,
450-
DriverChannelOptions.DEFAULT,
451-
heartbeatHandler,
452-
false);
453-
protocolInitHandler.setFeatureStore(ProtocolFeatureStore.EMPTY);
454-
455-
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, protocolInitHandler);
447+
channel
448+
.pipeline()
449+
.addLast(
450+
ChannelFactory.INIT_HANDLER_NAME,
451+
new ProtocolInitHandler(
452+
internalDriverContext,
453+
DefaultProtocolVersion.V4,
454+
"expectedClusterName",
455+
END_POINT,
456+
DriverChannelOptions.DEFAULT,
457+
heartbeatHandler,
458+
false));
456459

457460
ChannelFuture connectFuture = channel.connect(new InetSocketAddress("localhost", 9042));
458461

@@ -475,17 +478,18 @@ public void should_fail_to_initialize_if_cluster_name_does_not_match() {
475478
public void should_initialize_with_keyspace() {
476479
DriverChannelOptions options =
477480
DriverChannelOptions.builder().withKeyspace(CqlIdentifier.fromCql("ks")).build();
478-
ProtocolInitHandler protocolInitHandler =
479-
new ProtocolInitHandler(
480-
internalDriverContext,
481-
DefaultProtocolVersion.V4,
482-
null,
483-
END_POINT,
484-
options,
485-
heartbeatHandler,
486-
false);
487-
protocolInitHandler.setFeatureStore(ProtocolFeatureStore.EMPTY);
488-
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, protocolInitHandler);
481+
channel
482+
.pipeline()
483+
.addLast(
484+
ChannelFactory.INIT_HANDLER_NAME,
485+
new ProtocolInitHandler(
486+
internalDriverContext,
487+
DefaultProtocolVersion.V4,
488+
null,
489+
END_POINT,
490+
options,
491+
heartbeatHandler,
492+
false));
489493

490494
ChannelFuture connectFuture = channel.connect(new InetSocketAddress("localhost", 9042));
491495

@@ -506,17 +510,18 @@ public void should_initialize_with_events() {
506510
EventCallback eventCallback = mock(EventCallback.class);
507511
DriverChannelOptions driverChannelOptions =
508512
DriverChannelOptions.builder().withEvents(eventTypes, eventCallback).build();
509-
ProtocolInitHandler protocolInitHandler =
510-
new ProtocolInitHandler(
511-
internalDriverContext,
512-
DefaultProtocolVersion.V4,
513-
null,
514-
END_POINT,
515-
driverChannelOptions,
516-
heartbeatHandler,
517-
false);
518-
protocolInitHandler.setFeatureStore(ProtocolFeatureStore.EMPTY);
519-
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, protocolInitHandler);
513+
channel
514+
.pipeline()
515+
.addLast(
516+
ChannelFactory.INIT_HANDLER_NAME,
517+
new ProtocolInitHandler(
518+
internalDriverContext,
519+
DefaultProtocolVersion.V4,
520+
null,
521+
END_POINT,
522+
driverChannelOptions,
523+
heartbeatHandler,
524+
false));
520525

521526
ChannelFuture connectFuture = channel.connect(new InetSocketAddress("localhost", 9042));
522527

@@ -540,17 +545,18 @@ public void should_initialize_with_keyspace_and_events() {
540545
.withKeyspace(CqlIdentifier.fromCql("ks"))
541546
.withEvents(eventTypes, eventCallback)
542547
.build();
543-
ProtocolInitHandler protocolInitHandler =
544-
new ProtocolInitHandler(
545-
internalDriverContext,
546-
DefaultProtocolVersion.V4,
547-
null,
548-
END_POINT,
549-
driverChannelOptions,
550-
heartbeatHandler,
551-
false);
552-
protocolInitHandler.setFeatureStore(ProtocolFeatureStore.EMPTY);
553-
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, protocolInitHandler);
548+
channel
549+
.pipeline()
550+
.addLast(
551+
ChannelFactory.INIT_HANDLER_NAME,
552+
new ProtocolInitHandler(
553+
internalDriverContext,
554+
DefaultProtocolVersion.V4,
555+
null,
556+
END_POINT,
557+
driverChannelOptions,
558+
heartbeatHandler,
559+
false));
554560

555561
ChannelFuture connectFuture = channel.connect(new InetSocketAddress("localhost", 9042));
556562

@@ -574,17 +580,18 @@ public void should_initialize_with_keyspace_and_events() {
574580
public void should_fail_to_initialize_if_keyspace_is_invalid() {
575581
DriverChannelOptions driverChannelOptions =
576582
DriverChannelOptions.builder().withKeyspace(CqlIdentifier.fromCql("ks")).build();
577-
ProtocolInitHandler protocolInitHandler =
578-
new ProtocolInitHandler(
579-
internalDriverContext,
580-
DefaultProtocolVersion.V4,
581-
null,
582-
END_POINT,
583-
driverChannelOptions,
584-
heartbeatHandler,
585-
false);
586-
protocolInitHandler.setFeatureStore(ProtocolFeatureStore.EMPTY);
587-
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, protocolInitHandler);
583+
channel
584+
.pipeline()
585+
.addLast(
586+
ChannelFactory.INIT_HANDLER_NAME,
587+
new ProtocolInitHandler(
588+
internalDriverContext,
589+
DefaultProtocolVersion.V4,
590+
null,
591+
END_POINT,
592+
driverChannelOptions,
593+
heartbeatHandler,
594+
false));
588595

589596
ChannelFuture connectFuture = channel.connect(new InetSocketAddress("localhost", 9042));
590597

0 commit comments

Comments
 (0)