Skip to content

Commit 7715029

Browse files
committed
[FLINK-38783][runtime] Additional Test Cleanup for TieredStorageResourceRegistry Concurrency Tests
[FLINK-38783][runtime] Additional Test Cleanup for TieredStorageResourceRegistry Concurrency Tests
1 parent 188cf83 commit 7715029

1 file changed

Lines changed: 27 additions & 26 deletions

File tree

flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/hybrid/tiered/storage/TieredStorageResourceRegistryTest.java

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818

1919
package org.apache.flink.runtime.io.network.partition.hybrid.tiered.storage;
2020

21-
import static org.assertj.core.api.Assertions.assertThat;
22-
2321
import org.apache.flink.runtime.io.network.partition.hybrid.tiered.common.TieredStorageDataIdentifier;
22+
2423
import org.junit.jupiter.api.AfterEach;
2524
import org.junit.jupiter.api.BeforeEach;
2625
import org.junit.jupiter.api.RepeatedTest;
@@ -35,6 +34,8 @@
3534
import java.util.concurrent.TimeUnit;
3635
import java.util.concurrent.atomic.AtomicInteger;
3736

37+
import static org.assertj.core.api.Assertions.assertThat;
38+
3839
/** Tests for {@link TieredStorageResourceRegistry}. */
3940
class TieredStorageResourceRegistryTest {
4041

@@ -62,6 +63,30 @@ void tearDown() throws Exception {
6263
executor.awaitTermination(10, TimeUnit.SECONDS);
6364
}
6465

66+
@RepeatedTest(10)
67+
void testConcurrentRegisterResource() throws Exception {
68+
AtomicInteger releaseCount = new AtomicInteger(0);
69+
TestingDataIdentifier sharedOwner = new TestingDataIdentifier(0);
70+
71+
runConcurrentTask(
72+
threadId -> {
73+
for (int i = 0; i < NUM_OPERATIONS_PER_THREAD; i++) {
74+
registry.registerResource(
75+
sharedOwner, () -> releaseCount.incrementAndGet());
76+
}
77+
});
78+
79+
assertNoExceptions("Concurrent registerResource() calls");
80+
81+
// Clear resources and verify all were registered
82+
registry.clearResourceFor(sharedOwner);
83+
84+
// Verify that all registered resources were successfully release
85+
assertThat(releaseCount.get())
86+
.as("All registered resources should be released.")
87+
.isEqualTo(NUM_THREADS * NUM_OPERATIONS_PER_THREAD);
88+
}
89+
6590
@RepeatedTest(10)
6691
void testConcurrentRegisterResourceWithDifferentOwners() throws Exception {
6792
AtomicInteger successfulRegistrations = new AtomicInteger(0);
@@ -112,30 +137,6 @@ void testConcurrentRegisterAndClear() throws Exception {
112137
assertNoExceptions("Concurrent registration/clearing calls");
113138
}
114139

115-
@RepeatedTest(10)
116-
void testConcurrentRegisterResourceWithSameOwner() throws Exception {
117-
AtomicInteger releaseCount = new AtomicInteger(0);
118-
TestingDataIdentifier sharedOwner = new TestingDataIdentifier(0);
119-
120-
runConcurrentTask(
121-
threadId -> {
122-
for (int i = 0; i < NUM_OPERATIONS_PER_THREAD; i++) {
123-
registry.registerResource(
124-
sharedOwner, () -> releaseCount.incrementAndGet());
125-
}
126-
});
127-
128-
assertNoExceptions("concurrent registerResource() calls with same owner");
129-
130-
// Clear resources and verify all were registered
131-
registry.clearResourceFor(sharedOwner);
132-
133-
// Verify that all registered resources were successfully release
134-
assertThat(releaseCount.get())
135-
.as("All registered resources should be released.")
136-
.isEqualTo(NUM_THREADS * NUM_OPERATIONS_PER_THREAD);
137-
}
138-
139140
private void runConcurrentTask(ThrowingIntConsumer task) throws Exception {
140141
for (int t = 0; t < NUM_THREADS; t++) {
141142
final int threadId = t;

0 commit comments

Comments
 (0)