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 * update code that calls the request instead of the request code itself
- Loading branch information
1 parent
2fd0cc6
commit 7529618
Showing
4 changed files
with
71 additions
and
92 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
102 changes: 48 additions & 54 deletions
102
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 |
---|---|---|
@@ -1,63 +1,57 @@ | ||
package org.cloudfoundry.util; | ||
|
||
import static org.cloudfoundry.util.ResourceMatchingUtilsV3.getMatchedResources; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
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.cloudfoundry.client.v3.resourcematch.MatchedResource; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.core.io.ClassPathResource; | ||
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()); | ||
|
||
} | ||
|
||
} | ||
@Test | ||
void requestListMatchingResources2() throws IOException { | ||
CloudFoundryClient cloudFoundryClient = mock(CloudFoundryClient.class); | ||
when(cloudFoundryClient.resourceMatchV3()) | ||
.thenReturn( | ||
request -> | ||
Mono.just( | ||
ListMatchingResourcesResponse.builder() | ||
.addAllResources(request.getResources()) | ||
.build())); | ||
|
||
Path testApplication = new ClassPathResource("test-application.zip").getFile().toPath(); | ||
|
||
List<MatchedResource> result = | ||
getMatchedResources(cloudFoundryClient, testApplication).block(); | ||
assertNotNull(result); | ||
assertEquals(2, result.size()); | ||
} | ||
|
||
@Test | ||
void requestListMatchingResources15001() throws IOException { | ||
CloudFoundryClient cloudFoundryClient = mock(CloudFoundryClient.class); | ||
when(cloudFoundryClient.resourceMatchV3()) | ||
.thenReturn( | ||
request -> | ||
Mono.just( | ||
ListMatchingResourcesResponse.builder() | ||
.addAllResources(request.getResources()) | ||
.build())); | ||
Path testApplication = new ClassPathResource("15001_files.zip").getFile().toPath(); | ||
|
||
List<MatchedResource> result = | ||
getMatchedResources(cloudFoundryClient, testApplication).block(); | ||
assertNotNull(result); | ||
assertEquals(15001, result.size()); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.