Skip to content

Commit 9c96e04

Browse files
committed
Add tests for ReactiveDiscoveryClientAdapter.toList
Introduced test cases to verify the toList utility method in ReactiveDiscoveryClientAdapter using different schedulers. Ensures correct conversion of Flux to List under various scheduling scenarios.
1 parent 3e9cf7c commit 9c96e04

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/discovery/ReactiveDiscoveryClientAdapterTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@
2626
import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
2727
import org.springframework.cloud.client.discovery.simple.reactive.SimpleReactiveDiscoveryClient;
2828
import org.springframework.cloud.client.discovery.simple.reactive.SimpleReactiveDiscoveryProperties;
29+
import reactor.core.Disposable;
30+
import reactor.core.publisher.Flux;
31+
import reactor.core.scheduler.Scheduler;
2932

3033
import java.util.HashMap;
3134
import java.util.List;
3235
import java.util.Map;
36+
import java.util.concurrent.Callable;
3337

3438
import static io.microsphere.collection.Lists.ofList;
39+
import static io.microsphere.spring.cloud.client.discovery.ReactiveDiscoveryClientAdapter.toList;
3540
import static io.microsphere.spring.cloud.client.service.util.ServiceInstanceUtilsTest.createDefaultServiceInstance;
3641
import static org.junit.jupiter.api.Assertions.assertEquals;
3742
import static org.junit.jupiter.api.Assertions.assertSame;
43+
import static reactor.core.scheduler.Schedulers.immediate;
44+
import static reactor.core.scheduler.Schedulers.newSingle;
3845

3946
/**
4047
* {@link ReactiveDiscoveryClientAdapter}
@@ -97,4 +104,21 @@ void testProbe() {
97104
void testGetOrder() {
98105
assertEquals(this.client.getOrder(), this.adapter.getOrder());
99106
}
107+
108+
@Test
109+
void testToList() throws Exception {
110+
assertList(immediate(), "1,2,3");
111+
assertList(newSingle("test"), "1,2,3");
112+
}
113+
114+
<T> void assertList(Scheduler scheduler, T... values) throws Exception {
115+
Flux<T> flux = Flux.just(values);
116+
Disposable disposable = scheduler.schedule(() -> {
117+
List<T> list = toList(flux);
118+
assertEquals(ofList(values), list);
119+
});
120+
if (disposable instanceof Callable) {
121+
((Callable) disposable).call();
122+
}
123+
}
100124
}

0 commit comments

Comments
 (0)