|
| 1 | +/* |
| 2 | + * Copyright 2025 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.cloud.spanner.connection; |
| 18 | + |
| 19 | +import static org.junit.Assert.assertEquals; |
| 20 | +import static org.junit.Assert.assertFalse; |
| 21 | + |
| 22 | +import com.google.cloud.spanner.MockSpannerServiceImpl; |
| 23 | +import com.google.cloud.spanner.ResultSet; |
| 24 | +import com.google.cloud.spanner.Statement; |
| 25 | +import com.google.spanner.v1.ResultSetMetadata; |
| 26 | +import com.google.spanner.v1.StructType; |
| 27 | +import com.google.spanner.v1.StructType.Field; |
| 28 | +import com.google.spanner.v1.Type; |
| 29 | +import com.google.spanner.v1.TypeCode; |
| 30 | +import org.junit.Test; |
| 31 | +import org.junit.runner.RunWith; |
| 32 | +import org.junit.runners.JUnit4; |
| 33 | + |
| 34 | +@RunWith(JUnit4.class) |
| 35 | +public class CallTest extends AbstractMockServerTest { |
| 36 | + |
| 37 | + @Test |
| 38 | + public void testCancelQuery() { |
| 39 | + // 'CALL' should be recognized as a valid query keyword. |
| 40 | + Statement statement = Statement.of("call cancel_query('1234')"); |
| 41 | + mockSpanner.putStatementResult( |
| 42 | + MockSpannerServiceImpl.StatementResult.query( |
| 43 | + statement, |
| 44 | + com.google.spanner.v1.ResultSet.newBuilder() |
| 45 | + .setMetadata( |
| 46 | + ResultSetMetadata.newBuilder() |
| 47 | + .setRowType( |
| 48 | + StructType.newBuilder() |
| 49 | + .addFields( |
| 50 | + Field.newBuilder() |
| 51 | + .setName("call_result_tvf") |
| 52 | + .setType(Type.newBuilder().setCode(TypeCode.BOOL).build()) |
| 53 | + .build()) |
| 54 | + .build()) |
| 55 | + .build()) |
| 56 | + .build())); |
| 57 | + |
| 58 | + try (Connection connection = createConnection()) { |
| 59 | + try (ResultSet resultSet = connection.executeQuery(statement)) { |
| 60 | + assertFalse(resultSet.next()); |
| 61 | + assertEquals(1, resultSet.getColumnCount()); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments