2828import java .util .Arrays ;
2929import java .util .Collections ;
3030import java .util .HashMap ;
31+ import java .util .HashSet ;
3132import java .util .List ;
3233import java .util .Map ;
34+ import java .util .Set ;
3335
3436import static org .apache .fluss .record .TestData .DATA1_PHYSICAL_TABLE_PATH ;
3537import static org .apache .fluss .record .TestData .DATA1_SCHEMA ;
@@ -68,7 +70,7 @@ void setup() {
6870
6971 @ Test
7072 void testReturnModifiableCollections () {
71- Cluster cluster = createCluster ();
73+ Cluster cluster = createCluster (aliveTabletServersById );
7274 assertThatThrownBy (() -> cluster .getAliveTabletServers ().put (1 , NODES [3 ]))
7375 .isInstanceOf (UnsupportedOperationException .class );
7476 assertThatThrownBy (
@@ -87,7 +89,7 @@ void testReturnModifiableCollections() {
8789
8890 @ Test
8991 void testGetTable () {
90- Cluster cluster = createCluster ();
92+ Cluster cluster = createCluster (aliveTabletServersById );
9193 assertThat (cluster .getTable (DATA1_TABLE_PATH ).get ()).isEqualTo (DATA1_TABLE_INFO );
9294 assertThat (cluster .getTable (DATA2_TABLE_PATH ).get ()).isEqualTo (DATA2_TABLE_INFO );
9395 assertThat (cluster .getSchema (DATA1_TABLE_PATH ).get ())
@@ -98,7 +100,7 @@ void testGetTable() {
98100
99101 @ Test
100102 void testInvalidMetaAndUpdate () {
101- Cluster cluster = createCluster ();
103+ Cluster cluster = createCluster (aliveTabletServersById );
102104 for (int i = 0 ; i < 10000 ; i ++) {
103105 // mock invalid meta
104106 cluster =
@@ -130,7 +132,26 @@ void testInvalidMetaAndUpdate() {
130132 NODES_IDS )));
131133 }
132134
133- private Cluster createCluster () {
135+ @ Test
136+ void testGetRandomTabletServer () {
137+ Map <Integer , ServerNode > aliveTabletServersById = new HashMap <>();
138+ for (int i = 0 ; i < 10 ; i ++) {
139+ aliveTabletServersById .put (
140+ i , new ServerNode (i , "localhost" , 99 + i , ServerType .TABLET_SERVER ));
141+ }
142+ Cluster cluster = createCluster (aliveTabletServersById );
143+
144+ Set <ServerNode > selectedNodes = new HashSet <>();
145+ for (int i = 0 ; i < 10 ; i ++) {
146+ ServerNode serverNode = cluster .getRandomTabletServer ();
147+ assertThat (serverNode ).isNotNull ();
148+ selectedNodes .add (serverNode );
149+ }
150+
151+ assertThat (selectedNodes ).hasSizeGreaterThan (1 );
152+ }
153+
154+ private Cluster createCluster (Map <Integer , ServerNode > aliveTabletServersById ) {
134155 Map <PhysicalTablePath , List <BucketLocation >> tablePathToBucketLocations = new HashMap <>();
135156 tablePathToBucketLocations .put (
136157 DATA1_PHYSICAL_TABLE_PATH ,
0 commit comments