Skip to content

Commit

Permalink
Restores unit tests in MP gRPC module.
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Pericas-Geertsen <[email protected]>
  • Loading branch information
spericas committed Jun 6, 2024
1 parent 31a9f38 commit 5264aa7
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 32 deletions.
5 changes: 5 additions & 0 deletions microprofile/grpc/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.testing</groupId>
<artifactId>helidon-microprofile-testing-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.helidon.microprofile.grpc.server;

import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

import io.helidon.common.context.Context;
Expand Down Expand Up @@ -47,17 +48,17 @@ public Context context() {

@Override
public CompletionStage<GrpcServer> start() {
return null;
return CompletableFuture.completedFuture(null);
}

@Override
public CompletionStage<GrpcServer> whenShutdown() {
return null;
return CompletableFuture.completedFuture(null);
}

@Override
public CompletionStage<GrpcServer> shutdown() {
return null;
return CompletableFuture.completedFuture(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2019, 2024 Oracle and/or its affiliates.
*
* Licensed 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 io.helidon.microprofile.grpc.server;

import io.grpc.stub.StreamObserver;
import io.helidon.grpc.server.test.Echo.EchoRequest;
import io.helidon.grpc.server.test.Echo.EchoResponse;
import io.helidon.microprofile.grpc.core.Grpc;
import io.helidon.microprofile.grpc.core.Unary;
import jakarta.enterprise.context.ApplicationScoped;

import static io.helidon.grpc.core.ResponseHelper.complete;

/**
* A simple test gRPC echo service.
*/
@Grpc
@ApplicationScoped
public class EchoService {

/**
* Echo the message back to the caller.
*
* @param request the echo request containing the message to echo
* @param observer the call response
*/
@Unary
public void echo(EchoRequest request, StreamObserver<EchoResponse> observer) {
String message = request.getMessage();
EchoResponse response = EchoResponse.newBuilder().setMessage(message).build();
complete(observer, response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 Oracle and/or its affiliates.
*
* Licensed 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 io.helidon.microprofile.grpc.server;

import io.helidon.microprofile.testing.junit5.AddExtension;
import io.helidon.microprofile.testing.junit5.HelidonTest;
import jakarta.enterprise.inject.spi.CDI;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;

@HelidonTest
@AddExtension(GrpcServerCdiExtension.class)
class EchoServiceTest {

@Test
void test() {
assertThat(CDI.current(), is(notNullValue()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,20 @@
import java.util.List;
import java.util.Map;

import io.helidon.webserver.grpc.MethodDescriptor;
import io.helidon.webserver.grpc.ServiceDescriptor;
import io.helidon.microprofile.grpc.core.Grpc;
import io.helidon.microprofile.grpc.core.GrpcMarshaller;
import io.helidon.microprofile.grpc.core.GrpcMethod;

import io.grpc.Metadata;
import io.grpc.ServerCall;
import io.grpc.ServerCallHandler;
import io.grpc.stub.StreamObserver;
import io.helidon.microprofile.grpc.core.Grpc;
import io.helidon.microprofile.grpc.core.GrpcMarshaller;
import io.helidon.microprofile.grpc.core.GrpcMethod;
import io.helidon.webserver.grpc.MethodDescriptor;
import io.helidon.webserver.grpc.ServiceDescriptor;
import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.inject.Singleton;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Disabled;
import org.mockito.ArgumentCaptor;

import static org.hamcrest.CoreMatchers.is;
Expand All @@ -47,7 +45,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@Disabled
public class GrpcServiceBuilderTest {

private BeanManager beanManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
* This marshaller will not actually work and should not
* be used as a real marshaller.
*/
public class StubMarshaller<T>
implements MethodDescriptor.Marshaller<T> {
public class StubMarshaller<T> implements MethodDescriptor.Marshaller<T> {

@Override
public InputStream stream(T value) {
Expand All @@ -43,8 +42,8 @@ public T parse(InputStream stream) {
}

@Named("stub")
public static class Supplier
implements MarshallerSupplier {
public static class Supplier implements MarshallerSupplier {

@Override
public <T> MethodDescriptor.Marshaller<T> get(Class<T> clazz) {
return new StubMarshaller<>();
Expand Down
30 changes: 30 additions & 0 deletions microprofile/grpc/server/src/test/proto/echo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2019, 2024 Oracle and/or its affiliates.
*
* Licensed 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.
*/

syntax = "proto3";
option java_package = "io.helidon.grpc.server.test";

service EchoService {
rpc Echo (EchoRequest) returns (EchoResponse) {}
}

message EchoRequest {
string message = 1;
}

message EchoResponse {
string message = 1;
}

This file was deleted.

0 comments on commit 5264aa7

Please sign in to comment.