1717package org .apache .arrow .c ;
1818
1919import static org .assertj .core .api .Assertions .assertThat ;
20+ import static org .assertj .core .api .Assertions .catchThrowableOfType ;
2021
2122import java .io .IOException ;
2223import java .io .PrintWriter ;
@@ -55,16 +56,6 @@ public void testException() throws IOException {
5556
5657 try (BufferAllocator allocator = new RootAllocator ();
5758 VectorSchemaRoot root = VectorSchemaRoot .create (schema , allocator )) {
58- final IntVector ints = (IntVector ) root .getVector (0 );
59- VectorUnloader unloader = new VectorUnloader (root );
60-
61- root .allocateNew ();
62- ints .setSafe (0 , 1 );
63- ints .setSafe (1 , 2 );
64- ints .setSafe (2 , 4 );
65- ints .setSafe (3 , 8 );
66- root .setRowCount (4 );
67- batches .add (unloader .getRecordBatch ());
6859
6960 final String exceptionMessage = "This is a message for testing exception." ;
7061
@@ -83,29 +74,13 @@ public void testException() throws IOException {
8374 final VectorLoader loader = new VectorLoader (importRoot );
8475 Data .exportArrayStream (allocator , source , stream );
8576
86- Throwable exceptionThrowed = null ;
8777 try (final ArrowReader reader = Data .importArrayStream (allocator , stream )) {
88- assertThat (reader .getVectorSchemaRoot ().getSchema ()).isEqualTo (schema );
89-
90- for (Object batch : batches ) {
91- try {
92- reader .loadNextBatch ();
93- } catch (Exception e ) {
94- assertThat (exceptionThrowed ).isEqualTo (null );
95- final String eMessage = e .getMessage ();
96- // 1 for '}', ref to CDataJniException
97- assertThat (eMessage .length ()).isGreaterThan (expectExceptionMessage .length () + 1 );
98- assertThat (eMessage .substring (eMessage .length () - expectExceptionMessage .length () - 1 , eMessage .length () - 1 ))
78+ IOException jniException = catchThrowableOfType (IOException .class , reader ::loadNextBatch );
79+ final String jniMessage = jniException .getMessage ();
80+ assertThat (jniMessage .length ()).isGreaterThan (expectExceptionMessage .length () + 1 ); // 1 for '}'
81+ assertThat (jniMessage .substring (jniMessage .length () - expectExceptionMessage .length () - 1 , jniMessage .length () - 1 ))
9982 .isEqualTo (expectExceptionMessage );
100- exceptionThrowed = e ;
101- continue ;
102- }
103- loader .load ((ArrowRecordBatch ) batch );
104-
105- assertThat (reader .getVectorSchemaRoot ().getRowCount ()).isEqualTo (root .getRowCount ());
106- }
10783 }
108- assertThat (exceptionThrowed ).isNotEqualTo (null );
10984 }
11085 }
11186 }
0 commit comments