Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,22 @@ public long size(final String bucket, final String path) throws IOException
return blob.getSize();
}

/**
* Return the etag for an object. This is a value that changes whenever the object's data or metadata changes and is
* typically but not always the MD5 hash of the object. Ref:
* <a href="https://cloud.google.com/storage/docs/hashes-etags#etags">ETags</a>
* @param bucket
* @param path
* @return
* @throws IOException
*/
public String version(final String bucket, final String path) throws IOException
{
Blob blob = storage.get().get(bucket, path, Storage.BlobGetOption.fields(Storage.BlobField.GENERATION));
Blob blob = storage.get().get(bucket, path, Storage.BlobGetOption.fields(Storage.BlobField.ETAG));
if (blob == null) {
throw new IOE("Failed to fetch google cloud storage object from bucket [%s] and path [%s].", bucket, path);
}
return blob.getGeneratedId();
return blob.getEtag();
}

/***
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public URI getLatestVersion(URI descriptorBase, @Nullable Pattern pattern)
return latest;
}
catch (IOException e) {
throw new RuntimeException();
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,18 @@ public void testSize() throws IOException
@Test
public void testVersion() throws IOException
{
final String version = "7";
final String etag = "abcd";
EasyMock.expect(mockStorage.get(
EasyMock.eq(BUCKET),
EasyMock.eq(PATH),
EasyMock.anyObject(Storage.BlobGetOption.class)
)).andReturn(blob);

EasyMock.expect(blob.getGeneratedId()).andReturn(version);
EasyMock.expect(blob.getEtag()).andReturn(etag);

EasyMock.replay(mockStorage, blob);

assertEquals(version, googleStorage.version(BUCKET, PATH));
assertEquals(etag, googleStorage.version(BUCKET, PATH));
}

@Test
Expand Down