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

#800: fix last block of stream being ignored if size < 8k #802

Merged
merged 5 commits into from Apr 17, 2017

Conversation

Projects
None yet
3 participants
@slmsbrhgn
Contributor

slmsbrhgn commented Apr 5, 2017

Fixes #800 (data truncated at the end of the stream, while using setCharacterStream)

@@ -142,7 +142,7 @@ public int read(byte b[], int off, int len) throws IOException {
totalRead += remaining;
off += remaining;
len -= remaining;
if (len == 0) {
if (len >= 0) {

This comment has been minimized.

@vlsi

vlsi Apr 5, 2017

Member

This condition would effectively exit from the loop at the first iteration, so it will hurt performance.

// System.out.println(String.format("Read: %4d Start: %3d End: %3d", read, buffer[0], buffer[read - 1]));
total += read;
if (read == BLOCK) {
assertEquals("Byte values are not correct", buffer[0], buffer[read % BLOCK]);

This comment has been minimized.

@vlsi

vlsi Apr 5, 2017

Member

Please refrain from asserting multiple assorted things in a single testcase.

It is hard to understand what this test actually examines

@codecov-io

This comment has been minimized.

codecov-io commented Apr 5, 2017

Codecov Report

Merging #802 into master will increase coverage by 0.04%.
The diff coverage is 0%.

@@             Coverage Diff             @@
##             master    #802      +/-   ##
===========================================
+ Coverage     65.26%   65.3%   +0.04%     
- Complexity     3517    3525       +8     
===========================================
  Files           165     166       +1     
  Lines         15217   15230      +13     
  Branches       2465    2468       +3     
===========================================
+ Hits           9931    9946      +15     
+ Misses         4099    4097       -2     
  Partials       1187    1187

// initialize with values (0, 1, ... 127, 0, 1, ...)
for (int i = 0; i < data.length; i++) {
data[i] = (byte) (i & 0x7F);

This comment has been minimized.

@vlsi

vlsi Apr 5, 2017

Member

What is the purpose of this initialization?

This comment has been minimized.

@slmsbrhgn

slmsbrhgn Apr 5, 2017

Contributor

It was used to check if the read blocks were contiguous (ie last block ended with value 33, next one should start with 34), but is not needed anymore (it only makes sense with custom charBufferSize in ReaderInputStream). Will remove it.

int read;
int total = 0;

while ((read = r.read(buffer, 0, BLOCK)) > -1) {

This comment has been minimized.

@vlsi

vlsi Apr 5, 2017

Member

Can you write the same test without a loop?

This comment has been minimized.

@slmsbrhgn

slmsbrhgn Apr 5, 2017

Contributor

I can replace it with N calls to read (in this case 6). I don't think that using a single (bigger) read would fail the test when the problem occurs.

This comment has been minimized.

@vlsi

vlsi Apr 5, 2017

Member

Can you make a test that uses just two read calls?

This comment has been minimized.

@slmsbrhgn

slmsbrhgn Apr 5, 2017

Contributor

Sure

final byte[] buffer = new byte[BLOCK];

InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(data));
ReaderInputStream r = new ReaderInputStream(isr);

This comment has been minimized.

@vlsi

vlsi Apr 5, 2017

Member

Will the test still be valid if ReaderInputStream.DEFAULT_CHAR_BUFFER_SIZE is changed for some reason?

This comment has been minimized.

@slmsbrhgn

slmsbrhgn Apr 5, 2017

Contributor

Yes. Although ideally the value would be read from ReaderInputStream instead of being hardcoded there.

This comment has been minimized.

@slmsbrhgn

slmsbrhgn Apr 7, 2017

Contributor

Do you think it makes sense to make ReaderInputStream.DEFAULT_CHAR_BUFFER_SIZE public (or having a getter) and make the test using that?

This comment has been minimized.

@vlsi

vlsi Apr 8, 2017

Member

DEFAULT_CHAR_BUFFER_SIZE should be private, and it should not be accessed/visible from external point of view.

slmsbrhgn and others added some commits Apr 5, 2017

@vlsi vlsi added this to the 42.1.0 milestone Apr 16, 2017

@vlsi

vlsi approved these changes Apr 17, 2017

@vlsi vlsi merged commit 77cace4 into pgjdbc:master Apr 17, 2017

2 checks passed

codecov/project 65.3% (+0.04%) compared to 74a426b
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment