-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
139 additions
and
13 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...s/grpc/deployment/src/test/java/io/quarkus/grpc/client/bd/ClientBlockingDeadlineTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.quarkus.grpc.client.bd; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.grpc.Deadline; | ||
import io.grpc.Status; | ||
import io.grpc.StatusRuntimeException; | ||
import io.grpc.examples.helloworld.GreeterGrpc; | ||
import io.grpc.examples.helloworld.HelloRequest; | ||
import io.quarkus.grpc.GrpcClient; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ClientBlockingDeadlineTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addPackage(GreeterGrpc.class.getPackage()).addClasses(HelloService.class)) | ||
.withConfigurationResource("hello-config-deadline.properties"); | ||
|
||
@GrpcClient("hello-service") | ||
GreeterGrpc.GreeterBlockingStub stub; | ||
|
||
@Test | ||
public void testCallOptions() { | ||
Deadline deadline = stub.getCallOptions().getDeadline(); | ||
assertNotNull(deadline); | ||
try { | ||
//noinspection ResultOfMethodCallIgnored | ||
stub.sayHello(HelloRequest.newBuilder().setName("Scaladar").build()); | ||
} catch (Exception e) { | ||
Assertions.assertTrue(e instanceof StatusRuntimeException); | ||
StatusRuntimeException sre = (StatusRuntimeException) e; | ||
Status status = sre.getStatus(); | ||
Assertions.assertNotNull(status); | ||
Assertions.assertEquals(Status.DEADLINE_EXCEEDED.getCode(), status.getCode()); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
extensions/grpc/deployment/src/test/java/io/quarkus/grpc/client/bd/HelloService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.quarkus.grpc.client.bd; | ||
|
||
import java.time.Duration; | ||
|
||
import io.grpc.Context; | ||
import io.grpc.Deadline; | ||
import io.grpc.examples.helloworld.GreeterGrpc; | ||
import io.grpc.examples.helloworld.HelloReply; | ||
import io.grpc.examples.helloworld.HelloRequest; | ||
import io.grpc.stub.StreamObserver; | ||
import io.quarkus.grpc.GrpcService; | ||
import io.smallrye.common.annotation.Blocking; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
@GrpcService | ||
public class HelloService extends GreeterGrpc.GreeterImplBase { | ||
|
||
@Override | ||
@Blocking | ||
public void sayHello(HelloRequest request, StreamObserver<HelloReply> observer) { | ||
Deadline deadline = Context.current().getDeadline(); | ||
if (deadline == null) { | ||
throw new IllegalStateException("Null deadline"); | ||
} | ||
Uni.createFrom() | ||
.item(HelloReply.newBuilder().setMessage("OK").build()) | ||
.onItem() | ||
.delayIt() | ||
.by(Duration.ofMillis(400)).invoke(observer::onNext) | ||
.invoke(observer::onCompleted) | ||
.await() | ||
.indefinitely(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters