-
Notifications
You must be signed in to change notification settings - Fork 854
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the time marshalling issue when CBOR is disabled. See #1023
- Loading branch information
Showing
4 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
{ | ||
"category": "AWS SDK for Java v2", | ||
"type": "bugfix", | ||
"description": "Fixed the time marshalling issue when CBOR is disabled. See [#1023](https://github.com/aws/aws-sdk-java-v2/issues/1023)" | ||
} |
This file contains 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
57 changes: 57 additions & 0 deletions
57
...tocol/src/test/java/software/amazon/awssdk/protocols/cbor/AwsCborProtocolFactoryTest.java
This file contains 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,57 @@ | ||
/* | ||
* Copyright 2010-2019 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.protocols.cbor; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static software.amazon.awssdk.core.SdkSystemSetting.CBOR_ENABLED; | ||
import static software.amazon.awssdk.core.traits.TimestampFormatTrait.Format.RFC_822; | ||
import static software.amazon.awssdk.core.traits.TimestampFormatTrait.Format.UNIX_TIMESTAMP; | ||
import static software.amazon.awssdk.core.traits.TimestampFormatTrait.Format.UNIX_TIMESTAMP_MILLIS; | ||
|
||
import java.util.Map; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import software.amazon.awssdk.core.protocol.MarshallLocation; | ||
import software.amazon.awssdk.core.traits.TimestampFormatTrait; | ||
|
||
public class AwsCborProtocolFactoryTest { | ||
|
||
private static AwsCborProtocolFactory factory; | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
factory = AwsCborProtocolFactory.builder().build(); | ||
} | ||
|
||
@Test | ||
public void defaultTimestampFormats_cborEnabled() { | ||
Map<MarshallLocation, TimestampFormatTrait.Format> defaultTimestampFormats = factory.getDefaultTimestampFormats(); | ||
assertThat(defaultTimestampFormats.get(MarshallLocation.HEADER)).isEqualTo(RFC_822); | ||
assertThat(defaultTimestampFormats.get(MarshallLocation.PAYLOAD)).isEqualTo(UNIX_TIMESTAMP_MILLIS); | ||
} | ||
|
||
@Test | ||
public void defaultTimestampFormats_cborDisabled() { | ||
System.setProperty(CBOR_ENABLED.property(), "false"); | ||
try { | ||
Map<MarshallLocation, TimestampFormatTrait.Format> defaultTimestampFormats = factory.getDefaultTimestampFormats(); | ||
assertThat(defaultTimestampFormats.get(MarshallLocation.HEADER)).isEqualTo(RFC_822); | ||
assertThat(defaultTimestampFormats.get(MarshallLocation.PAYLOAD)).isEqualTo(UNIX_TIMESTAMP); | ||
} finally { | ||
System.clearProperty(CBOR_ENABLED.property()); | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...esis/src/test/java/software/amazon/awssdk/services/kinesis/DateTimeUnmarshallingTest.java
This file contains 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,86 @@ | ||
/* | ||
* Copyright 2010-2019 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.services.kinesis; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.post; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static software.amazon.awssdk.core.SdkSystemSetting.CBOR_ENABLED; | ||
|
||
import com.github.tomakehurst.wiremock.junit.WireMockRule; | ||
import java.net.URI; | ||
import java.time.Instant; | ||
import java.util.List; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.kinesis.model.Record; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class DateTimeUnmarshallingTest { | ||
|
||
private KinesisClient client; | ||
|
||
@Rule | ||
public WireMockRule wireMock = new WireMockRule(0); | ||
|
||
@Before | ||
public void setup() { | ||
System.setProperty(CBOR_ENABLED.property(), "false"); | ||
client = KinesisClient.builder() | ||
.endpointOverride(URI.create("http://localhost:" + wireMock.port())) | ||
.credentialsProvider(() -> AwsBasicCredentials.create("test", "test")) | ||
.region(Region.US_EAST_1) | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void cborDisabled_dateUnmarshalling_shouldSucceed() { | ||
String content = content(); | ||
int length = content.getBytes().length; | ||
Instant instant = Instant.ofEpochMilli(1548118964772L); | ||
|
||
stubFor(post(anyUrl()) | ||
.willReturn(aResponse().withStatus(200) | ||
.withHeader("Content-Length", String.valueOf(length)) | ||
.withBody(content))); | ||
|
||
|
||
List<Record> records = client.getRecords(b -> b.shardIterator("test")).records(); | ||
|
||
assertThat(records).isNotEmpty(); | ||
assertThat(records.get(0).approximateArrivalTimestamp()).isEqualTo(instant); | ||
} | ||
|
||
private String content() { | ||
return "{\n" | ||
+ " \"MillisBehindLatest\": 0,\n" | ||
+ " \"NextShardIterator\": \"test\",\n" | ||
+ " \"Records\": [{\n" | ||
+ " \"ApproximateArrivalTimestamp\": 1.548118964772E9,\n" | ||
+ " \"Data\": \"U2VlIE5vIEV2aWw=\",\n" | ||
+ " \"PartitionKey\": \"foobar\",\n" | ||
+ " \"SequenceNumber\": \"12345678\"\n" | ||
+ " }]\n" | ||
+ "}"; | ||
} | ||
} |