Skip to content

Commit eca849d

Browse files
Fix ali cloud file existence check (#1807)
1 parent 2e70b8c commit eca849d

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

multiapps-controller-persistence/src/main/java/org/cloudfoundry/multiapps/controller/persistence/services/JCloudsObjectStoreFileStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public List<FileEntry> getFileEntriesWithoutContent(List<FileEntry> fileEntries)
7777

7878
@Override
7979
protected boolean existsInObjectStore(FileEntry fileEntry) {
80-
return blobStore.blobMetadata(container, fileEntry.getId()) != null;
80+
return blobStore.blobExists(container, fileEntry.getId());
8181
}
8282

8383
@Override

multiapps-controller-persistence/src/test/java/org/cloudfoundry/multiapps/controller/persistence/services/JCloudsObjectStoreFileStorageTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,17 @@
3131

3232
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
3333
import static org.junit.jupiter.api.Assertions.assertEquals;
34+
import static org.junit.jupiter.api.Assertions.assertFalse;
3435
import static org.junit.jupiter.api.Assertions.assertNull;
3536
import static org.junit.jupiter.api.Assertions.assertThrows;
3637
import static org.junit.jupiter.api.Assertions.assertTrue;
38+
import static org.mockito.ArgumentMatchers.any;
39+
import static org.mockito.ArgumentMatchers.eq;
40+
import static org.mockito.Mockito.mock;
41+
import static org.mockito.Mockito.never;
42+
import static org.mockito.Mockito.times;
43+
import static org.mockito.Mockito.verify;
44+
import static org.mockito.Mockito.when;
3745

3846
class JCloudsObjectStoreFileStorageTest {
3947

@@ -368,4 +376,47 @@ protected void assertFileExists(boolean expectedFileExist, FileEntry actualFile)
368376
assertEquals(expectedFileExist, blobExists);
369377
}
370378

379+
@Test
380+
void existsInObjectStoreWithMockedBlobStoreVerifiesBlobExistsCalled() {
381+
BlobStore mockBlobStore = mock(BlobStore.class);
382+
FileEntry fileEntry = createFileEntry();
383+
JCloudsObjectStoreFileStorage testFileStorage = new JCloudsObjectStoreFileStorage(mockBlobStore, CONTAINER);
384+
385+
when(mockBlobStore.blobExists(CONTAINER, fileEntry.getId())).thenReturn(true);
386+
387+
boolean result = testFileStorage.existsInObjectStore(fileEntry);
388+
389+
verify(mockBlobStore, times(1)).blobExists(CONTAINER, fileEntry.getId());
390+
assertTrue(result);
391+
}
392+
393+
@Test
394+
void existsInObjectStoreWithMockedBlobStoreFileNotFound() {
395+
BlobStore mockBlobStore = mock(BlobStore.class);
396+
FileEntry fileEntry = createFileEntry();
397+
JCloudsObjectStoreFileStorage testFileStorage = new JCloudsObjectStoreFileStorage(mockBlobStore, CONTAINER);
398+
399+
when(mockBlobStore.blobExists(CONTAINER, fileEntry.getId())).thenReturn(false);
400+
401+
boolean result = testFileStorage.existsInObjectStore(fileEntry);
402+
403+
verify(mockBlobStore, times(1)).blobExists(CONTAINER, fileEntry.getId());
404+
assertFalse(result);
405+
}
406+
407+
@Test
408+
void existsInObjectStoreWithMockedBlobStoreVerifiesCorrectContainer() {
409+
BlobStore mockBlobStore = mock(BlobStore.class);
410+
String testContainer = "test-container";
411+
FileEntry fileEntry = createFileEntry();
412+
JCloudsObjectStoreFileStorage testFileStorage = new JCloudsObjectStoreFileStorage(mockBlobStore, testContainer);
413+
414+
when(mockBlobStore.blobExists(testContainer, fileEntry.getId())).thenReturn(true);
415+
416+
boolean result = testFileStorage.existsInObjectStore(fileEntry);
417+
418+
verify(mockBlobStore, times(1)).blobExists(testContainer, fileEntry.getId());
419+
verify(mockBlobStore, never()).blobExists(eq("wrong-container"), any());
420+
assertTrue(result);
421+
}
371422
}

0 commit comments

Comments
 (0)