Skip to content

Commit

Permalink
Remove deprecated newConnect methods (apache#1315)
Browse files Browse the repository at this point in the history
* Remove deprecated and unused code

* Revert "Remove deprecated and unused code"

This reverts commit 95114c6.

* Move old newConnect funtions to tests for backward compat
  • Loading branch information
mgodave authored and merlimat committed Mar 1, 2018
1 parent 1db47ca commit ccf1812
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -210,15 +212,32 @@ 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();
assertTrue(channel.isActive());
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit ccf1812

Please sign in to comment.