3737import java .util .ArrayList ;
3838import java .util .List ;
3939
40+ import static org .apache .iotdb .db .it .utils .TestUtils .assertTestFail ;
4041import static org .apache .iotdb .db .it .utils .TestUtils .prepareData ;
4142import static org .junit .Assert .assertEquals ;
4243import static org .junit .Assert .assertFalse ;
@@ -178,17 +179,9 @@ public void testTimestampNegation() {
178179
179180 @ Test
180181 public void testUnaryWrongType () {
181- try (Connection connection = EnvFactory .getEnv ().getConnection ();
182- Statement statement = connection .createStatement ()) {
183- tsAssertTestFail (
184- statement , "select -s5 from root.sg.d1" , "Invalid input expression data type" );
185- tsAssertTestFail (
186- statement , "select -s6 from root.sg.d1" , "Invalid input expression data type" );
187- tsAssertTestFail (
188- statement , "select -s9 from root.sg.d1" , "Invalid input expression data type" );
189- } catch (SQLException throwable ) {
190- fail (throwable .getMessage ());
191- }
182+ assertTestFail ("select -s5 from root.sg.d1" , "Invalid input expression data type" );
183+ assertTestFail ("select -s6 from root.sg.d1" , "Invalid input expression data type" );
184+ assertTestFail ("select -s9 from root.sg.d1" , "Invalid input expression data type" );
192185 }
193186
194187 @ Test
@@ -312,15 +305,10 @@ public void testDateAndTimestampArithmetic() {
312305
313306 @ Test
314307 public void testDivisionByZero () {
315- try (Connection connection = EnvFactory .getEnv ().getConnection ();
316- Statement statement = connection .createStatement ()) {
317- tsAssertTestFail (statement , "select s1/0 from root.sg.d1" , "Division by zero" );
318- tsAssertTestFail (statement , "select s2/0 from root.sg.d1" , "Division by zero" );
319- tsAssertTestFail (statement , "select s1%0 from root.sg.d1" , "Division by zero" );
320- tsAssertTestFail (statement , "select s2%0 from root.sg.d1" , "Division by zero" );
321- } catch (SQLException throwable ) {
322- fail (throwable .getMessage ());
323- }
308+ assertTestFail ("select s1/0 from root.sg.d1" , "Division by zero" );
309+ assertTestFail ("select s2/0 from root.sg.d1" , "Division by zero" );
310+ assertTestFail ("select s1%0 from root.sg.d1" , "Division by zero" );
311+ assertTestFail ("select s2%0 from root.sg.d1" , "Division by zero" );
324312 }
325313
326314 @ Test
@@ -365,17 +353,12 @@ public void testDoubleModuloByZero() {
365353
366354 @ Test
367355 public void testBinaryWrongType () {
368- try (Connection connection = EnvFactory .getEnv ().getConnection ();
369- Statement statement = connection .createStatement ()) {
370- tsAssertTestFail (statement , "select s9 * s1 from root.sg.d1" , "Invalid" );
371- tsAssertTestFail (statement , "select s9 / s1 from root.sg.d1" , "Invalid" );
372- tsAssertTestFail (statement , "select s9 % s1 from root.sg.d1" , "Invalid" );
373- tsAssertTestFail (statement , "select s10 * s1 from root.sg.d1" , "Invalid" );
374- tsAssertTestFail (statement , "select s10 / s1 from root.sg.d1" , "Invalid" );
375- tsAssertTestFail (statement , "select s10 % s1 from root.sg.d1" , "Invalid" );
376- } catch (SQLException throwable ) {
377- fail (throwable .getMessage ());
378- }
356+ assertTestFail ("select s9 * s1 from root.sg.d1" , "Invalid" );
357+ assertTestFail ("select s9 / s1 from root.sg.d1" , "Invalid" );
358+ assertTestFail ("select s9 % s1 from root.sg.d1" , "Invalid" );
359+ assertTestFail ("select s10 * s1 from root.sg.d1" , "Invalid" );
360+ assertTestFail ("select s10 / s1 from root.sg.d1" , "Invalid" );
361+ assertTestFail ("select s10 % s1 from root.sg.d1" , "Invalid" );
379362 }
380363
381364 @ Test
@@ -414,24 +397,17 @@ public void testOverflow() {
414397 Integer .MIN_VALUE / 2 - 1 ,
415398 Integer .MAX_VALUE / 2 + 1 ));
416399
417- tsAssertTestFail (
418- statement , "select s1+s7 from root.sg.d2 where time=1" , "int Addition overflow" );
419- tsAssertTestFail (
420- statement , "select s1-s8 from root.sg.d2 where time=2" , "int Subtraction overflow" );
421- tsAssertTestFail (
422- statement , "select s1*s7 from root.sg.d2 where time=1" , "int Multiplication overflow" );
400+ assertTestFail ("select s1+s7 from root.sg.d2 where time=1" , "int Addition overflow" );
401+ assertTestFail ("select s1-s8 from root.sg.d2 where time=2" , "int Subtraction overflow" );
402+ assertTestFail ("select s1*s7 from root.sg.d2 where time=1" , "int Multiplication overflow" );
423403
424- tsAssertTestFail (
425- statement , "select s2+s2 from root.sg.d2 where time=1" , "long Addition overflow" );
426- tsAssertTestFail (
427- statement , "select s3-s2 from root.sg.d2 where time=1" , "long Subtraction overflow" );
404+ assertTestFail ("select s2+s2 from root.sg.d2 where time=1" , "long Addition overflow" );
405+ assertTestFail ("select s3-s2 from root.sg.d2 where time=1" , "long Subtraction overflow" );
428406
429- tsAssertTestFail (
430- statement ,
407+ assertTestFail (
431408 String .format ("select s10+%d from root.sg.d2 where time=1" , Long .MAX_VALUE ),
432409 "long Addition overflow" );
433- tsAssertTestFail (
434- statement ,
410+ assertTestFail (
435411 String .format ("select s10-(%d) from root.sg.d2 where time=1" , Long .MIN_VALUE ),
436412 "long Subtraction overflow" );
437413
@@ -448,27 +424,14 @@ public void testDateOutOfRange() {
448424 statement .execute ("insert into root.sg.d3(time, date) values (1, '9999-12-31')" );
449425 statement .execute ("insert into root.sg.d3(time, date) values (2, '1000-01-01')" );
450426
451- tsAssertTestFail (
452- statement ,
427+ assertTestFail (
453428 "select date + 86400000 from root.sg.d3 where time = 1" ,
454429 "Year must be between 1000 and 9999" );
455- tsAssertTestFail (
456- statement ,
430+ assertTestFail (
457431 "select date - 86400000 from root.sg.d3 where time = 2" ,
458432 "Year must be between 1000 and 9999" );
459433 } catch (SQLException throwable ) {
460434 fail (throwable .getMessage ());
461435 }
462436 }
463-
464- private void tsAssertTestFail (Statement statement , String sql , String expectedErrorMsg ) {
465- try {
466- statement .executeQuery (sql );
467- fail ("Expected exception with message: " + expectedErrorMsg );
468- } catch (SQLException e ) {
469- assertTrue (
470- "Expected error message '" + expectedErrorMsg + "' but got: " + e .getMessage (),
471- e .getMessage ().contains (expectedErrorMsg ));
472- }
473- }
474437}
0 commit comments