-
Notifications
You must be signed in to change notification settings - Fork 56
GH-759: Get length of byte[] in TryCopyLastError #760
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
base: main
Are you sure you want to change the base?
Conversation
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.
Is it possible to add a test?
The error message in CI doesn't seem to be related to my PR:
linkage: https://github.com/apache/arrow-java/actions/runs/15140171347/job/42594091462?pr=760 Do you have some suggestions? |
I'll try to add a test case in |
Could you open a separated issue for it? |
Do you need an integration test? IMO, you should be able to export a stream, then immediately import it, all within Java. |
issue: #767 |
Thanks. (We've fixed this problem in apache/arrow. Sorry for not sharing it here...) |
I add a unittest but I think it can't make sure |
This comment has been minimized.
This comment has been minimized.
Can't the test validate that the exception has the right error message after making it through the FFI boundary? |
PTAL. |
root.setRowCount(4); | ||
batches.add(unloader.getRecordBatch()); | ||
|
||
final String exceptionMessage = "java.lang.RuntimeException: Error occurred while getting next schema root.\n\tat org.apache.arrow.adapter.jdbc.ArrowVectorIterator.next(ArrowVectorIterator.java:205)\n\tat com.oceanbase.external.jdbc.JdbcScanner.loadNextBatch(JdbcScanner.java:73)\n\tat org.apache.arrow.c.ArrayStreamExporter$ExportedArrayStreamPrivateData.getNext(ArrayStreamExporter.java:72)\nCaused by: java.lang.RuntimeException: Error occurred while consuming data.\n\tat org.apache.arrow.adapter.jdbc.ArrowVectorIterator.consumeData(ArrowVectorIterator.java:127)\n\tat org.apache.arrow.adapter.jdbc.ArrowVectorIterator.load(ArrowVectorIterator.java:178)\n\tat org.apache.arrow.adapter.jdbc.ArrowVectorIterator.next(ArrowVectorIterator.java:198)\n\t... 2 more\nCaused by: java.lang.OutOfMemoryError: Java heap space\n"; |
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.
Um, this is a little excessive. Can we just use a short canary string?
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.
fixed
} | ||
} | ||
} | ||
} |
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.
We need to assert that we did indeed get an exception.
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.
DONE
assertThat(eMessage.length()).isGreaterThan(expectExceptionMessage.length() + 1); | ||
assertThat(eMessage.substring(eMessage.length() - expectExceptionMessage.length() - 1, eMessage.length() - 1)) | ||
.isEqualTo(expectExceptionMessage); |
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.
Just use contains
...
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, we must make sure the string in the exception is the same with we throws.
"abc\x037" contains "abc", but it's not correct and we want to catch the bug.
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.
...then you just want endsWith?
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.
I use endsWith
to simplified the code.
for (Object batch : batches) { | ||
try { | ||
reader.loadNextBatch(); | ||
} catch (Exception e) { | ||
assertThat(exceptionThrowed).isEqualTo(null); | ||
final String eMessage = e.getMessage(); | ||
// 1 for '}', ref to CDataJniException | ||
assertThat(eMessage.length()).isGreaterThan(expectExceptionMessage.length() + 1); | ||
assertThat(eMessage.substring(eMessage.length() - expectExceptionMessage.length() - 1, eMessage.length() - 1)) | ||
.isEqualTo(expectExceptionMessage); | ||
exceptionThrowed = e; | ||
continue; | ||
} |
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.
Use assertThrows.
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.
DONE.
What's Changed
We should get the length of byte[] by
GetArrayLength
, notstrlen
which may cause invalid memory access.Closes #759.