Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 663eec0

Browse files
author
Alistair Crook
authored
Support new graql update queries (#177)
## What is the goal of this PR? We synchronised client-python with the current master versions of protocol, behavioural tests, and grakn core server, to enable support for the new update query type, as well as adding support for related tests and automation. ## What are the changes implemented in this PR? - Updated protocol version - Added update queries to querymanager - Added test steps for rules, relations, and update queries - Added insert, delete and match to behavioural tests. - Reformatted automation.yml Closes #176
1 parent 91f8696 commit 663eec0

File tree

9 files changed

+169
-7
lines changed

9 files changed

+169
-7
lines changed

.grabl/automation.yml

+59-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ build:
4848
bazel build //...
4949
bazel run @graknlabs_dependencies//tool/checkstyle:test-coverage
5050
bazel test $(bazel query 'kind(checkstyle_test, //...)') --test_output=errors
51-
test-behaviour:
51+
test-behaviour-connection:
5252
image: graknlabs-ubuntu-20.04
5353
type: foreground
5454
command: |
@@ -61,10 +61,65 @@ build:
6161
export ARTIFACT_PASSWORD=$REPO_GRAKN_PASSWORD
6262
bazel run @graknlabs_dependencies//distribution/artifact:create-netrc
6363
bazel test //tests/behaviour/connection/... --test_output=errors --jobs=1
64+
test-behaviour-concept:
65+
image: graknlabs-ubuntu-20.04
66+
type: foreground
67+
command: |
68+
pyenv global 3.6.10
69+
pip install -r requirements_dev.txt
70+
sudo unlink /usr/bin/python3
71+
sudo ln -s $(which python3) /usr/bin/python3
72+
sudo ln -s /usr/share/pyshared/lsb_release.py /opt/pyenv/versions/3.6.10/lib/python3.6/site-packages/lsb_release.py
73+
export ARTIFACT_USERNAME=$REPO_GRAKN_USERNAME
74+
export ARTIFACT_PASSWORD=$REPO_GRAKN_PASSWORD
75+
bazel run @graknlabs_dependencies//distribution/artifact:create-netrc
6476
bazel test //tests/behaviour/concept/... --test_output=errors --jobs=1
77+
test-behaviour-match:
78+
image: graknlabs-ubuntu-20.04
79+
type: foreground
80+
command: |
81+
pyenv global 3.6.10
82+
pip install -r requirements_dev.txt
83+
sudo unlink /usr/bin/python3
84+
sudo ln -s $(which python3) /usr/bin/python3
85+
sudo ln -s /usr/share/pyshared/lsb_release.py /opt/pyenv/versions/3.6.10/lib/python3.6/site-packages/lsb_release.py
86+
export ARTIFACT_USERNAME=$REPO_GRAKN_USERNAME
87+
export ARTIFACT_PASSWORD=$REPO_GRAKN_PASSWORD
88+
bazel run @graknlabs_dependencies//distribution/artifact:create-netrc
89+
bazel test //tests/behaviour/graql/language/match/... --test_output=errors --jobs=1
6590
bazel test //tests/behaviour/graql/language/get/... --test_output=errors --jobs=1
66-
# TODO: add other Graql Language tests once they stabilise fully
67-
# TODO: remove --jobs=1 from Concept and Graql tests once Grakn runner is parallelisable
91+
test-behaviour-writable:
92+
image: graknlabs-ubuntu-20.04
93+
type: foreground
94+
command: |
95+
pyenv global 3.6.10
96+
pip install -r requirements_dev.txt
97+
sudo unlink /usr/bin/python3
98+
sudo ln -s $(which python3) /usr/bin/python3
99+
sudo ln -s /usr/share/pyshared/lsb_release.py /opt/pyenv/versions/3.6.10/lib/python3.6/site-packages/lsb_release.py
100+
export ARTIFACT_USERNAME=$REPO_GRAKN_USERNAME
101+
export ARTIFACT_PASSWORD=$REPO_GRAKN_PASSWORD
102+
bazel run @graknlabs_dependencies//distribution/artifact:create-netrc
103+
bazel test //tests/behaviour/graql/language/insert/... --test_output=errors --jobs=1
104+
bazel test //tests/behaviour/graql/language/delete/... --test_output=errors --jobs=1
105+
bazel test //tests/behaviour/graql/language/update:checkstyle --test_output=errors --jobs=1
106+
bazel test //tests/behaviour/graql/language/update:test-core --test_output=errors --jobs=1
107+
test-behaviour-definable:
108+
image: graknlabs-ubuntu-20.04
109+
type: foreground
110+
command: |
111+
pyenv global 3.6.10
112+
pip install -r requirements_dev.txt
113+
sudo unlink /usr/bin/python3
114+
sudo ln -s $(which python3) /usr/bin/python3
115+
sudo ln -s /usr/share/pyshared/lsb_release.py /opt/pyenv/versions/3.6.10/lib/python3.6/site-packages/lsb_release.py
116+
export ARTIFACT_USERNAME=$REPO_GRAKN_USERNAME
117+
export ARTIFACT_PASSWORD=$REPO_GRAKN_PASSWORD
118+
bazel run @graknlabs_dependencies//distribution/artifact:create-netrc
119+
bazel test //tests/behaviour/graql/language/define:checkstyle --test_output=errors --jobs=1
120+
bazel test //tests/behaviour/graql/language/define:test-core --test_output=errors --jobs=1
121+
bazel test //tests/behaviour/graql/language/undefine:checkstyle --test_output=errors --jobs=1
122+
bazel test //tests/behaviour/graql/language/undefine:test-core --test_output=errors --jobs=1
68123
test-cluster-failover:
69124
image: graknlabs-ubuntu-20.04
70125
type: foreground
@@ -80,7 +135,7 @@ build:
80135
bazel test //tests:test_cluster_failover --test_output=errors
81136
deploy-pip-snapshot:
82137
image: graknlabs-ubuntu-20.04
83-
dependencies: [build, test-behaviour, test-cluster-failover]
138+
dependencies: [build, test-behaviour-connection, test-behaviour-concept, test-behaviour-match, test-behaviour-writable, test-behaviour-definable, test-cluster-failover]
84139
filter:
85140
owner: graknlabs
86141
branch: master

dependencies/graknlabs/artifacts.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def graknlabs_grakn_core_artifacts():
2727
artifact_name = "grakn-core-server-{platform}-{version}.{ext}",
2828
tag_source = deployment["artifact.release"],
2929
commit_source = deployment["artifact.snapshot"],
30-
commit = "c2efc0a71a215b59650a3ea0e8b6f4c2c83737e3",
30+
commit = "0efbea38aaf0f187e03168cf2c515aa5c7b44f26",
3131
)
3232

3333
def graknlabs_grakn_cluster_artifacts():

dependencies/graknlabs/repositories.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ def graknlabs_behaviour():
3737
git_repository(
3838
name = "graknlabs_behaviour",
3939
remote = "https://github.com/graknlabs/behaviour",
40-
commit = "71f72dce4e7b46488f0f1f5a6c457018b83660c5" # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_behaviour
40+
commit = "bc4730a40866f64decd22cb0cb35c9b6a6b77b31" # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_behaviour
4141
)

grakn/query/query_manager.py

+9
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ def delete(self, query: str, options: GraknOptions = None):
9292
request.delete_req.CopyFrom(delete_req)
9393
return self._iterate_query(request, lambda res: [], options)
9494

95+
def update(self, query: str, options: GraknOptions = None):
96+
if not options:
97+
options = GraknOptions.core()
98+
request = query_proto.Query.Req()
99+
update_req = query_proto.Query.Update.Req()
100+
update_req.query = query
101+
request.update_req.CopyFrom(update_req)
102+
return map(lambda answer_proto: concept_map._of(answer_proto), self._iterate_query(request, lambda res: res.query_res.update_res.answers, options))
103+
95104
def define(self, query: str, options: GraknOptions = None):
96105
if not options:
97106
options = GraknOptions.core()

tests/behaviour/background/environment_base.py

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from tests.behaviour.config.parameters import RootLabel
2424
from tests.behaviour.context import Context, ThingSubtype
2525

26+
import time
27+
2628
IGNORE_TAGS = ["ignore", "ignore-client-python"]
2729

2830

@@ -78,6 +80,9 @@ def after_scenario(context: Context, scenario):
7880
if scenario.status == Status.skipped:
7981
return
8082

83+
#TODO: REMOVE THIS ONCE THE CRASHES ARE FIXED
84+
time.sleep(0.01)
85+
8186
for session in context.sessions:
8287
session.close()
8388
for future_session in context.sessions_parallel:
@@ -87,4 +92,7 @@ def after_scenario(context: Context, scenario):
8792

8893

8994
def after_all(context: Context):
95+
#TODO: REMOVE THIS ONCE THE CRASHES ARE FIXED
96+
time.sleep(0.01)
97+
9098
context.client.close()

tests/behaviour/concept/thing/relation/relation_steps.py

+14
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ def step_impl(context: Context, var1: str, role_label: str, var2: str):
7676
def step_impl(context: Context, var1: str, role_label: str, var2: str):
7777
context.get(var1).as_remote(context.tx()).remove_player(context.get(var1).as_remote(context.tx()).get_type().as_remote(context.tx()).get_relates(role_label), context.get(var2))
7878

79+
@step("relation {var1:Var} add player for role({role_label}): {var2:Var}; throws exception")
80+
def step_impl(context: Context, var1: str, role_label: str, var2: str):
81+
adding_player_throws_exception(context, var1, role_label, var2)
82+
83+
def adding_player_throws_exception(context: Context, var1: str, role_label: str, var2: str):
84+
try:
85+
context.get(var1).as_remote(context.tx()).add_player(
86+
context.get(var1).as_remote(context.tx()).get_type().as_remote(context.tx()).get_relates(role_label),
87+
context.get(var2))
88+
assert False;
89+
except GraknClientException:
90+
pass
91+
92+
7993

8094
@step("relation {var:Var} get players contain")
8195
def step_impl(context: Context, var: str):

tests/behaviour/graql/graql_steps.py

+23
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ def step_impl(context: Context, exception: str):
9696
assert_that(calling(next).with_args(context.tx().query().insert(query=context.text)), raises(GraknClientException, exception))
9797

9898

99+
@step("graql update")
100+
def step_impl(context: Context):
101+
context.tx().query().update(query=context.text)
102+
103+
104+
@step("graql update; throws exception")
105+
def step_impl(context: Context):
106+
assert_that(calling(next).with_args(context.tx().query().update(query=context.text)), raises(GraknClientException))
107+
108+
109+
@step("graql update; throws exception containing \"{exception}\"")
110+
def step_impl(context: Context, exception: str):
111+
assert_that(calling(next).with_args(context.tx().query().update(query=context.text)), raises(GraknClientException, exception))
112+
99113
@step("get answers of graql insert")
100114
def step_impl(context: Context):
101115
context.clear_answers()
@@ -136,6 +150,15 @@ def step_impl(context: Context, expected_size: int):
136150
assert_that(context.answers, has_length(expected_size), "Expected [%d] answers, but got [%d]" % (expected_size, len(context.answers)))
137151

138152

153+
@step("rules contain: {rule_label}")
154+
def step_impl(context: Context, rule_label: str):
155+
return rule_label in [rule.get_label() for rule in context.tx().logic().get_rules()]
156+
157+
@step("rules do not contain: {rule_label}")
158+
def step_impl(context: Context, rule_label: str):
159+
return not (rule_label in [rule.get_label() for rule in context.tx().logic().get_rules()])
160+
161+
139162
class ConceptMatcher:
140163

141164
def matches(self, context: Context, concept: ConceptSubtype):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
package(default_visibility = ["//tests/behaviour:__subpackages__"])
21+
load("//tools:behave_rule.bzl", "grakn_behaviour_py_test")
22+
load("@graknlabs_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
23+
24+
grakn_behaviour_py_test(
25+
name = "test",
26+
feats = ["@graknlabs_behaviour//graql/language:update.feature"],
27+
background_core = ["//tests/behaviour/background:core"],
28+
background_cluster = ["//tests/behaviour/background:cluster"],
29+
steps = [
30+
"//tests/behaviour/connection:steps",
31+
"//tests/behaviour/connection/database:steps",
32+
"//tests/behaviour/connection/session:steps",
33+
"//tests/behaviour/connection/transaction:steps",
34+
"//tests/behaviour/graql:steps",
35+
],
36+
deps = [
37+
"//:client_python",
38+
"//tests/behaviour:context",
39+
"//tests/behaviour:util",
40+
"//tests/behaviour/config:parameters",
41+
"//tests/behaviour/background",
42+
],
43+
native_grakn_artifact_core = "//tests:native-grakn-core-artifact",
44+
native_grakn_artifact_cluster = "//tests:native-grakn-cluster-artifact",
45+
size = "medium",
46+
)
47+
48+
checkstyle_test(
49+
name = "checkstyle",
50+
include = glob(["*"]),
51+
license_type = "apache",
52+
size = "small",
53+
)

tools/cluster_test_rule.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _rule_implementation(ctx):
5757
./1/grakn server --data data --address=127.0.0.1:11729:11730 --peers=127.0.0.1:11729:11730,127.0.0.1:21729:21730,127.0.0.1:31729:31730 &
5858
./2/grakn server --data data --address=127.0.0.1:21729:21730 --peers=127.0.0.1:11729:11730,127.0.0.1:21729:21730,127.0.0.1:31729:31730 &
5959
./3/grakn server --data data --address=127.0.0.1:31729:31730 --peers=127.0.0.1:11729:11730,127.0.0.1:21729:21730,127.0.0.1:31729:31730 &
60-
sleep 14
60+
sleep 20
6161
6262
"""
6363

0 commit comments

Comments
 (0)