Skip to content

Commit

Permalink
IGNITE-23114 Add one more case to testGetBinaryStream
Browse files Browse the repository at this point in the history
  • Loading branch information
skorotkov committed Oct 28, 2024
1 parent f98eeb0 commit e414308
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.Test;

import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -140,11 +141,14 @@ public void testGetBinaryStream() throws Exception {
JdbcBlob blob = new JdbcBlob(arr);

InputStream is = blob.getBinaryStream();

byte[] res = readBytes(is);

assertTrue(Arrays.equals(arr, res));

is = blob.getBinaryStream();
res = new byte[20];
assertEquals(16, is.read(res, 0, 20));
assertArrayEquals(arr, Arrays.copyOfRange(res, 0, 16));

blob.free();

try {
Expand Down Expand Up @@ -218,6 +222,12 @@ public void testGetBinaryStreamWithParams() throws Exception {
assertEquals(5, res[0]);
assertEquals(14, res[9]);

is = blob.getBinaryStream(6, 10);
res = new byte[14];
assertEquals(10, is.read(res, 1, 13));
assertArrayEquals(new byte[] {0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 0, 0}, res);
assertEquals(-1, is.read(res, 0, 1));

blob.free();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ public int length() {
* @return Number of bytes read. -1 if end of data reached.
*/
public int read(int pos, byte[] resBuf, int resOff, int resLen) {
Objects.checkFromIndexSize(resOff, resLen, resBuf.length);

if (pos >= length)
return -1;

Expand Down

0 comments on commit e414308

Please sign in to comment.