Skip to content

Commit 15d20dc

Browse files
committed
chore: Followup to Issue 1626
* Added explanatory comment * Removed many cases of `throws Exception` in tests that could (should) be specific so we catch new exceptions or unhandled failures * Removed `throws Exception` from `S3Client.close()` that was forcing all users to catch or declare `Exception`. * This was particularly pernicious because the method did not actually throw _any_ checked exceptions. * Replaced `new String(stdout, charset)` with `stdout.toString(charset)`. Signed-off-by: Joseph S. <[email protected]>
1 parent a97205f commit 15d20dc

File tree

11 files changed

+81
-59
lines changed

11 files changed

+81
-59
lines changed

block-node/app/src/testFixtures/java/org/hiero/block/node/app/fixtures/server/TestBlockNodeServer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public TestBlockNodeServer(int port, HistoricalBlockFacility historicalBlockFaci
3434
if (historicalBlockFacility
3535
.availableBlocks()
3636
.contains(request.startBlockNumber(), request.endBlockNumber())) {
37+
// publishes one set of block items and an EndOfBlock response for each block
3738
for (long i = request.startBlockNumber(); i <= request.endBlockNumber(); i++) {
3839
replies.onNext(SubscribeStreamResponse.newBuilder()
3940
.blockItems(BlockItemSet.newBuilder()

block-node/base/src/main/java/org/hiero/block/node/base/s3/S3Client.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ public S3Client(
142142
/**
143143
* Closes the HTTP client.
144144
*
145-
* @throws Exception if an error occurs while closing the client
146145
*/
147146
@Override
148-
public void close() throws Exception {
147+
public void close() {
149148
this.httpClient.close();
150149
}
151150

@@ -595,7 +594,8 @@ private <T> HttpResponse<T> request(
595594
case PUT -> requestBuilder.PUT(HttpRequest.BodyPublishers.ofByteArray(requestBody));
596595
case GET -> requestBuilder.GET();
597596
case DELETE -> requestBuilder.DELETE();
598-
default -> throw new IllegalArgumentException("Unsupported HTTP method: " + httpMethod);};
597+
default -> throw new IllegalArgumentException("Unsupported HTTP method: " + httpMethod);
598+
};
599599
requestBuilder = requestBuilder.headers(localHeaders.entrySet().stream()
600600
.flatMap(entry -> Stream.of(entry.getKey(), entry.getValue()))
601601
.toArray(String[]::new));

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
import java.util.ArrayList;
88
import java.util.List;
99
import java.util.concurrent.CountDownLatch;
10+
import java.util.concurrent.ExecutionException;
1011
import java.util.concurrent.ExecutorService;
1112
import java.util.concurrent.Executors;
1213
import java.util.concurrent.Future;
1314
import java.util.concurrent.ThreadLocalRandom;
1415
import java.util.concurrent.TimeUnit;
16+
import java.util.concurrent.TimeoutException;
1517
import java.util.concurrent.atomic.AtomicBoolean;
1618
import java.util.concurrent.atomic.AtomicInteger;
1719
import org.junit.jupiter.api.DisplayName;
@@ -35,7 +37,7 @@ class ConcurrentLongRangeSetThreadingTest {
3537
@Test
3638
@DisplayName("Concurrent additions should not lose or corrupt data")
3739
@Timeout(value = 10, unit = TimeUnit.SECONDS)
38-
void testConcurrentAdditions() throws Exception {
40+
void testConcurrentAdditions() throws ExecutionException, InterruptedException {
3941
final ConcurrentLongRangeSet set = new ConcurrentLongRangeSet();
4042
final CountDownLatch startLatch = new CountDownLatch(1);
4143
final List<Future<?>> futures = new ArrayList<>();
@@ -89,7 +91,7 @@ void testConcurrentAdditions() throws Exception {
8991
@Test
9092
@DisplayName("Concurrent removals should not corrupt data")
9193
@Timeout(value = 10, unit = TimeUnit.SECONDS)
92-
void testConcurrentRemovals() throws Exception {
94+
void testConcurrentRemovals() throws ExecutionException, InterruptedException {
9395
// Initialize with a large continuous range
9496
final ConcurrentLongRangeSet set = new ConcurrentLongRangeSet(0, THREAD_COUNT * OPERATIONS_PER_THREAD * 2L - 1);
9597

@@ -135,7 +137,7 @@ void testConcurrentRemovals() throws Exception {
135137
@Test
136138
@DisplayName("Concurrent mixed operations should not corrupt data")
137139
@Timeout(value = 10, unit = TimeUnit.SECONDS)
138-
void testConcurrentMixedOperations() throws Exception {
140+
void testConcurrentMixedOperations() throws ExecutionException, InterruptedException {
139141
final ConcurrentLongRangeSet set = new ConcurrentLongRangeSet();
140142
final CountDownLatch startLatch = new CountDownLatch(1);
141143
final List<Future<?>> futures = new ArrayList<>();
@@ -192,7 +194,7 @@ void testConcurrentMixedOperations() throws Exception {
192194
@Test
193195
@DisplayName("High contention operations should complete without deadlock or corruption")
194196
@Timeout(value = 15, unit = TimeUnit.SECONDS)
195-
void testHighContention() throws Exception {
197+
void testHighContention() throws ExecutionException, InterruptedException {
196198
final ConcurrentLongRangeSet set = new ConcurrentLongRangeSet();
197199
final CountDownLatch startLatch = new CountDownLatch(1);
198200
final List<Future<?>> futures = new ArrayList<>();
@@ -247,7 +249,7 @@ void testHighContention() throws Exception {
247249
@Test
248250
@DisplayName("Operations should be lock-free")
249251
@Timeout(value = 10, unit = TimeUnit.SECONDS)
250-
void testOperationsAreLockFree() throws Exception {
252+
void testOperationsAreLockFree() throws ExecutionException, InterruptedException, TimeoutException {
251253
final ConcurrentLongRangeSet set = new ConcurrentLongRangeSet();
252254
final AtomicBoolean slowThreadRunning = new AtomicBoolean(true);
253255
final AtomicInteger completedOperations = new AtomicInteger(0);
@@ -313,7 +315,7 @@ void testOperationsAreLockFree() throws Exception {
313315
@ValueSource(ints = {1, 2, 4, 8, 16})
314316
@DisplayName("Performance should scale reasonably with thread count")
315317
@Timeout(value = 30, unit = TimeUnit.SECONDS)
316-
void testConcurrentPerformance(int threadCount) throws Exception {
318+
void testConcurrentPerformance(int threadCount) throws ExecutionException, InterruptedException {
317319
// Skip this test if we don't have enough cores for the higher thread counts
318320
if (threadCount > Runtime.getRuntime().availableProcessors() * 2) {
319321
return;

block-node/base/src/test/java/org/hiero/block/node/base/s3/S3ClientTest.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
import io.minio.MakeBucketArgs;
1212
import io.minio.MinioClient;
1313
import io.minio.PutObjectArgs;
14+
import io.minio.errors.MinioException;
1415
import java.io.ByteArrayInputStream;
16+
import java.io.IOException;
1517
import java.nio.charset.StandardCharsets;
18+
import java.security.GeneralSecurityException;
1619
import java.util.ArrayList;
1720
import java.util.Iterator;
1821
import java.util.List;
@@ -43,7 +46,7 @@ public class S3ClientTest {
4346

4447
@SuppressWarnings({"resource", "HttpUrlsUsage"})
4548
@BeforeAll
46-
void setup() throws Exception {
49+
void setup() throws S3ClientException, IOException, GeneralSecurityException, MinioException {
4750
// Start MinIO container
4851
minioContainer = new GenericContainer<>("minio/minio:latest")
4952
.withCommand("server /data")
@@ -75,7 +78,7 @@ void teardown() {
7578
*/
7679
@Test
7780
@DisplayName("Test listObjects() correctly returns existing objects in a bucket")
78-
void testList() throws Exception {
81+
void testList() throws S3ClientException, IOException, GeneralSecurityException, MinioException {
7982
// Setup
8083
final String content = "Hello, MinIO!";
8184
final String keyPrefix = "block-";
@@ -121,7 +124,7 @@ void testList() throws Exception {
121124
*/
122125
@Test
123126
@DisplayName("Test listObjects() returns empty when no objects are found")
124-
void testListNonExistentObjects() throws Exception {
127+
void testListNonExistentObjects() throws S3ClientException, IOException {
125128
try (final S3Client s3Client = client()) {
126129
// Call
127130
final List<String> actual = s3Client.listObjects("non-existent-prefix", 100);
@@ -140,7 +143,7 @@ void testListNonExistentObjects() throws Exception {
140143
*/
141144
@Test
142145
@DisplayName("Test multipart upload")
143-
void testMultipartUpload() throws Exception {
146+
void testMultipartUpload() throws S3ClientException, IOException, GeneralSecurityException, MinioException {
144147
// Setup
145148
final String key = "testMultipartUploadSuccess.txt";
146149
// check that the object does not exist before the test
@@ -190,7 +193,7 @@ void testMultipartUpload() throws Exception {
190193
*/
191194
@Test
192195
@DisplayName("Test upload of a large file")
193-
void testUploadFile() throws Exception {
196+
void testUploadFile() throws S3ClientException, IOException, GeneralSecurityException, MinioException {
194197
// Setup
195198
final int testContentSize = 8 * 1024 * 1024 + 826;
196199
final String key = "uploadOfLargeFileSuccessful.txt";
@@ -251,7 +254,8 @@ void testUploadFile() throws Exception {
251254
*/
252255
@Test
253256
@DisplayName("Test upload and download of a text file")
254-
void testTextFileUploadAndDownload() throws Exception {
257+
void testTextFileUploadAndDownload()
258+
throws S3ClientException, IOException, GeneralSecurityException, MinioException {
255259
// Setup
256260
final String key = "uploadSimpleTextFile.txt";
257261
final String expected = "Hello, MinIO!";
@@ -292,7 +296,7 @@ void testTextFileUploadAndDownload() throws Exception {
292296
*/
293297
@Test
294298
@DisplayName("Test listMultipartUpload() will correctly return existing multipart uploads")
295-
void testListMultipartUploads() throws Exception {
299+
void testListMultipartUploads() throws S3ClientException, IOException, GeneralSecurityException, MinioException {
296300
// Setup
297301
final String key = "testListMultipartUploads.txt";
298302
try (final S3Client s3Client = client()) {
@@ -327,7 +331,8 @@ void testListMultipartUploads() throws Exception {
327331
*/
328332
@Test
329333
@DisplayName("Test listMultipartUpload() will correctly return existing multipart uploads")
330-
void testListMultipartUploadsMultiKeyValue() throws Exception {
334+
void testListMultipartUploadsMultiKeyValue()
335+
throws S3ClientException, IOException, GeneralSecurityException, MinioException {
331336
// Setup
332337
final String key1 = "testListMultipartUploads1.txt";
333338
final String key2 = "testListMultipartUploads2.txt";
@@ -362,7 +367,7 @@ void testListMultipartUploadsMultiKeyValue() throws Exception {
362367
*/
363368
@Test
364369
@DisplayName("Test abortMultipartUpload() will correctly abort an existing multipart upload")
365-
void testAbortMultipartUpload() throws Exception {
370+
void testAbortMultipartUpload() throws S3ClientException, IOException, GeneralSecurityException, MinioException {
366371
// Setup
367372
final String key = "testAbortMultipartUpload.txt";
368373
try (final S3Client s3Client = client()) {
@@ -404,7 +409,8 @@ void testAbortMultipartUpload() throws Exception {
404409
*/
405410
@Test
406411
@DisplayName("Test abortMultipartUpload() will correctly abort an existing multipart upload with multiple parts")
407-
void testAbortMultipartUploadMultiKeyValue() throws Exception {
412+
void testAbortMultipartUploadMultiKeyValue()
413+
throws S3ClientException, IOException, GeneralSecurityException, MinioException {
408414
// Setup
409415
final String key1 = "testAbortMultipartUploads1.txt";
410416
final String key2 = "testAbortMultipartUploads2.txt";
@@ -456,7 +462,7 @@ void testAbortMultipartUploadMultiKeyValue() throws Exception {
456462
*/
457463
@Test
458464
@DisplayName("Test fetching a non-existent object")
459-
void testFetchNonExistentObject() throws Exception {
465+
void testFetchNonExistentObject() throws S3ClientException, IOException {
460466
try (final S3Client s3Client = client()) {
461467
assertNull(s3Client.downloadTextFile("non-existent-object.txt"));
462468
}

block-node/messaging/src/main/java/org/hiero/block/node/messaging/BlockMessagingFacilityImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,8 @@ private interface InformedEventHandler<T> {
688688
* @param sequence of the event being processed
689689
* @param endOfBatch flag to indicate if this is the last event in a batch from the {@link RingBuffer}
690690
* @param percentageBehindRingHead percentage 0.0 to 100.0 behind the ring head this handler is
691-
* @throws Exception if the EventHandler would like the exception handled further up the chain.
692691
*/
693-
void onEvent(T event, long sequence, boolean endOfBatch, double percentageBehindRingHead) throws Exception;
692+
void onEvent(T event, long sequence, boolean endOfBatch, double percentageBehindRingHead);
694693
}
695694

696695
/**

block-node/s3-archive/src/test/java/org/hiero/block/node/archive/s3/S3ArchivePluginTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
import io.minio.ListObjectsArgs;
1313
import io.minio.MakeBucketArgs;
1414
import io.minio.MinioClient;
15+
import io.minio.errors.MinioException;
1516
import java.io.BufferedReader;
1617
import java.io.IOException;
1718
import java.io.InputStreamReader;
1819
import java.nio.file.Files;
1920
import java.nio.file.Path;
21+
import java.security.GeneralSecurityException;
2022
import java.time.Duration;
2123
import java.time.Instant;
2224
import java.time.ZoneOffset;
@@ -56,7 +58,7 @@ class S3ArchivePluginTest extends PluginTestBase<S3ArchivePlugin, BlockingExecut
5658
private final BlockingExecutor pluginExecutor;
5759

5860
@SuppressWarnings("resource")
59-
public S3ArchivePluginTest() throws Exception {
61+
public S3ArchivePluginTest() throws GeneralSecurityException, IOException, MinioException {
6062
super(new BlockingExecutor(new LinkedBlockingQueue<>()));
6163
// Start MinIO container
6264
GenericContainer<?> minioContainer = new GenericContainer<>("minio/minio:latest")
@@ -88,7 +90,7 @@ public S3ArchivePluginTest() throws Exception {
8890

8991
@Test
9092
@DisplayName("ArchivePlugin should upload a tar file for single batch of blocks")
91-
void startWithSingleBatch(@TempDir Path tempDir) throws Exception {
93+
void startWithSingleBatch(@TempDir Path tempDir) throws IOException, InterruptedException {
9294
// create 10 sample blocks, this should trigger the plugin to archive them
9395
sendBlocks(START_TIME, 0, 9);
9496
// execute archive task

tools-and-tests/simulator/src/test/java/org/hiero/block/simulator/grpc/impl/PublishStreamObserverTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void onCompleted() {
106106
}
107107

108108
@Test
109-
void verifyUpdateLatestAckBlockStartupDataHandlesIOException() throws Exception {
109+
void verifyUpdateLatestAckBlockStartupDataHandlesIOException() throws IOException {
110110
PublishStreamResponse response = PublishStreamResponse.newBuilder()
111111
.setAcknowledgement(
112112
PublishStreamResponse.BlockAcknowledgement.newBuilder().setBlockNumber(12345L))

tools-and-tests/simulator/src/test/java/org/hiero/block/simulator/mode/PublishClientManagerTest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.hiero.block.simulator.config.data.SimulatorStartupDataConfig;
2828
import org.hiero.block.simulator.config.data.UnorderedStreamConfig;
2929
import org.hiero.block.simulator.config.types.EndStreamMode;
30+
import org.hiero.block.simulator.exception.BlockSimulatorParsingException;
3031
import org.hiero.block.simulator.generator.BlockStreamManager;
3132
import org.hiero.block.simulator.generator.CraftBlockStreamManager;
3233
import org.hiero.block.simulator.grpc.PublishStreamGrpcClient;
@@ -83,7 +84,7 @@ void setUp() throws IOException {
8384
}
8485

8586
@Test
86-
void handleEndOfStreamOnSuccess() throws Exception {
87+
void handleEndOfStreamOnSuccess() throws BlockSimulatorParsingException, IOException, InterruptedException {
8788
Block nextBlock = createBlocks(0, 1);
8889
PublishStreamResponse response = mock(PublishStreamResponse.class);
8990
PublishStreamResponse.EndOfStream endOfStream = mock(PublishStreamResponse.EndOfStream.class);
@@ -100,7 +101,7 @@ void handleEndOfStreamOnSuccess() throws Exception {
100101
}
101102

102103
@Test
103-
void handleEndOfStreamOnBehind() throws Exception {
104+
void handleEndOfStreamOnBehind() throws BlockSimulatorParsingException, IOException, InterruptedException {
104105
Block nextBlock = createBlocks(0, 1);
105106
PublishStreamResponse response = mock(PublishStreamResponse.class);
106107
PublishStreamResponse.EndOfStream endOfStream = mock(PublishStreamResponse.EndOfStream.class);
@@ -117,7 +118,7 @@ void handleEndOfStreamOnBehind() throws Exception {
117118
}
118119

119120
@Test
120-
void handleEndOfStreamOnDuplicateBlock() throws Exception {
121+
void handleEndOfStreamOnDuplicateBlock() throws BlockSimulatorParsingException, IOException, InterruptedException {
121122
Block nextBlock = createBlocks(0, 1);
122123
PublishStreamResponse response = mock(PublishStreamResponse.class);
123124
PublishStreamResponse.EndOfStream endOfStream = mock(PublishStreamResponse.EndOfStream.class);
@@ -134,7 +135,7 @@ void handleEndOfStreamOnDuplicateBlock() throws Exception {
134135
}
135136

136137
@Test
137-
void handleEndOfStreamOnTimeout() throws Exception {
138+
void handleEndOfStreamOnTimeout() throws BlockSimulatorParsingException, IOException, InterruptedException {
138139
Block nextBlock = createBlocks(0, 1);
139140
PublishStreamResponse response = mock(PublishStreamResponse.class);
140141
PublishStreamResponse.EndOfStream endOfStream = mock(PublishStreamResponse.EndOfStream.class);
@@ -151,7 +152,7 @@ void handleEndOfStreamOnTimeout() throws Exception {
151152
}
152153

153154
@Test
154-
void handleEndOfStreamOnBadBlockProof() throws Exception {
155+
void handleEndOfStreamOnBadBlockProof() throws BlockSimulatorParsingException, IOException, InterruptedException {
155156
Block nextBlock = createBlocks(0, 1);
156157
PublishStreamResponse response = mock(PublishStreamResponse.class);
157158
PublishStreamResponse.EndOfStream endOfStream = mock(PublishStreamResponse.EndOfStream.class);
@@ -168,7 +169,7 @@ void handleEndOfStreamOnBadBlockProof() throws Exception {
168169
}
169170

170171
@Test
171-
void handleEndOfStreamOnInternalError() throws Exception {
172+
void handleEndOfStreamOnInternalError() throws BlockSimulatorParsingException, IOException, InterruptedException {
172173
Block nextBlock = createBlocks(0, 1);
173174
PublishStreamResponse response = mock(PublishStreamResponse.class);
174175
PublishStreamResponse.EndOfStream endOfStream = mock(PublishStreamResponse.EndOfStream.class);
@@ -185,7 +186,8 @@ void handleEndOfStreamOnInternalError() throws Exception {
185186
}
186187

187188
@Test
188-
void handleEndOfStreamOnPersistenceFailed() throws Exception {
189+
void handleEndOfStreamOnPersistenceFailed()
190+
throws BlockSimulatorParsingException, IOException, InterruptedException {
189191
Block nextBlock = createBlocks(0, 1);
190192
PublishStreamResponse response = mock(PublishStreamResponse.class);
191193
PublishStreamResponse.EndOfStream endOfStream = mock(PublishStreamResponse.EndOfStream.class);
@@ -202,7 +204,7 @@ void handleEndOfStreamOnPersistenceFailed() throws Exception {
202204
}
203205

204206
@Test
205-
void handleResendBlock() throws Exception {
207+
void handleResendBlock() throws BlockSimulatorParsingException, IOException, InterruptedException {
206208
Block nextBlock = createBlocks(0, 1);
207209
PublishStreamResponse response = mock(PublishStreamResponse.class);
208210
PublishStreamResponse.ResendBlock resendBlock = mock(PublishStreamResponse.ResendBlock.class);
@@ -218,7 +220,7 @@ void handleResendBlock() throws Exception {
218220
}
219221

220222
@Test
221-
void handleSkipBlock() throws Exception {
223+
void handleSkipBlock() throws BlockSimulatorParsingException, IOException, InterruptedException {
222224
Block nextBlock = createBlocks(0, 1);
223225
PublishStreamResponse response = mock(PublishStreamResponse.class);
224226
PublishStreamResponse.SkipBlock skipBlock = mock(PublishStreamResponse.SkipBlock.class);
@@ -235,7 +237,8 @@ void handleSkipBlock() throws Exception {
235237

236238
@ParameterizedTest
237239
@MethodSource("provideEndStreamMode")
238-
void sendEndStream(EndStreamMode endStreamMode, EndStream.Code endStreamCode) throws Exception {
240+
void sendEndStream(EndStreamMode endStreamMode, EndStream.Code endStreamCode)
241+
throws BlockSimulatorParsingException, IOException, InterruptedException {
239242
publishClientManager.sendEndStream(endStreamMode);
240243
verify(publishStreamGrpcClient).handleEndStreamModeIfSet(endStreamCode);
241244
}

0 commit comments

Comments
 (0)