forked from cloudfoundry/cf-java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix cloudfoundry#1222: Chunk request with large number of matched res…
…ources * CAPI, with v3 API, is limited to returning responses with max 5000 max matched resources; so we chunk them into request with max 5000 matched resources * first try
- Loading branch information
1 parent
6c5652e
commit 2fd0cc6
Showing
2 changed files
with
99 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
cloudfoundry-util/src/test/java/org/cloudfoundry/util/ResourceMatchingUtilsV3Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.cloudfoundry.util; | ||
|
||
import org.cloudfoundry.client.CloudFoundryClient; | ||
import org.cloudfoundry.client.v3.Checksum; | ||
import org.cloudfoundry.client.v3.resourcematch.ListMatchingResourcesRequest; | ||
import org.cloudfoundry.client.v3.resourcematch.ListMatchingResourcesResponse; | ||
import org.cloudfoundry.client.v3.resourcematch.ResourceMatchV3; | ||
import org.junit.jupiter.api.Test; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.stream.IntStream; | ||
|
||
import static org.cloudfoundry.util.ResourceMatchingUtilsV3.requestListMatchingResources; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class ResourceMatchingUtilsV3Test { | ||
|
||
|
||
@Test | ||
void requestListMatchingResources5() { | ||
CloudFoundryClient cloudFoundryClient = mock(CloudFoundryClient.class); | ||
Collection<ResourceMatchingUtilsV3.ArtifactMetadata> artifactMetadatas = new ArrayList<>(); | ||
|
||
IntStream.range(0,5).forEach(value -> { | ||
artifactMetadatas.add(new ResourceMatchingUtilsV3.ArtifactMetadata(Checksum.builder().value("pif" + value).build(), "path"+value, "0644", value)); | ||
}); | ||
when(cloudFoundryClient.resourceMatchV3()).thenReturn(new ResourceMatchV3() { | ||
@Override | ||
public Mono<ListMatchingResourcesResponse> list(ListMatchingResourcesRequest request) { | ||
return Mono.just(ListMatchingResourcesResponse.builder().addAllResources(request.getResources()).build()); | ||
} | ||
}); | ||
|
||
ListMatchingResourcesResponse listMatchingResourcesResponse = requestListMatchingResources(cloudFoundryClient, artifactMetadatas).block(); | ||
assertEquals(5, listMatchingResourcesResponse.getResources().size()); | ||
|
||
} | ||
|
||
@Test | ||
void requestListMatchingResources15001() { | ||
CloudFoundryClient cloudFoundryClient = mock(CloudFoundryClient.class); | ||
Collection<ResourceMatchingUtilsV3.ArtifactMetadata> artifactMetadatas = new ArrayList<>(); | ||
|
||
IntStream.range(0,15001).forEach(value -> { | ||
artifactMetadatas.add(new ResourceMatchingUtilsV3.ArtifactMetadata(Checksum.builder().value("pif" + value).build(), "path"+value, "0644", value)); | ||
}); | ||
when(cloudFoundryClient.resourceMatchV3()).thenReturn(new ResourceMatchV3() { | ||
@Override | ||
public Mono<ListMatchingResourcesResponse> list(ListMatchingResourcesRequest request) { | ||
return Mono.just(ListMatchingResourcesResponse.builder().addAllResources(request.getResources()).build()); | ||
} | ||
}); | ||
|
||
ListMatchingResourcesResponse listMatchingResourcesResponse = requestListMatchingResources(cloudFoundryClient, artifactMetadatas).block(); | ||
assertEquals(15001, listMatchingResourcesResponse.getResources().size()); | ||
|
||
} | ||
|
||
} |