-
Notifications
You must be signed in to change notification settings - Fork 974
Add utils-lite package #6395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
RanVaknin
merged 3 commits into
feature/master/utils-lite-lambda-trace
from
feature/master/lambda-trace-id-utils-lite
Sep 5, 2025
Merged
Add utils-lite package #6395
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...chitecture-tests/src/test/java/software/amazon/awssdk/archtests/UtilsLitePackageTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.archtests; | ||
|
|
||
| import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; | ||
|
|
||
| import com.tngtech.archunit.core.domain.JavaClasses; | ||
| import com.tngtech.archunit.core.importer.ClassFileImporter; | ||
| import com.tngtech.archunit.lang.ArchRule; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Architecture tests for the utils-lite package to ensure it only contains allowed classes. | ||
| */ | ||
| public class UtilsLitePackageTest { | ||
|
|
||
| private static final JavaClasses CLASSES = new ClassFileImporter() | ||
| .importPackages("software.amazon.awssdk.utilslite"); | ||
|
|
||
| @Test | ||
| public void utilsLitePackage_shouldOnlyContainAllowedClasses() { | ||
| ArchRule rule = classes() | ||
| .that().resideInAPackage("software.amazon.awssdk.utilslite") | ||
| .should().haveNameMatching(".*\\.(SdkInternalThreadLocal|SdkInternalThreadLocalTest)") | ||
| .allowEmptyShould(true) | ||
| .because("utils-lite package should only contain SdkInternalThreadLocal and its test"); | ||
|
|
||
| rule.check(CLASSES); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| ~ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| ~ | ||
| ~ Licensed under the Apache License, Version 2.0 (the "License"). | ||
| ~ You may not use this file except in compliance with the License. | ||
| ~ A copy of the License is located at | ||
| ~ | ||
| ~ http://aws.amazon.com/apache2.0 | ||
| ~ | ||
| ~ or in the "license" file accompanying this file. This file is distributed | ||
| ~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| ~ express or implied. See the License for the specific language governing | ||
| ~ permissions and limitations under the License. | ||
| --> | ||
|
|
||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>software.amazon.awssdk</groupId> | ||
| <artifactId>aws-sdk-java-pom</artifactId> | ||
| <version>2.33.3-SNAPSHOT</version> | ||
| </parent> | ||
| <artifactId>utils-lite</artifactId> | ||
| <name>AWS Java SDK :: Utils Lite</name> | ||
| <description> | ||
| A package providing minimal external utils. | ||
| </description> | ||
| <url>https://aws.amazon.com/sdkforjava</url> | ||
|
|
||
| <dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>software.amazon.awssdk</groupId> | ||
| <artifactId>bom-internal</artifactId> | ||
| <version>${project.version}</version> | ||
| <type>pom</type> | ||
| <scope>import</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </dependencyManagement> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>software.amazon.awssdk</groupId> | ||
| <artifactId>annotations</artifactId> | ||
| <version>${awsjavasdk.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.assertj</groupId> | ||
| <artifactId>assertj-core</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-jar-plugin</artifactId> | ||
| <configuration> | ||
| <archive> | ||
| <manifestEntries> | ||
| <Automatic-Module-Name>software.amazon.awssdk.utilslite</Automatic-Module-Name> | ||
| </manifestEntries> | ||
| </archive> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> |
55 changes: 55 additions & 0 deletions
55
utils-lite/src/main/java/software/amazon/awssdk/utilslite/SdkInternalThreadLocal.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.utilslite; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import software.amazon.awssdk.annotations.SdkProtectedApi; | ||
|
|
||
| /** | ||
| * Utility for thread-local context storage. | ||
| */ | ||
| @SdkProtectedApi | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could not use SdkInternalApi because the TraceIdExecutionInterceptor (SdkProtectedApi) is using this class and archunit throws an error "no internal APIs across modules" |
||
| public final class SdkInternalThreadLocal { | ||
| private static final ThreadLocal<Map<String, String>> STORAGE = ThreadLocal.withInitial(HashMap::new); | ||
|
|
||
| private SdkInternalThreadLocal() { | ||
| } | ||
|
|
||
| public static void put(String key, String value) { | ||
| if (value == null) { | ||
| STORAGE.get().remove(key); | ||
| } else { | ||
| STORAGE.get().put(key, value); | ||
| } | ||
| } | ||
|
|
||
| public static String get(String key) { | ||
| return STORAGE.get().get(key); | ||
| } | ||
|
|
||
| public static String remove(String key) { | ||
| return STORAGE.get().remove(key); | ||
| } | ||
|
|
||
| public static void clear() { | ||
| STORAGE.get().clear(); | ||
| } | ||
|
|
||
| public static boolean containsKey(String key) { | ||
| return STORAGE.get().containsKey(key); | ||
| } | ||
| } | ||
70 changes: 70 additions & 0 deletions
70
utils-lite/src/test/java/software/amazon/awssdk/utilslite/ThreadStorageTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.utilslite; | ||
|
|
||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| class SdkInternalThreadLocalTest { | ||
|
|
||
| @AfterEach | ||
| void cleanup() { | ||
| SdkInternalThreadLocal.clear(); | ||
| } | ||
|
|
||
| @Test | ||
| void putAndGet_shouldStoreAndRetrieveValue() { | ||
| SdkInternalThreadLocal.put("test-key", "test-value"); | ||
|
|
||
| assertThat(SdkInternalThreadLocal.get("test-key")).isEqualTo("test-value"); | ||
| } | ||
|
|
||
| @Test | ||
| void get_withNonExistentKey_shouldReturnNull() { | ||
| assertThat(SdkInternalThreadLocal.get("non-existent")).isNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void put_withValidKeyValue_shouldStoreValue() { | ||
| SdkInternalThreadLocal.put("test-key", "test-value"); | ||
|
|
||
| String removed = SdkInternalThreadLocal.remove("test-key"); | ||
|
|
||
| assertThat(removed).isEqualTo("test-value"); | ||
| assertThat(SdkInternalThreadLocal.get("test-key")).isNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void remove_withExistingKey_shouldRemoveAndReturnValue() { | ||
| SdkInternalThreadLocal.put("test-key", "test-value"); | ||
| SdkInternalThreadLocal.put("test-key", null); | ||
|
|
||
| assertThat(SdkInternalThreadLocal.get("test-key")).isNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void clear_withMultipleValues_shouldRemoveAllValues() { | ||
| SdkInternalThreadLocal.put("key1", "value1"); | ||
| SdkInternalThreadLocal.put("key2", "value2"); | ||
|
|
||
| SdkInternalThreadLocal.clear(); | ||
|
|
||
| assertThat(SdkInternalThreadLocal.get("key1")).isNull(); | ||
| assertThat(SdkInternalThreadLocal.get("key2")).isNull(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was bumped because the build was failing with:
It's not entirely clear why the build fails with it, and why these changes cause this since they seem completely unrelated, but we do have mixed versions of the shade plugin across multiple packages, so i just bumped it to the most recent version