1414import java .util .Timer ;
1515import java .util .TimerTask ;
1616import java .util .concurrent .Executor ;
17+ import java .util .concurrent .ExecutorService ;
18+ import java .util .concurrent .Executors ;
1719import org .junit .jupiter .api .*;
1820import org .mariadb .jdbc .*;
1921import org .mariadb .jdbc .integration .util .SocketFactoryBasicTest ;
@@ -937,7 +939,10 @@ public void useNoDatabase() throws SQLException {
937939 public void windowsNamedPipe () throws SQLException {
938940 ResultSet rs = null ;
939941 try {
940- rs = sharedConn .createStatement ().executeQuery ("select @@named_pipe,@@socket,@@named_pipe_full_access_group" );
942+ rs =
943+ sharedConn
944+ .createStatement ()
945+ .executeQuery ("select @@named_pipe,@@socket,@@named_pipe_full_access_group" );
941946 } catch (SQLException sqle ) {
942947 // on non Windows system, named_pipe doesn't exist.
943948 }
@@ -956,15 +961,14 @@ public void windowsNamedPipe() throws SQLException {
956961 // skip test if no namedPipeName was obtained because then we do not use a socket connection
957962 Assumptions .assumeTrue (namedPipeName != null );
958963 String connUrl =
959- password == null || password .isEmpty ()
960- ? String .format (
961- "jdbc:mariadb:///%s?user=%s%s" , database , user , defaultOther )
962- : String .format (
963- "jdbc:mariadb:///%s?user=%s&password=%s%s" ,
964- database , user , password , defaultOther );
964+ password == null || password .isEmpty ()
965+ ? String .format ("jdbc:mariadb:///%s?user=%s%s" , database , user , defaultOther )
966+ : String .format (
967+ "jdbc:mariadb:///%s?user=%s&password=%s%s" ,
968+ database , user , password , defaultOther );
965969
966-
967- try ( Connection connection = DriverManager .getConnection (connUrl + "&pipe=" + namedPipeName )) {
970+ try ( Connection connection =
971+ DriverManager .getConnection (connUrl + "&pipe=" + namedPipeName )) {
968972 java .sql .Statement stmt = connection .createStatement ();
969973 try (ResultSet rs2 = stmt .executeQuery ("SELECT 1" )) {
970974 assertTrue (rs2 .next ());
@@ -987,6 +991,60 @@ public void windowsNamedPipe() throws SQLException {
987991 }
988992 }
989993
994+ @ Test
995+ public void windowsNamedPipeCancel () throws SQLException {
996+ Assumptions .assumeFalse (isMariaDBServer ());
997+ ResultSet rs = null ;
998+ try {
999+ rs =
1000+ sharedConn
1001+ .createStatement ()
1002+ .executeQuery ("select @@named_pipe,@@socket,@@named_pipe_full_access_group" );
1003+ } catch (SQLException sqle ) {
1004+ // on non Windows system, named_pipe doesn't exist.
1005+ }
1006+ if (rs != null ) {
1007+ assertTrue (rs .next ());
1008+ System .out .println ("named_pipe:" + rs .getString (1 ));
1009+ Assumptions .assumeTrue (rs .getBoolean (1 ));
1010+ String namedPipeName = rs .getString (2 );
1011+ System .out .println ("namedPipeName:" + namedPipeName );
1012+ if (!isMariaDBServer () && minVersion (8 , 0 , 14 )) {
1013+ String namedPipeFullAccess = rs .getString (3 );
1014+ System .out .println ("namedPipeFullAccess:" + namedPipeFullAccess );
1015+ Assumptions .assumeTrue (namedPipeFullAccess != null && !namedPipeFullAccess .isEmpty ());
1016+ }
1017+
1018+ // skip test if no namedPipeName was obtained because then we do not use a socket connection
1019+ Assumptions .assumeTrue (namedPipeName != null );
1020+ String connUrl =
1021+ password == null || password .isEmpty ()
1022+ ? String .format ("jdbc:mariadb:///%s?user=%s%s" , database , user , defaultOther )
1023+ : String .format (
1024+ "jdbc:mariadb:///%s?user=%s&password=%s%s" ,
1025+ database , user , password , defaultOther );
1026+
1027+ try (Connection connection =
1028+ DriverManager .getConnection (connUrl + "&pipe=" + namedPipeName )) {
1029+ Statement stmt = connection .createStatement ();
1030+ stmt .cancel (); // will do nothing
1031+
1032+ ExecutorService exec = Executors .newFixedThreadPool (1 );
1033+
1034+ Common .assertThrowsContains (
1035+ SQLTimeoutException .class ,
1036+ () -> {
1037+ exec .execute (new StatementTest .CancelThread (stmt ));
1038+ stmt .execute (
1039+ "select * from information_schema.columns as c1, information_schema.tables, information_schema"
1040+ + ".tables as t2" );
1041+ exec .shutdown ();
1042+ },
1043+ "Query execution was interrupted" );
1044+ }
1045+ }
1046+ }
1047+
9901048 @ Test
9911049 public void localSocket () throws Exception {
9921050 Assumptions .assumeTrue (
0 commit comments