Skip to content

Commit 940b66c

Browse files
committed
Added complex transaction example to tests
1 parent 2c6fd74 commit 940b66c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

ydb-cookbook/src/main/java/tech/ydb/examples/simple/ComplexTransaction.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ protected void run(GrpcTransport transport, String pathPrefix) {
4444
TableTransaction transaction = session.beginTransaction(TxMode.SERIALIZABLE_RW)
4545
.join().getValue();
4646

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

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

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

71-
String query = "SELECT * FROM [" + tablePath + "];";
71+
String query = "SELECT * FROM `" + tablePath + "`;";
7272
DataQueryResult result = session.executeDataQuery(query, TxControl.onlineRo().setCommitTx(true))
7373
.join()
7474
.getValue();
@@ -81,4 +81,9 @@ protected void run(GrpcTransport transport, String pathPrefix) {
8181
public static void main(String[] args) {
8282
new ComplexTransaction().doMain(args);
8383
}
84+
85+
public static int test(String[] args) {
86+
new ComplexTransaction().doMain(args);
87+
return 0;
88+
}
8489
}

ydb-cookbook/src/test/java/tech/ydb/examples/ExamplesTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import tech.ydb.examples.batch_upload.BatchUpload;
88
import tech.ydb.examples.bulk_upsert.BulkUpsert;
99
import tech.ydb.examples.pagination.PaginationApp;
10+
import tech.ydb.examples.simple.ComplexTransaction;
1011
import tech.ydb.examples.simple.ReadTableExample;
1112
import tech.ydb.test.junit5.YdbHelperExtension;
1213

@@ -52,4 +53,9 @@ public void testReadTable() {
5253
public void testPagination() {
5354
Assertions.assertEquals(0, PaginationApp.test(args(), "Pagination test"));
5455
}
56+
57+
@Test
58+
public void testComplexTransaction() {
59+
Assertions.assertEquals(0, ComplexTransaction.test(connectionString()));
60+
}
5561
}

0 commit comments

Comments
 (0)