|
110 | 110 | import static org.apache.flink.table.functions.FunctionKind.AGGREGATE; |
111 | 111 | import static org.apache.flink.table.functions.FunctionKind.OTHER; |
112 | 112 | import static org.apache.flink.table.functions.FunctionKind.SCALAR; |
| 113 | +import static org.apache.flink.table.gateway.api.config.SqlGatewayServiceConfigOptions.SQL_GATEWAY_READ_ONLY_MODE; |
113 | 114 | import static org.apache.flink.table.gateway.api.results.ResultSet.ResultType.PAYLOAD; |
114 | 115 | import static org.apache.flink.table.gateway.service.utils.SqlGatewayServiceTestUtil.awaitOperationTermination; |
115 | 116 | import static org.apache.flink.table.gateway.service.utils.SqlGatewayServiceTestUtil.createInitializedSession; |
@@ -1048,6 +1049,68 @@ void testGetOperationSchemaWhenOperationGetError() throws Exception { |
1048 | 1049 | .satisfies(anyCauseMatches(SqlGatewayException.class, msg))); |
1049 | 1050 | } |
1050 | 1051 |
|
| 1052 | + @Test |
| 1053 | + void testReadOnlyModeWithModificationOperations() { |
| 1054 | + Configuration config = new Configuration(MINI_CLUSTER.getClientConfiguration()); |
| 1055 | + config.set(SQL_GATEWAY_READ_ONLY_MODE, true); |
| 1056 | + |
| 1057 | + SessionEnvironment sessionEnvironment = |
| 1058 | + SessionEnvironment.newBuilder() |
| 1059 | + .setSessionEndpointVersion(MockedEndpointVersion.V1) |
| 1060 | + .build(); |
| 1061 | + |
| 1062 | + SessionHandle sessionHandle = service.openSession(sessionEnvironment); |
| 1063 | + String sourceDdl = "CREATE TABLE source (a STRING) WITH ('connector'='datagen');"; |
| 1064 | + String sinkDdl = "CREATE TABLE sink (a STRING) WITH ('connector'='blackhole');"; |
| 1065 | + |
| 1066 | + service.executeStatement(sessionHandle, sourceDdl, -1, config); |
| 1067 | + service.executeStatement(sessionHandle, sinkDdl, -1, config); |
| 1068 | + |
| 1069 | + OperationHandle insertOperationHandle = |
| 1070 | + service.executeStatement( |
| 1071 | + sessionHandle, "INSERT INTO sink SELECT * FROM source;", -1, config); |
| 1072 | + |
| 1073 | + assertThatThrownBy(() -> fetchAllResults(service, sessionHandle, insertOperationHandle)) |
| 1074 | + .satisfies( |
| 1075 | + anyCauseMatches( |
| 1076 | + SqlExecutionException.class, |
| 1077 | + "SQL Gateway is in read-only mode. The following statement is not allowed: INSERT INTO sink SELECT * FROM source")); |
| 1078 | + } |
| 1079 | + |
| 1080 | + @Test |
| 1081 | + void testReadOnlyModeWithStatementSet() { |
| 1082 | + Configuration config = new Configuration(MINI_CLUSTER.getClientConfiguration()); |
| 1083 | + config.set(SQL_GATEWAY_READ_ONLY_MODE, true); |
| 1084 | + |
| 1085 | + SessionEnvironment sessionEnvironment = |
| 1086 | + SessionEnvironment.newBuilder() |
| 1087 | + .setSessionEndpointVersion(MockedEndpointVersion.V1) |
| 1088 | + .build(); |
| 1089 | + |
| 1090 | + SessionHandle sessionHandle = service.openSession(sessionEnvironment); |
| 1091 | + String sourceDdl = "CREATE TABLE source (a STRING) WITH ('connector'='datagen');"; |
| 1092 | + String sinkDdl1 = "CREATE TABLE sink1 (a STRING) WITH ('connector'='blackhole');"; |
| 1093 | + String sinkDdl2 = "CREATE TABLE sink2 (a STRING) WITH ('connector'='blackhole');"; |
| 1094 | + |
| 1095 | + service.executeStatement(sessionHandle, sourceDdl, -1, config); |
| 1096 | + service.executeStatement(sessionHandle, sinkDdl1, -1, config); |
| 1097 | + service.executeStatement(sessionHandle, sinkDdl2, -1, config); |
| 1098 | + |
| 1099 | + service.executeStatement(sessionHandle, "BEGIN STATEMENT SET", -1, config); |
| 1100 | + service.executeStatement( |
| 1101 | + sessionHandle, "INSERT INTO sink1 SELECT * FROM source", -1, config); |
| 1102 | + service.executeStatement( |
| 1103 | + sessionHandle, "INSERT INTO sink2 SELECT * FROM source", -1, config); |
| 1104 | + |
| 1105 | + OperationHandle endOpHandle = service.executeStatement(sessionHandle, "END", -1, config); |
| 1106 | + |
| 1107 | + assertThatThrownBy(() -> fetchAllResults(service, sessionHandle, endOpHandle)) |
| 1108 | + .satisfies( |
| 1109 | + anyCauseMatches( |
| 1110 | + SqlExecutionException.class, |
| 1111 | + "SQL Gateway is in read-only mode. Modification operations are not allowed.")); |
| 1112 | + } |
| 1113 | + |
1051 | 1114 | // -------------------------------------------------------------------------------------------- |
1052 | 1115 |
|
1053 | 1116 | private OperationHandle submitDefaultOperation( |
|
0 commit comments