-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: GCS data source returns part stream failure if source blob doesn…
…'t exist (#81) * GCS data source throwing runtime exception if source blob doesn't exist - GcsDataSource.GoogleStoragePart openStream throws EdcException if the requested blob doesn't exist - GcsDataSink transferParts handles EdcException, plus minor update in log messages * chore: updated DEPENDENCIES * fix: GCS DataSource checks source blob when creating part stream, not when opening the stream * chore: updated DEPENDENCIES * refactor: removed unused catch block, minor refactor of GCS data source test - check for source blob existence has been moved to the source, sink not handling it anymore - minor refactor of test, mock doesn't need class argument when type explicit * chore: updated DEPENDENCIES * chore: updated DEPENDENCIES from gh workflow
- Loading branch information
Showing
4 changed files
with
104 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...rage/src/test/java/org/eclipse/edc/connector/dataplane/gcp/storage/GcsDataSourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2023 Google LLC | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Google LCC - Initial implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.connector.dataplane.gcp.storage; | ||
|
||
import com.google.cloud.storage.Blob; | ||
import com.google.cloud.storage.BlobId; | ||
import com.google.cloud.storage.Storage; | ||
import org.eclipse.edc.spi.monitor.Monitor; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class GcsDataSourceTest { | ||
|
||
Monitor monitor = mock(); | ||
Storage storageClient = mock(); | ||
String bucketName = "TestBucketName"; | ||
String blobName = "TestBlobName"; | ||
GcsDataSource dataSource = GcsDataSource.Builder.newInstance() | ||
.storageClient(storageClient) | ||
.monitor(monitor) | ||
.bucketName(bucketName) | ||
.blobName(blobName) | ||
.build(); | ||
|
||
BlobId blobId = BlobId.of(bucketName, blobName); | ||
|
||
|
||
@Test | ||
void openPartStream_failsIfBlobIsNull() { | ||
when(storageClient.get(blobId)) | ||
.thenReturn(null); | ||
|
||
var partStream = dataSource.openPartStream(); | ||
|
||
assertThat(partStream.failed()).isTrue(); | ||
} | ||
|
||
@Test | ||
void openPartStream_failsIfBlobDoesntExist() { | ||
var blob = mock(Blob.class); | ||
|
||
when(blob.exists()) | ||
.thenReturn(false); | ||
|
||
when(storageClient.get(blobId)) | ||
.thenReturn(blob); | ||
|
||
var partStream = dataSource.openPartStream(); | ||
|
||
assertThat(partStream.failed()).isTrue(); | ||
} | ||
|
||
@Test | ||
void openPartStream_succeedsIfBlobExists() { | ||
var blob = mock(Blob.class); | ||
|
||
when(blob.exists()) | ||
.thenReturn(true); | ||
|
||
when(storageClient.get(blobId)) | ||
.thenReturn(blob); | ||
|
||
var partStream = dataSource.openPartStream(); | ||
|
||
assertThat(partStream.succeeded()).isTrue(); | ||
} | ||
} |