|
26 | 26 | import com.amazonaws.athena.connector.lambda.domain.Split; |
27 | 27 | import com.amazonaws.athena.connector.lambda.domain.TableName; |
28 | 28 | import com.amazonaws.athena.connector.lambda.domain.predicate.Constraints; |
| 29 | +import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException; |
29 | 30 | import com.amazonaws.athena.connector.lambda.metadata.GetSplitsRequest; |
30 | 31 | import com.amazonaws.athena.connector.lambda.metadata.GetSplitsResponse; |
31 | 32 | import com.amazonaws.athena.connector.lambda.metadata.GetTableLayoutRequest; |
@@ -401,28 +402,41 @@ blockAllocator, new ListTablesRequest(this.federatedIdentity, "testQueryId", |
401 | 402 | Assert.assertNull(listTablesResponse.getNextToken()); |
402 | 403 | Assert.assertArrayEquals(expected, listTablesResponse.getTables().toArray()); |
403 | 404 |
|
404 | | - // Test 4: Testing when requesting pageSize UNLIMITED_PAGE_SIZE_VALUE(-1) and nextToken is 2. |
| 405 | + // Test 4: nextToken is 2 and pageSize is UNLIMITED. Return all tables starting from index 2. |
405 | 406 | preparedStatement = Mockito.mock(PreparedStatement.class); |
406 | 407 | Mockito.when(this.connection.prepareStatement(Db2Constants.LIST_PAGINATED_TABLES_QUERY)).thenReturn(preparedStatement); |
407 | | - values = new Object[][]{{"testSchema", "testTable2"}}; |
408 | | - expected = new TableName[]{new TableName("testSchema", "testTable2")}; |
| 408 | + values = new Object[][]{{"testSchema", "testTable3"}, {"testSchema", "testTable4"}}; |
| 409 | + expected = new TableName[]{new TableName("testSchema", "testTable3"), new TableName("testSchema", "testTable4")}; |
409 | 410 | resultSet = mockResultSet(schema, values, new AtomicInteger(-1)); |
410 | 411 | Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); |
411 | 412 |
|
412 | | - PreparedStatement preparedStatement1 = Mockito.mock(PreparedStatement.class); |
413 | | - Mockito.when(this.connection.prepareStatement(Db2Constants.ALL_TABLES_COUNT_QUERY)).thenReturn(preparedStatement1); |
414 | | - schema = new String[]{"ALL_TABLES_COUNT"}; |
415 | | - values = new Object[][] {{5}}; |
416 | | - resultSet = mockResultSet(schema, values, new AtomicInteger(1)); |
417 | | - Mockito.when(preparedStatement1.executeQuery()).thenReturn(resultSet); |
418 | | - Mockito.when(resultSet.next()).thenReturn(true).thenReturn(false); |
419 | | - Mockito.when(resultSet.getInt(1)).thenReturn(5); |
420 | | - |
421 | 413 | listTablesResponse = this.db2MetadataHandler.doListTables( |
422 | 414 | blockAllocator, new ListTablesRequest(this.federatedIdentity, "testQueryId", |
423 | 415 | "testCatalog", "testSchema", "2", ListTablesRequest.UNLIMITED_PAGE_SIZE_VALUE)); |
424 | 416 | Assert.assertNull(listTablesResponse.getNextToken()); |
425 | 417 | Assert.assertArrayEquals(expected, listTablesResponse.getTables().toArray()); |
| 418 | + |
| 419 | + // Test 5: AthenaConnectorException with negative nextToken value |
| 420 | + preparedStatement = Mockito.mock(PreparedStatement.class); |
| 421 | + Mockito.when(this.connection.prepareStatement(Db2Constants.LIST_PAGINATED_TABLES_QUERY)).thenReturn(preparedStatement); |
| 422 | + values = new Object[][]{{"testSchema", "testTable3"}, {"testSchema", "testTable4"}}; |
| 423 | + resultSet = mockResultSet(schema, values, new AtomicInteger(-1)); |
| 424 | + Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); |
| 425 | + |
| 426 | + Assert.assertThrows(AthenaConnectorException.class, () -> this.db2MetadataHandler.doListTables( |
| 427 | + blockAllocator, new ListTablesRequest(this.federatedIdentity, "testQueryId", |
| 428 | + "testCatalog", "testSchema", "-1", 3))); |
| 429 | + |
| 430 | + // Test 6: AthenaConnectorException with negative pageSize value |
| 431 | + preparedStatement = Mockito.mock(PreparedStatement.class); |
| 432 | + Mockito.when(this.connection.prepareStatement(Db2Constants.LIST_PAGINATED_TABLES_QUERY)).thenReturn(preparedStatement); |
| 433 | + values = new Object[][]{{"testSchema", "testTable3"}, {"testSchema", "testTable4"}}; |
| 434 | + resultSet = mockResultSet(schema, values, new AtomicInteger(-1)); |
| 435 | + Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); |
| 436 | + |
| 437 | + Assert.assertThrows(AthenaConnectorException.class, () -> this.db2MetadataHandler.doListTables( |
| 438 | + blockAllocator, new ListTablesRequest(this.federatedIdentity, "testQueryId", |
| 439 | + "testCatalog", "testSchema", "0", -3))); |
426 | 440 | } |
427 | 441 | } |
428 | 442 |
|
0 commit comments