Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public static class EventType {
public static final String TOPOLOGY_CHANGE = "TOPOLOGY_CHANGE";
public static final String STATUS_CHANGE = "STATUS_CHANGE";
public static final String SCHEMA_CHANGE = "SCHEMA_CHANGE";
public static final String GRACEFUL_DISCONNECT = "GRACEFUL_DISCONNECT";
}

public static class SchemaChangeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.datastax.oss.protocol.internal.PrimitiveSizes;
import com.datastax.oss.protocol.internal.ProtocolConstants;
import com.datastax.oss.protocol.internal.ProtocolErrors;
import com.datastax.oss.protocol.internal.response.event.GracefulDisconnectEvent;
import com.datastax.oss.protocol.internal.response.event.SchemaChangeEvent;
import com.datastax.oss.protocol.internal.response.event.StatusChangeEvent;
import com.datastax.oss.protocol.internal.response.event.TopologyChangeEvent;
Expand Down Expand Up @@ -54,7 +55,8 @@ public Codec(int protocolVersion) {
protocolVersion,
new TopologyChangeEvent.SubCodec(protocolVersion),
new StatusChangeEvent.SubCodec(protocolVersion),
new SchemaChangeEvent.SubCodec(protocolVersion));
new SchemaChangeEvent.SubCodec(protocolVersion),
new GracefulDisconnectEvent.SubCodec(protocolVersion));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.datastax.oss.protocol.internal.response.event;

import com.datastax.oss.protocol.internal.Message;
import com.datastax.oss.protocol.internal.PrimitiveCodec;
import com.datastax.oss.protocol.internal.ProtocolConstants;
import com.datastax.oss.protocol.internal.response.Event;

public class GracefulDisconnectEvent extends Event {
public GracefulDisconnectEvent() {
super(ProtocolConstants.EventType.GRACEFUL_DISCONNECT);
}

@Override
public String toString() {
return "EVENT GRACEFUL_DISCONNECT";
}

public static class SubCodec extends Event.SubCodec {

public SubCodec(int protocolVersion) {
super(ProtocolConstants.EventType.GRACEFUL_DISCONNECT, protocolVersion);
}

@Override
public <B> void encode(B dest, Message message, PrimitiveCodec<B> encoder) {
// no-op: the event has no body, the type string is enough
}

@Override
public int encodedSize(Message message) {
return 0;
}

@Override
public <B> Message decode(B source, PrimitiveCodec<B> decoder) {
return new GracefulDisconnectEvent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright DataStax, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.datastax.oss.protocol.internal.response.event;

import static com.datastax.oss.protocol.internal.Assertions.assertThat;

import com.datastax.oss.protocol.internal.Message;
import com.datastax.oss.protocol.internal.MessageTestBase;
import com.datastax.oss.protocol.internal.PrimitiveSizes;
import com.datastax.oss.protocol.internal.ProtocolConstants;
import com.datastax.oss.protocol.internal.TestDataProviders;
import com.datastax.oss.protocol.internal.binary.MockBinaryString;
import com.datastax.oss.protocol.internal.response.Event;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(DataProviderRunner.class)
public class GracefulDisconnectEventTest extends MessageTestBase<GracefulDisconnectEvent> {

public GracefulDisconnectEventTest() {
super(GracefulDisconnectEvent.class);
}

@Override
protected Message.Codec newCodec(int protocolVersion) {
return new Event.Codec(protocolVersion);
}

@Test
@UseDataProvider(location = TestDataProviders.class, value = "protocolV5OrAbove")
public void should_encode_and_decode(int protocolVersion) {
GracefulDisconnectEvent initial = new GracefulDisconnectEvent();

MockBinaryString encoded = encode(initial, protocolVersion);

assertThat(encoded)
.isEqualTo(new MockBinaryString().string(ProtocolConstants.EventType.GRACEFUL_DISCONNECT));
assertThat(encodedSize(initial, protocolVersion))
.isEqualTo(PrimitiveSizes.SHORT + ProtocolConstants.EventType.GRACEFUL_DISCONNECT.length());

GracefulDisconnectEvent decoded = decode(encoded, protocolVersion);

assertThat(decoded.type).isEqualTo(ProtocolConstants.EventType.GRACEFUL_DISCONNECT);
}
}