Skip to content

Commit f02d9d2

Browse files
committed
Merge branch 'main' into manual-puback
2 parents 45286e2 + a147b32 commit f02d9d2

4 files changed

Lines changed: 96 additions & 7 deletions

File tree

src/main/java/software/amazon/awssdk/crt/CRT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,16 +492,16 @@ private static native void awsCrtInit(int memoryTracingLevel, boolean debugWait,
492492
* Given an error code, get a boolean to check if an error is transient or not.
493493
*
494494
* Transient errors are defined as IO level errors where we are unable to read an HTTP response.
495-
* This can occur due to connect timeouts, read timeouts, or the server closing the connection without
495+
* This can occur due to connect timeouts, read timeouts, or the server closing the connection without
496496
* sending a response. This method helps identify CRT error codes that are not generic or widely adopted.
497497
*
498-
* This is not the complete logic to identify transient or retryable errors, this includes only IO level
498+
* This is not the complete logic to identify transient or retryable errors, this includes only IO level
499499
* errors that are transient.
500500
*
501501
* @param errorCode An error code returned from an exception or other native function call
502502
* @return A boolean for if the error is transient or not
503503
*/
504-
public static native Boolean awsIsTransientError(int errorCode);
504+
public static native boolean awsIsTransientError(int errorCode);
505505

506506
/**
507507
* @return The number of bytes allocated in native resources. If

src/native/crt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ void JNICALL Java_software_amazon_awssdk_crt_CRT_awsCrtInit(
709709
}
710710

711711
JNIEXPORT
712-
bool JNICALL
712+
jboolean JNICALL
713713
Java_software_amazon_awssdk_crt_CRT_awsIsTransientError(JNIEnv *env, jclass jni_crt_class, jint error_code) {
714714
(void)env;
715715
(void)jni_crt_class;

src/test/java/software/amazon/awssdk/crt/test/ClientBootstrapTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
package software.amazon.awssdk.crt.test;
77

88
import org.junit.Test;
9-
import software.amazon.awssdk.crt.CrtResource;
10-
import software.amazon.awssdk.crt.CrtRuntimeException;
9+
1110
import software.amazon.awssdk.crt.io.ClientBootstrap;
1211
import software.amazon.awssdk.crt.io.EventLoopGroup;
1312
import software.amazon.awssdk.crt.io.HostResolver;
@@ -18,7 +17,7 @@
1817

1918
public class ClientBootstrapTest extends CrtTestFixture {
2019
public ClientBootstrapTest() {}
21-
20+
2221
@Test
2322
public void testCreateDestroy() throws ExecutionException, InterruptedException {
2423
EventLoopGroup elg = new EventLoopGroup(1);
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
package software.amazon.awssdk.crt.test;
7+
8+
import org.junit.Test;
9+
import software.amazon.awssdk.crt.CRT;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Test suite for static methods in CRT class.
15+
*/
16+
public class CrtStaticTest extends CrtTestFixture {
17+
18+
public CrtStaticTest() {
19+
}
20+
21+
/**
22+
* Test that AWS_CRT_SUCCESS (0) is not considered a transient error.
23+
*/
24+
@Test
25+
public void testAwsIsTransientErrorWithSuccess() {
26+
assertFalse("Success code should not be transient", CRT.awsIsTransientError(CRT.AWS_CRT_SUCCESS));
27+
}
28+
29+
/**
30+
* Test that the method returns a valid boolean for various error codes.
31+
*/
32+
@Test
33+
public void testAwsIsTransientErrorWithVariousErrorCodes() {
34+
// Test with a range of error codes to ensure the method doesn't crash
35+
int[] testErrorCodes = {0, 1, 1024, 2048, 3072, 4096};
36+
37+
for (int errorCode : testErrorCodes) {
38+
// The method should return a valid boolean without throwing an exception
39+
boolean result = CRT.awsIsTransientError(errorCode);
40+
// Just verify the call completes successfully - the actual result depends on native implementation
41+
assertNotNull("Should return a valid boolean", Boolean.valueOf(result));
42+
}
43+
}
44+
45+
/**
46+
* Test that the method handles invalid error codes gracefully.
47+
*/
48+
@Test
49+
public void testAwsIsTransientErrorWithInvalidCodes() {
50+
// Test with invalid error codes
51+
assertFalse("Negative error code should not be transient", CRT.awsIsTransientError(-1));
52+
assertFalse("Large error code should not be transient", CRT.awsIsTransientError(999999));
53+
}
54+
55+
/**
56+
* Test awsLastError returns a valid error code.
57+
*/
58+
@Test
59+
public void testAwsLastError() {
60+
int lastError = CRT.awsLastError();
61+
// The error code should be non-negative
62+
assertTrue("Last error should be non-negative", lastError >= 0);
63+
}
64+
65+
/**
66+
* Test awsErrorString returns a non-null string for valid error codes.
67+
*/
68+
@Test
69+
public void testAwsErrorString() {
70+
String errorString = CRT.awsErrorString(0);
71+
assertNotNull("Error string should not be null", errorString);
72+
73+
// Test with a non-zero error code
74+
errorString = CRT.awsErrorString(1);
75+
assertNotNull("Error string should not be null", errorString);
76+
}
77+
78+
/**
79+
* Test awsErrorName returns a non-null string for valid error codes.
80+
*/
81+
@Test
82+
public void testAwsErrorName() {
83+
String errorName = CRT.awsErrorName(0);
84+
assertNotNull("Error name should not be null", errorName);
85+
86+
// Test with a non-zero error code
87+
errorName = CRT.awsErrorName(1);
88+
assertNotNull("Error name should not be null", errorName);
89+
}
90+
}

0 commit comments

Comments
 (0)