-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
GH-42030: [Java] Update Unit Tests for Adapter Module #42038
Changes from all commits
eb39e2d
41203ec
bb991d2
2e3a62c
7ce2273
297e5b7
536f97a
803a7d8
d5f1375
4e83d20
37f868c
dfd023f
b4e8ef0
76d62b8
0c50f7f
e563b45
14138d5
93b80b6
58a81ab
993e4da
1d4c4d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,9 +37,7 @@ | |
import org.apache.arrow.vector.VectorSchemaRoot; | ||
import org.apache.arrow.vector.types.pojo.ArrowType; | ||
import org.apache.arrow.vector.util.ValueVectorUtility; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.jupiter.api.AfterEach; | ||
|
||
/** Class to abstract out some common test functionality for testing JDBC to Arrow. */ | ||
public abstract class AbstractJdbcToArrowTest { | ||
|
@@ -94,8 +92,9 @@ protected static Table getTable(String ymlFilePath, @SuppressWarnings("rawtypes" | |
* @throws SQLException on error | ||
* @throws ClassNotFoundException on error | ||
*/ | ||
@Before | ||
public void setUp() throws SQLException, ClassNotFoundException { | ||
protected void initializeDatabase(Table table) throws SQLException, ClassNotFoundException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vibhatha I'll look into it more, but if you have any suggestions for a better structure, I would really appreciate your advice. cc @lidavidm classDiagram
direction LR
class AbstractJdbcToArrowTest {
}
class JdbcToArrowCharSetTest {
}
class JdbcToArrowDataTypesTest {
}
class JdbcToArrowMapDataTypeTest {
}
class JdbcToArrowNullTest {
}
class JdbcToArrowOptionalColumnsTest {
}
class JdbcToArrowTest {
}
class JdbcToArrowTimeZoneTest {
}
class JdbcToArrowVectorIteratorTest {
}
AbstractJdbcToArrowTest <|-- JdbcToArrowCharSetTest
AbstractJdbcToArrowTest <|-- JdbcToArrowDataTypesTest
AbstractJdbcToArrowTest <|-- JdbcToArrowMapDataTypeTest
AbstractJdbcToArrowTest <|-- JdbcToArrowNullTest
AbstractJdbcToArrowTest <|-- JdbcToArrowOptionalColumnsTest
AbstractJdbcToArrowTest <|-- JdbcToArrowTest
AbstractJdbcToArrowTest <|-- JdbcToArrowTimeZoneTest
JdbcToArrowTest <|-- JdbcToArrowVectorIteratorTest
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @llama90 I will review this tomorrow. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess what you are concerned about is making the database connection for each test case with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we need to create a database connection with a different I described something similar here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is fine |
||
this.table = table; | ||
|
||
TimeZone.setDefault(TimeZone.getTimeZone("UTC")); | ||
String url = "jdbc:h2:mem:JdbcToArrowTest"; | ||
String driver = "org.h2.Driver"; | ||
|
@@ -114,7 +113,7 @@ public void setUp() throws SQLException, ClassNotFoundException { | |
* | ||
* @throws SQLException on error | ||
*/ | ||
@After | ||
@AfterEach | ||
public void destroy() throws SQLException { | ||
if (conn != null) { | ||
conn.close(); | ||
|
@@ -146,11 +145,12 @@ public static Object[][] prepareTestData( | |
/** | ||
* Abstract method to implement test Functionality to test JdbcToArrow methods. | ||
* | ||
* @param table Table object | ||
* @throws SQLException on error | ||
* @throws IOException on error | ||
*/ | ||
@Test | ||
public abstract void testJdbcToArrowValues() throws SQLException, IOException; | ||
public abstract void testJdbcToArrowValues(Table table) | ||
throws SQLException, IOException, ClassNotFoundException; | ||
|
||
/** | ||
* Abstract method to implement logic to assert test various datatype values. | ||
|
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 was getting an error in Windows saying "failed to delete temp directory" because "The process cannot access the file because it is being used by another process."
To fix this, I found out that using
try-with-resources
to properly close resources would help.But for the
convert
method, theFileInputStream
(fis) needs to stay open for theiterator
after theconvert
method is called. This caused the error because thefis
wasn't properly closed. So, I made awriteDataToFile
method for theFileOutputStream
and usedtry-with-resources
forfis
in the same method where theiterator
is used.Now, the tests run fine on Windows too.
Here are the different approaches I tried:
Attempt 1:
convert method:
try-with-resources
try-with-resources
Error:
Stream Closed
- because thefis
was closed while theiterator
still needed it.Attempt 2:
convert method:
try-with-resources
Error:
failed to delete temp directory
- because thefis
wasn't closed.Attempt 3:
convert method:
try-with-resources
FileInputStream
as a parameter to the convert method and explicitly closed it in the test method.Didn't work as expected.
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.
Thanks for pushing this one and evaluating diverse approaches.