Skip to content

Commit 4ff2e5f

Browse files
committed
[test] Move DescribeTabletServers ITCases to FlussAdmin2ITCase
After rebasing onto main, FlussAdminITCase grew to 3,047 lines and failed Checkstyle's 3,000-line FileLength rule in every Java CI job. FlussAdmin2ITCase exists for exactly this overflow, so the rolling upgrade test moves there unchanged (using DATA1_TABLE_DESCRIPTOR_PK instead of the schema borrowed from FlussAdminITCase), and the server tag assertions that piggybacked on testAddAndRemoveServerTags become a small dedicated test. FlussAdminITCase is back to its upstream content.
1 parent 128cc24 commit 4ff2e5f

2 files changed

Lines changed: 109 additions & 98 deletions

File tree

‎fluss-client/src/test/java/org/apache/fluss/client/admin/FlussAdmin2ITCase.java‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

2020
package org.apache.fluss.client.admin;
2121

22+
import org.apache.fluss.cluster.rebalance.ServerTag;
2223
import org.apache.fluss.config.AutoPartitionTimeUnit;
2324
import org.apache.fluss.config.ConfigOptions;
2425
import org.apache.fluss.exception.TableNotPartitionedException;
2526
import org.apache.fluss.metadata.PartitionInfo;
2627
import org.apache.fluss.metadata.Schema;
28+
import org.apache.fluss.metadata.TableBucket;
2729
import org.apache.fluss.metadata.TableDescriptor;
2830
import org.apache.fluss.metadata.TablePath;
2931
import org.apache.fluss.rpc.messages.ListPartitionInfosRequest;
@@ -33,12 +35,15 @@
3335

3436
import org.junit.jupiter.api.Test;
3537

38+
import java.time.Duration;
39+
import java.util.Collections;
3640
import java.util.List;
3741
import java.util.Map;
3842

3943
import static org.apache.fluss.metadata.DataLakeFormat.PAIMON;
4044
import static org.apache.fluss.record.TestData.DATA1_PARTITIONED_TABLE_DESCRIPTOR;
4145
import static org.apache.fluss.record.TestData.DATA1_TABLE_DESCRIPTOR_PK;
46+
import static org.apache.fluss.testutils.common.CommonTestUtils.waitUntil;
4247
import static org.apache.fluss.utils.PartitionUtils.HISTORICAL_PARTITION_VALUE;
4348
import static org.assertj.core.api.Assertions.assertThat;
4449
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -164,6 +169,94 @@ void testListPartitionInfos() throws Exception {
164169
.doesNotContain(HISTORICAL_PARTITION_VALUE);
165170
}
166171

172+
@Test
173+
void testDescribeTabletServersReportsServerTags() throws Exception {
174+
admin.addServerTag(Collections.singletonList(0), ServerTag.PERMANENT_OFFLINE).get();
175+
try {
176+
List<TabletServerDescription> servers = admin.describeTabletServers().get();
177+
assertThat(getTabletServerDescription(servers, 0).getServerTag())
178+
.contains(ServerTag.PERMANENT_OFFLINE);
179+
assertThat(getTabletServerDescription(servers, 1).getServerTag()).isNotPresent();
180+
assertThat(getTabletServerDescription(servers, 2).getServerTag()).isNotPresent();
181+
} finally {
182+
admin.removeServerTag(Collections.singletonList(0), ServerTag.PERMANENT_OFFLINE).get();
183+
}
184+
assertThat(admin.describeTabletServers().get())
185+
.allSatisfy(server -> assertThat(server.getServerTag()).isNotPresent());
186+
}
187+
188+
@Test
189+
void testDescribeTabletServersDuringRollingUpgrade() throws Exception {
190+
TablePath tablePath = TablePath.of("test_db", "describe_tablet_servers_table");
191+
long tableId = createTable(tablePath, DATA1_TABLE_DESCRIPTOR_PK, true);
192+
waitAllReplicasReady(tableId, 3);
193+
194+
// Phase 1: Cluster is healthy - every live server is reported, hosts replicas of the
195+
// created table (replication factor 3 on 3 servers) and is green. The cluster is shared
196+
// with other tests, so wait until residue from them (e.g. a recovering ISR) has settled
197+
// before taking the snapshot asserted below.
198+
waitUntil(
199+
() ->
200+
admin.describeTabletServers().get().stream()
201+
.allMatch(FlussAdmin2ITCase::isServerGreen),
202+
Duration.ofMinutes(1),
203+
"All tablet servers should be green before the rolling upgrade starts");
204+
205+
List<TabletServerDescription> servers = admin.describeTabletServers().get();
206+
assertThat(servers).extracting(TabletServerDescription::getServerId).contains(0, 1, 2);
207+
for (TabletServerDescription server : servers) {
208+
assertThat(server.getNumReplicas()).isGreaterThan(0);
209+
assertThat(isServerGreen(server)).isTrue();
210+
}
211+
212+
// The per-server counters must sum up to the cluster-wide health counters.
213+
ClusterHealth health = admin.getClusterHealth().get();
214+
assertThat(servers.stream().mapToInt(TabletServerDescription::getNumReplicas).sum())
215+
.isEqualTo(health.getNumReplicas());
216+
assertThat(servers.stream().mapToInt(TabletServerDescription::getInSyncReplicas).sum())
217+
.isEqualTo(health.getInSyncReplicas());
218+
assertThat(servers.stream().mapToInt(TabletServerDescription::getNumLeaderReplicas).sum())
219+
.isEqualTo(health.getNumLeaderReplicas());
220+
assertThat(
221+
servers.stream()
222+
.mapToInt(TabletServerDescription::getActiveLeaderReplicas)
223+
.sum())
224+
.isEqualTo(health.getActiveLeaderReplicas());
225+
226+
// Phase 2: Stop one tablet server (simulate server crash during rolling upgrade). It must
227+
// still be reported with its assigned replicas, but no longer green - an operator must
228+
// not treat it as safe to remove.
229+
int stoppedServerId = 0;
230+
FLUSS_CLUSTER_EXTENSION.stopTabletServer(stoppedServerId);
231+
FLUSS_CLUSTER_EXTENSION.assertHasTabletServerNumber(2);
232+
233+
for (int bucket = 0; bucket < 3; bucket++) {
234+
TableBucket tb = new TableBucket(tableId, bucket);
235+
FLUSS_CLUSTER_EXTENSION.waitUntilReplicaShrinkFromIsr(tb, stoppedServerId);
236+
}
237+
238+
TabletServerDescription stopped =
239+
getTabletServerDescription(admin.describeTabletServers().get(), stoppedServerId);
240+
assertThat(stopped.getNumReplicas()).isGreaterThan(0);
241+
assertThat(stopped.getInSyncReplicas()).isLessThan(stopped.getNumReplicas());
242+
243+
// Phase 3: Restart the server and wait until every server is green again.
244+
FLUSS_CLUSTER_EXTENSION.startTabletServer(stoppedServerId);
245+
FLUSS_CLUSTER_EXTENSION.assertHasTabletServerNumber(3);
246+
247+
for (int bucket = 0; bucket < 3; bucket++) {
248+
TableBucket tb = new TableBucket(tableId, bucket);
249+
FLUSS_CLUSTER_EXTENSION.waitUntilReplicaExpandToIsr(tb, stoppedServerId);
250+
}
251+
252+
waitUntil(
253+
() ->
254+
admin.describeTabletServers().get().stream()
255+
.allMatch(FlussAdmin2ITCase::isServerGreen),
256+
Duration.ofMinutes(1),
257+
"All tablet servers should become green again after server restart");
258+
}
259+
167260
private static ListPartitionInfosRequest requestFor(
168261
TablePath tablePath, boolean includeSystemPartitions) {
169262
ListPartitionInfosRequest request =
@@ -177,4 +270,20 @@ private static ListPartitionInfosRequest requestFor(
177270
}
178271
return request;
179272
}
273+
274+
private static TabletServerDescription getTabletServerDescription(
275+
List<TabletServerDescription> servers, int serverId) {
276+
return servers.stream()
277+
.filter(server -> server.getServerId() == serverId)
278+
.findFirst()
279+
.orElseThrow(
280+
() ->
281+
new AssertionError(
282+
"no description reported for tablet server " + serverId));
283+
}
284+
285+
private static boolean isServerGreen(TabletServerDescription server) {
286+
return server.getInSyncReplicas() == server.getNumReplicas()
287+
&& server.getActiveLeaderReplicas() == server.getNumLeaderReplicas();
288+
}
180289
}

‎fluss-client/src/test/java/org/apache/fluss/client/admin/FlussAdminITCase.java‎

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,14 +2342,6 @@ public void testAddAndRemoveServerTags() throws Exception {
23422342
.containsEntry(0, ServerTag.PERMANENT_OFFLINE)
23432343
.containsEntry(1, ServerTag.PERMANENT_OFFLINE);
23442344

2345-
// the tags are also visible via describeTabletServers.
2346-
List<TabletServerDescription> described = admin.describeTabletServers().get();
2347-
assertThat(getTabletServerDescription(described, 0).getServerTag())
2348-
.contains(ServerTag.PERMANENT_OFFLINE);
2349-
assertThat(getTabletServerDescription(described, 1).getServerTag())
2350-
.contains(ServerTag.PERMANENT_OFFLINE);
2351-
assertThat(getTabletServerDescription(described, 2).getServerTag()).isNotPresent();
2352-
23532345
// 3.add different server tag for server 0,2. error will be thrown and tag for 2 will not be
23542346
// added.
23552347
assertThatThrownBy(
@@ -2954,94 +2946,4 @@ void testClusterHealthDuringRollingUpgrade() throws Exception {
29542946
assertThat(afterRecovery.getNumLeaderReplicas())
29552947
.isEqualTo(afterRecovery.getActiveLeaderReplicas());
29562948
}
2957-
2958-
@Test
2959-
void testDescribeTabletServersDuringRollingUpgrade() throws Exception {
2960-
TablePath tablePath = TablePath.of("test_db", "describe_tablet_servers_table");
2961-
TableDescriptor tableDescriptor =
2962-
TableDescriptor.builder().schema(DEFAULT_SCHEMA).distributedBy(3, "id").build();
2963-
long tableId = createTable(tablePath, tableDescriptor, true);
2964-
waitAllReplicasReady(tableId, 3);
2965-
2966-
// Phase 1: Cluster is healthy - every live server is reported, hosts replicas of the
2967-
// created table (replication factor 3 on 3 servers) and is green. The cluster is shared
2968-
// with other tests, so wait until residue from them (e.g. a recovering ISR) has settled
2969-
// before taking the snapshot asserted below.
2970-
waitUntil(
2971-
() ->
2972-
admin.describeTabletServers().get().stream()
2973-
.allMatch(FlussAdminITCase::isServerGreen),
2974-
Duration.ofMinutes(1),
2975-
"All tablet servers should be green before the rolling upgrade starts");
2976-
2977-
List<TabletServerDescription> servers = admin.describeTabletServers().get();
2978-
assertThat(servers).extracting(TabletServerDescription::getServerId).contains(0, 1, 2);
2979-
for (TabletServerDescription server : servers) {
2980-
assertThat(server.getNumReplicas()).isGreaterThan(0);
2981-
assertThat(isServerGreen(server)).isTrue();
2982-
}
2983-
2984-
// The per-server counters must sum up to the cluster-wide health counters.
2985-
ClusterHealth health = admin.getClusterHealth().get();
2986-
assertThat(servers.stream().mapToInt(TabletServerDescription::getNumReplicas).sum())
2987-
.isEqualTo(health.getNumReplicas());
2988-
assertThat(servers.stream().mapToInt(TabletServerDescription::getInSyncReplicas).sum())
2989-
.isEqualTo(health.getInSyncReplicas());
2990-
assertThat(servers.stream().mapToInt(TabletServerDescription::getNumLeaderReplicas).sum())
2991-
.isEqualTo(health.getNumLeaderReplicas());
2992-
assertThat(
2993-
servers.stream()
2994-
.mapToInt(TabletServerDescription::getActiveLeaderReplicas)
2995-
.sum())
2996-
.isEqualTo(health.getActiveLeaderReplicas());
2997-
2998-
// Phase 2: Stop one tablet server (simulate server crash during rolling upgrade). It must
2999-
// still be reported with its assigned replicas, but no longer green - an operator must
3000-
// not treat it as safe to remove.
3001-
int stoppedServerId = 0;
3002-
FLUSS_CLUSTER_EXTENSION.stopTabletServer(stoppedServerId);
3003-
FLUSS_CLUSTER_EXTENSION.assertHasTabletServerNumber(2);
3004-
3005-
for (int bucket = 0; bucket < 3; bucket++) {
3006-
TableBucket tb = new TableBucket(tableId, bucket);
3007-
FLUSS_CLUSTER_EXTENSION.waitUntilReplicaShrinkFromIsr(tb, stoppedServerId);
3008-
}
3009-
3010-
TabletServerDescription stopped =
3011-
getTabletServerDescription(admin.describeTabletServers().get(), stoppedServerId);
3012-
assertThat(stopped.getNumReplicas()).isGreaterThan(0);
3013-
assertThat(stopped.getInSyncReplicas()).isLessThan(stopped.getNumReplicas());
3014-
3015-
// Phase 3: Restart the server and wait until every server is green again.
3016-
FLUSS_CLUSTER_EXTENSION.startTabletServer(stoppedServerId);
3017-
FLUSS_CLUSTER_EXTENSION.assertHasTabletServerNumber(3);
3018-
3019-
for (int bucket = 0; bucket < 3; bucket++) {
3020-
TableBucket tb = new TableBucket(tableId, bucket);
3021-
FLUSS_CLUSTER_EXTENSION.waitUntilReplicaExpandToIsr(tb, stoppedServerId);
3022-
}
3023-
3024-
waitUntil(
3025-
() ->
3026-
admin.describeTabletServers().get().stream()
3027-
.allMatch(FlussAdminITCase::isServerGreen),
3028-
Duration.ofMinutes(1),
3029-
"All tablet servers should become green again after server restart");
3030-
}
3031-
3032-
private static TabletServerDescription getTabletServerDescription(
3033-
List<TabletServerDescription> servers, int serverId) {
3034-
return servers.stream()
3035-
.filter(server -> server.getServerId() == serverId)
3036-
.findFirst()
3037-
.orElseThrow(
3038-
() ->
3039-
new AssertionError(
3040-
"no description reported for tablet server " + serverId));
3041-
}
3042-
3043-
private static boolean isServerGreen(TabletServerDescription server) {
3044-
return server.getInSyncReplicas() == server.getNumReplicas()
3045-
&& server.getActiveLeaderReplicas() == server.getNumLeaderReplicas();
3046-
}
30472949
}

0 commit comments

Comments
 (0)