forked from helidon-io/helidon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Santiago Pericas-Geertsen <[email protected]>
- Loading branch information
Showing
13 changed files
with
551 additions
and
0 deletions.
There are no files selected for viewing
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
139 changes: 139 additions & 0 deletions
139
.../client/src/test/java/io/helidon/microprofile/grpc/client/ClientMethodDescriptorTest.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,139 @@ | ||
/* | ||
* 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.client; | ||
|
||
import io.helidon.microprofile.grpc.client.test.Echo; | ||
import io.helidon.microprofile.grpc.client.test.EchoServiceGrpc; | ||
|
||
import io.grpc.MethodDescriptor; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.collection.IsEmptyIterable.emptyIterable; | ||
|
||
public class ClientMethodDescriptorTest { | ||
|
||
private MethodDescriptor.Builder<?, ?> grpcDescriptor; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
grpcDescriptor = EchoServiceGrpc.getServiceDescriptor() | ||
.getMethods() | ||
.stream() | ||
.filter(md -> md.getFullMethodName().equals("EchoService/Echo")) | ||
.findFirst() | ||
.orElseThrow(() -> new AssertionError("Could not find echo method")) | ||
.toBuilder(); | ||
} | ||
|
||
@Test | ||
public void shouldCreateMethodDescriptorFromGrpcDescriptor() { | ||
ClientMethodDescriptor descriptor = ClientMethodDescriptor.create("FooService", | ||
"foo", | ||
grpcDescriptor); | ||
|
||
assertThat(descriptor, is(notNullValue())); | ||
assertThat(descriptor.name(), is("foo")); | ||
assertThat(descriptor.interceptors(), is(emptyIterable())); | ||
|
||
MethodDescriptor<?, ?> expected = grpcDescriptor.build(); | ||
MethodDescriptor<?, ?> methodDescriptor = descriptor.descriptor(); | ||
assertThat(methodDescriptor.getFullMethodName(), is("FooService/foo")); | ||
assertThat(methodDescriptor.getType(), is(expected.getType())); | ||
assertThat(methodDescriptor.getRequestMarshaller(), is(expected.getRequestMarshaller())); | ||
assertThat(methodDescriptor.getResponseMarshaller(), is(expected.getResponseMarshaller())); | ||
} | ||
|
||
@Test | ||
public void shouldCreateBidirectionalMethod() { | ||
ClientMethodDescriptor descriptor = ClientMethodDescriptor.bidirectional("FooService", "foo") | ||
.defaultMarshallerSupplier(new JavaMarshaller.Supplier()) | ||
.build(); | ||
assertThat(descriptor, is(notNullValue())); | ||
assertThat(descriptor.name(), is("foo")); | ||
MethodDescriptor<?, ?> methodDescriptor = descriptor.descriptor(); | ||
assertThat(methodDescriptor.getFullMethodName(), is("FooService/foo")); | ||
assertThat(methodDescriptor.getType(), is(MethodDescriptor.MethodType.BIDI_STREAMING)); | ||
} | ||
|
||
@Test | ||
public void shouldCreateClientStreamingMethod() { | ||
ClientMethodDescriptor descriptor = ClientMethodDescriptor.clientStreaming("FooService", "foo") | ||
.defaultMarshallerSupplier(new JavaMarshaller.Supplier()) | ||
.build(); | ||
assertThat(descriptor, is(notNullValue())); | ||
assertThat(descriptor.name(), is("foo")); | ||
MethodDescriptor<?, ?> methodDescriptor = descriptor.descriptor(); | ||
assertThat(methodDescriptor.getFullMethodName(), is("FooService/foo")); | ||
assertThat(methodDescriptor.getType(), is(MethodDescriptor.MethodType.CLIENT_STREAMING)); | ||
} | ||
|
||
@Test | ||
public void shouldCreateServerStreamingMethod() { | ||
ClientMethodDescriptor descriptor = ClientMethodDescriptor.serverStreaming("FooService", "foo") | ||
.defaultMarshallerSupplier(new JavaMarshaller.Supplier()) | ||
.build(); | ||
assertThat(descriptor, is(notNullValue())); | ||
assertThat(descriptor.name(), is("foo")); | ||
MethodDescriptor<?, ?> methodDescriptor = descriptor.descriptor(); | ||
assertThat(methodDescriptor.getFullMethodName(), is("FooService/foo")); | ||
assertThat(methodDescriptor.getType(), is(MethodDescriptor.MethodType.SERVER_STREAMING)); | ||
} | ||
|
||
@Test | ||
public void shouldCreateUnaryMethod() { | ||
ClientMethodDescriptor descriptor = ClientMethodDescriptor.unary("FooService", "foo") | ||
.defaultMarshallerSupplier(new JavaMarshaller.Supplier()) | ||
.build(); | ||
assertThat(descriptor, is(notNullValue())); | ||
assertThat(descriptor.name(), is("foo")); | ||
MethodDescriptor<?, ?> methodDescriptor = descriptor.descriptor(); | ||
assertThat(methodDescriptor.getFullMethodName(), is("FooService/foo")); | ||
assertThat(methodDescriptor.getType(), is(MethodDescriptor.MethodType.UNARY)); | ||
} | ||
|
||
@Test | ||
public void shouldSetName() { | ||
ClientMethodDescriptor.Builder builder = ClientMethodDescriptor | ||
.unary("FooService", "foo") | ||
.defaultMarshallerSupplier(new JavaMarshaller.Supplier()); | ||
|
||
builder.fullName("Foo/Bar"); | ||
|
||
ClientMethodDescriptor descriptor = builder.build(); | ||
|
||
assertThat(descriptor.name(), is("Bar")); | ||
assertThat(descriptor.descriptor().getFullMethodName(), is("Foo/Bar")); | ||
} | ||
|
||
@Test | ||
public void testMarshallerTypesForProtoBuilder() { | ||
ClientMethodDescriptor descriptor = ClientMethodDescriptor | ||
.unary("EchoService", "Echo") | ||
.requestType(Echo.EchoRequest.class) | ||
.responseType(Echo.EchoResponse.class) | ||
.build(); | ||
|
||
MethodDescriptor<?, ?> methodDescriptor = descriptor.descriptor(); | ||
assertThat(methodDescriptor.getRequestMarshaller(), instanceOf(MethodDescriptor.PrototypeMarshaller.class)); | ||
assertThat(methodDescriptor.getResponseMarshaller(), instanceOf(MethodDescriptor.PrototypeMarshaller.class)); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...profile/grpc/client/src/test/java/io/helidon/microprofile/grpc/client/JavaMarshaller.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,67 @@ | ||
/* | ||
* Copyright (c) 2022, 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.client; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.InputStream; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
|
||
import io.helidon.grpc.core.MarshallerSupplier; | ||
|
||
import io.grpc.MethodDescriptor; | ||
|
||
/** | ||
* An implementation of a gRPC {@link io.grpc.MethodDescriptor.Marshaller} that | ||
* uses Java serialization for testing. | ||
*/ | ||
public class JavaMarshaller<T> implements MethodDescriptor.Marshaller<T> { | ||
|
||
@Override | ||
public InputStream stream(T obj) { | ||
try (ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
ObjectOutputStream oos = new ObjectOutputStream(out)) { | ||
oos.writeObject(obj); | ||
return new ByteArrayInputStream(out.toByteArray()); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public T parse(InputStream in) { | ||
try (ObjectInputStream ois = new ObjectInputStream(in)) { | ||
return (T) ois.readObject(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* A {@link io.helidon.grpc.core.MarshallerSupplier} implementation that supplies | ||
* instances of {@link io.helidon.microprofile.grpc.client.JavaMarshaller}. | ||
*/ | ||
public static class Supplier | ||
implements MarshallerSupplier { | ||
@Override | ||
public <T> MethodDescriptor.Marshaller<T> get(Class<T> clazz) { | ||
return new JavaMarshaller<>(); | ||
} | ||
} | ||
} |
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,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.microprofile.grpc.client.test"; | ||
|
||
service EchoService { | ||
rpc Echo (EchoRequest) returns (EchoResponse) {} | ||
} | ||
|
||
message EchoRequest { | ||
string message = 1; | ||
} | ||
|
||
message EchoResponse { | ||
string message = 1; | ||
} |
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,31 @@ | ||
/* | ||
* 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.microprofile.grpc.client.test"; | ||
|
||
service StringService { | ||
rpc Upper (StringMessage) returns (StringMessage) {} | ||
rpc Lower (StringMessage) returns (StringMessage) {} | ||
rpc Split (StringMessage) returns (stream StringMessage) {} | ||
rpc Join (stream StringMessage) returns (StringMessage) {} | ||
rpc Echo (stream StringMessage) returns (stream StringMessage) {} | ||
} | ||
|
||
message StringMessage { | ||
string text = 1; | ||
} |
34 changes: 34 additions & 0 deletions
34
microprofile/grpc/client/src/test/resources/logging.properties
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,34 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
# Example Logging Configuration File | ||
# For more information see $JAVA_HOME/jre/lib/logging.properties | ||
|
||
# Send messages to the console | ||
handlers=io.helidon.common.HelidonConsoleHandler | ||
|
||
# HelidonConsoleHandler uses a SimpleFormatter subclass that replaces "!thread!" with the current thread | ||
java.util.logging.SimpleFormatter.format=%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS %4$s %3$s !thread!: %5$s%6$s%n | ||
|
||
# Global logging level. Can be overridden by specific loggers | ||
.level=INFO | ||
|
||
# Component specific log levels | ||
#io.helidon.webserver.level=INFO | ||
#io.helidon.config.level=INFO | ||
#io.helidon.security.level=INFO | ||
#io.helidon.common.level=INFO | ||
#io.netty.level=INFO |
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,17 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIICpjCCAY4CCQDsAfroMCH4tDANBgkqhkiG9w0BAQsFADAUMRIwEAYDVQQDDAls | ||
b2NhbGhvc3QwIBcNMjAwMzMwMDk1NjU3WhgPMjI5NDAxMTIwOTU2NTdaMBQxEjAQ | ||
BgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB | ||
AKbUgPWd5YM775bazo8MmuMHmYsSacUx+01NKVjbXPz8QHJULfdrYzJEs3yJ2bpP | ||
mOBrXDTmW2+v1TUdSRjytf9b6/+NWixovGwhGF/iXJ9dhMhwp1AwL8PViuuJPTcf | ||
acoAbFn1yJtNjZgalevyyN+eto+UFW+qJ+jn7ncTdReke3DeHiEA+lmk1DlAsGLR | ||
sB2gQBC2Xb8wcCltivb/WJRJG+sHja2BTIUbywmYO9UtuLsLE/Wptl+t8ybObj2G | ||
eE/t7/aM6KTOtXb6Q/Z7YPYSrVtIa/MwkFssmcVG0ldaAszUpq5bLanH5H3AHPN5 | ||
1atNHVIYlwom2SrRazg5IisCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAWnMcVDGq | ||
NxigGhtSFdmbnauLPd47ZEFh6iL+bG7QkT15XtpR5Q4GkxaIb1fTsqaxfj6WUG6Z | ||
n6f9OHSuFGiQbV+h2zNVR4q+i7DcDFkbFrK0XtyUYkdHOot+I7XzURsocnZhWoKO | ||
g+Yi0z4uBSol4olK4KNQLS39ePPrm76CqLf4i8wSUF5YEi0ExWhFgM4+19JvVyQ7 | ||
tqRM1rAWajWp696fKP47ZV2Qn39+BRh8TYKIEdStaWWUxtycC8qhnkXspIG7etcN | ||
3kju90KNuLky6WhNOm84GVZ4w339QTSk65yzUgxTxqJMK6elqgCESTuyGS1EJV00 | ||
t2Dcg5m1p2llRQ== | ||
-----END CERTIFICATE----- |
16 changes: 16 additions & 0 deletions
16
microprofile/grpc/client/src/test/resources/ssl/clientCert.pem
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,16 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIICmTCCAYECAQEwDQYJKoZIhvcNAQEFBQAwFDESMBAGA1UEAwwJbG9jYWxob3N0 | ||
MCAXDTIwMDMzMDA5NTY1N1oYDzIyOTQwMTEyMDk1NjU3WjAPMQ0wCwYDVQQDDAR0 | ||
ZXN0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxcZyW23ksgNBBo2P | ||
f4VZxHLj+j6jWVVC5B4Wh3dl9VdSLII3T4uWQbNCoe9vIKZRhsuXn/fbHkd89MFi | ||
GkC02kI+d0RpWULqgnRijbEu5fCsxBYa7dpI0DHkHWjTT2qk2vAw1h+z79orRiVt | ||
wLy4vD4Ig6sbna/1AyK89FRHeq/YSMT3b0jhcxRxWSXmKb81UJ1HjNXIW8bElRcj | ||
Z0vMNQsFWkOWOfyN31NRkM+sqy42fKsMPysitpUz5UQzVxpkm0rom89vDO1VubQl | ||
zGK1gBV3Ll9kkZt5+UjkW/XE9leyRg1iSsY8l5NTp0RJNqpzZkrrPYHFIFhszLNe | ||
NvtB4QIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQBv5M6wwOroq1iCz1wyWu/RxSGS | ||
nGn4MdFEeIKTx9urMqTiHp9bW7gVGLHQ96ApxFF30PZ58X1JrJn+eerBaaI7yOo0 | ||
FmVDlacqh5jSDvBoIzC8gFIfcDT/Q1xXmeB0KcgMdoZOhdkrX59qVenxrnihtd2I | ||
uIWhutQB9T6VrTGiCB09gWkULsjHvKMJ1ucSG0a2K18Aqccypd3twXmllwPa/vrt | ||
Kv7s9ZVvYibW7xXJBCV1kiZtx5TV+VO100/Ze94vvnAs7kCLZ16oGOFSj0JpCEFz | ||
CAVAif0/huKd4bpMzwCosCPiKSGLETc6S+WTzoy0FAFmygZHEL9diXriQrMa | ||
-----END CERTIFICATE----- |
Oops, something went wrong.