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