From 2ad7dc0e9ae07568a6d544eda83cd02af85a6e67 Mon Sep 17 00:00:00 2001 From: Georgii Novoselov Date: Fri, 20 Dec 2024 16:01:25 +0000 Subject: [PATCH 1/3] Add a write query fetch test to driver --- driver/driver.feature | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/driver/driver.feature b/driver/driver.feature index 371f6630..e780e7d3 100644 --- a/driver/driver.feature +++ b/driver/driver.feature @@ -612,7 +612,7 @@ Feature: TypeDB Driver Then transaction commits - Scenario: Driver processes concept document query answers correctly + Scenario: Driver processes concept document query answers from read queries correctly Given connection open schema transaction for database: typedb Given typeql schema query """ @@ -799,6 +799,44 @@ Feature: TypeDB Driver """ + Scenario: Driver processes concept document query answers from write queries correctly + Given connection open schema transaction for database: typedb + Given typeql schema query + """ + define entity person owns name @key; attribute name, value string; + """ + Given transaction commits + When connection open write transaction for database: typedb + When get answers of typeql write query + """ + insert $p isa person, has name "John"; + fetch { + "name": $p.name, + "sub fetch": { + "all attributes": { $p.* }, + } + }; + """ + Then answer type is: concept documents + Then answer type is not: ok + Then answer type is not: concept rows + Then answer query type is: write + Then answer query type is not: schema + Then answer query type is not: read + Then answer size is: 1 + Then answer contains document: + """ + { + "name": "John", + "sub fetch": { + "all attributes": { + "name": "John" + } + } + } + """ + + Scenario: Driver processes query errors correctly Given connection open schema transaction for database: typedb Then typeql schema query; fails From aebb14962ffe42e8d44dabb6abb10660aff461b9 Mon Sep 17 00:00:00 2001 From: Georgii Novoselov Date: Fri, 20 Dec 2024 16:09:39 +0000 Subject: [PATCH 2/3] Made the test more interesting --- driver/driver.feature | 45 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/driver/driver.feature b/driver/driver.feature index e780e7d3..99e8e749 100644 --- a/driver/driver.feature +++ b/driver/driver.feature @@ -803,7 +803,7 @@ Feature: TypeDB Driver Given connection open schema transaction for database: typedb Given typeql schema query """ - define entity person owns name @key; attribute name, value string; + define entity person owns name @card(1); attribute name, value string; attribute age @abstract; """ Given transaction commits When connection open write transaction for database: typedb @@ -835,6 +835,49 @@ Feature: TypeDB Driver } } """ + When get answers of typeql write query + """ + match + attribute $a; + insert + $p1 isa person, has name "Alice"; + $p2 isa person, has name "Bob"; + fetch { + "Alice's name": $p1.name, + "sub fetch": { + "Bob's all": { $p2.* }, + } + }; + """ + Then answer type is: concept documents + Then answer type is not: ok + Then answer type is not: concept rows + Then answer query type is: write + Then answer query type is not: schema + Then answer query type is not: read + Then answer size is: 2 + Then answer contains document: + """ + { + "Alice's name": "Alice", + "sub fetch": { + "Bob's all": { + "name": "Bob" + } + } + } + """ + Then answer does not contain document: + """ + { + "Alice's name": "Bob", + "sub fetch": { + "Bob's all": { + "name": "Alice" + } + } + } + """ Scenario: Driver processes query errors correctly From 3d42364d175514dabacaaccacc6cbf8c8db4a239 Mon Sep 17 00:00:00 2001 From: Georgii Novoselov Date: Mon, 23 Dec 2024 12:11:33 +0000 Subject: [PATCH 3/3] Uncomment and fix rollback tests --- connection/transaction.feature | 120 ++++++++++++++++++++------------- driver/driver.feature | 39 +++++------ 2 files changed, 92 insertions(+), 67 deletions(-) diff --git a/connection/transaction.feature b/connection/transaction.feature index bc9f6d6e..530d6aec 100644 --- a/connection/transaction.feature +++ b/connection/transaction.feature @@ -48,16 +48,15 @@ Feature: Connection Transaction | write | | schema | - # TODO: Fix rollback -# Scenario Outline: one database, transaction rollback -# When connection create database: typedb -# Given connection open transaction for database: typedb -# Then transaction rollbacks -# Then transaction is open: true -# Examples: -# | type | -# | write | -# | schema | + Scenario Outline: one database, transaction rollback + When connection create database: typedb + Given connection open transaction for database: typedb + Then transaction rollbacks + Then transaction is open: true + Examples: + | type | + | write | + | schema | Scenario: read transaction cannot be rollbacked When connection create database: typedb @@ -302,45 +301,70 @@ Feature: Connection Transaction """ Then transaction commits - # TODO: Fix rollback -# Scenario: commit after a schema transaction rollback does nothing -# Given connection create database: typedb -# Given connection open schema transaction for database: typedb -# When typeql schema query -# """ -# define entity person; -# """ -# When transaction rollbacks -# When transaction commits -# When connection open read transaction for database: typedb -# When typeql read query -# """ -# match entity $x; -# """ -# Then answer size is: 0 + Scenario: commit after a schema transaction rollback does nothing + Given connection create database: typedb + Given connection open schema transaction for database: typedb + When typeql schema query + """ + define entity person; + """ + Then get answers of typeql read query + """ + match entity $x; + """ + Then answer size is: 1 + Then get answers of typeql read query + """ + match entity $x; + """ + Then answer size is: 1 - # TODO: Fix rollback -# Scenario: commit after a write transaction rollback does nothing -# Given connection create database: typedb -# Given connection open schema transaction for database: typedb -# Given typeql schema query -# """ -# define entity person; -# """ -# Given transaction commits -# Given connection open write transaction for database: typedb -# When typeql write query -# """ -# insert $x isa person; -# """ -# When transaction rollbacks -# When transaction commits -# When connection open read transaction for database: typedb -# When typeql read query -# """ -# match $x isa person; -# """ -# Then answer size is: 0 + When transaction rollbacks + Then typeql read query; fails with a message containing: "empty-set for some variable" + """ + match entity $x; + """ + + When transaction commits + When connection open read transaction for database: typedb + Then typeql read query; fails with a message containing: "empty-set for some variable" + """ + match entity $x; + """ + + Scenario: commit after a write transaction rollback does nothing + Given connection create database: typedb + Given connection open schema transaction for database: typedb + Given typeql schema query + """ + define entity person; + """ + Given transaction commits + Given connection open write transaction for database: typedb + When typeql write query + """ + insert $x isa person; + """ + When get answers of typeql read query + """ + match $x isa person; + """ + Then answer size is: 1 + + When transaction rollbacks + When get answers of typeql read query + """ + match $x isa person; + """ + Then answer size is: 0 + + When transaction commits + When connection open read transaction for database: typedb + When get answers of typeql read query + """ + match $x isa person; + """ + Then answer size is: 0 # TODO: Uncomment when options are implemented. Decide if it needs the following tag. # @ignore-typedb diff --git a/driver/driver.feature b/driver/driver.feature index 99e8e749..63164b21 100644 --- a/driver/driver.feature +++ b/driver/driver.feature @@ -300,25 +300,26 @@ Feature: TypeDB Driver Then transaction is open: false - # TODO: Fix rollbacks on the server side -# Scenario: Driver can rollback transactions of schema and write types, cannot rollback transaction of type read -# When connection open schema transaction for database: typedb -# Then transaction has type: schema -# Then transaction is open: true -# When transaction rollbacks -# Then transaction is open: false -# -# When connection open write transaction for database: typedb -# Then transaction has type: write -# Then transaction is open: true -# When transaction rollbacks -# Then transaction is open: false -# -# When connection open read transaction for database: typedb -# Then transaction has type: read -# Then transaction is open: true -# Then transaction rollbacks; fails with a message containing: "todo" -# Then transaction is open: false + Scenario: Driver can rollback transactions of schema and write types, cannot rollback transaction of type read + When connection open schema transaction for database: typedb + Then transaction has type: schema + Then transaction is open: true + When transaction rollbacks + Then transaction is open: true + + When transaction closes + When connection open write transaction for database: typedb + Then transaction has type: write + Then transaction is open: true + When transaction rollbacks + Then transaction is open: true + + When transaction closes + When connection open read transaction for database: typedb + Then transaction has type: read + Then transaction is open: true + Then transaction rollbacks; fails with a message containing: "Read transactions cannot be rolled back" + Then transaction is open: false # TODO: Check options setting and retrieval