Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,14 @@ python scripts/protogen.py

### Running tests

Make sure you have a Dgraph server running on localhost before you run this task.

```sh
python setup.py test
```
To run the tests in your local machine you can run the script
`scripts/local-tests.sh`. This script assumes Dgraph and dgo (Go client) are
already built on the local machine. The script will take care of bringing up a
Dgraph cluster and bringing it down after the tests are executed. The script
uses the port 9180 by default to prevent interference with clusters running on
the default port. Docker and docker-compose need to be installed before running
the script. Refer to the official Docker documentation for instructions on how
to install those packages.

The `test.sh` script downloads and installs Dgraph. It is meant for use by our
CI systems and using it for local development is not recommended.
35 changes: 28 additions & 7 deletions pydgraph/proto/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,28 @@
* limitations under the License.
*/

// Style guide for Protocol Buffer 3.
// Use CamelCase (with an initial capital) for message names – for example,
// SongServerRequest. Use underscore_separated_names for field names – for
// example, song_name.

syntax = "proto3";

package api;

/* import "gogoproto/gogo.proto"; */

/* option (gogoproto.marshaler_all) = true; */
/* option (gogoproto.sizer_all) = true; */
/* option (gogoproto.unmarshaler_all) = true; */
/* option (gogoproto.goproto_getters_all) = true; */

option java_package = "io.dgraph";
option java_outer_classname = "DgraphProto";

// Graph response.
service Dgraph {
rpc Login (LoginRequest) returns (Response) {}
rpc Query (Request) returns (Response) {}
rpc Mutate (Mutation) returns (Assigned) {}
rpc Alter (Operation) returns (Payload) {}
Expand All @@ -36,6 +49,7 @@ message Request {

uint64 start_ts = 13;
LinRead lin_read = 14;
bool read_only = 15;
}

message Response {
Expand All @@ -61,15 +75,10 @@ message Mutation {
repeated NQuad del = 11;
uint64 start_ts = 13;
bool commit_now = 14;
bool ignore_index_conflict = 15;
bool ignore_index_conflict = 15; // this field is not parsed and used by the server anymore.
}


message AssignedIds {
uint64 startId = 1;
uint64 endId = 2;
}

message Operation {
string schema = 1;
string drop_attr = 2;
Expand All @@ -85,7 +94,8 @@ message TxnContext {
uint64 start_ts = 1;
uint64 commit_ts = 2;
bool aborted = 3;
repeated string keys = 4;
repeated string keys = 4; // List of keys to be used for conflict detection.
repeated string preds = 5; // List of predicates involved in this transaction.
LinRead lin_read = 13;
}

Expand Down Expand Up @@ -165,4 +175,15 @@ message SchemaNode {
bool lang = 9;
}

message LoginRequest {
string userid = 1;
string password = 2;
string refresh_token = 3;
}

message Jwt {
string access_jwt = 1;
string refresh_jwt = 2;
}

// vim: noexpandtab sw=2 ts=2
490 changes: 281 additions & 209 deletions pydgraph/proto/api_pb2.py

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions pydgraph/proto/api_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def __init__(self, channel):
Args:
channel: A grpc.Channel.
"""
self.Login = channel.unary_unary(
'/api.Dgraph/Login',
request_serializer=api__pb2.LoginRequest.SerializeToString,
response_deserializer=api__pb2.Response.FromString,
)
self.Query = channel.unary_unary(
'/api.Dgraph/Query',
request_serializer=api__pb2.Request.SerializeToString,
Expand Down Expand Up @@ -45,6 +50,13 @@ class DgraphServicer(object):
"""Graph response.
"""

def Login(self, request, context):
# missing associated documentation comment in .proto file
pass
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def Query(self, request, context):
# missing associated documentation comment in .proto file
pass
Expand Down Expand Up @@ -83,6 +95,11 @@ def CheckVersion(self, request, context):

def add_DgraphServicer_to_server(servicer, server):
rpc_method_handlers = {
'Login': grpc.unary_unary_rpc_method_handler(
servicer.Login,
request_deserializer=api__pb2.LoginRequest.FromString,
response_serializer=api__pb2.Response.SerializeToString,
),
'Query': grpc.unary_unary_rpc_method_handler(
servicer.Query,
request_deserializer=api__pb2.Request.FromString,
Expand Down
4 changes: 2 additions & 2 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fi

function quit {
echo "Shutting down Dgraph Alpha and zero."
curl -s localhost:8080/admin/shutdown
curl -s localhost:8180/admin/shutdown
# Kill Dgraph zero.
kill -9 $(pgrep -f "dgraph zero") > /dev/null

Expand All @@ -26,7 +26,7 @@ function quit {

function start {
echo -e "Starting first Alpha."
dgraph alpha -p data/p -w data/w --lru_mb 4096 --zero localhost:5080 > data/alpha.log 2>&1 &
dgraph alpha -o 100 -p data/p -w data/w --lru_mb 4096 --zero localhost:5080 > data/alpha.log 2>&1 &
# Wait for membership sync to happen.
sleep $sleepTime
return 0
Expand Down
19 changes: 19 additions & 0 deletions scripts/local-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# Runs the 6-node test cluster (3 Zeros, 3 Alphas, replication level 3) whose
# first Alpha runs on port 9180. This script does not install Dgraph since it
# is intended for local development. Instead it assumes dgraph is already
# installed.

readonly SRCDIR=$(readlink -f ${BASH_SOURCE[0]%/*})

# Install dependencies
pip install -r requirements.txt
pip install coveralls

# Run cluster and tests
pushd $(dirname $SRCDIR)
source $GOPATH/src/github.com/dgraph-io/dgraph/contrib/scripts/functions.sh
restartCluster
coverage run --source=pydgraph --omit=pydgraph/proto/* setup.py test
stopCluster
popd
23 changes: 6 additions & 17 deletions tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create_lin_read(src_ids):
ids = lr.ids
for key, value in src_ids.items():
ids[key] = value

return lr


Expand All @@ -35,15 +35,15 @@ def are_lin_reads_equal(a, b):

if len(a_ids) != len(b_ids):
return False

for (key, value) in a_ids.items():
if key not in b_ids or b.ids[key] != value:
return False

return True


SERVER_ADDR = 'localhost:9080'
SERVER_ADDR = 'localhost:9180'


def create_client(addr=SERVER_ADDR):
Expand All @@ -66,23 +66,12 @@ def setup():

class ClientIntegrationTestCase(unittest.TestCase):
"""Base class for other integration test cases. Provides a client object
with a connection to the dgraph server and ensures that the server is
v1.0 or greater.
with a connection to the dgraph server.
"""

TEST_SERVER_ADDR = SERVER_ADDR

def setUp(self):
"""Sets up the client and verifies the version is compatible."""
"""Sets up the client."""

self.client = create_client(self.TEST_SERVER_ADDR)
version = self.client.any_client().check_version(pydgraph.Check())

# version.tag string format is v<MAJOR>.<MINOR>.<PATCH>
# version_tup = [MAJOR, MINOR, PATCH]
version_tup = version.tag[1:].split('.')

version_supported = int(version_tup[0]) > 0
self.assertTrue(
version_supported,
'Dgraph server version must be >= v1.0.0, got %s' % version.tag)
2 changes: 1 addition & 1 deletion tests/test_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def run_transfers(addr, transfer_count, account_ids, success_ctr, retry_ctr):
except:
with retry_ctr.get_lock():
retry_ctr.value += 1

with success_ctr.get_lock(), retry_ctr.get_lock():
log.info('success: %d, retries: %d', success_ctr.value, retry_ctr.value)

Expand Down
12 changes: 7 additions & 5 deletions tests/test_client_stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
import sys

import pydgraph
from . import helper

class TestDgraphClientStub(helper.ClientIntegrationTestCase):

class TestDgraphClientStub(unittest.TestCase):
def validate_version_object(self, version):
tag = version.tag
if sys.version_info[0] < 3:
Expand All @@ -34,14 +35,15 @@ def check_version(self, stub):
self.validate_version_object(stub.check_version(pydgraph.Check()))

def test_constructor(self):
self.check_version(pydgraph.DgraphClientStub())
self.check_version(pydgraph.DgraphClientStub(addr=self.TEST_SERVER_ADDR))

def test_timeout(self):
with self.assertRaises(Exception):
pydgraph.DgraphClientStub().check_version(pydgraph.Check(), timeout=-1)
pydgraph.DgraphClientStub(self.TEST_SERVER_ADDR).check_version(
pydgraph.Check(), timeout=-1)

def test_close(self):
client_stub = pydgraph.DgraphClientStub()
client_stub = pydgraph.DgraphClientStub(addr=self.TEST_SERVER_ADDR)
self.check_version(client_stub)
client_stub.close()
with self.assertRaises(Exception):
Expand Down