Skip to content

Commit

Permalink
add actual positive tests
Browse files Browse the repository at this point in the history
Signed-off-by: georgi-l95 <[email protected]>
  • Loading branch information
georgi-l95 committed Sep 18, 2024
1 parent ffead9a commit 6ac8e9b
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 143 deletions.
5 changes: 5 additions & 0 deletions server/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@ RUN tar -xvf server-${VERSION}.tar
# Copy the logging properties file
COPY logging.properties logging.properties

# HEALTHCHECK for liveness and readiness
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/healthz/livez || exit 1 && \
curl -f http://localhost:8080/healthz/readyz || exit 1

# RUN the bin script for starting the server
ENTRYPOINT ["/bin/bash", "-c", "/app/server-${VERSION}/bin/server"]
15 changes: 10 additions & 5 deletions suites/src/main/java/com/hedera/block/suites/BaseSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@
* <p>This class is responsible for:
*
* <ul>
* <li>Starting a Docker container running the Block Node server with a specified version.
* <li>Starting a Docker container running the Block Node Application with a specified version.
* <li>Stopping the container after tests have been executed.
* </ul>
*
* <p>The Block Node server version is retrieved dynamically from an environment file (.env).
* <p>The Block Node Application version is retrieved dynamically from an environment file (.env).
*/
public abstract class BaseSuite {

/** Container running the Block Node server */
/** Container running the Block Node Application */
protected static GenericContainer<?> blockNodeContainer;

/** Port that is used by the Block Node Application */
protected static int blockNodePort;

/**
* Default constructor for the BaseSuite class.
*
Expand All @@ -59,12 +62,14 @@ public BaseSuite() {
@BeforeAll
public static void setup() {
String blockNodeVersion = BaseSuite.getBlockNodeVersion();
blockNodePort = 8080;
blockNodeContainer =
new GenericContainer<>(
DockerImageName.parse("block-node-server:" + blockNodeVersion))
.withExposedPorts(8080)
.withExposedPorts(blockNodePort)
.withEnv("VERSION", blockNodeVersion)
.waitingFor(Wait.forListeningPort());
.waitingFor(Wait.forListeningPort())
.waitingFor(Wait.forHealthcheck());
blockNodeContainer.start();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2022-2024 Hedera Hashgraph, LLC
*
* 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 com.hedera.block.suites.grpc;

import com.hedera.block.suites.grpc.negative.NegativeServerAvailabilityTests;
import com.hedera.block.suites.grpc.positive.PositiveServerAvailabilityTests;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

/**
* Test suite for running gRPC server availability tests, including both positive and negative test
* scenarios.
*
* <p>This suite aggregates the tests from {@link PositiveServerAvailabilityTests} and {@link
* NegativeServerAvailabilityTests}. The {@code @Suite} annotation allows running all selected
* classes in a single test run.
*/
@Suite
@SelectClasses({PositiveServerAvailabilityTests.class, NegativeServerAvailabilityTests.class})
public class GrpcTestSuites {

/**
* Default constructor for the {@link GrpcTestSuites} class. This constructor is empty as it
* does not need to perform any initialization.
*/
public GrpcTestSuites() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2022-2024 Hedera Hashgraph, LLC
*
* 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 com.hedera.block.suites.grpc.negative;

import org.junit.jupiter.api.DisplayName;

@DisplayName("Negative Server Availability Tests")
public class NegativeServerAvailabilityTests {

public NegativeServerAvailabilityTests() {}

public void handleServerStartupWithMissingConfig() {}

public void handleServerStartupWithTakenPort() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2022-2024 Hedera Hashgraph, LLC
*
* 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 com.hedera.block.suites.grpc.positive;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.hedera.block.suites.BaseSuite;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

/**
* Test class for verifying the positive scenarios for server availability, specifically related to
* the gRPC server. This class contains tests to check that the gRPC server starts successfully and
* listens on the correct port.
*
* <p>Inherits from {@link BaseSuite} to reuse the container setup and teardown logic for the Block
* Node.
*/
@DisplayName("Positive Server Availability Tests")
public class PositiveServerAvailabilityTests extends BaseSuite {

/** Default constructor for the {@link PositiveServerAvailabilityTests} class. */
public PositiveServerAvailabilityTests() {}

/**
* Test to verify that the gRPC server starts successfully.
*
* <p>The test checks if the Block Node container is running and marked as healthy.
*/
@Test
public void verifyGrpcServerStartsSuccessfully() {
assertTrue(blockNodeContainer.isRunning(), "Block Node container should be running.");
assertTrue(blockNodeContainer.isHealthy(), "Block Node container should be healthy.");
}

/**
* Test to verify that the gRPC server is listening on the correct port.
*
* <p>The test asserts that the container is running, exposes exactly one port, and that the
* exposed port matches the expected gRPC server port.
*/
@Test
public void verifyGrpcServerListeningOnCorrectPort() {
assertTrue(blockNodeContainer.isRunning(), "Block Node container should be running.");
assertEquals(
1,
blockNodeContainer.getExposedPorts().size(),
"There should be exactly one exposed port.");
assertEquals(
blockNodePort,
blockNodeContainer.getExposedPorts().getFirst(),
"The exposed port should match the expected gRPC server port.");
}
}

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 6ac8e9b

Please sign in to comment.