Skip to content

Commit

Permalink
Added test case testBulkCopyOptionDefaultsTimeoutLowerValue
Browse files Browse the repository at this point in the history
  • Loading branch information
muskan124947 committed Dec 19, 2024
1 parent 2306130 commit df2a292
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.sql.Connection;
Expand Down Expand Up @@ -565,6 +566,47 @@ public void testBulkCopyOptionDefaultsTimeout() throws Exception {
}
}

/**
* Test with useBulkCopyBatchInsert=true and bulkCopyOptionDefaultsTimeout set to a lower value
*
* @throws SQLException
*/
@Test
public void testBulkCopyOptionDefaultsTimeoutLowerValue() throws Exception {
try (Connection connection = PrepUtil.getConnection(
connectionString + ";useBulkCopyForBatchInsert=true;bulkCopyOptionDefaultsTimeout=1")) {
try (PreparedStatement pstmt = connection.prepareStatement("WAITFOR DELAY '00:00:02'; insert into " + tableName + " values(?, ?)")) {
pstmt.setInt(1, 1);
pstmt.setInt(2, 1);
pstmt.addBatch();

pstmt.setInt(1, 2);
pstmt.setInt(2, 2);
pstmt.addBatch();

pstmt.setInt(1, 3);
pstmt.setInt(2, 3);
pstmt.addBatch();

pstmt.setInt(1, 4);
pstmt.setInt(2, 4);
pstmt.addBatch();

// Set a query timeout to a lower value to simulate timeout
pstmt.setQueryTimeout(1);

try {
pstmt.executeBatch();
fail("Expected timeout exception was not thrown");
} catch (SQLException e) {
assertTrue(e.getMessage().contains("The query has timed out") || e.getMessage().contains("timeout"), "Expected timeout exception");
}
}
} catch (SQLException e) {
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}
}

/**
* Test with useBulkCopyBatchInsert=true and
* bulkCopyOptionDefaultsFireTriggers=true
Expand Down

0 comments on commit df2a292

Please sign in to comment.