Skip to content

Commit 87e6ecb

Browse files
committed
Merge branch '770-random-route'
2 parents d36b24b + 25b3231 commit 87e6ecb

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/routes/DefaultRoutes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ private static Mono<String> getOptionalDomainId(CloudFoundryClient cloudFoundryC
269269

270270
private static Mono<AbstractRouteResource> getOrCreateRoute(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceId, String domain, String host, String path, Integer port,
271271
Boolean randomPort) {
272+
if (randomPort != null) {
273+
return getDomainId(cloudFoundryClient, organizationId, domain)
274+
.then(domainId -> requestCreateRoute(cloudFoundryClient, domainId, host, path, port, randomPort, spaceId));
275+
}
276+
272277
return getDomainId(cloudFoundryClient, organizationId, domain)
273278
.then(domainId -> getRoute(cloudFoundryClient, domainId, host, path, port)
274279
.cast(AbstractRouteResource.class)

integration-test/src/test/java/org/cloudfoundry/operations/ApplicationsTest.java

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public void getTcp() throws TimeoutException, InterruptedException, IOException
235235
.get(GetApplicationRequest.builder()
236236
.name(applicationName)
237237
.build()))
238-
.map(applicationDetail -> applicationDetail.getUrls().get(0))
238+
.map(applicationDetail -> applicationDetail.getUrls().get(0))
239239
.as(StepVerifier::create)
240240
.consumeNextWith(route -> assertThat(route).matches(domainName + "+?:\\d+$"))
241241
.expectComplete()
@@ -626,6 +626,59 @@ public void pushUpdateRoute() throws TimeoutException, InterruptedException, IOE
626626
.verify(Duration.ofMinutes(5));
627627
}
628628

629+
@Test
630+
public void pushUpdateTcpRoute() throws TimeoutException, InterruptedException, IOException {
631+
String applicationName = this.nameFactory.getApplicationName();
632+
String domainName = this.nameFactory.getDomainName();
633+
634+
requestCreateTcpDomain(this.cloudFoundryOperations, domainName, DEFAULT_ROUTER_GROUP)
635+
.then(this.cloudFoundryOperations.applications()
636+
.pushManifest(PushApplicationManifestRequest.builder()
637+
.manifest(ApplicationManifest.builder()
638+
.path(new ClassPathResource("test-application.zip").getFile().toPath())
639+
.buildpack("staticfile_buildpack")
640+
.disk(512)
641+
.healthCheckType(ApplicationHealthCheck.PROCESS)
642+
.memory(64)
643+
.name(applicationName)
644+
.randomRoute(true)
645+
.route(Route.builder()
646+
.route(domainName)
647+
.build())
648+
.build())
649+
.noStart(true)
650+
.build()))
651+
.then(this.cloudFoundryOperations.applications()
652+
.pushManifest(PushApplicationManifestRequest.builder()
653+
.manifest(ApplicationManifest.builder()
654+
.path(new ClassPathResource("test-application.zip").getFile().toPath())
655+
.buildpack("staticfile_buildpack")
656+
.disk(512)
657+
.healthCheckType(ApplicationHealthCheck.PROCESS)
658+
.memory(64)
659+
.name(applicationName)
660+
.randomRoute(true)
661+
.route(Route.builder()
662+
.route(domainName)
663+
.build())
664+
.build())
665+
.noStart(true)
666+
.build()))
667+
.then(this.cloudFoundryOperations.applications()
668+
.get(GetApplicationRequest.builder()
669+
.name(applicationName)
670+
.build()))
671+
.map(ApplicationDetail::getUrls)
672+
.as(StepVerifier::create)
673+
.consumeNextWith(routes -> {
674+
assertThat(routes.get(0).matches(domainName + "+?:\\d+$"));
675+
assertThat(routes.get(1).matches(domainName + "+?:\\d+$"));
676+
assertThat(!routes.get(0).matches(routes.get(1)));
677+
})
678+
.expectComplete()
679+
.verify(Duration.ofMinutes(5));
680+
}
681+
629682
@Test
630683
public void pushWithHost() throws TimeoutException, InterruptedException, IOException {
631684
String applicationName = this.nameFactory.getApplicationName();

integration-test/src/test/java/org/cloudfoundry/operations/RoutesTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,36 @@ public void mapTcpRoute() throws TimeoutException, InterruptedException, IOExcep
407407
.verify(Duration.ofMinutes(5));
408408
}
409409

410+
@Test
411+
public void mapTcpRouteTwice() throws TimeoutException, InterruptedException, IOException {
412+
String applicationName = this.nameFactory.getApplicationName();
413+
String domainName = this.nameFactory.getDomainName();
414+
415+
Mono
416+
.when(
417+
requestCreateSharedDomain(this.cloudFoundryOperations, domainName, DEFAULT_ROUTER_GROUP),
418+
requestCreateApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true)
419+
)
420+
.then(this.cloudFoundryOperations.routes()
421+
.map(MapRouteRequest.builder()
422+
.applicationName(applicationName)
423+
.domain(domainName)
424+
.randomPort(true)
425+
.build()))
426+
.then(this.cloudFoundryOperations.routes()
427+
.map(MapRouteRequest.builder()
428+
.applicationName(applicationName)
429+
.domain(domainName)
430+
.randomPort(true)
431+
.build()))
432+
.thenMany(requestListRoutes(this.cloudFoundryOperations))
433+
.filter(response -> domainName.equals(response.getDomain()))
434+
.as(StepVerifier::create)
435+
.expectNextCount(2)
436+
.expectComplete()
437+
.verify(Duration.ofMinutes(5));
438+
}
439+
410440
@Test
411441
public void unmap() throws TimeoutException, InterruptedException, IOException {
412442
String applicationName = this.nameFactory.getApplicationName();

0 commit comments

Comments
 (0)