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 @@ -17,6 +17,8 @@

import java.util.List;

import static java.lang.String.format;

public class HealthChecker
implements TrinoClusterStatsObserver
{
Expand Down Expand Up @@ -48,20 +50,16 @@ public void observe(List<ClusterStats> clustersStats)

private void notifyUnhealthyCluster(ClusterStats clusterStats)
{
notifier.sendNotification(String.format("%s - Cluster unhealthy",
clusterStats.clusterId()),
clusterStats.toString());
notifier.sendNotification(format("%s - Cluster unhealthy", clusterStats.clusterId()), clusterStats.toString());
}

private void notifyForTooManyQueuedQueries(ClusterStats clusterStats)
{
notifier.sendNotification(String.format("%s - Too many queued queries",
clusterStats.clusterId()), clusterStats.toString());
notifier.sendNotification(format("%s - Too many queued queries", clusterStats.clusterId()), clusterStats.toString());
}

private void notifyForNoWorkers(ClusterStats clusterStats)
{
notifier.sendNotification(String.format("%s - Number of workers",
clusterStats.clusterId()), clusterStats.toString());
notifier.sendNotification(format("%s - Number of workers", clusterStats.clusterId()), clusterStats.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.util.HashMap;

import static java.lang.String.format;

public class ConnectionChecker
{
private static final Logger log = LoggerFactory.getLogger(ConnectionChecker.class);
Expand All @@ -31,8 +33,7 @@ public class ConnectionChecker
ConnectionCheck getChecker(String server, int port, int interval,
int failcount, int disableDuration)
{
String key = String.format("%s-%d-%d-%d-%d",
server, port, interval, failcount, disableDuration);
String key = format("%s-%d-%d-%d-%d", server, port, interval, failcount, disableDuration);
log.info("key is {}", key);
ConnectionCheck obj = connectionChecks.get(key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.ArrayList;
import java.util.List;

import static java.lang.String.format;

public class HaResourceGroupsManager
implements ResourceGroupsManager
{
Expand Down Expand Up @@ -199,7 +201,7 @@ public SelectorsDetail updateSelector(SelectorsDetail selector, SelectorsDetail
try {
connectionManager.open(routingGroupDatabase);
String query =
String.format(
format(
"resource_group_id %s and priority %s "
+ "and user_regex %s and source_regex %s "
+ "and query_type %s and client_tags %s "
Expand Down Expand Up @@ -235,7 +237,7 @@ public void deleteSelector(SelectorsDetail selector, @Nullable String routingGro
try {
connectionManager.open(routingGroupDatabase);
String query =
String.format(
format(
"resource_group_id %s and priority %s "
+ "and user_regex %s and source_regex %s "
+ "and query_type %s and client_tags %s "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public String findRoutingGroup(HttpServletRequest request)
if (attr.lastModifiedTime().toMillis() > lastUpdatedTime) {
// This check is performed again to prevent parsing the rules twice in case another
// thread finds the condition true and acquires the lock before this one
log.info(String.format("Updating rules to file modified at %s",
attr.lastModifiedTime()));
log.info("Updating rules to file modified at {}", attr.lastModifiedTime());
rules = ruleFactory.createRules(
new FileReader(rulesConfigPath, UTF_8));
lastUpdatedTime = attr.lastModifiedTime().toMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import java.util.Objects;
import java.util.Optional;

import static java.lang.String.format;

public class LbOAuthManager
{
private static final Logger log = LoggerFactory.getLogger(LbOAuthManager.class);
Expand Down Expand Up @@ -83,11 +85,8 @@ public Response exchangeCodeForToken(String code, String redirectLocation)
.request()
.post(Entity.form(form));

if (tokenResponse.getStatusInfo()
.getFamily() != Response.Status.Family.SUCCESSFUL) {
String message = String.format("token response failed with code %d - %s",
tokenResponse.getStatus(),
tokenResponse.readEntity(String.class));
if (tokenResponse.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
String message = format("token response failed with code %d - %s", tokenResponse.getStatus(), tokenResponse.readEntity(String.class));
log.error(message);
return Response.status(500).entity(message).build();
}
Expand All @@ -111,7 +110,7 @@ public Response getAuthorizationCode()
String clientId = oauthConfig.getClientId();
String redirectUrl = oauthConfig.getRedirectUrl();
String scopes = String.join("+", oauthConfig.getScopes());
String url = String.format(
String url = format(
"%s?client_id=%s&response_type=code&redirect_uri=%s&scope=%s",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be unwrapped? Line length should be 146 characters, which is less than RIGHT_MARGIN

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be, but I didn't touch as unrelated to import.

authorizationEndpoint, clientId, redirectUrl, scopes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.io.IOException;

import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;

@TestInstance(Lifecycle.PER_CLASS)
Expand Down Expand Up @@ -57,14 +58,13 @@ public void testForwardedHostHeaderOnProxyRequest()
String backendServer = "trinocluster";
String backendPort = "80";
HttpServletRequest mockServletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(mockServletRequest.getHeader("proxytarget")).thenReturn(String.format("http://%s"
+ ":%s", backendServer, backendPort));
Mockito.when(mockServletRequest.getHeader("proxytarget")).thenReturn(format("http://%s:%s", backendServer, backendPort));
HttpClient httpClient = new HttpClient();
Request proxyRequest = httpClient.newRequest("http://localhost:80");
QueryIdCachingProxyHandler.setForwardedHostHeaderOnProxyRequest(mockServletRequest,
proxyRequest);
assertThat(proxyRequest.getHeaders().get("Host"))
.isEqualTo(String.format("%s:%s", backendServer, backendPort));
.isEqualTo(format("%s:%s", backendServer, backendPort));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void testSuccessfulHeaderAuthentication()
configuration.setUser(MEMBER_OF.orElseThrow());

MultivaluedHashMap<String, String> headers = new MultivaluedHashMap<>();
headers.addFirst(HttpHeaders.AUTHORIZATION, String.format("Bearer %s", ID_TOKEN));
headers.addFirst(HttpHeaders.AUTHORIZATION, "Bearer " + ID_TOKEN);

Mockito
.when(requestContext.getCookies())
Expand Down