Skip to content

test that shows getRowsUpdated returns 0 in upsert #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/test/java/io/r2dbc/mssql/TransactionIntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,58 @@ void shouldResetLockTimeoutAfterTransaction() {
.verifyComplete();
}

@Test
void shouldGetRowsUpdatedInUpsert() throws Exception {
createTable(connection);
String insertSql = "INSERT INTO r2dbc_example (id, first_name, last_name) VALUES(1, 'Jessi', 'Pinkmann')";


reactor.core.publisher.Flux<Long> flux = connection
.createStatement(insertSql)
.execute()
.flatMap(MssqlResult::getRowsUpdated);

java.util.concurrent.CompletableFuture<Long> future = reactor.core.publisher.Mono.from(flux).toFuture();
Long result = future.get(2, java.util.concurrent.TimeUnit.SECONDS);
org.junit.jupiter.api.Assertions.assertEquals(1L, result);

String updateSql = "UPDATE r2dbc_example SET id = 1, first_name = 'Jesse', last_name = 'Pinkman' WHERE id = 1";
reactor.core.publisher.Flux<Long> fluxUpdate = connection
.createStatement(updateSql)
.execute()
.flatMap(MssqlResult::getRowsUpdated);
java.util.concurrent.CompletableFuture<Long> futureUpdate = reactor.core.publisher.Mono.from(fluxUpdate).toFuture();
Long resultUpdate = futureUpdate.get(2, java.util.concurrent.TimeUnit.SECONDS);
org.junit.jupiter.api.Assertions.assertEquals(1L, resultUpdate);

//clean the state
createTable(connection);

String upsertSQl = updateSql + " if @@ROWCOUNT = 0 " + insertSql;
reactor.core.publisher.Flux<Long> fluxUpsert = connection
.createStatement(upsertSQl)
.execute()
.flatMap(MssqlResult::getRowsUpdated);

java.util.concurrent.CompletableFuture<Long> futureUpsert = reactor.core.publisher.Mono.from(fluxUpsert).toFuture();
Long resultUpsert = futureUpsert.get(2, java.util.concurrent.TimeUnit.SECONDS);

// should also have 1 updated row (from the insert part of the upsert)
org.junit.jupiter.api.Assertions.assertEquals(1L, resultUpsert);

reactor.core.publisher.Flux<Long> secondFluxUpsert = connection
.createStatement(upsertSQl)
.execute()
.flatMap(MssqlResult::getRowsUpdated);

java.util.concurrent.CompletableFuture<Long> secondFutureUpsert = reactor.core.publisher.Mono.from(secondFluxUpsert).toFuture();
Long secondResultUpsert = secondFutureUpsert.get(2, java.util.concurrent.TimeUnit.SECONDS);

// should also have 1 updated row (from the update part of the upsert)
org.junit.jupiter.api.Assertions.assertEquals(1L, secondResultUpsert);
}


Mono<IsolationLevel> getIsolationLevel() {

return connection.createStatement("SELECT CASE transaction_isolation_level \n" +
Expand Down