This repository was archived by the owner on Apr 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Change distribution value type to ByteString #14
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,7 +94,8 @@ public void testSerializeDistributionValue() throws InvalidProtocolBufferExcepti | |
| final byte [] pointVal = DISTRIBUTION_DATA_POINT.getBytes(StandardCharsets.UTF_8); | ||
| ByteBuffer byteBuffer = ByteBuffer.allocate(pointVal.length); | ||
| byteBuffer.put(pointVal); | ||
| Metric metricV1 = (new Metric()).value(Value.distributionValue(byteBuffer)); | ||
| Metric metricV1 = (new Metric()).value(Value | ||
| .distributionValue(ByteString.copyFrom(byteBuffer.array()))); | ||
|
Member
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. Nit: ByteString.copyFrom(byteBuffer) might be cleaner, but perhaps you would then first need to flip the buffer
Member
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. Actually - just do ByteString.copyFromUtf8(DISTRIBUTION_DATA_POINT) instead |
||
| byte[] bytes = metricV1.serialize(); | ||
| Protocol1.Metric out = Protocol1.Message.newBuilder().mergeFrom(bytes).build().getMetric(); | ||
| Protocol1.Value outVal = out.getValue(); | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -23,6 +23,8 @@ | |
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
|
|
||
| import com.google.protobuf.ByteString; | ||
| import java.nio.ByteBuffer; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.ArrayList; | ||
|
|
@@ -32,7 +34,7 @@ | |
|
|
||
| public class ValueTest { | ||
| private static final double DOUBLE_VAL = 0.976; | ||
| private static final ByteBuffer DISTRIBUTION_VAL = createSample(); | ||
| private static final ByteString DISTRIBUTION_VAL = createSample(); | ||
|
|
||
|
|
||
| @Test | ||
|
|
@@ -66,9 +68,9 @@ public Object apply(Double arg) { | |
| return null; | ||
| } | ||
| }, | ||
| new Function<ByteBuffer, Object>() { | ||
| new Function<ByteString, Object>() { | ||
| @Override | ||
| public Object apply(ByteBuffer arg) { | ||
| public Object apply(ByteString arg) { | ||
| actual.add(Value.distributionValue(arg)); | ||
| return null; | ||
| } | ||
|
|
@@ -86,12 +88,12 @@ public Object apply(Value arg) { | |
|
|
||
| } | ||
|
|
||
| private static ByteBuffer createSample(){ | ||
| final String fakeDistData = "FAKEDISTRIBUTIONFAKEDISTRIBUTION"; | ||
| final byte [] bytes = fakeDistData.getBytes(StandardCharsets.UTF_8); | ||
| private static ByteString createSample(){ | ||
| final String data = "FAKEDISTRIBUTIONFAKEDISTRIBUTION"; | ||
| final byte [] bytes = data.getBytes(StandardCharsets.UTF_8); | ||
| ByteBuffer out = ByteBuffer.allocate(bytes.length); | ||
| out.put(bytes); | ||
| return out; | ||
| return ByteString.copyFrom(out.array()); | ||
|
Member
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. Seems unnecessary to go from byte[] -> ByteBuffer -> ByteString Simplify to ByteString.copyFromUtf8(...)? |
||
| } | ||
|
|
||
|
|
||
|
|
||
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 would be a breaking change, which I think we can live with if we are sure no one is depending on this.
Otherwise, we would need to keep the old method signature too
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.
No one is using it. Nothing will break.