Skip to content

Commit

Permalink
fix: throw io exception instead of storage exception (#229)
Browse files Browse the repository at this point in the history
* fix: throw io exception instead of storage exception

* fix: throw io exception instead of storage exception
  • Loading branch information
dmitry-fa committed Apr 7, 2020
1 parent 1bb5787 commit 4d42a4e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
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());
throw new IOException(messageBuilder.toString());
}
lastEtag = result.x();
buffer = result.y();
} catch (RetryHelper.RetryHelperException e) {
throw StorageException.translateAndThrow(e);
throw new IOException(e);
}
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 @@ -1751,22 +1751,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 @@ -1798,7 +1798,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

0 comments on commit 4d42a4e

Please sign in to comment.