Skip to content

Commit

Permalink
feat(lb): deterministic subsetting algorithm to limit the number of i…
Browse files Browse the repository at this point in the history
…nstances
  • Loading branch information
jizhuozhi committed Oct 28, 2023
1 parent 22e212a commit 48bbf98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public SubsetServiceInstanceListSupplier(ServiceInstanceListSupplier delegate, S
@Override
public Flux<List<ServiceInstance>> get() {
return delegate.get().map(instances -> {
if (instances.isEmpty()) {
if (instances.size() <= subsetSize) {
return instances;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ void shouldReturnSublistWithGivenSubsetSize() {
assertThat(serviceInstances).hasSize(5);
}

@Test
void shouldReturnRawWhenLessThanSubsetSize() {
List<ServiceInstance> instances = IntStream.range(0, 101)
.mapToObj(i -> new DefaultServiceInstance(Integer.toString(i), "test", "host" + i, 8080, false, null))
.collect(Collectors.toList());

when(delegate.get()).thenReturn(Flux.just(instances));
SubsetServiceInstanceListSupplier supplier = new SubsetServiceInstanceListSupplier(delegate, 1000);

List<ServiceInstance> serviceInstances = Objects.requireNonNull(supplier.get().blockFirst());
assertThat(serviceInstances).hasSize(101);
}

@Test
void shouldReturnSameSublistForSameInstanceId() {
List<ServiceInstance> instances = IntStream.range(0, 101)
Expand Down

0 comments on commit 48bbf98

Please sign in to comment.