diff --git a/server/docker/Dockerfile b/server/docker/Dockerfile index 50b1c5ad4..2e3bfb056 100644 --- a/server/docker/Dockerfile +++ b/server/docker/Dockerfile @@ -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"] diff --git a/suites/src/main/java/com/hedera/block/suites/BaseSuite.java b/suites/src/main/java/com/hedera/block/suites/BaseSuite.java index a8b373da4..287a33b62 100644 --- a/suites/src/main/java/com/hedera/block/suites/BaseSuite.java +++ b/suites/src/main/java/com/hedera/block/suites/BaseSuite.java @@ -30,17 +30,20 @@ *

This class is responsible for: * *

* - *

The Block Node server version is retrieved dynamically from an environment file (.env). + *

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. * @@ -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(); } diff --git a/suites/src/main/java/com/hedera/block/suites/grpc/GrpcTestSuites.java b/suites/src/main/java/com/hedera/block/suites/grpc/GrpcTestSuites.java new file mode 100644 index 000000000..9210c8f9b --- /dev/null +++ b/suites/src/main/java/com/hedera/block/suites/grpc/GrpcTestSuites.java @@ -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. + * + *

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() {} +} diff --git a/suites/src/main/java/com/hedera/block/suites/grpc/negative/NegativeServerAvailabilityTests.java b/suites/src/main/java/com/hedera/block/suites/grpc/negative/NegativeServerAvailabilityTests.java new file mode 100644 index 000000000..43e6c2524 --- /dev/null +++ b/suites/src/main/java/com/hedera/block/suites/grpc/negative/NegativeServerAvailabilityTests.java @@ -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() {} +} diff --git a/suites/src/main/java/com/hedera/block/suites/grpc/positive/PositiveServerAvailabilityTests.java b/suites/src/main/java/com/hedera/block/suites/grpc/positive/PositiveServerAvailabilityTests.java new file mode 100644 index 000000000..e675e3f56 --- /dev/null +++ b/suites/src/main/java/com/hedera/block/suites/grpc/positive/PositiveServerAvailabilityTests.java @@ -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. + * + *

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. + * + *

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. + * + *

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."); + } +} diff --git a/suites/src/main/java/com/hedera/block/suites/stream/StreamTestSuites.java b/suites/src/main/java/com/hedera/block/suites/stream/StreamTestSuites.java deleted file mode 100644 index 733b1b0d2..000000000 --- a/suites/src/main/java/com/hedera/block/suites/stream/StreamTestSuites.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.stream; - -import com.hedera.block.suites.stream.negative.NegativeBlockStreamTests; -import com.hedera.block.suites.stream.positive.PositiveBlockStreamTests; -import org.junit.platform.suite.api.SelectClasses; -import org.junit.platform.suite.api.Suite; - -/** - * StreamTestSuites is a test suite that aggregates and runs a set of test classes related to the - * stream processing functionality of the Block Node. - * - *

This suite includes both positive and negative test cases. - * - *

The suite uses the {@link org.junit.platform.suite.api.Suite} annotation to indicate that this - * class is an entry point for running multiple test classes together. It selects the following test - * classes: - * - *

- */ -@Suite -@SelectClasses({PositiveBlockStreamTests.class, NegativeBlockStreamTests.class}) -public class StreamTestSuites { - /** - * Default constructor for the StreamTestSuites class. - * - *

This constructor is required by the JUnit framework to run the suite. - */ - public StreamTestSuites() { - // No additional setup required - } -} diff --git a/suites/src/main/java/com/hedera/block/suites/stream/negative/NegativeBlockStreamTests.java b/suites/src/main/java/com/hedera/block/suites/stream/negative/NegativeBlockStreamTests.java deleted file mode 100644 index f013a2e0f..000000000 --- a/suites/src/main/java/com/hedera/block/suites/stream/negative/NegativeBlockStreamTests.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.stream.negative; - -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; - -/** TBD */ -@DisplayName("Negative Block Stream Tests") -public class NegativeBlockStreamTests extends BaseSuite { - - /** - * Default constructor for the NegativeBlockStreamTests class. - * - *

This constructor is required by the testing framework (JUnit) to create instances of the - * test class. It does not perform any additional setup. - */ - public NegativeBlockStreamTests() { - // No additional setup required - } - - /** TBD */ - @Test - public void testInvalidBlockStreamProcessing() { - assertTrue(blockNodeContainer.isRunning()); - } -} diff --git a/suites/src/main/java/com/hedera/block/suites/stream/positive/PositiveBlockStreamTests.java b/suites/src/main/java/com/hedera/block/suites/stream/positive/PositiveBlockStreamTests.java deleted file mode 100644 index 6749521c6..000000000 --- a/suites/src/main/java/com/hedera/block/suites/stream/positive/PositiveBlockStreamTests.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.stream.positive; - -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; - -/** TBD */ -@DisplayName("Positive Block Stream Tests") -public class PositiveBlockStreamTests extends BaseSuite { - - /** - * Default constructor for the PositiveBlockStreamTests class. - * - *

This constructor is required by the testing framework (JUnit) to create instances of the - * test class. It does not perform any additional setup. - */ - public PositiveBlockStreamTests() { - // No additional setup required - } - - /** TBD */ - @Test - public void testValidBlockStreamProcessing() { - assertTrue(blockNodeContainer.isRunning()); - } -}