Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public TestBlockNodeServer(int port, HistoricalBlockFacility historicalBlockFaci
if (historicalBlockFacility
.availableBlocks()
.contains(request.startBlockNumber(), request.endBlockNumber())) {
// publishes one set of block items and an EndOfBlock response for each block
for (long i = request.startBlockNumber(); i <= request.endBlockNumber(); i++) {
replies.onNext(SubscribeStreamResponse.newBuilder()
.blockItems(BlockItemSet.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -35,7 +37,7 @@
@Test
@DisplayName("Concurrent additions should not lose or corrupt data")
@Timeout(value = 10, unit = TimeUnit.SECONDS)
void testConcurrentAdditions() throws Exception {
void testConcurrentAdditions() throws ExecutionException, InterruptedException {
final ConcurrentLongRangeSet set = new ConcurrentLongRangeSet();
final CountDownLatch startLatch = new CountDownLatch(1);
final List<Future<?>> futures = new ArrayList<>();
Expand Down Expand Up @@ -89,7 +91,7 @@
@Test
@DisplayName("Concurrent removals should not corrupt data")
@Timeout(value = 10, unit = TimeUnit.SECONDS)
void testConcurrentRemovals() throws Exception {
void testConcurrentRemovals() throws ExecutionException, InterruptedException {
// Initialize with a large continuous range
final ConcurrentLongRangeSet set = new ConcurrentLongRangeSet(0, THREAD_COUNT * OPERATIONS_PER_THREAD * 2L - 1);

Expand Down Expand Up @@ -135,7 +137,7 @@
@Test
@DisplayName("Concurrent mixed operations should not corrupt data")
@Timeout(value = 10, unit = TimeUnit.SECONDS)
void testConcurrentMixedOperations() throws Exception {
void testConcurrentMixedOperations() throws ExecutionException, InterruptedException {

Check warning on line 140 in block-node/base/src/test/java/org/hiero/block/node/base/ranges/ConcurrentLongRangeSetThreadingTest.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

block-node/base/src/test/java/org/hiero/block/node/base/ranges/ConcurrentLongRangeSetThreadingTest.java#L140

JUnit tests should include assert() or fail()
final ConcurrentLongRangeSet set = new ConcurrentLongRangeSet();
final CountDownLatch startLatch = new CountDownLatch(1);
final List<Future<?>> futures = new ArrayList<>();
Expand Down Expand Up @@ -192,7 +194,7 @@
@Test
@DisplayName("High contention operations should complete without deadlock or corruption")
@Timeout(value = 15, unit = TimeUnit.SECONDS)
void testHighContention() throws Exception {
void testHighContention() throws ExecutionException, InterruptedException {

Check warning on line 197 in block-node/base/src/test/java/org/hiero/block/node/base/ranges/ConcurrentLongRangeSetThreadingTest.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

block-node/base/src/test/java/org/hiero/block/node/base/ranges/ConcurrentLongRangeSetThreadingTest.java#L197

JUnit tests should include assert() or fail()
final ConcurrentLongRangeSet set = new ConcurrentLongRangeSet();
final CountDownLatch startLatch = new CountDownLatch(1);
final List<Future<?>> futures = new ArrayList<>();
Expand Down Expand Up @@ -247,7 +249,7 @@
@Test
@DisplayName("Operations should be lock-free")
@Timeout(value = 10, unit = TimeUnit.SECONDS)
void testOperationsAreLockFree() throws Exception {
void testOperationsAreLockFree() throws ExecutionException, InterruptedException, TimeoutException {
final ConcurrentLongRangeSet set = new ConcurrentLongRangeSet();
final AtomicBoolean slowThreadRunning = new AtomicBoolean(true);
final AtomicInteger completedOperations = new AtomicInteger(0);
Expand Down Expand Up @@ -313,7 +315,7 @@
@ValueSource(ints = {1, 2, 4, 8, 16})
@DisplayName("Performance should scale reasonably with thread count")
@Timeout(value = 30, unit = TimeUnit.SECONDS)
void testConcurrentPerformance(int threadCount) throws Exception {
void testConcurrentPerformance(int threadCount) throws ExecutionException, InterruptedException {

Check warning on line 318 in block-node/base/src/test/java/org/hiero/block/node/base/ranges/ConcurrentLongRangeSetThreadingTest.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

block-node/base/src/test/java/org/hiero/block/node/base/ranges/ConcurrentLongRangeSetThreadingTest.java#L318

JUnit tests should include assert() or fail()
// Skip this test if we don't have enough cores for the higher thread counts
if (threadCount > Runtime.getRuntime().availableProcessors() * 2) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.errors.MinioException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -43,7 +46,7 @@ public class S3ClientTest {

@SuppressWarnings({"resource", "HttpUrlsUsage"})
@BeforeAll
void setup() throws Exception {
void setup() throws S3ClientException, IOException, GeneralSecurityException, MinioException {
// Start MinIO container
minioContainer = new GenericContainer<>("minio/minio:latest")
.withCommand("server /data")
Expand Down Expand Up @@ -75,7 +78,7 @@ void teardown() {
*/
@Test
@DisplayName("Test listObjects() correctly returns existing objects in a bucket")
void testList() throws Exception {
void testList() throws S3ClientException, IOException, GeneralSecurityException, MinioException {
// Setup
final String content = "Hello, MinIO!";
final String keyPrefix = "block-";
Expand Down Expand Up @@ -121,7 +124,7 @@ void testList() throws Exception {
*/
@Test
@DisplayName("Test listObjects() returns empty when no objects are found")
void testListNonExistentObjects() throws Exception {
void testListNonExistentObjects() throws S3ClientException, IOException {
try (final S3Client s3Client = client()) {
// Call
final List<String> actual = s3Client.listObjects("non-existent-prefix", 100);
Expand All @@ -140,7 +143,7 @@ void testListNonExistentObjects() throws Exception {
*/
@Test
@DisplayName("Test multipart upload")
void testMultipartUpload() throws Exception {
void testMultipartUpload() throws S3ClientException, IOException, GeneralSecurityException, MinioException {
// Setup
final String key = "testMultipartUploadSuccess.txt";
// check that the object does not exist before the test
Expand Down Expand Up @@ -190,7 +193,7 @@ void testMultipartUpload() throws Exception {
*/
@Test
@DisplayName("Test upload of a large file")
void testUploadFile() throws Exception {
void testUploadFile() throws S3ClientException, IOException, GeneralSecurityException, MinioException {
// Setup
final int testContentSize = 8 * 1024 * 1024 + 826;
final String key = "uploadOfLargeFileSuccessful.txt";
Expand Down Expand Up @@ -251,7 +254,8 @@ void testUploadFile() throws Exception {
*/
@Test
@DisplayName("Test upload and download of a text file")
void testTextFileUploadAndDownload() throws Exception {
void testTextFileUploadAndDownload()
throws S3ClientException, IOException, GeneralSecurityException, MinioException {
// Setup
final String key = "uploadSimpleTextFile.txt";
final String expected = "Hello, MinIO!";
Expand Down Expand Up @@ -292,7 +296,7 @@ void testTextFileUploadAndDownload() throws Exception {
*/
@Test
@DisplayName("Test listMultipartUpload() will correctly return existing multipart uploads")
void testListMultipartUploads() throws Exception {
void testListMultipartUploads() throws S3ClientException, IOException, GeneralSecurityException, MinioException {
// Setup
final String key = "testListMultipartUploads.txt";
try (final S3Client s3Client = client()) {
Expand Down Expand Up @@ -327,7 +331,8 @@ void testListMultipartUploads() throws Exception {
*/
@Test
@DisplayName("Test listMultipartUpload() will correctly return existing multipart uploads")
void testListMultipartUploadsMultiKeyValue() throws Exception {
void testListMultipartUploadsMultiKeyValue()
throws S3ClientException, IOException, GeneralSecurityException, MinioException {
// Setup
final String key1 = "testListMultipartUploads1.txt";
final String key2 = "testListMultipartUploads2.txt";
Expand Down Expand Up @@ -362,7 +367,7 @@ void testListMultipartUploadsMultiKeyValue() throws Exception {
*/
@Test
@DisplayName("Test abortMultipartUpload() will correctly abort an existing multipart upload")
void testAbortMultipartUpload() throws Exception {
void testAbortMultipartUpload() throws S3ClientException, IOException, GeneralSecurityException, MinioException {
// Setup
final String key = "testAbortMultipartUpload.txt";
try (final S3Client s3Client = client()) {
Expand Down Expand Up @@ -404,7 +409,8 @@ void testAbortMultipartUpload() throws Exception {
*/
@Test
@DisplayName("Test abortMultipartUpload() will correctly abort an existing multipart upload with multiple parts")
void testAbortMultipartUploadMultiKeyValue() throws Exception {
void testAbortMultipartUploadMultiKeyValue()
throws S3ClientException, IOException, GeneralSecurityException, MinioException {
// Setup
final String key1 = "testAbortMultipartUploads1.txt";
final String key2 = "testAbortMultipartUploads2.txt";
Expand Down Expand Up @@ -456,7 +462,7 @@ void testAbortMultipartUploadMultiKeyValue() throws Exception {
*/
@Test
@DisplayName("Test fetching a non-existent object")
void testFetchNonExistentObject() throws Exception {
void testFetchNonExistentObject() throws S3ClientException, IOException {
try (final S3Client s3Client = client()) {
assertNull(s3Client.downloadTextFile("non-existent-object.txt"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,8 @@ private interface InformedEventHandler<T> {
* @param sequence of the event being processed
* @param endOfBatch flag to indicate if this is the last event in a batch from the {@link RingBuffer}
* @param percentageBehindRingHead percentage 0.0 to 100.0 behind the ring head this handler is
* @throws Exception if the EventHandler would like the exception handled further up the chain.
*/
void onEvent(T event, long sequence, boolean endOfBatch, double percentageBehindRingHead) throws Exception;
void onEvent(T event, long sequence, boolean endOfBatch, double percentageBehindRingHead);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.RemoveBucketArgs;
import io.minio.errors.MinioException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.GeneralSecurityException;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneOffset;
Expand Down Expand Up @@ -66,7 +68,7 @@ class S3ArchivePluginTest extends PluginTestBase<S3ArchivePlugin, ExecutorServic
private final MinioClient minioClient;

@SuppressWarnings("resource")
public S3ArchivePluginTest() throws Exception {
public S3ArchivePluginTest() throws GeneralSecurityException, IOException, MinioException {
super(Executors.newSingleThreadExecutor());
// Start MinIO container
GenericContainer<?> minioContainer = new GenericContainer<>("minio/minio:latest")
Expand Down Expand Up @@ -97,7 +99,7 @@ public S3ArchivePluginTest() throws Exception {

@Test
@DisplayName("ArchivePlugin should upload a tar file for single batch of blocks")
void startWithSingleBatch(@TempDir Path tempDir) throws Exception {
void startWithSingleBatch(@TempDir Path tempDir) throws IOException, InterruptedException {
// create 10 sample blocks, this should trigger the plugin to archive them
sendBlocks(START_TIME, 0, 9);
// await archive task to complete
Expand Down Expand Up @@ -214,17 +216,17 @@ void testFailUpload() throws Exception {
});
}

private void createTestBucket() throws Exception {
private void createTestBucket() throws GeneralSecurityException, IOException, MinioException {
minioClient.makeBucket(MakeBucketArgs.builder().bucket(BUCKET_NAME).build());
assertTrue(testBucketExists());
}

private void removeTestBucket() throws Exception {
private void removeTestBucket() throws GeneralSecurityException, IOException, MinioException {
minioClient.removeBucket(RemoveBucketArgs.builder().bucket(BUCKET_NAME).build());
assertFalse(testBucketExists());
}

private boolean testBucketExists() throws Exception {
private boolean testBucketExists() throws GeneralSecurityException, IOException, MinioException {
return minioClient.bucketExists(
BucketExistsArgs.builder().bucket(BUCKET_NAME).build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void onCompleted() {
}

@Test
void verifyUpdateLatestAckBlockStartupDataHandlesIOException() throws Exception {
void verifyUpdateLatestAckBlockStartupDataHandlesIOException() throws IOException {
PublishStreamResponse response = PublishStreamResponse.newBuilder()
.setAcknowledgement(
PublishStreamResponse.BlockAcknowledgement.newBuilder().setBlockNumber(12345L))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.hiero.block.simulator.config.data.SimulatorStartupDataConfig;
import org.hiero.block.simulator.config.data.UnorderedStreamConfig;
import org.hiero.block.simulator.config.types.EndStreamMode;
import org.hiero.block.simulator.exception.BlockSimulatorParsingException;
import org.hiero.block.simulator.generator.BlockStreamManager;
import org.hiero.block.simulator.generator.CraftBlockStreamManager;
import org.hiero.block.simulator.grpc.PublishStreamGrpcClient;
Expand Down Expand Up @@ -83,7 +84,7 @@ void setUp() throws IOException {
}

@Test
void handleEndOfStreamOnSuccess() throws Exception {
void handleEndOfStreamOnSuccess() throws BlockSimulatorParsingException, IOException, InterruptedException {
Block nextBlock = createBlocks(0, 1);
PublishStreamResponse response = mock(PublishStreamResponse.class);
PublishStreamResponse.EndOfStream endOfStream = mock(PublishStreamResponse.EndOfStream.class);
Expand All @@ -100,7 +101,7 @@ void handleEndOfStreamOnSuccess() throws Exception {
}

@Test
void handleEndOfStreamOnBehind() throws Exception {
void handleEndOfStreamOnBehind() throws BlockSimulatorParsingException, IOException, InterruptedException {
Block nextBlock = createBlocks(0, 1);
PublishStreamResponse response = mock(PublishStreamResponse.class);
PublishStreamResponse.EndOfStream endOfStream = mock(PublishStreamResponse.EndOfStream.class);
Expand All @@ -117,7 +118,7 @@ void handleEndOfStreamOnBehind() throws Exception {
}

@Test
void handleEndOfStreamOnDuplicateBlock() throws Exception {
void handleEndOfStreamOnDuplicateBlock() throws BlockSimulatorParsingException, IOException, InterruptedException {
Block nextBlock = createBlocks(0, 1);
PublishStreamResponse response = mock(PublishStreamResponse.class);
PublishStreamResponse.EndOfStream endOfStream = mock(PublishStreamResponse.EndOfStream.class);
Expand All @@ -134,7 +135,7 @@ void handleEndOfStreamOnDuplicateBlock() throws Exception {
}

@Test
void handleEndOfStreamOnTimeout() throws Exception {
void handleEndOfStreamOnTimeout() throws BlockSimulatorParsingException, IOException, InterruptedException {
Block nextBlock = createBlocks(0, 1);
PublishStreamResponse response = mock(PublishStreamResponse.class);
PublishStreamResponse.EndOfStream endOfStream = mock(PublishStreamResponse.EndOfStream.class);
Expand All @@ -151,7 +152,7 @@ void handleEndOfStreamOnTimeout() throws Exception {
}

@Test
void handleEndOfStreamOnBadBlockProof() throws Exception {
void handleEndOfStreamOnBadBlockProof() throws BlockSimulatorParsingException, IOException, InterruptedException {
Block nextBlock = createBlocks(0, 1);
PublishStreamResponse response = mock(PublishStreamResponse.class);
PublishStreamResponse.EndOfStream endOfStream = mock(PublishStreamResponse.EndOfStream.class);
Expand All @@ -168,7 +169,7 @@ void handleEndOfStreamOnBadBlockProof() throws Exception {
}

@Test
void handleEndOfStreamOnInternalError() throws Exception {
void handleEndOfStreamOnInternalError() throws BlockSimulatorParsingException, IOException, InterruptedException {
Block nextBlock = createBlocks(0, 1);
PublishStreamResponse response = mock(PublishStreamResponse.class);
PublishStreamResponse.EndOfStream endOfStream = mock(PublishStreamResponse.EndOfStream.class);
Expand All @@ -185,7 +186,8 @@ void handleEndOfStreamOnInternalError() throws Exception {
}

@Test
void handleEndOfStreamOnPersistenceFailed() throws Exception {
void handleEndOfStreamOnPersistenceFailed()
throws BlockSimulatorParsingException, IOException, InterruptedException {
Block nextBlock = createBlocks(0, 1);
PublishStreamResponse response = mock(PublishStreamResponse.class);
PublishStreamResponse.EndOfStream endOfStream = mock(PublishStreamResponse.EndOfStream.class);
Expand All @@ -202,7 +204,7 @@ void handleEndOfStreamOnPersistenceFailed() throws Exception {
}

@Test
void handleResendBlock() throws Exception {
void handleResendBlock() throws BlockSimulatorParsingException, IOException, InterruptedException {
Block nextBlock = createBlocks(0, 1);
PublishStreamResponse response = mock(PublishStreamResponse.class);
PublishStreamResponse.ResendBlock resendBlock = mock(PublishStreamResponse.ResendBlock.class);
Expand All @@ -218,7 +220,7 @@ void handleResendBlock() throws Exception {
}

@Test
void handleSkipBlock() throws Exception {
void handleSkipBlock() throws BlockSimulatorParsingException, IOException, InterruptedException {
Block nextBlock = createBlocks(0, 1);
PublishStreamResponse response = mock(PublishStreamResponse.class);
PublishStreamResponse.SkipBlock skipBlock = mock(PublishStreamResponse.SkipBlock.class);
Expand All @@ -235,7 +237,8 @@ void handleSkipBlock() throws Exception {

@ParameterizedTest
@MethodSource("provideEndStreamMode")
void sendEndStream(EndStreamMode endStreamMode, EndStream.Code endStreamCode) throws Exception {
void sendEndStream(EndStreamMode endStreamMode, EndStream.Code endStreamCode)
throws BlockSimulatorParsingException, IOException, InterruptedException {
publishClientManager.sendEndStream(endStreamMode);
verify(publishStreamGrpcClient).handleEndStreamModeIfSet(endStreamCode);
}
Expand Down
Loading
Loading