summaryrefslogtreecommitdiffstats
path: root/examples/examples-grpc/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/examples-grpc/src')
-rw-r--r--examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestDummyGrpcServer.java14
-rw-r--r--examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java4
-rw-r--r--examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java23
3 files changed, 29 insertions, 12 deletions
diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestDummyGrpcServer.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestDummyGrpcServer.java
index bef0a81c8..c8e38bc54 100644
--- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestDummyGrpcServer.java
+++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestDummyGrpcServer.java
@@ -17,17 +17,21 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.apex.examples.grpc;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
+
import io.grpc.Server;
import io.grpc.netty.NettyServerBuilder;
import io.grpc.stub.StreamObserver;
+
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Files;
import java.nio.file.Paths;
+
import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
@@ -40,12 +44,18 @@ import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
public class GrpcTestDummyGrpcServer {
private Server server;
+ /**
+ * Dummy server for gRPC.
+ *
+ * @param host hostname of the server
+ * @param port port of the server
+ */
public GrpcTestDummyGrpcServer(String host, int port) {
// Implement the dummy gRPC server
BluePrintProcessingServiceImplBase testCdsBlueprintServerImpl = new BluePrintProcessingServiceImplBase() {
@Override
- public StreamObserver<ExecutionServiceInput> process(
- final StreamObserver<ExecutionServiceOutput> responseObserver) {
+ public StreamObserver<ExecutionServiceInput>
+ process(final StreamObserver<ExecutionServiceOutput> responseObserver) {
return new StreamObserver<ExecutionServiceInput>() {
@Override
public void onNext(final ExecutionServiceInput executionServiceInput) {
diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java
index ae35d1ff2..fcdf55322 100644
--- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java
+++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestServerSim.java
@@ -47,14 +47,14 @@ public class GrpcTestServerSim {
restServer.addServletClass(null, GrpcTestRestSimEndpoint.class.getName());
restServer.setSerializationProvider(GsonMessageBodyHandler.class.getName());
restServer.start();
- if (!NetworkUtil.isTcpPortOpen(HOST, restServerPort, 2000, 1L)) {
+ if (!NetworkUtil.isTcpPortOpen(HOST, restServerPort, 50, 200L)) {
throw new IllegalStateException("port " + restServerPort + " is still not in use");
}
int grpcServerPort = 54322;
grpcServer = new GrpcTestDummyGrpcServer(HOST, grpcServerPort);
grpcServer.start();
- if (!NetworkUtil.isTcpPortOpen(HOST, grpcServerPort, 2000, 1L)) {
+ if (!NetworkUtil.isTcpPortOpen(HOST, grpcServerPort, 50, 200L)) {
throw new IllegalStateException("port " + grpcServerPort + " is still not in use");
}
}
diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java
index 06d1d33f9..05d6e4ce5 100644
--- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java
+++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java
@@ -17,6 +17,7 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.apex.examples.grpc;
import static org.awaitility.Awaitility.await;
@@ -25,18 +26,20 @@ import static org.junit.Assert.assertEquals;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
+
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
+
import org.junit.Test;
import org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain;
import org.onap.policy.apex.service.engine.main.ApexMain;
/**
- * Test class to run an example policy for APEX-CDS interaction over gRPC.
- * Event received on unauthenticated.DCAE_CL_OUTPUT DMaaP topic (dummy REST Endpoint here) triggers the policy
- * Based on the event, a create/delete subscription gRPC request is triggered to the CDS (a dummy gRPC server here).
- * Response received from CDS is used to send a final output Log event on POLICY_CL_MGT topic.
+ * Test class to run an example policy for APEX-CDS interaction over gRPC. Event received on
+ * unauthenticated.DCAE_CL_OUTPUT DMaaP topic (dummy REST Endpoint here) triggers the policy Based on the event, a
+ * create/delete subscription gRPC request is triggered to the CDS (a dummy gRPC server here). Response received from
+ * CDS is used to send a final output Log event on POLICY_CL_MGT topic.
*/
public class TestApexGrpcExample {
@Test
@@ -65,21 +68,25 @@ public class TestApexGrpcExample {
};
// @formatter:on
- GrpcTestServerSim sim = new GrpcTestServerSim();
+ final GrpcTestServerSim sim = new GrpcTestServerSim();
+
final Client client = ClientBuilder.newClient();
- String expectedLoggedOutputEvent = Files
- .readString(Paths.get("src/main/resources/examples/events/APEXgRPC/LogEvent.json")).replaceAll("\r", "");
final ApexMain apexMain = new ApexMain(apexArgs);
+ await().atMost(5000, TimeUnit.MILLISECONDS).until(() -> apexMain.isAlive());
+
String getLoggedEventUrl = "http://localhost:54321/GrpcTestRestSim/sim/event/getLoggedEvent";
// wait for success response code to be received, until a timeout
- await().atMost(5000, TimeUnit.MILLISECONDS).until(() -> {
+ await().atMost(20000, TimeUnit.MILLISECONDS).until(() -> {
return 200 == client.target(getLoggedEventUrl).request("application/json").get().getStatus();
});
apexMain.shutdown();
Response response = client.target(getLoggedEventUrl).request("application/json").get();
sim.tearDown();
String responseEntity = response.readEntity(String.class);
+
+ String expectedLoggedOutputEvent = Files
+ .readString(Paths.get("src/main/resources/examples/events/APEXgRPC/LogEvent.json")).replaceAll("\r", "");
assertEquals(expectedLoggedOutputEvent, responseEntity);
}
}