Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Collection;
import java.util.Enumeration;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.cloudfoundry.client.CloudFoundryClient;
Expand All @@ -46,6 +47,7 @@ public final class ResourceMatchingUtilsV3 {

private static final Logger LOGGER =
LoggerFactory.getLogger("cloudfoundry-client.resource-matching-v3");
public static final int MAX_RESOURCES_SIZE = 5000;

private ResourceMatchingUtilsV3() {}

Expand All @@ -55,9 +57,9 @@ public static Mono<List<MatchedResource>> getMatchedResources(
? getArtifactMetadataFromDirectory(application)
: getArtifactMetadataFromZip(application))
.collectList()
.flatMap(
(List<ArtifactMetadata> artifactMetadatas) ->
requestListMatchingResources(cloudFoundryClient, artifactMetadatas))
.flatMapMany(Flux::fromIterable)
.buffer(MAX_RESOURCES_SIZE)
.flatMap(chunk -> requestListMatchingResources(cloudFoundryClient, chunk))
.map(ListMatchingResourcesResponse::getResources)
.doOnNext(
matched ->
Expand All @@ -68,6 +70,8 @@ public static Mono<List<MatchedResource>> getMatchedResources(
matched.stream()
.mapToInt(MatchedResource::getSize)
.sum())))
.collectList()
.map(lists -> lists.stream().flatMap(List::stream).collect(Collectors.toList()))
.subscribeOn(Schedulers.boundedElastic());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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.resourcematch.ListMatchingResourcesResponse;
import org.cloudfoundry.client.v3.resourcematch.MatchedResource;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import reactor.core.publisher.Mono;

class ResourceMatchingUtilsV3Test {

@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.