|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Alibaba Group Holding Ltd. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.alibaba.fluss.rpc.netty.client; |
| 18 | + |
| 19 | +import com.alibaba.fluss.cluster.ServerType; |
| 20 | +import com.alibaba.fluss.rpc.messages.PbApiVersion; |
| 21 | +import com.alibaba.fluss.rpc.protocol.ApiKeys; |
| 22 | +import com.alibaba.fluss.rpc.protocol.ApiManager; |
| 23 | + |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +import java.util.ArrayList; |
| 27 | +import java.util.List; |
| 28 | +import java.util.Set; |
| 29 | + |
| 30 | +import static org.assertj.core.api.Assertions.assertThat; |
| 31 | + |
| 32 | +/** The unit test for {@link ServerApiVersions}. */ |
| 33 | +class ServerApiVersionsTest { |
| 34 | + |
| 35 | + @Test |
| 36 | + void testClientUnSupportedApiVersions() { |
| 37 | + ApiManager apiManager = new ApiManager(ServerType.TABLET_SERVER); |
| 38 | + Set<ApiKeys> apiKeys = apiManager.enabledApis(); |
| 39 | + List<PbApiVersion> apiVersions = new ArrayList<>(); |
| 40 | + for (ApiKeys api : apiKeys) { |
| 41 | + apiVersions.add( |
| 42 | + new PbApiVersion() |
| 43 | + .setApiKey(api.id) |
| 44 | + .setMinVersion(api.lowestSupportedVersion) |
| 45 | + .setMaxVersion(api.highestSupportedVersion)); |
| 46 | + } |
| 47 | + // add a api key that client don't support, we use -1 as apiKey to mock |
| 48 | + // the client unsupported api key |
| 49 | + apiVersions.add(new PbApiVersion().setApiKey(-1).setMinVersion(0).setMaxVersion(0)); |
| 50 | + |
| 51 | + ServerApiVersions serverApiVersions = new ServerApiVersions(apiVersions); |
| 52 | + // verify we get get highest available version for supported api key |
| 53 | + assertThat(serverApiVersions.highestAvailableVersion(ApiKeys.API_VERSIONS)) |
| 54 | + .isEqualTo(ApiKeys.API_VERSIONS.highestSupportedVersion); |
| 55 | + } |
| 56 | +} |
0 commit comments