Skip to content
Open
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ configurations {
dependencies {
intTestImplementation "junit:junit:4.13.2"
intTestImplementation "org.assertj:assertj-core:3.27.7"
intTestImplementation "io.grpc:grpc-testing:${grpcVersion}"
}

tasks.register('integrationTest', Test) {
Expand Down
8 changes: 6 additions & 2 deletions src/intTest/java/TestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.authzed.grpcutil.BearerToken;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.testing.GrpcCleanupRule;

import java.util.Random;

Expand All @@ -14,8 +15,11 @@ public class TestClient {
public PermissionsServiceGrpc.PermissionsServiceBlockingStub permissionsService;
public PermissionsServiceGrpc.PermissionsServiceStub asyncPermissionsService;
public ExperimentalServiceGrpc.ExperimentalServiceBlockingStub experimentalService;
public TestClient() {
ManagedChannel channel = ManagedChannelBuilder.forTarget("localhost:50051").usePlaintext().build();
public TestClient(GrpcCleanupRule cleanupRule) {
// Registering the channel guarantees it is shut down when the test finishes:
// https://grpc.io/blog/graceful-cleanup-junit-tests/
ManagedChannel channel = cleanupRule.register(
ManagedChannelBuilder.forTarget("localhost:50051").usePlaintext().build());
String token = generateToken();
schemaService = SchemaServiceGrpc.newBlockingStub(channel)
.withCallCredentials(new BearerToken(token));
Expand Down
23 changes: 14 additions & 9 deletions src/intTest/java/V1ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.authzed.api.v1.*;

import io.grpc.stub.StreamObserver;
import io.grpc.testing.GrpcCleanupRule;
import org.junit.Rule;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -20,10 +22,13 @@
public class V1ClientTest {
private static final Consistency fullyConsistent = Consistency.newBuilder().setFullyConsistent(true).build();

@Rule
public final GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();

@Test
public void testBasicSchema() {
// Initialize services
TestClient client = new TestClient();
TestClient client = new TestClient(grpcCleanup);
String schema = "definition document {\n"
+ "relation reader: user\n"
+ "}\n"
Expand All @@ -40,15 +45,15 @@ public void testBasicSchema() {

@Test
public void testSchemaWithCaveats() {
TestClient client = new TestClient();
TestClient client = new TestClient(grpcCleanup);
writeTestSchema(client);
}

// For an example with flow control, see
// https://github.com/grpc/grpc-java/blob/9071c1ad7c842f4e73b6ae95b71f11c517b177a4/examples/src/main/java/io/grpc/examples/manualflowcontrol/ManualFlowControlClient.java
@Test
public void testCheck() {
TestClient client = new TestClient();
TestClient client = new TestClient(grpcCleanup);
writeTestSchema(client);
TestTuples testTuples = writeTestTuples(client);

Expand Down Expand Up @@ -87,7 +92,7 @@ public void testCheck() {

@Test
public void testCaveatedCheck() {
TestClient client = new TestClient();
TestClient client = new TestClient(grpcCleanup);
writeTestSchema(client);
TestTuples testTuples = writeTestTuples(client);

Expand Down Expand Up @@ -126,7 +131,7 @@ public void testCaveatedCheck() {

@Test
public void testLookupResources() {
TestClient client = new TestClient();
TestClient client = new TestClient(grpcCleanup);
writeTestSchema(client);
TestTuples testTuples = writeTestTuples(client);

Expand All @@ -148,7 +153,7 @@ public void testLookupResources() {

@Test
public void testLookupSubjects() {
TestClient client = new TestClient();
TestClient client = new TestClient(grpcCleanup);
writeTestSchema(client);
TestTuples testTuples = writeTestTuples(client);

Expand All @@ -171,7 +176,7 @@ public void testLookupSubjects() {

@Test
public void testCheckBulkPermissions() {
TestClient client = new TestClient();
TestClient client = new TestClient(grpcCleanup);
writeTestSchema(client);
TestTuples testTuples = writeTestTuples(client);

Expand All @@ -195,7 +200,7 @@ public void testCheckBulkPermissions() {

@Test
public void testBulkImport() throws InterruptedException {
TestClient client = new TestClient();
TestClient client = new TestClient(grpcCleanup);
writeTestSchema(client);
writeTestTuples(client);

Expand All @@ -212,7 +217,7 @@ public void testBulkImport() throws InterruptedException {

// Note that this has a different preshared key
// Validate import
TestClient emptyClient = new TestClient();
TestClient emptyClient = new TestClient(grpcCleanup);
writeTestSchema(emptyClient);

final CountDownLatch done = new CountDownLatch(1);
Expand Down
Loading