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
1 change: 1 addition & 0 deletions sdk/cosmos/azure-cosmos-spark_3-1_2-12/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
<includes>
<include>META-INF/project.properties</include>
<include>META-INF/services/org.apache.spark.sql.sources.DataSourceRegister</include>
<include>azure-cosmos-spark.properties</include>
</includes>
</resource>
</resources>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=${project.artifactId}
version=${project.version}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import com.azure.cosmos.implementation.HttpConstants

// cosmos db related constants
private object CosmosConstants {
private[this] val currentVersion =
CoreUtils.getProperties(HttpConstants.Versions.AZURE_COSMOS_PROPERTIES_FILE_NAME).get("version")
val userAgentSuffix = s" SparkConnector/$currentVersion"
private[this] val propertiesFileName = "azure-cosmos-spark.properties"
val currentVersion: String =
CoreUtils.getProperties(propertiesFileName).get("version")
val currentName: String =
CoreUtils.getProperties(propertiesFileName).get("name")
val userAgentSuffix = s"SparkConnector/$currentName/$currentVersion"

object Names {
val ItemsDataSourceShortName = "cosmos.oltp"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.cosmos.spark

class CosmosConstantsSpec extends UnitSpec {
"CurrentVersion" should "not be null" in {
CosmosConstants.currentVersion == null shouldBe false
CosmosConstants.currentVersion.startsWith("4.") shouldBe true
}

"CurrentName" should "not be null" in {
CosmosConstants.currentName == null shouldBe false
CosmosConstants.currentName.startsWith("azure-cosmos-spark") shouldBe true
}

"UserAgentSuffix" should "combine name and version" in {
CosmosConstants.userAgentSuffix shouldBe
s"SparkConnector/${CosmosConstants.currentName}/${CosmosConstants.currentVersion}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
*/
public class UserAgentContainer {

private static final int MAX_SUFFIX_LENGTH = 64;
private static final int MAX_USER_AGENT_LENGTH = 255;
private final int maxSuffixLength;
private final String baseUserAgent;
private String suffix;
private String userAgent;
Expand All @@ -18,6 +19,7 @@ private UserAgentContainer(String sdkName, String sdkVersion) {
this.baseUserAgent = Utils.getUserAgent(sdkName, sdkVersion);
this.suffix = "";
this.userAgent = baseUserAgent;
this.maxSuffixLength = MAX_USER_AGENT_LENGTH - 1 - baseUserAgent.length();
}

public UserAgentContainer() {
Expand All @@ -29,8 +31,8 @@ public String getSuffix() {
}

public void setSuffix(String suffix) {
if (suffix.length() > MAX_SUFFIX_LENGTH) {
suffix = suffix.substring(0, MAX_SUFFIX_LENGTH);
if (suffix.length() > maxSuffixLength) {
suffix = suffix.substring(0, maxSuffixLength);
}

this.suffix = suffix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ public void userAgentContainerSetSuffix() {
assertThat(userAgentContainer.getUserAgent()).isEqualTo(expectedString);

//With suffix greater than 64 character
userProvidedSuffix = "greater than 64 characters ###########################################";
userProvidedSuffix = "greater than 255 characters in total ################################################" +
"##########################################################################################################" +
"##########################################################################################################";
userAgentContainer = new UserAgentContainer();
userAgentContainer.setSuffix(userProvidedSuffix);
expectedString = expectedStringFixedPart + SPACE + userProvidedSuffix.substring(0, 64);
expectedString = (expectedStringFixedPart + SPACE + userProvidedSuffix).substring(0, 255);
assertThat(userAgentContainer.getUserAgent()).isEqualTo(expectedString);
}

Expand Down