This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
TimestampLeaseRequests
serialization (#7421)
- Loading branch information
1 parent
b186990
commit a83a02f
Showing
5 changed files
with
69 additions
and
5 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
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
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 @@ | ||
type: fix | ||
fix: | ||
description: Fix `TimestampLeaseRequests` serialization and de-serialization. | ||
links: | ||
- https://github.com/palantir/atlasdb/pull/7421 |
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
60 changes: 60 additions & 0 deletions
60
timelock-api/src/test/java/com/palantir/atlasdb/timelock/api/TimestampLeaseRequestsTest.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,60 @@ | ||
/* | ||
* (c) Copyright 2024 Palantir Technologies Inc. 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License 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 com.palantir.atlasdb.timelock.api; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.palantir.atlasdb.common.api.timelock.TimestampLeaseName; | ||
import com.palantir.conjure.java.serialization.ObjectMappers; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TimestampLeaseRequestsTest { | ||
private static final ObjectMapper SERIALIZATION_MAPPER = | ||
ObjectMappers.newClientObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); | ||
private static final ObjectMapper DESERIALIZATION_MAPPER = | ||
ObjectMappers.newServerObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); | ||
|
||
@Test | ||
void canSerializeAndDeserialize() throws IOException { | ||
Namespace namespace1 = Namespace.of("timelock-client-namespace"); | ||
TimestampLeaseRequests leaseRequests1 = TimestampLeaseRequests.of( | ||
RequestId.of(new UUID(0, 0)), | ||
Map.of( | ||
TimestampLeaseName.of("timestamp-lease-name-1"), 10, | ||
TimestampLeaseName.of("timestamp-lease-name-2"), 20)); | ||
|
||
Namespace namespace2 = Namespace.of("another-timelock-client-namespace"); | ||
TimestampLeaseRequests leaseRequests2 = TimestampLeaseRequests.of( | ||
RequestId.of(new UUID(0, 1)), Map.of(TimestampLeaseName.of("another-timestamp-lease-name"), 30)); | ||
|
||
MultiClientTimestampLeaseRequest request = MultiClientTimestampLeaseRequest.of(Map.of( | ||
namespace1, | ||
NamespaceTimestampLeaseRequest.of(List.of(leaseRequests1)), | ||
namespace2, | ||
NamespaceTimestampLeaseRequest.of(List.of(leaseRequests2)))); | ||
byte[] asBytes = SERIALIZATION_MAPPER.writeValueAsBytes(request); | ||
MultiClientTimestampLeaseRequest deserialized = | ||
DESERIALIZATION_MAPPER.readValue(asBytes, MultiClientTimestampLeaseRequest.class); | ||
assertThat(deserialized).isEqualTo(request); | ||
} | ||
} |