Skip to content
Permalink
Browse files

Basic client connection

  • Loading branch information...
JoeHegarty committed Aug 27, 2019
1 parent 150ecfd commit 8525f5794a2456578482be6ffa35bb18ca81056a
@@ -103,9 +103,9 @@ configure(withKotlin) {
}

dependencies {
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$coroutinesVersion")
api("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
api("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$coroutinesVersion")
}
}

@@ -7,4 +7,6 @@
dependencies {
compile(project(":src:orbit-proto"))
implementation("io.grpc:grpc-netty-shaded:$grpcVersion")

testImplementation(project(":src:orbit-server"))
}
@@ -6,5 +6,37 @@

package orbit.client;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.StatusRuntimeException;
import orbit.shared.proto.GreeterGrpc;
import orbit.shared.proto.GreeterOuterClass;

public final class OrbitClient {
private final OrbitClientConfig config;
private ManagedChannel channel = null;

public OrbitClient(final OrbitClientConfig config) {
this.config = config;
}

public void start() {
channel = ManagedChannelBuilder
.forAddress(config.getGrpcHost(), config.getGrpcPort())
.usePlaintext()
.build();
}

public void stop() {
if(channel != null) channel.shutdown();
}

public String tempGreeter(final String name) {
GreeterGrpc.GreeterBlockingStub greeter = GreeterGrpc.newBlockingStub(channel);
GreeterOuterClass.HelloRequest request = GreeterOuterClass.HelloRequest.newBuilder().setName(name).build();
GreeterOuterClass.HelloReply response;
response = greeter.sayHello(request);
return response.getMessage();
}

}
@@ -0,0 +1,28 @@
/*
Copyright (C) 2015 - 2019 Electronic Arts Inc. All rights reserved.
This file is part of the Orbit Project <https://www.orbit.cloud>.
See license in LICENSE.
*/

package orbit.client;

public class OrbitClientConfig {
private String grpcHost = "localhost";
private Integer grpcPort = 50056;

public String getGrpcHost() {
return grpcHost;
}

public void setGrpcHost(String grpcHost) {
this.grpcHost = grpcHost;
}

public Integer getGrpcPort() {
return grpcPort;
}

public void setGrpcPort(Integer grpcPort) {
this.grpcPort = grpcPort;
}
}
@@ -0,0 +1,32 @@
/*
Copyright (C) 2015 - 2019 Electronic Arts Inc. All rights reserved.
This file is part of the Orbit Project <https://www.orbit.cloud>.
See license in LICENSE.
*/

package orbit.client;

import kotlinx.coroutines.future.FutureKt;
import orbit.server.OrbitServer;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

class BasicTest {

@Test
void basicConnectionTest() {
final OrbitServer server = new OrbitServer();
FutureKt.asCompletableFuture(server.start()).join();

final OrbitClientConfig config = new OrbitClientConfig();
final OrbitClient client = new OrbitClient(config);
client.start();

final String greeting = client.tempGreeter("Joe");
Assertions.assertThat(greeting).isEqualTo("Hello Joe");

client.stop();

FutureKt.asCompletableFuture(server.stop()).join();
}
}
@@ -10,6 +10,7 @@ import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.delay
import kotlinx.coroutines.future.asCompletableFuture
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import orbit.common.logging.logger
@@ -37,6 +38,8 @@ import org.kodein.di.erased.singleton
import kotlin.coroutines.CoroutineContext

class OrbitServer(private val config: OrbitServerConfig) {
constructor() : this(OrbitServerConfig())

private val logger by logger()

private val nodeDirectory = InMemoryNodeDirectory.Instance

0 comments on commit 8525f57

Please sign in to comment.
You can’t perform that action at this time.