Skip to content

Commit af6ae85

Browse files
committed
[test] fix unstable test for weighted external-path
1 parent 87a4c91 commit af6ae85

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

paimon-common/src/test/java/org/apache/paimon/fs/WeightedExternalPathProviderTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,35 @@ public class WeightedExternalPathProviderTest {
3737

3838
@Test
3939
public void testEqualWeights() {
40-
int fileNum = 3000;
40+
int fileNum = 30000;
4141
int[] weights = {10, 10, 10};
4242
Map<String, Integer> pathCounts = generatePaths(fileNum, weights);
4343

4444
int expectedCount = fileNum / 3;
4545
for (int count : pathCounts.values()) {
46-
assertThat(count).isBetween(expectedCount - 100, expectedCount + 100);
46+
assertThat(count).isBetween(expectedCount - 1000, expectedCount + 1000);
4747
}
4848
}
4949

5050
@Test
5151
public void testDifferentWeights() {
5252
int[] weights = {10, 5, 15};
53-
int fileNum = 3000;
53+
int fileNum = 30000;
5454
Map<String, Integer> pathCounts = generatePaths(fileNum, weights);
5555

5656
int totalWeight = 30;
5757
assertThat(pathCounts.get("s3://bucket1/data"))
5858
.isBetween(
59-
(int) (fileNum * 10.0 / totalWeight) - 100,
60-
(int) (fileNum * 10.0 / totalWeight) + 100);
59+
(int) (fileNum * 10.0 / totalWeight) - 1000,
60+
(int) (fileNum * 10.0 / totalWeight) + 1000);
6161
assertThat(pathCounts.get("oss://bucket2/data"))
6262
.isBetween(
63-
(int) (fileNum * 5.0 / totalWeight) - 100,
64-
(int) (fileNum * 5.0 / totalWeight) + 100);
63+
(int) (fileNum * 5.0 / totalWeight) - 1000,
64+
(int) (fileNum * 5.0 / totalWeight) + 1000);
6565
assertThat(pathCounts.get("hdfs://namenode/data"))
6666
.isBetween(
67-
(int) (fileNum * 15.0 / totalWeight) - 100,
68-
(int) (fileNum * 15.0 / totalWeight) + 100);
67+
(int) (fileNum * 15.0 / totalWeight) - 1000,
68+
(int) (fileNum * 15.0 / totalWeight) + 1000);
6969
}
7070

7171
@Test

paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/AppendOnlyTableITCase.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import java.io.IOException;
3838
import java.nio.file.Files;
39+
import java.nio.file.NoSuchFileException;
3940
import java.nio.file.Path;
4041
import java.nio.file.Paths;
4142
import java.time.LocalDateTime;
@@ -248,26 +249,29 @@ public void testReadWriteWithExternalPathWeightRobinStrategy() throws IOExceptio
248249
+ "'write-only' = 'true'"
249250
+ ")");
250251

251-
int fileNum = 50;
252+
int fileNum = 30;
252253
for (int i = 1; i <= fileNum; i++) {
253254
batchSql("INSERT INTO append_table VALUES (" + i + ", 'AAA')");
254255
}
255256

256257
List<Row> rows = batchSql("SELECT * FROM append_table");
257258
assertThat(rows.size()).isEqualTo(fileNum);
258259

259-
// Verify file distribution based on weights
260-
long filesInPath1 =
261-
Files.list(Paths.get(tempExternalPath1.toString() + "/bucket-0")).count();
262-
long filesInPath2 =
263-
Files.list(Paths.get(tempExternalPath2.toString() + "/bucket-0")).count();
260+
long filesInPath1 = 0;
261+
long filesInPath2 = 0;
262+
try {
263+
filesInPath1 =
264+
Files.list(Paths.get(tempExternalPath1.toString() + "/bucket-0")).count();
265+
filesInPath2 =
266+
Files.list(Paths.get(tempExternalPath2.toString() + "/bucket-0")).count();
267+
268+
} catch (NoSuchFileException ignored) {
269+
}
270+
264271
long totalFiles = filesInPath1 + filesInPath2;
265272

266-
// Since the file sample size is small in IT case, we only verify that higher-weighted path
267-
// has more files
268-
assertThat(filesInPath1).isGreaterThan(0);
269-
assertThat(filesInPath2).isGreaterThan(0);
270-
assertThat(filesInPath2).isGreaterThan(filesInPath1);
273+
// Since the file sample size is small in IT case, we only verify the writing and reading
274+
// For tests on file distribution by weights, see WeightedExternalPathProviderTest
271275
assertThat(totalFiles).isEqualTo(fileNum);
272276
}
273277

paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/PrimaryKeyFileStoreTableITCase.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
import java.io.IOException;
5454
import java.nio.file.Files;
55+
import java.nio.file.NoSuchFileException;
5556
import java.nio.file.Paths;
5657
import java.util.ArrayList;
5758
import java.util.Arrays;
@@ -340,7 +341,7 @@ public void testTableReadWriteWithExternalPathWeightRobin() throws Exception {
340341

341342
CloseableIterator<Row> it = collect(sEnv.executeSql("SELECT * FROM T2"));
342343

343-
int fileNum = 50;
344+
int fileNum = 30;
344345
for (int i = 1; i <= fileNum; i++) {
345346
sEnv.executeSql("INSERT INTO T2 VALUES (" + i + ", 'data" + i + "')").await();
346347
}
@@ -352,15 +353,18 @@ public void testTableReadWriteWithExternalPathWeightRobin() throws Exception {
352353
// Verify all data is readable
353354
assertThat(actual).hasSize(fileNum);
354355

355-
long filesInPath1 = Files.list(Paths.get(externalPath1.toString() + "/bucket-0")).count();
356-
long filesInPath2 = Files.list(Paths.get(externalPath2.toString() + "/bucket-0")).count();
356+
long filesInPath1 = 0;
357+
long filesInPath2 = 0;
358+
try {
359+
filesInPath1 = Files.list(Paths.get(externalPath1.toString() + "/bucket-0")).count();
360+
filesInPath2 = Files.list(Paths.get(externalPath2.toString() + "/bucket-0")).count();
361+
362+
} catch (NoSuchFileException ignored) {
363+
}
357364
long totalFiles = filesInPath1 + filesInPath2;
358365

359-
// Since the file sample size is small in IT case, we only verify that higher-weighted path
360-
// has more files
361-
assertThat(filesInPath1).isGreaterThan(0);
362-
assertThat(filesInPath2).isGreaterThan(0);
363-
assertThat(filesInPath1).isGreaterThan(filesInPath2);
366+
// Since the file sample size is small in IT case, we only verify the writing and reading
367+
// For tests on file distribution by weights, see WeightedExternalPathProviderTest
364368
assertThat(totalFiles).isEqualTo(fileNum);
365369
}
366370

0 commit comments

Comments
 (0)