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 @@ -70,7 +70,7 @@ Map<String, String> getRequestTags() {

@Value.Default
Mono<String> getRoot() {
final Mono<String> cached = getConnectionContext().getRootProvider().getRoot("log-cache", getConnectionContext())
final Mono<String> cached = getConnectionContext().getRootProvider().getRoot("log_cache", getConnectionContext())
.onErrorResume(IllegalArgumentException.class, e -> deriveLogCacheUrl());

return getConnectionContext().getCacheDuration()
Expand All @@ -85,7 +85,7 @@ Mono<String> getRoot() {

private Mono<String> deriveLogCacheUrl() {
return getConnectionContext().getRootProvider().getRoot(getConnectionContext())
.map(root -> root.replace("api", "log-cache"))
.map(root -> root.replaceFirst("://api", "://log-cache"))
.map(URI::create)
.delayUntil(uri -> getConnectionContext().trust(uri.getHost(), uri.getPort()))
.map(URI::toString);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2021 the original author or authors.
* Copyright 2013-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,13 @@

import static io.netty.handler.codec.http.HttpMethod.GET;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.net.URI;
import java.time.Duration;
import java.util.Collections;
import org.cloudfoundry.logcache.v1.Envelope;
Expand All @@ -34,18 +40,81 @@
import org.cloudfoundry.logcache.v1.Metric;
import org.cloudfoundry.logcache.v1.ReadRequest;
import org.cloudfoundry.logcache.v1.ReadResponse;
import org.cloudfoundry.reactor.ConnectionContext;
import org.cloudfoundry.reactor.DefaultConnectionContext;
import org.cloudfoundry.reactor.InteractionContext;
import org.cloudfoundry.reactor.RootProvider;
import org.cloudfoundry.reactor.TestRequest;
import org.cloudfoundry.reactor.TestResponse;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

class ReactorLogCacheClientTest extends AbstractLogCacheApiTest {
private static final String API_ROOT =
"http://api.my.rapid.server.com"; // the ".rAPId." part also contains the string "api".
private static final String LOGCACHE =
"http://log-cache.my.rapid.server.com"; // only the "api" at the start of
// the url should be replaced.

private final ReactorLogCacheEndpoints logCacheEndpoints =
new ReactorLogCacheEndpoints(
CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER, Collections.emptyMap());

@Test
void getRootFromFallback() {
URI webServerUri = URI.create(this.root.block(Duration.ofSeconds(5)));
Mono<String> apiRoot = Mono.just(API_ROOT);
RootProvider rootProvider = mock(RootProvider.class);
when(rootProvider.getRoot(eq("log_cache"), any()))
.thenReturn(Mono.error(new IllegalArgumentException())); // trigger fallback
when(rootProvider.getRoot(any())).thenReturn(apiRoot);
ConnectionContext connectionContext =
DefaultConnectionContext.builder()
.rootProvider(rootProvider)
.apiHost(webServerUri.getHost())
.port(webServerUri.getPort())
.secure(false)
.build();
ReactorLogCacheClient examinee =
ReactorLogCacheClient.builder()
.connectionContext(connectionContext)
.tokenProvider(TOKEN_PROVIDER)
.build();
Mono<String> logCacheRoot = examinee.getRoot();
String rootString = logCacheRoot.block(Duration.ofSeconds(15));
assertThat(rootString).isEqualTo(LOGCACHE);
}

@Test
void getRootFromEndpoint() {
mockRequest(
InteractionContext.builder()
.request(TestRequest.builder().method(GET).path("/").build())
.response(
TestResponse.builder()
.status(OK)
.payload("fixtures/GET_response.json")
.build())
.build());
URI webServerUri = URI.create(this.root.block(Duration.ofSeconds(5)));
ConnectionContext connectionContext =
DefaultConnectionContext.builder()
.apiHost(webServerUri.getHost())
.port(webServerUri.getPort())
.secure(false)
.build();
ReactorLogCacheClient examinee =
ReactorLogCacheClient.builder()
.connectionContext(connectionContext)
.tokenProvider(TOKEN_PROVIDER)
.build();
Mono<String> logCacheRoot = examinee.getRoot();
String rootString = logCacheRoot.block(Duration.ofSeconds(5));
assertThat(rootString)
.isEqualTo("http://cache-for-logging.run.pivotal.io:" + webServerUri.getPort());
}

@Test
void info() {
mockRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"uaa": {
"href": "https://uaa.run.pivotal.io"
},
"log_cache": {
"href": "https://cache-for-logging.run.pivotal.io"
},
"logging": {
"href": "wss://doppler.run.pivotal.io:443"
}
Expand Down