Skip to content

Commit 0a5544f

Browse files
committed
Added noTx test to QueryService
1 parent 44a0d8c commit 0a5544f

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

query/src/test/java/tech/ydb/query/impl/QueryIntegrationTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.slf4j.LoggerFactory;
1717

1818
import tech.ydb.common.transaction.TxMode;
19+
import tech.ydb.core.Issue;
1920
import tech.ydb.core.Result;
2021
import tech.ydb.core.Status;
2122
import tech.ydb.core.StatusCode;
@@ -519,4 +520,52 @@ public void testMultiStatement() {
519520
}
520521
}
521522
}
523+
524+
@Test
525+
public void testNoTxStatement() {
526+
try (QueryClient client = QueryClient.newClient(ydbTransport).build()) {
527+
try (QuerySession session = client.createSession(Duration.ofSeconds(5)).join().getValue()) {
528+
String query = ""
529+
+ "DECLARE $s1 AS Int32;"
530+
+ "DECLARE $s2 AS Int32;"
531+
+ "DECLARE $id1 AS Int32;"
532+
+ "DECLARE $id2 AS Int32;"
533+
+ "DECLARE $name1 AS Text;"
534+
+ "DECLARE $name2 AS Text;"
535+
+ "SELECT * FROM `" + TEST_TABLE + "` WHERE id = $s1;"
536+
+ "INSERT INTO `" + TEST_TABLE + "` (id, name) VALUES ($id1, $name1);"
537+
+ "SELECT * FROM `" + TEST_TABLE + "` WHERE id = $s2;"
538+
+ "INSERT INTO `" + TEST_TABLE + "` (id, name) VALUES ($id2, $name2);"
539+
+ "SELECT * FROM `" + TEST_TABLE + "` ORDER BY id";
540+
541+
Params params = Params.of(
542+
"$s1", PrimitiveValue.newInt32(100),
543+
"$s2", PrimitiveValue.newInt32(100),
544+
"$id1", PrimitiveValue.newInt32(100),
545+
"$name1", PrimitiveValue.newText("TEST1"),
546+
"$id2", PrimitiveValue.newInt32(100),
547+
"$name2", PrimitiveValue.newText("TEST2")
548+
);
549+
550+
Result<QueryReader> result = QueryReader.readFrom(
551+
session.createQuery(query, TxMode.NONE, params)
552+
).join();
553+
554+
Assert.assertFalse(result.isSuccess());
555+
Assert.assertEquals(StatusCode.PRECONDITION_FAILED, result.getStatus().getCode());
556+
Assert.assertArrayEquals(
557+
new Issue[] { Issue.of(2012, "Conflict with existing key.", Issue.Severity.ERROR)},
558+
result.getStatus().getIssues()
559+
);
560+
561+
Iterator<ResultSetReader> rsIter = QueryReader.readFrom(
562+
session.createQuery("SELECT id, name FROM " + TEST_TABLE + " ORDER BY id", TxMode.NONE)
563+
).join().getValue().iterator();
564+
565+
Assert.assertTrue(rsIter.hasNext());
566+
ResultSetReader rs = rsIter.next();
567+
Assert.assertFalse(rs.next());
568+
}
569+
}
570+
}
522571
}

0 commit comments

Comments
 (0)