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 @@ -34,6 +34,7 @@
import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
Expand All @@ -44,6 +45,8 @@
import org.cloudfoundry.client.v2.organizations.CreateOrganizationRequest;
import org.cloudfoundry.client.v2.spaces.CreateSpaceRequest;
import org.cloudfoundry.client.v2.stacks.ListStacksRequest;
import org.cloudfoundry.client.v2.stacks.StackEntity;
import org.cloudfoundry.client.v2.stacks.StackResource;
import org.cloudfoundry.client.v2.userprovidedserviceinstances.CreateUserProvidedServiceInstanceRequest;
import org.cloudfoundry.doppler.DopplerClient;
import org.cloudfoundry.logcache.v1.TestLogCacheEndpoints;
Expand Down Expand Up @@ -527,16 +530,20 @@ String spaceName(NameFactory nameFactory) {

@Bean(initMethod = "block")
@DependsOn("cloudFoundryCleaner")
Mono<String> stackId(CloudFoundryClient cloudFoundryClient, String stackName) {
return PaginationUtils.requestClientV2Resources(
page ->
cloudFoundryClient
.stacks()
.list(
ListStacksRequest.builder()
.name(stackName)
.page(page)
.build()))
Mono<String> stackId(CloudFoundryClient cloudFoundryClient, Mono<String> stackName) {
return stackName
.flux()
.flatMap(
name ->
PaginationUtils.requestClientV2Resources(
page ->
cloudFoundryClient
.stacks()
.list(
ListStacksRequest.builder()
.name(name)
.page(page)
.build())))
.single()
.map(ResourceUtils::getId)
.doOnSubscribe(s -> this.logger.debug(">> STACK ({}) <<", stackName))
Expand All @@ -545,9 +552,24 @@ Mono<String> stackId(CloudFoundryClient cloudFoundryClient, String stackName) {
.cache();
}

@Bean
String stackName() {
return "cflinuxfs3";
/**
* Select the most recent stack available, matching {@code cflinuxfs*}, based
* on the stack number.
*/
@Bean(initMethod = "block")
@DependsOn("cloudFoundryCleaner")
Mono<String> stackName(CloudFoundryClient cloudFoundryClient) {
return PaginationUtils.requestClientV2Resources(
page ->
cloudFoundryClient
.stacks()
.list(ListStacksRequest.builder().page(page).build()))
.map(StackResource::getEntity)
.map(StackEntity::getName)
.filter(s -> s.matches("^cflinuxfs\\d$"))
.sort(Comparator.reverseOrder())
.single()
.cache();
}

@Bean(initMethod = "block")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.cloudfoundry.util.JobUtils;
import org.cloudfoundry.util.PaginationUtils;
import org.cloudfoundry.util.ResourceUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import reactor.core.publisher.Flux;
Expand All @@ -41,7 +42,12 @@ public final class StacksTest extends AbstractIntegrationTest {

@Autowired private CloudFoundryClient cloudFoundryClient;

@Autowired private String stackName;
private String stackName;

@BeforeEach
void setUp(@Autowired Mono<String> stackName) {
this.stackName = stackName.block();
}

@Test
public void create() {
Expand All @@ -54,7 +60,7 @@ public void create() {
.description("Test stack description")
.name(stackName)
.build())
.thenMany(requestListStacks(this.cloudFoundryClient, stackName))
.thenMany(requestListStacks(stackName))
.map(response -> ResourceUtils.getEntity(response).getDescription())
.as(StepVerifier::create)
.expectNext("Test stack description")
Expand Down Expand Up @@ -122,7 +128,7 @@ public void deleteAsync() {

@Test
public void get() {
getStackId(this.cloudFoundryClient, this.stackName)
getStackId()
.flatMap(
stackId ->
this.cloudFoundryClient
Expand All @@ -137,7 +143,7 @@ public void get() {

@Test
public void list() {
getStackId(this.cloudFoundryClient, this.stackName)
getStackId()
.flatMapMany(
stackId ->
PaginationUtils.requestClientV2Resources(
Expand All @@ -161,15 +167,7 @@ public void list() {

@Test
public void listFilterByName() {
PaginationUtils.requestClientV2Resources(
page ->
this.cloudFoundryClient
.stacks()
.list(
ListStacksRequest.builder()
.name(this.stackName)
.page(page)
.build()))
this.requestListStacks(this.stackName)
.map(resource -> resource.getEntity().getName())
.as(StepVerifier::create)
.expectNext(this.stackName)
Expand All @@ -182,9 +180,8 @@ private static Mono<String> createStackId(
return requestCreateStack(cloudFoundryClient, stackName).map(ResourceUtils::getId);
}

private static Mono<String> getStackId(
CloudFoundryClient cloudFoundryClient, String stackName) {
return requestListStacks(cloudFoundryClient, stackName).single().map(ResourceUtils::getId);
private Mono<String> getStackId() {
return this.requestListStacks(this.stackName).single().map(ResourceUtils::getId);
}

private static Mono<CreateStackResponse> requestCreateStack(
Expand All @@ -203,11 +200,10 @@ private static Mono<GetStackResponse> requestGetStack(
return cloudFoundryClient.stacks().get(GetStackRequest.builder().stackId(stackId).build());
}

private static Flux<StackResource> requestListStacks(
CloudFoundryClient cloudFoundryClient, String stackName) {
private Flux<StackResource> requestListStacks(String stackName) {
return PaginationUtils.requestClientV2Resources(
page ->
cloudFoundryClient
this.cloudFoundryClient
.stacks()
.list(
ListStacksRequest.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ private static Mono<CreateBuildpackResponse> requestCreateBuildpack(
.locked(false)
.name(buildpackName)
.position(3)
.stack("cflinuxfs3")
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.cloudfoundry.client.v3.stacks.Stack;
import org.cloudfoundry.client.v3.stacks.StackResource;
import org.cloudfoundry.util.PaginationUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import reactor.core.publisher.Flux;
Expand All @@ -40,7 +41,12 @@ public final class StacksTest extends AbstractIntegrationTest {

@Autowired private CloudFoundryClient cloudFoundryClient;

@Autowired private String stackName;
private String stackName;

@BeforeEach
void setUp(@Autowired Mono<String> stackName) {
this.stackName = stackName.block();
}

@Test
public void create() {
Expand All @@ -53,7 +59,7 @@ public void create() {
.description("Test stack description")
.name(stackName)
.build())
.thenMany(requestListStacks(this.cloudFoundryClient, stackName))
.thenMany(requestListStacks(stackName))
.map(Stack::getDescription)
.as(StepVerifier::create)
.expectNext("Test stack description")
Expand Down Expand Up @@ -88,7 +94,7 @@ public void delete() {

@Test
public void get() {
getStackId(this.cloudFoundryClient, this.stackName)
getStackId()
.flatMap(
stackId ->
this.cloudFoundryClient
Expand All @@ -103,7 +109,7 @@ public void get() {

@Test
public void list() {
getStackId(this.cloudFoundryClient, this.stackName)
getStackId()
.flatMapMany(
stackId ->
PaginationUtils.requestClientV3Resources(
Expand All @@ -124,15 +130,7 @@ public void list() {

@Test
public void listFilterByName() {
PaginationUtils.requestClientV3Resources(
page ->
this.cloudFoundryClient
.stacksV3()
.list(
ListStacksRequest.builder()
.name(this.stackName)
.page(page)
.build()))
this.requestListStacks(this.stackName)
.map(Stack::getName)
.as(StepVerifier::create)
.expectNext(this.stackName)
Expand All @@ -145,9 +143,8 @@ private static Mono<String> createStackId(
return requestCreateStack(cloudFoundryClient, stackName).map(Stack::getId);
}

private static Mono<String> getStackId(
CloudFoundryClient cloudFoundryClient, String stackName) {
return requestListStacks(cloudFoundryClient, stackName).single().map(Stack::getId);
private Mono<String> getStackId() {
return this.requestListStacks(this.stackName).single().map(Stack::getId);
}

private static Mono<CreateStackResponse> requestCreateStack(
Expand All @@ -168,11 +165,10 @@ private static Mono<GetStackResponse> requestGetStack(
.get(GetStackRequest.builder().stackId(stackId).build());
}

private static Flux<StackResource> requestListStacks(
CloudFoundryClient cloudFoundryClient, String stackName) {
private Flux<StackResource> requestListStacks(String stackName) {
return PaginationUtils.requestClientV3Resources(
page ->
cloudFoundryClient
this.cloudFoundryClient
.stacksV3()
.list(
ListStacksRequest.builder()
Expand Down