From 2a4cbb37d07cbd1252154b3660b25c0b9d797740 Mon Sep 17 00:00:00 2001 From: Toby Zhang Date: Mon, 8 Jan 2024 23:32:05 +0000 Subject: [PATCH] update logic --- .../ingest/connection/RequestBuilder.java | 5 +++-- .../SnowflakeStreamingIngestClientFactory.java | 5 ++--- ...SnowflakeStreamingIngestClientInternal.java | 12 +++--------- .../ingest/utils/ParameterProvider.java | 18 ++++++++++-------- .../internal/ParameterProviderTest.java | 14 ++++++++++++++ 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/snowflake/ingest/connection/RequestBuilder.java b/src/main/java/net/snowflake/ingest/connection/RequestBuilder.java index 9456ca2db..869f734eb 100644 --- a/src/main/java/net/snowflake/ingest/connection/RequestBuilder.java +++ b/src/main/java/net/snowflake/ingest/connection/RequestBuilder.java @@ -295,7 +295,8 @@ public RequestBuilder( SecurityManager securityManager, CloseableHttpClient httpClient, String clientName) { - this(accountName, + this( + accountName, userName, credential, schemeName, @@ -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); } } diff --git a/src/main/java/net/snowflake/ingest/streaming/SnowflakeStreamingIngestClientFactory.java b/src/main/java/net/snowflake/ingest/streaming/SnowflakeStreamingIngestClientFactory.java index 9ba87cffb..ecab62432 100644 --- a/src/main/java/net/snowflake/ingest/streaming/SnowflakeStreamingIngestClientFactory.java +++ b/src/main/java/net/snowflake/ingest/streaming/SnowflakeStreamingIngestClientFactory.java @@ -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; @@ -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); } } } diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/SnowflakeStreamingIngestClientInternal.java b/src/main/java/net/snowflake/ingest/streaming/internal/SnowflakeStreamingIngestClientInternal.java index d125b90f4..47aa76d3b 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/SnowflakeStreamingIngestClientInternal.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/SnowflakeStreamingIngestClientInternal.java @@ -214,7 +214,8 @@ public class SnowflakeStreamingIngestClientInternal 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, @@ -275,14 +276,7 @@ public SnowflakeStreamingIngestClientInternal( Properties prop, Map parameterOverrides, boolean addAccountNameInRequest) { - this(name, - accountURL, - prop, - null, - false, - null, - parameterOverrides, - addAccountNameInRequest); + this(name, accountURL, prop, null, false, null, parameterOverrides, addAccountNameInRequest); } /** diff --git a/src/main/java/net/snowflake/ingest/utils/ParameterProvider.java b/src/main/java/net/snowflake/ingest/utils/ParameterProvider.java index 854387647..7967f1fdd 100644 --- a/src/main/java/net/snowflake/ingest/utils/ParameterProvider.java +++ b/src/main/java/net/snowflake/ingest/utils/ParameterProvider.java @@ -109,6 +109,16 @@ private void updateValue( * @param props Properties file provided to client constructor */ private void setParameterMap(Map 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, @@ -182,14 +192,6 @@ private void setParameterMap(Map 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; } diff --git a/src/test/java/net/snowflake/ingest/streaming/internal/ParameterProviderTest.java b/src/test/java/net/snowflake/ingest/streaming/internal/ParameterProviderTest.java index e455741c8..1ee6b9542 100644 --- a/src/test/java/net/snowflake/ingest/streaming/internal/ParameterProviderTest.java +++ b/src/test/java/net/snowflake/ingest/streaming/internal/ParameterProviderTest.java @@ -272,6 +272,20 @@ public void testMaxClientLagEnabledThresholdAbove() { } } + @Test + public void testMaxClientLagEnableEmptyInput() { + Properties prop = new Properties(); + Map 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();