Skip to content

Commit

Permalink
update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-tzhang committed Jan 8, 2024
1 parent 6328403 commit 2a4cbb3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ public RequestBuilder(
SecurityManager securityManager,
CloseableHttpClient httpClient,
String clientName) {
this(accountName,
this(
accountName,
userName,
credential,
schemeName,
Expand Down Expand Up @@ -648,7 +649,7 @@ private static void addUserAgent(HttpUriRequest request, String userAgentSuffix)
public void addToken(HttpUriRequest request) {
request.setHeader(HttpHeaders.AUTHORIZATION, BEARER_PARAMETER + securityManager.getToken());
request.setHeader(SF_HEADER_AUTHORIZATION_TOKEN_TYPE, this.securityManager.getTokenType());
if(addAccountNameInRequest) {
if (addAccountNameInRequest) {
request.setHeader(SF_HEADER_ACCOUNT_NAME, accountName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.util.Map;
import java.util.Properties;

import net.snowflake.ingest.streaming.internal.SnowflakeStreamingIngestClientInternal;
import net.snowflake.ingest.utils.Constants;
import net.snowflake.ingest.utils.SnowflakeURL;
Expand Down Expand Up @@ -71,10 +70,10 @@ public SnowflakeStreamingIngestClient build() {

if (addAccountNameInRequest) {
return new SnowflakeStreamingIngestClientInternal<>(
this.name, accountURL, prop, this.parameterOverrides, addAccountNameInRequest);
this.name, accountURL, prop, this.parameterOverrides, addAccountNameInRequest);
}
return new SnowflakeStreamingIngestClientInternal<>(
this.name, accountURL, prop, this.parameterOverrides);
this.name, accountURL, prop, this.parameterOverrides);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ public class SnowflakeStreamingIngestClientInternal<T> implements SnowflakeStrea
prop.getProperty(Constants.OAUTH_CLIENT_SECRET),
prop.getProperty(Constants.OAUTH_REFRESH_TOKEN));
}
this.requestBuilder = new RequestBuilder(
this.requestBuilder =
new RequestBuilder(
accountURL,
prop.get(USER).toString(),
credential,
Expand Down Expand Up @@ -275,14 +276,7 @@ public SnowflakeStreamingIngestClientInternal(
Properties prop,
Map<String, Object> parameterOverrides,
boolean addAccountNameInRequest) {
this(name,
accountURL,
prop,
null,
false,
null,
parameterOverrides,
addAccountNameInRequest);
this(name, accountURL, prop, null, false, null, parameterOverrides, addAccountNameInRequest);
}

/**
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/net/snowflake/ingest/utils/ParameterProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ private void updateValue(
* @param props Properties file provided to client constructor
*/
private void setParameterMap(Map<String, Object> parameterOverrides, Properties props) {
// BUFFER_FLUSH_INTERVAL_IN_MILLIS is deprecated and disallowed
if ((parameterOverrides != null
&& parameterOverrides.containsKey(BUFFER_FLUSH_INTERVAL_IN_MILLIS))
|| (props != null && props.containsKey(BUFFER_FLUSH_INTERVAL_IN_MILLIS))) {
throw new IllegalArgumentException(
String.format(
"%s is deprecated, please use %s instead",
BUFFER_FLUSH_INTERVAL_IN_MILLIS, MAX_CLIENT_LAG));
}

this.updateValue(
BUFFER_FLUSH_CHECK_INTERVAL_IN_MILLIS,
BUFFER_FLUSH_CHECK_INTERVAL_IN_MILLIS_DEFAULT,
Expand Down Expand Up @@ -182,14 +192,6 @@ private void setParameterMap(Map<String, Object> parameterOverrides, Properties

/** @return Longest interval in milliseconds between buffer flushes */
public long getCachedMaxClientLagInMs() {
// BUFFER_FLUSH_INTERVAL_IN_MILLIS is deprecated and disallowed
if (this.parameterMap.containsKey(BUFFER_FLUSH_INTERVAL_IN_MILLIS)) {
throw new IllegalArgumentException(
String.format(
"%s is deprecated, please use %s instead",
BUFFER_FLUSH_INTERVAL_IN_MILLIS, MAX_CLIENT_LAG));
}

if (cachedBufferFlushIntervalMs != -1L) {
return cachedBufferFlushIntervalMs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ public void testMaxClientLagEnabledThresholdAbove() {
}
}

@Test
public void testMaxClientLagEnableEmptyInput() {
Properties prop = new Properties();
Map<String, Object> parameterMap = getStartingParameterMap();
parameterMap.put(ParameterProvider.MAX_CLIENT_LAG, "");
ParameterProvider parameterProvider = new ParameterProvider(parameterMap, prop);
try {
parameterProvider.getCachedMaxClientLagInMs();
Assert.fail("Should not have succeeded");
} catch (IllegalArgumentException e) {
Assert.assertEquals(e.getCause().getClass(), NumberFormatException.class);
}
}

@Test
public void testMaxChunksInBlobAndRegistrationRequest() {
Properties prop = new Properties();
Expand Down

0 comments on commit 2a4cbb3

Please sign in to comment.