Skip to content

Commit

Permalink
Added complex transaction example to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alex268 committed Mar 25, 2024
1 parent 2c6fd74 commit 940b66c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ protected void run(GrpcTransport transport, String pathPrefix) {
TableTransaction transaction = session.beginTransaction(TxMode.SERIALIZABLE_RW)
.join().getValue();

String query1 = "UPSERT INTO [" + tablePath + "] (key, value) VALUES (1, 'one');";
String query1 = "UPSERT INTO `" + tablePath + "` (key, value) VALUES (1, 'one');";
DataQueryResult result1 = transaction.executeDataQuery(query1).join().getValue();
System.out.println("--[insert1]-------------------");
DataQueryResults.print(result1);
System.out.println("------------------------------");

String query2 = "UPSERT INTO [" + tablePath + "] (key, value) VALUES (2, 'two');";
String query2 = "UPSERT INTO `" + tablePath + "` (key, value) VALUES (2, 'two');";
DataQueryResult result2 = transaction.executeDataQuery(query2).join().getValue();
System.out.println("--[insert2]-------------------");
DataQueryResults.print(result2);
System.out.println("------------------------------");

String query3 = "SELECT * FROM [" + tablePath + "];";
String query3 = "SELECT * FROM `" + tablePath + "`;";
DataQueryResult result3 = session.executeDataQuery(query3, TxControl.onlineRo().setCommitTx(true))
.join()
.getValue();
Expand All @@ -68,7 +68,7 @@ protected void run(GrpcTransport transport, String pathPrefix) {
.join()
.expectSuccess("cannot commit transaction");

String query = "SELECT * FROM [" + tablePath + "];";
String query = "SELECT * FROM `" + tablePath + "`;";
DataQueryResult result = session.executeDataQuery(query, TxControl.onlineRo().setCommitTx(true))
.join()
.getValue();
Expand All @@ -81,4 +81,9 @@ protected void run(GrpcTransport transport, String pathPrefix) {
public static void main(String[] args) {
new ComplexTransaction().doMain(args);
}

public static int test(String[] args) {
new ComplexTransaction().doMain(args);
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tech.ydb.examples.batch_upload.BatchUpload;
import tech.ydb.examples.bulk_upsert.BulkUpsert;
import tech.ydb.examples.pagination.PaginationApp;
import tech.ydb.examples.simple.ComplexTransaction;
import tech.ydb.examples.simple.ReadTableExample;
import tech.ydb.test.junit5.YdbHelperExtension;

Expand Down Expand Up @@ -52,4 +53,9 @@ public void testReadTable() {
public void testPagination() {
Assertions.assertEquals(0, PaginationApp.test(args(), "Pagination test"));
}

@Test
public void testComplexTransaction() {
Assertions.assertEquals(0, ComplexTransaction.test(connectionString()));
}
}

0 comments on commit 940b66c

Please sign in to comment.