Skip to content

Commit

Permalink
First e2e gRPC MP client and server test.
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 26, 2024
1 parent f70b197 commit eaab42e
Show file tree
Hide file tree
Showing 25 changed files with 927 additions and 746 deletions.
202 changes: 0 additions & 202 deletions grpc/core/src/main/java/io/helidon/grpc/core/GrpcTlsDescriptor.java

This file was deleted.

14 changes: 11 additions & 3 deletions microprofile/grpc/client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
<artifactId>helidon-grpc-core</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config</artifactId>
<groupId>io.helidon.microprofile.grpc</groupId>
<artifactId>helidon-microprofile-grpc-core</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-object-mapping</artifactId>
<artifactId>helidon-config</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.tracing</groupId>
Expand All @@ -53,6 +53,14 @@
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common-tls</artifactId>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-grpc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* 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 java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

import io.helidon.config.Config;

import io.grpc.Channel;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.enterprise.inject.spi.InjectionPoint;
import jakarta.inject.Inject;

/**
* A producer of gRPC {@link io.grpc.Channel Channels}.
*/
@ApplicationScoped
public class ChannelProducer {

private final GrpcChannelsProvider provider;
private final ReentrantLock lock = new ReentrantLock();
private final Map<String, Channel> channelMap = new HashMap<>();

/**
* Create a {@link ChannelProducer}.
*
* @param config the {@link io.helidon.config.Config} to use to configure
* the provided {@link io.grpc.Channel}s
*/
@Inject
ChannelProducer(Config config) {
provider = GrpcChannelsProvider.create(config.get("grpc"));
}

/**
* Produces a gRPC {@link io.grpc.Channel}.
*
* @param injectionPoint the injection point
* @return a gRPC {@link io.grpc.Channel}
*/
@Produces
@GrpcChannel(name = GrpcChannelsProvider.DEFAULT_CHANNEL_NAME)
public Channel get(InjectionPoint injectionPoint) {
GrpcChannel qualifier = injectionPoint.getQualifiers()
.stream()
.filter(q -> q.annotationType().equals(GrpcChannel.class))
.map(q -> (GrpcChannel) q)
.findFirst()
.orElse(null);

String name = (qualifier == null) ? GrpcChannelsProvider.DEFAULT_CHANNEL_NAME : qualifier.name();
return findChannel(name);
}

/**
* Produces the default gRPC {@link io.grpc.Channel}.
*
* @return the default gRPC {@link io.grpc.Channel}
*/
@Produces
public Channel getDefaultChannel() {
return findChannel(GrpcChannelsProvider.DEFAULT_CHANNEL_NAME);
}

/**
* Obtain the named {@link io.grpc.Channel}.
*
* @param name the channel name
* @return the named {@link io.grpc.Channel}
*/
public Channel findChannel(String name) {
try {
lock.lock();
return channelMap.computeIfAbsent(name, provider::channel);
} finally {
lock.unlock();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ public Rules callCredentials(CallCredentials callCredentials) {
return this;
}


/**
* Builds and returns a new instance of {@link ClientMethodDescriptor}.
*
Expand All @@ -405,10 +404,10 @@ public ClientMethodDescriptor build() {
}

return new ClientMethodDescriptor(name,
descriptor.build(),
interceptors,
callCredentials,
methodHandler);
descriptor.build(),
interceptors,
callCredentials,
methodHandler);
}

}
Expand Down
Loading

0 comments on commit eaab42e

Please sign in to comment.