From ccf1812da9f9280ef829527d3a97ee23c4ad3691 Mon Sep 17 00:00:00 2001 From: Dave Rusek Date: Thu, 1 Mar 2018 15:20:46 -0700 Subject: [PATCH] Remove deprecated newConnect methods (#1315) * Remove deprecated and unused code * Revert "Remove deprecated and unused code" This reverts commit 95114c6f573cd8ef26bc2c3c0ad2691a1af6f268. * Move old newConnect funtions to tests for backward compat --- .../pulsar/broker/service/ServerCnxTest.java | 23 +++++++++++-- .../apache/pulsar/common/api/Commands.java | 34 +++---------------- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java index 486f1cdee8b68..61584952479c7 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java @@ -58,6 +58,7 @@ import org.apache.bookkeeper.mledger.ManagedLedgerException; import org.apache.bookkeeper.mledger.ManagedLedgerFactory; import org.apache.bookkeeper.mledger.impl.PositionImpl; +import org.apache.bookkeeper.tools.cli.helpers.Command; import org.apache.pulsar.broker.PulsarService; import org.apache.pulsar.broker.ServiceConfiguration; import org.apache.pulsar.broker.admin.AdminResource; @@ -75,6 +76,7 @@ import org.apache.pulsar.common.api.Commands; import org.apache.pulsar.common.api.Commands.ChecksumType; import org.apache.pulsar.common.api.PulsarHandler; +import org.apache.pulsar.common.api.proto.PulsarApi; import org.apache.pulsar.common.api.proto.PulsarApi.AuthMethod; import org.apache.pulsar.common.api.proto.PulsarApi.CommandAck.AckType; import org.apache.pulsar.common.api.proto.PulsarApi.CommandConnected; @@ -210,6 +212,24 @@ public void testConnectCommand() throws Exception { channel.finish(); } + private static ByteBuf newConnect(AuthMethod authMethod, String authData, int protocolVersion) { + PulsarApi.CommandConnect.Builder connectBuilder = PulsarApi.CommandConnect.newBuilder(); + connectBuilder.setClientVersion("Pulsar Client"); + connectBuilder.setAuthMethod(authMethod); + connectBuilder.setAuthData(ByteString.copyFromUtf8(authData)); + connectBuilder.setProtocolVersion(protocolVersion); + PulsarApi.CommandConnect connect = connectBuilder.build(); + ByteBuf res = Commands.serializeWithSize(PulsarApi.BaseCommand.newBuilder().setType(PulsarApi.BaseCommand.Type.CONNECT).setConnect(connect)); + connect.recycle(); + connectBuilder.recycle(); + return res; + } + + /** + * Ensure that old clients may still connect to new servers + * + * @throws Exception + */ @Test(timeOut = 30000) public void testConnectCommandWithEnum() throws Exception { resetChannel(); @@ -217,8 +237,7 @@ public void testConnectCommandWithEnum() throws Exception { assertEquals(serverCnx.getState(), State.Start); // test server response to CONNECT - @SuppressWarnings("deprecation") // We're actually testing that the deprecated method still works - ByteBuf clientCommand = Commands.newConnect(AuthMethod.AuthMethodNone, ""); + ByteBuf clientCommand = newConnect(AuthMethod.AuthMethodNone, "", Commands.getCurrentProtocolVersion()); channel.writeInbound(clientCommand); assertEquals(serverCnx.getState(), State.Connected); diff --git a/pulsar-common/src/main/java/org/apache/pulsar/common/api/Commands.java b/pulsar-common/src/main/java/org/apache/pulsar/common/api/Commands.java index 073de6b0a767c..b51d29ea070e5 100644 --- a/pulsar-common/src/main/java/org/apache/pulsar/common/api/Commands.java +++ b/pulsar-common/src/main/java/org/apache/pulsar/common/api/Commands.java @@ -21,6 +21,7 @@ import static com.scurrilous.circe.checksum.Crc32cIntChecksum.computeChecksum; import static com.scurrilous.circe.checksum.Crc32cIntChecksum.resumeChecksum; +import com.google.common.annotations.VisibleForTesting; import com.google.protobuf.ByteString; import io.netty.buffer.ByteBuf; import io.netty.buffer.PooledByteBufAllocator; @@ -136,33 +137,6 @@ public static ByteBuf newConnect(String authMethodName, String authData, int pro return res; } - /** - * @deprecated AuthMethod has been deprecated. Use {@link #newConnect(String authMethodName, String authData)} - * instead. - */ - @Deprecated - public static ByteBuf newConnect(AuthMethod authMethod, String authData) { - return newConnect(authMethod, authData, getCurrentProtocolVersion()); - } - - /** - * @deprecated AuthMethod has been deprecated. Use - * {@link #newConnect(String authMethodName, String authData, int protocolVersion)} instead. - */ - @Deprecated - public static ByteBuf newConnect(AuthMethod authMethod, String authData, int protocolVersion) { - CommandConnect.Builder connectBuilder = CommandConnect.newBuilder(); - connectBuilder.setClientVersion("Pulsar Client"); - connectBuilder.setAuthMethod(authMethod); - connectBuilder.setAuthData(ByteString.copyFromUtf8(authData)); - connectBuilder.setProtocolVersion(protocolVersion); - CommandConnect connect = connectBuilder.build(); - ByteBuf res = serializeWithSize(BaseCommand.newBuilder().setType(Type.CONNECT).setConnect(connect)); - connect.recycle(); - connectBuilder.recycle(); - return res; - } - public static ByteBuf newConnected(int clientProtocolVersion) { CommandConnected.Builder connectedBuilder = CommandConnected.newBuilder(); connectedBuilder.setServerVersion("Pulsar Server"); @@ -702,7 +676,8 @@ public static ByteBuf newGetLastMessageIdResponse(long requestId, MessageIdData return res; } - private static ByteBuf serializeWithSize(BaseCommand.Builder cmdBuilder) { + @VisibleForTesting + public static ByteBuf serializeWithSize(BaseCommand.Builder cmdBuilder) { // / Wire format // [TOTAL_SIZE] [CMD_SIZE][CMD] BaseCommand cmd = cmdBuilder.build(); @@ -941,7 +916,8 @@ private static ByteBufPair serializeCommandMessageWithSize(BaseCommand cmd, Byte return (ByteBufPair) ByteBufPair.get(headers, metadataAndPayload); } - private static int getCurrentProtocolVersion() { + @VisibleForTesting + public static int getCurrentProtocolVersion() { // Return the last ProtocolVersion enum value return ProtocolVersion.values()[ProtocolVersion.values().length - 1].getNumber(); }