-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix marshaler self suppression error (#5318)
* Fix marshaler self suppression error * spotless * PR feedback
- Loading branch information
Showing
2 changed files
with
60 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
50 changes: 50 additions & 0 deletions
50
exporters/common/src/test/java/io/opentelemetry/exporter/internal/marshal/MarshalerTest.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,50 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.internal.marshal; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyInt; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class MarshalerTest { | ||
|
||
@Test | ||
void writeTo_NoSelfSuppressionError() throws IOException { | ||
Marshaler marshaler = | ||
new Marshaler() { | ||
@Override | ||
public int getBinarySerializedSize() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
protected void writeTo(Serializer output) throws IOException { | ||
for (int i = 0; i < (50 * 1024 + 100) / 8; i++) { | ||
output.writeFixed64Value(i); | ||
} | ||
} | ||
}; | ||
OutputStream os = mock(OutputStream.class); | ||
|
||
IOException error = new IOException("error!"); | ||
doThrow(error).when(os).write(any(), anyInt(), anyInt()); | ||
doThrow(error).when(os).write(any()); | ||
doThrow(error).when(os).write(anyInt()); | ||
doThrow(error).when(os).flush(); | ||
|
||
// If an exception is thrown writing bytes, and that same exception is thrown in the #close | ||
// method cleaning up the AutoCloseable resource, an IllegalArgumentException will be thrown | ||
// indicating illegal self suppression. Ensure an IOException is thrown instead. | ||
assertThatThrownBy(() -> marshaler.writeBinaryTo(os)).isInstanceOf(IOException.class); | ||
assertThatThrownBy(() -> marshaler.writeJsonTo(os)).isInstanceOf(IOException.class); | ||
} | ||
} |