mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-06-11 02:33:10 +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,
|
||||
|
||||
Reference in New Issue
Block a user