Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingsilverfin committed Dec 17, 2021
1 parent 3b36810 commit c7aa564
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 21 deletions.
14 changes: 8 additions & 6 deletions connection/TypeDBTransactionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import com.vaticle.typedb.protocol.TransactionProto.Transaction.Req;
import com.vaticle.typedb.protocol.TransactionProto.Transaction.Res;
import com.vaticle.typedb.protocol.TransactionProto.Transaction.ResPart;
import io.grpc.StatusRuntimeException;

import java.util.List;
import java.util.stream.Stream;

import static com.vaticle.typedb.client.common.exception.ErrorMessage.Client.TRANSACTION_CLOSED;
Expand Down Expand Up @@ -110,21 +112,21 @@ public QueryFuture<Res> query(Req.Builder request) {
}

private QueryFuture<Res> query(Req.Builder request, boolean batch) {
if (!isOpen()) drainAndThrow();
if (!isOpen()) throwTransactionClosed();
BidirectionalStream.Single<Res> single = bidirectionalStream.single(request, batch);
return single::get;
}

@Override
public Stream<ResPart> stream(Req.Builder request) {
if (!isOpen()) drainAndThrow();
if (!isOpen()) throwTransactionClosed();
return bidirectionalStream.stream(request);
}

private void drainAndThrow() {
if (bidirectionalStream.hasErrors()) {
throw new TypeDBClientException(TRANSACTION_CLOSED_WITH_ERRORS, bidirectionalStream.drainErrors());
} else throw new TypeDBClientException(TRANSACTION_CLOSED);
private void throwTransactionClosed() {
List<StatusRuntimeException> errors = bidirectionalStream.drainErrors();
if (errors.isEmpty()) throw new TypeDBClientException(TRANSACTION_CLOSED);
else throw new TypeDBClientException(TRANSACTION_CLOSED_WITH_ERRORS, errors);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion dependencies/vaticle/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def vaticle_typedb_behaviour():
git_repository(
name = "vaticle_typedb_behaviour",
remote = "https://github.com/vaticle/typedb-behaviour",
commit = "036d7f3188c187fee1ce505f282fb43f14b68cd7", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
commit = "d92d840dd40cc8393936d6f6042820ebcd3a9cef", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
)

def vaticle_factory_tracing():
Expand Down
3 changes: 0 additions & 3 deletions test/behaviour/connection/ConnectionStepsBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,4 @@ void connection_does_not_have_any_database() {
assertTrue(client.isOpen());
}

void wait_seconds(int seconds) throws InterruptedException {
Thread.sleep(seconds * 1000L);
}
}
6 changes: 1 addition & 5 deletions test/behaviour/connection/ConnectionStepsCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.cucumber.java.Before;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import org.junit.BeforeClass;

import java.io.IOException;
import java.util.concurrent.TimeoutException;
Expand All @@ -47,7 +48,6 @@ void beforeAll() {
}
server.start();
TypeDBSingleton.setTypeDBRunner(server);
ConnectionStepsBase.isBeforeAllRan = true;
}

@Before
Expand Down Expand Up @@ -80,8 +80,4 @@ public void connection_does_not_have_any_database() {
super.connection_does_not_have_any_database();
}

@Then("wait {int} seconds")
public void wait_seconds(int seconds) throws InterruptedException {
super.wait_seconds(seconds);
}
}
5 changes: 0 additions & 5 deletions test/behaviour/connection/ConnectionStepsCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ void beforeAll() {
}
server.start();
TypeDBSingleton.setTypeDBRunner(server);
ConnectionStepsBase.isBeforeAllRan = true;
}

@Before
Expand Down Expand Up @@ -79,8 +78,4 @@ public void connection_does_not_have_any_database() {
super.connection_does_not_have_any_database();
}

@Then("wait {int} seconds")
public void wait_seconds(int seconds) throws InterruptedException {
super.wait_seconds(seconds);
}
}
1 change: 1 addition & 0 deletions test/behaviour/connection/transaction/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedb_behaviour_java_test(
"//test/behaviour/connection/database:steps",
"//test/behaviour/connection/session:steps",
"//test/behaviour/typeql:steps",
"//test/behaviour/util:steps",
],
deps = [
# Internal Package Dependencies
Expand Down
16 changes: 15 additions & 1 deletion test/behaviour/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")

java_library(
name = "util",
srcs = glob(["**/*.java"]),
srcs = ["Util.java"],
visibility = ["//visibility:public"],
deps = [

Expand All @@ -37,6 +37,20 @@ java_library(
],
)

java_library(
name = "steps",
srcs = ["UtilSteps.java"],
deps = [

# Internal Repository Dependencies
# "@vaticle_typedb_common//:common",

# External Maven Dependencies
"@maven//:junit_junit",
"@maven//:io_cucumber_cucumber_java",
],
)

checkstyle_test(
name = "checkstyle",
include = glob(["*"]),
Expand Down
32 changes: 32 additions & 0 deletions test/behaviour/util/UtilSteps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2021 Vaticle
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.vaticle.typedb.client.test.behaviour.util;

import io.cucumber.java.en.Then;

public class UtilSteps {

@Then("wait {int} seconds")
public void wait_seconds(int seconds) throws InterruptedException {
Thread.sleep(seconds * 1000L);
}
}

0 comments on commit c7aa564

Please sign in to comment.