-
Notifications
You must be signed in to change notification settings - Fork 163
Fix Corruption issue. #524
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
Merged
Changes from all commits
Commits
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
Fixed issue where mutiple serialize/de-serialize operations would res…
…ult in corrupted data if the data was a protobuf message object. Introduced equality checks for ProtoDataWrapper. Refactored and cleaned up data-wrappers. Signed-off-by: Jem Day <Jem.Day@cliffhanger.com>
- Loading branch information
commit 7d48b26be27e1a1d972060392391bdb672e13316
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
98 changes: 98 additions & 0 deletions
98
formats/protobuf/src/test/java/io/cloudevents/protobuf/ProtoDataWrapperTest.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,98 @@ | ||
/* | ||
* Copyright 2018-Present The CloudEvents Authors | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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 io.cloudevents.protobuf; | ||
|
||
import com.google.protobuf.Any; | ||
import com.google.protobuf.Message; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class ProtoDataWrapperTest { | ||
|
||
// == Closing Quotes for 2023/02/23 | ||
private final Message quote1 = io.cloudevents.test.v1.proto.Test.Quote.newBuilder() | ||
.setPrice(io.cloudevents.test.v1.proto.Test.Decimal.newBuilder().setScale(2).setUnscaled(7519).build()) | ||
.setHigh(io.cloudevents.test.v1.proto.Test.Decimal.newBuilder().setScale(2).setUnscaled(7628).build()) | ||
.setSymbol("PYPL") | ||
.build(); | ||
|
||
private final Message quote2 = io.cloudevents.test.v1.proto.Test.Quote.newBuilder() | ||
.setPrice(io.cloudevents.test.v1.proto.Test.Decimal.newBuilder().setScale(2).setUnscaled(13097).build()) | ||
.setHigh(io.cloudevents.test.v1.proto.Test.Decimal.newBuilder().setScale(2).setUnscaled(13170).build()) | ||
.setSymbol("IBM") | ||
.build(); | ||
|
||
@Test | ||
public void testBasic() { | ||
|
||
ProtoDataWrapper pdw = new ProtoDataWrapper(quote1); | ||
|
||
assertThat(pdw).isNotNull(); | ||
assertThat(pdw.getMessage()).isNotNull(); | ||
assertThat(pdw.toBytes()).withFailMessage("toBytes was NULL").isNotNull(); | ||
assertThat(pdw.toBytes()).withFailMessage("toBytes[] returned empty array").hasSizeGreaterThan(0); | ||
|
||
// This is current behavior and will probably change in the next version. | ||
assertThat(pdw.getMessage()).isInstanceOf(io.cloudevents.test.v1.proto.Test.Quote.class); | ||
} | ||
|
||
@Test | ||
public void testEquality() { | ||
|
||
ProtoDataWrapper pdw1 = new ProtoDataWrapper(quote1); | ||
ProtoDataWrapper pdw2 = new ProtoDataWrapper(quote1); | ||
|
||
ProtoDataWrapper pdw3 = new ProtoDataWrapper(quote2); | ||
|
||
assertThat(pdw1).withFailMessage("Self Equality Failed - 1").isEqualTo(pdw1); | ||
assertThat(pdw2).withFailMessage("Self Equality Failed - 2").isEqualTo(pdw2); | ||
assertThat(pdw1).withFailMessage("Self Equality Failed - 3").isEqualTo(pdw2); | ||
assertThat(pdw2).withFailMessage("Self Equality Failed - 4").isEqualTo(pdw1); | ||
|
||
assertThat(pdw1).withFailMessage("Non-Equality Failed - 1").isNotEqualTo(null); | ||
assertThat(pdw1).withFailMessage("Non-Equality Failed - 2").isNotEqualTo(pdw3); | ||
assertThat(pdw3).withFailMessage("Non-Equality Failed - 3").isNotEqualTo(pdw2); | ||
|
||
} | ||
|
||
/** | ||
* Verify the generated bytes[] is correct | ||
*/ | ||
@Test | ||
6CB1 | public void testBytes() { | |
|
||
// Our expected 'Any' | ||
final Any expAny = Any.pack(quote1); | ||
|
||
// Our expected 'data' | ||
final byte[] expData = expAny.toByteArray(); | ||
|
||
// Build the wrapper | ||
final ProtoDataWrapper pdw = new ProtoDataWrapper(quote1); | ||
|
||
// Get the actual data | ||
final byte[] actData = pdw.toBytes(); | ||
|
||
// Verify | ||
Arrays.equals(expData, actData); | ||
|
||
} | ||
|
||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.