-
Notifications
You must be signed in to change notification settings - Fork 13
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
Test binary io compression modes #247
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0bdf10c
Added test for the different compression modes of binary serializer
DavyLandman c274f1d
Fixed bugs found by the compression tests
DavyLandman b2576d7
Added binary output as reference to make sure we can keep reading ser…
DavyLandman fbf0f20
Cleanup of how we report failures
DavyLandman 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 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
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
105 changes: 105 additions & 0 deletions
105
src/test/java/io/usethesource/vallang/io/FileChannelOutputStreamTest.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,105 @@ | ||
package io.usethesource.vallang.io; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import java.io.IOException; | ||
import java.nio.channels.FileChannel; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardOpenOption; | ||
import java.util.Random; | ||
import org.junit.jupiter.api.Test; | ||
import io.usethesource.vallang.io.binary.util.FileChannelDirectInputStream; | ||
import io.usethesource.vallang.io.binary.util.FileChannelDirectOutputStream; | ||
|
||
class FileChannelOutputStreamTest { | ||
private static final Path targetFile; | ||
static { | ||
Path file = null; | ||
try { | ||
file = Files.createTempFile("file-channel-test", "bin"); | ||
} catch (IOException e) { | ||
System.err.println(e); | ||
} | ||
targetFile = file; | ||
} | ||
|
||
private FileChannel openWriteChannel() throws IOException { | ||
return FileChannel.open(targetFile, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); | ||
} | ||
|
||
private FileChannel openReadChannel() throws IOException { | ||
return FileChannel.open(targetFile, StandardOpenOption.READ); | ||
} | ||
|
||
@Test | ||
void testSimpleWrite() throws IOException { | ||
roundTripChannel(new byte[][]{{42}}); | ||
} | ||
|
||
@Test | ||
void testBigWrite() throws IOException { | ||
byte[] buffer = new byte[1024*1024]; | ||
new Random().nextBytes(buffer); | ||
roundTripChannel(new byte[][]{buffer}); | ||
} | ||
|
||
@Test | ||
void testChunkedBigWrite() throws IOException { | ||
byte[][] buffers = new byte[1024][]; | ||
var r = new Random(); | ||
for (int i = 0; i < buffers.length; i++) { | ||
buffers[i] = new byte[i * 128]; | ||
r.nextBytes(buffers[i]); | ||
} | ||
roundTripChannel(buffers); | ||
} | ||
|
||
|
||
private void roundTripChannel(byte[][] buffers) throws IOException { | ||
writeChannelInBulk(buffers); | ||
verifyChannelInBulk(buffers); | ||
writeChannelBytePerByte(buffers); | ||
verifyChannelBytePerByte(buffers); | ||
} | ||
|
||
private void verifyChannelBytePerByte(byte[][] buffers) throws IOException { | ||
try (var reader = new FileChannelDirectInputStream(openReadChannel())) { | ||
for (byte[] expected: buffers) { | ||
for (byte expect: expected) { | ||
assertEquals(expect & 0xFF, reader.read()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
private void verifyChannelInBulk(byte[][] buffers) throws IOException { | ||
try (var reader = new FileChannelDirectInputStream(openReadChannel())) { | ||
for (byte[] expected: buffers) { | ||
byte[] actual = new byte[expected.length]; | ||
reader.read(actual); | ||
assertArrayEquals(expected, actual); | ||
} | ||
} | ||
} | ||
|
||
private void writeChannelBytePerByte(byte[][] buffers) throws IOException { | ||
try (var writer = new FileChannelDirectOutputStream(openWriteChannel(), 1)) { | ||
for (byte[] buf: buffers) { | ||
for (byte b: buf) { | ||
writer.write(b); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void writeChannelInBulk(byte[][] buffers) throws IOException { | ||
try (var writer = new FileChannelDirectOutputStream(openWriteChannel(), 1)) { | ||
for (byte[] buf: buffers) { | ||
writer.write(buf); | ||
} | ||
} | ||
} | ||
|
||
} |
Binary file not shown.
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.
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 was outdated, so removed it.