Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: throw io exception instead of storage exception #229

Merged
merged 2 commits into from Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -133,12 +133,12 @@ public Tuple<String, byte[]> call() {
if (result.y().length > 0 && lastEtag != null && !Objects.equals(result.x(), lastEtag)) {
StringBuilder messageBuilder = new StringBuilder();
messageBuilder.append("Blob ").append(blob).append(" was updated while reading");
throw new StorageException(0, messageBuilder.toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this will no longer be retried. Well it shouldn't be so maybe that's not an issue.

throw new IOException(messageBuilder.toString());
}
lastEtag = result.x();
buffer = result.y();
} catch (RetryHelper.RetryHelperException e) {
throw StorageException.translateAndThrow(e);
throw new IOException(e);
dmitry-fa marked this conversation as resolved.
Show resolved Hide resolved
}
if (toRead > buffer.length) {
endOfStream = true;
Expand Down
Expand Up @@ -23,6 +23,7 @@
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand Down Expand Up @@ -71,7 +72,7 @@ public void setUp() {
}

@After
public void tearDown() throws Exception {
public void tearDown() {
verify(rpcFactoryMock, storageRpcMock);
}

Expand Down Expand Up @@ -154,7 +155,7 @@ public void testClose() {
reader = new BlobReadChannel(options, BLOB_ID, EMPTY_RPC_OPTIONS);
assertTrue(reader.isOpen());
reader.close();
assertTrue(!reader.isOpen());
assertFalse(reader.isOpen());
}

@Test
Expand Down Expand Up @@ -190,7 +191,7 @@ public void testReadGenerationChanged() throws IOException {
try {
reader.read(secondReadBuffer);
fail("Expected ReadChannel read to throw StorageException");
} catch (StorageException ex) {
} catch (IOException ex) {
StringBuilder messageBuilder = new StringBuilder();
messageBuilder.append("Blob ").append(blobId).append(" was updated while reading");
assertEquals(messageBuilder.toString(), ex.getMessage());
Expand Down
Expand Up @@ -1756,22 +1756,22 @@ public void testReadChannelFail() throws IOException {
storage.reader(blob.getBlobId(), Storage.BlobSourceOption.metagenerationMatch(-1L))) {
reader.read(ByteBuffer.allocate(42));
fail("StorageException was expected");
} catch (StorageException ex) {
} catch (IOException ex) {
// expected
}
try (ReadChannel reader =
storage.reader(blob.getBlobId(), Storage.BlobSourceOption.generationMatch(-1L))) {
reader.read(ByteBuffer.allocate(42));
fail("StorageException was expected");
} catch (StorageException ex) {
} catch (IOException ex) {
// expected
}
BlobId blobIdWrongGeneration = BlobId.of(BUCKET, blobName, -1L);
try (ReadChannel reader =
storage.reader(blobIdWrongGeneration, Storage.BlobSourceOption.generationMatch())) {
reader.read(ByteBuffer.allocate(42));
fail("StorageException was expected");
} catch (StorageException ex) {
} catch (IOException ex) {
// expected
}
}
Expand Down Expand Up @@ -1803,7 +1803,7 @@ public void testReadChannelFailUpdatedGeneration() throws IOException {
readBytes = ByteBuffer.allocate(chunkSize);
reader.read(readBytes);
fail("StorageException was expected");
} catch (StorageException ex) {
} catch (IOException ex) {
StringBuilder messageBuilder = new StringBuilder();
messageBuilder.append("Blob ").append(blob.getBlobId()).append(" was updated while reading");
assertEquals(messageBuilder.toString(), ex.getMessage());
Expand Down