|
17 | 17 | package com.google.cloud.spanner.connection;
|
18 | 18 |
|
19 | 19 | import static org.junit.Assert.assertEquals;
|
| 20 | +import static org.junit.Assert.assertNotNull; |
20 | 21 | import static org.junit.Assert.assertThrows;
|
21 | 22 | import static org.junit.Assert.assertTrue;
|
22 | 23 | import static org.junit.Assert.fail;
|
|
30 | 31 | import com.google.cloud.spanner.SpannerException;
|
31 | 32 | import com.google.cloud.spanner.SpannerExceptionFactory;
|
32 | 33 | import com.google.cloud.spanner.Struct;
|
| 34 | +import com.google.cloud.spanner.Type; |
33 | 35 | import java.util.ArrayList;
|
34 | 36 | import java.util.BitSet;
|
35 | 37 | import java.util.Collection;
|
@@ -140,6 +142,19 @@ public void testAllResultsAreReturned() {
|
140 | 142 | while (resultSet.next()) {
|
141 | 143 | assertRowExists(results.allRows, resultSet.getCurrentRowAsStruct(), rowsFound);
|
142 | 144 | }
|
| 145 | + // Verify that we can get the metadata after having gotten all rows. |
| 146 | + // This failed in the initial release of this feature for result sets that were empty. The |
| 147 | + // reason for that was that the initial implementation would do a call to currentRowAsStruct, |
| 148 | + // which would always be null for result sets that never returned any data. |
| 149 | + assertNotNull(resultSet.getMetadata()); |
| 150 | + if (numPartitions == 0) { |
| 151 | + assertEquals(0, resultSet.getColumnCount()); |
| 152 | + } else { |
| 153 | + assertEquals(18, resultSet.getColumnCount()); |
| 154 | + assertEquals(Type.bool(), resultSet.getColumnType(0)); |
| 155 | + assertEquals(Type.bool(), resultSet.getColumnType("COL0")); |
| 156 | + assertEquals(10, resultSet.getColumnIndex("COL10")); |
| 157 | + } |
143 | 158 | // Check that all rows were found.
|
144 | 159 | assertEquals(results.allRows.size(), rowsFound.nextClearBit(0));
|
145 | 160 | // Check extended metadata.
|
|
0 commit comments