mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-06-10 18:23:12 +08:00
fix: resolve compile errors in quarkus code examples
- Add missing @Slf4j and bucketName field to FileStorageService - Fix PaginatedList → List type mismatch (Panache returns List) - Fix executorService.submit → execute mock (supplyAsync uses execute) - Update S3 failure test to throw from putObject instead of failed future Applied to English + all 3 locale copies (tr, ja-JP, zh-CN).
This commit is contained in:
@@ -340,7 +340,7 @@ public class DocumentResource {
|
||||
public Response list(
|
||||
@QueryParam("page") @DefaultValue("0") int page,
|
||||
@QueryParam("size") @DefaultValue("20") int size) {
|
||||
PaginatedList<Document> documents = documentService.list(page, size);
|
||||
List<Document> documents = documentService.list(page, size);
|
||||
return Response.ok(documents).build();
|
||||
}
|
||||
|
||||
@@ -415,7 +415,7 @@ public class DocumentService {
|
||||
return repo.findByIdOptional(id);
|
||||
}
|
||||
|
||||
public PaginatedList<Document> list(int page, int size) {
|
||||
public List<Document> list(int page, int size) {
|
||||
return repo.findAll()
|
||||
.page(page, size)
|
||||
.list();
|
||||
@@ -474,12 +474,15 @@ public class GenericExceptionMapper implements ExceptionMapper<Exception> {
|
||||
## CompletableFuture非同期操作
|
||||
|
||||
```java
|
||||
@Slf4j
|
||||
@ApplicationScoped
|
||||
@RequiredArgsConstructor
|
||||
public class FileStorageService {
|
||||
private final S3Client s3Client;
|
||||
private final ExecutorService executorService;
|
||||
|
||||
@ConfigProperty(name = "storage.bucket-name") String bucketName;
|
||||
|
||||
public CompletableFuture<StoredDocumentInfo> uploadOriginalFile(
|
||||
InputStream inputStream,
|
||||
long size,
|
||||
|
||||
@@ -340,7 +340,7 @@ public class DocumentResource {
|
||||
public Response list(
|
||||
@QueryParam("page") @DefaultValue("0") int page,
|
||||
@QueryParam("size") @DefaultValue("20") int size) {
|
||||
PaginatedList<Document> documents = documentService.list(page, size);
|
||||
List<Document> documents = documentService.list(page, size);
|
||||
return Response.ok(documents).build();
|
||||
}
|
||||
|
||||
@@ -415,7 +415,7 @@ public class DocumentService {
|
||||
return repo.findByIdOptional(id);
|
||||
}
|
||||
|
||||
public PaginatedList<Document> list(int page, int size) {
|
||||
public List<Document> list(int page, int size) {
|
||||
return repo.findAll()
|
||||
.page(page, size)
|
||||
.list();
|
||||
@@ -474,12 +474,15 @@ public class GenericExceptionMapper implements ExceptionMapper<Exception> {
|
||||
## CompletableFuture Async İşlemleri
|
||||
|
||||
```java
|
||||
@Slf4j
|
||||
@ApplicationScoped
|
||||
@RequiredArgsConstructor
|
||||
public class FileStorageService {
|
||||
private final S3Client s3Client;
|
||||
private final ExecutorService executorService;
|
||||
|
||||
@ConfigProperty(name = "storage.bucket-name") String bucketName;
|
||||
|
||||
public CompletableFuture<StoredDocumentInfo> uploadOriginalFile(
|
||||
InputStream inputStream,
|
||||
long size,
|
||||
|
||||
@@ -528,10 +528,10 @@ class FileStorageServiceTest {
|
||||
@DisplayName("Dosyayı başarıyla yüklemeli ve belge bilgisi döndürmeli")
|
||||
void givenValidFile_whenUpload_thenReturnsDocumentInfo() throws Exception {
|
||||
// ARRANGE
|
||||
when(executorService.submit(any(Callable.class))).thenAnswer(invocation -> {
|
||||
Callable<?> callable = invocation.getArgument(0);
|
||||
return CompletableFuture.completedFuture(callable.call());
|
||||
});
|
||||
doAnswer(invocation -> {
|
||||
((Runnable) invocation.getArgument(0)).run();
|
||||
return null;
|
||||
}).when(executorService).execute(any(Runnable.class));
|
||||
|
||||
when(s3Client.putObject(any(PutObjectRequest.class), any(RequestBody.class)))
|
||||
.thenReturn(PutObjectResponse.builder().build());
|
||||
@@ -556,9 +556,13 @@ class FileStorageServiceTest {
|
||||
@DisplayName("S3 yükleme başarısızlığını ele almalı")
|
||||
void givenS3Failure_whenUpload_thenCompletableFutureFails() {
|
||||
// ARRANGE
|
||||
when(executorService.submit(any(Callable.class))).thenAnswer(invocation -> {
|
||||
return CompletableFuture.failedFuture(new StorageException("S3 unavailable"));
|
||||
});
|
||||
doAnswer(invocation -> {
|
||||
((Runnable) invocation.getArgument(0)).run();
|
||||
return null;
|
||||
}).when(executorService).execute(any(Runnable.class));
|
||||
|
||||
when(s3Client.putObject(any(PutObjectRequest.class), any(RequestBody.class)))
|
||||
.thenThrow(new StorageException("S3 unavailable"));
|
||||
|
||||
// ACT
|
||||
CompletableFuture<StoredDocumentInfo> future =
|
||||
@@ -578,11 +582,11 @@ class FileStorageServiceTest {
|
||||
// ARRANGE
|
||||
AtomicReference<LogContext> capturedContext = new AtomicReference<>();
|
||||
|
||||
when(executorService.submit(any(Callable.class))).thenAnswer(invocation -> {
|
||||
Callable<?> callable = invocation.getArgument(0);
|
||||
doAnswer(invocation -> {
|
||||
capturedContext.set(CustomLog.getCurrentContext());
|
||||
return CompletableFuture.completedFuture(callable.call());
|
||||
});
|
||||
((Runnable) invocation.getArgument(0)).run();
|
||||
return null;
|
||||
}).when(executorService).execute(any(Runnable.class));
|
||||
|
||||
// ACT
|
||||
fileStorageService.uploadOriginalFile(testInputStream, 1024L,
|
||||
|
||||
@@ -320,7 +320,7 @@ public class DocumentResource {
|
||||
public Response list(
|
||||
@QueryParam("page") @DefaultValue("0") int page,
|
||||
@QueryParam("size") @DefaultValue("20") int size) {
|
||||
PaginatedList<Document> documents = documentService.list(page, size);
|
||||
List<Document> documents = documentService.list(page, size);
|
||||
return Response.ok(documents).build();
|
||||
}
|
||||
|
||||
@@ -448,12 +448,15 @@ public class GenericExceptionMapper implements ExceptionMapper<Exception> {
|
||||
## CompletableFuture异步操作
|
||||
|
||||
```java
|
||||
@Slf4j
|
||||
@ApplicationScoped
|
||||
@RequiredArgsConstructor
|
||||
public class FileStorageService {
|
||||
private final S3Client s3Client;
|
||||
private final ExecutorService executorService;
|
||||
|
||||
@ConfigProperty(name = "storage.bucket-name") String bucketName;
|
||||
|
||||
public CompletableFuture<StoredDocumentInfo> uploadOriginalFile(
|
||||
InputStream inputStream,
|
||||
long size,
|
||||
|
||||
@@ -343,7 +343,7 @@ public class DocumentResource {
|
||||
public Response list(
|
||||
@QueryParam("page") @DefaultValue("0") int page,
|
||||
@QueryParam("size") @DefaultValue("20") int size) {
|
||||
PaginatedList<Document> documents = documentService.list(page, size);
|
||||
List<Document> documents = documentService.list(page, size);
|
||||
return Response.ok(documents).build();
|
||||
}
|
||||
|
||||
@@ -477,12 +477,16 @@ public class GenericExceptionMapper implements ExceptionMapper<Exception> {
|
||||
## CompletableFuture Async Operations
|
||||
|
||||
```java
|
||||
@Slf4j
|
||||
@ApplicationScoped
|
||||
@RequiredArgsConstructor
|
||||
public class FileStorageService {
|
||||
private final S3Client s3Client;
|
||||
private final ExecutorService executorService;
|
||||
|
||||
@ConfigProperty(name = "storage.bucket-name")
|
||||
String bucketName;
|
||||
|
||||
public CompletableFuture<StoredDocumentInfo> uploadOriginalFile(
|
||||
InputStream inputStream,
|
||||
long size,
|
||||
|
||||
@@ -531,10 +531,10 @@ class FileStorageServiceTest {
|
||||
@DisplayName("Should successfully upload file and return document info")
|
||||
void givenValidFile_whenUpload_thenReturnsDocumentInfo() throws Exception {
|
||||
// ARRANGE
|
||||
when(executorService.submit(any(Callable.class))).thenAnswer(invocation -> {
|
||||
Callable<?> callable = invocation.getArgument(0);
|
||||
return CompletableFuture.completedFuture(callable.call());
|
||||
});
|
||||
doAnswer(invocation -> {
|
||||
((Runnable) invocation.getArgument(0)).run();
|
||||
return null;
|
||||
}).when(executorService).execute(any(Runnable.class));
|
||||
|
||||
when(s3Client.putObject(any(PutObjectRequest.class), any(RequestBody.class)))
|
||||
.thenReturn(PutObjectResponse.builder().build());
|
||||
@@ -558,10 +558,14 @@ class FileStorageServiceTest {
|
||||
@Test
|
||||
@DisplayName("Should handle S3 upload failure")
|
||||
void givenS3Failure_whenUpload_thenCompletableFutureFails() {
|
||||
// ARRANGE
|
||||
when(executorService.submit(any(Callable.class))).thenAnswer(invocation -> {
|
||||
return CompletableFuture.failedFuture(new StorageException("S3 unavailable"));
|
||||
});
|
||||
// ARRANGE — run synchronously so exception propagates through the future
|
||||
doAnswer(invocation -> {
|
||||
((Runnable) invocation.getArgument(0)).run();
|
||||
return null;
|
||||
}).when(executorService).execute(any(Runnable.class));
|
||||
|
||||
when(s3Client.putObject(any(PutObjectRequest.class), any(RequestBody.class)))
|
||||
.thenThrow(new StorageException("S3 unavailable"));
|
||||
|
||||
// ACT
|
||||
CompletableFuture<StoredDocumentInfo> future =
|
||||
@@ -581,11 +585,11 @@ class FileStorageServiceTest {
|
||||
// ARRANGE
|
||||
AtomicReference<LogContext> capturedContext = new AtomicReference<>();
|
||||
|
||||
when(executorService.submit(any(Callable.class))).thenAnswer(invocation -> {
|
||||
Callable<?> callable = invocation.getArgument(0);
|
||||
doAnswer(invocation -> {
|
||||
capturedContext.set(CustomLog.getCurrentContext());
|
||||
return CompletableFuture.completedFuture(callable.call());
|
||||
});
|
||||
((Runnable) invocation.getArgument(0)).run();
|
||||
return null;
|
||||
}).when(executorService).execute(any(Runnable.class));
|
||||
|
||||
// ACT
|
||||
fileStorageService.uploadOriginalFile(testInputStream, 1024L,
|
||||
|
||||
Reference in New Issue
Block a user