-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aedb0ba
commit 1244e24
Showing
29 changed files
with
832 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/integrationTest/java/org/itsallcode/jdbc/BatchInsertPerformanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.itsallcode.jdbc; | ||
|
||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.IntStream; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.Timeout; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class BatchInsertPerformanceTest { | ||
@Mock | ||
SimpleConnection connectionMock; | ||
@Mock | ||
SimplePreparedStatement preparedStatementMock; | ||
|
||
@Test | ||
@Timeout(value = 10, unit = TimeUnit.SECONDS) | ||
void performanceTestRowStmtSetter() { | ||
final int rowCount = 10_000_000; | ||
testee().into("TEST", List.of("ID", "NAME")) | ||
.mapping((row, stmt) -> { | ||
stmt.setInt(1, row.id); | ||
stmt.setString(2, row.name); | ||
}).rows(generateStream(rowCount)).start(); | ||
} | ||
|
||
private BatchInsertBuilder<NameRow> testee() { | ||
final PreparedStatement stmt = new NoopPreparedStatement(); | ||
when(connectionMock.prepareStatement(anyString())) | ||
.thenReturn(new SimplePreparedStatement(null, null, stmt, "sql")); | ||
return new BatchInsertBuilder<NameRow>(connectionMock::prepareStatement, Context.builder().build()); | ||
} | ||
|
||
@Test | ||
@Timeout(value = 10, unit = TimeUnit.SECONDS) | ||
void performanceTestObjectArray() { | ||
final int rowCount = 10_000_000; | ||
testee().into("TEST", List.of("ID", "NAME")) | ||
.mapping(row -> new Object[] { row.id, row.name }).rows(generateStream(rowCount)).start(); | ||
} | ||
|
||
private Stream<NameRow> generateStream(final int rowCount) { | ||
return IntStream.range(0, rowCount).mapToObj(id -> new NameRow(id, "Name " + id)); | ||
} | ||
|
||
private record NameRow(int id, String name) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.