use of com.google.api.client.util.DateTime in project druid by druid-io.
the class GoogleTimestampVersionedDataFinderTest method getLatestVersion.
@Test
public void getLatestVersion() {
String bucket = "bucket";
String keyPrefix = "prefix/dir/0";
// object for directory prefix/dir/0/
final StorageObject storageObject1 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "//", 0);
storageObject1.setUpdated(new DateTime(System.currentTimeMillis()));
final StorageObject storageObject2 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "/v1", 1);
storageObject2.setUpdated(new DateTime(System.currentTimeMillis()));
final StorageObject storageObject3 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "/v2", 1);
storageObject3.setUpdated(new DateTime(System.currentTimeMillis() + 100));
final StorageObject storageObject4 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "/other", 4);
storageObject4.setUpdated(new DateTime(System.currentTimeMillis() + 100));
final GoogleStorage storage = ObjectStorageIteratorTest.makeMockClient(ImmutableList.of(storageObject1, storageObject2, storageObject3, storageObject4));
final GoogleTimestampVersionedDataFinder finder = new GoogleTimestampVersionedDataFinder(storage);
Pattern pattern = Pattern.compile("v.*");
URI latest = finder.getLatestVersion(URI.create(StringUtils.format("gs://%s/%s", bucket, keyPrefix)), pattern);
URI expected = URI.create(StringUtils.format("gs://%s/%s", bucket, storageObject3.getName()));
Assert.assertEquals(expected, latest);
}
use of com.google.api.client.util.DateTime in project druid by druid-io.
the class GoogleTimestampVersionedDataFinderTest method getLatestVersionTrailingSlashKeyPrefix.
@Test
public void getLatestVersionTrailingSlashKeyPrefix() {
String bucket = "bucket";
String keyPrefix = "prefix/dir/0/";
// object for directory prefix/dir/0/
final StorageObject storageObject1 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "/", 0);
storageObject1.setUpdated(new DateTime(System.currentTimeMillis()));
final StorageObject storageObject2 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "v1", 1);
storageObject2.setUpdated(new DateTime(System.currentTimeMillis()));
final StorageObject storageObject3 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "v2", 1);
storageObject3.setUpdated(new DateTime(System.currentTimeMillis() + 100));
final StorageObject storageObject4 = ObjectStorageIteratorTest.makeStorageObject(bucket, keyPrefix + "other", 4);
storageObject4.setUpdated(new DateTime(System.currentTimeMillis() + 100));
final GoogleStorage storage = ObjectStorageIteratorTest.makeMockClient(ImmutableList.of(storageObject1, storageObject2, storageObject3, storageObject4));
final GoogleTimestampVersionedDataFinder finder = new GoogleTimestampVersionedDataFinder(storage);
Pattern pattern = Pattern.compile("v.*");
URI latest = finder.getLatestVersion(URI.create(StringUtils.format("gs://%s/%s", bucket, keyPrefix)), pattern);
URI expected = URI.create(StringUtils.format("gs://%s/%s", bucket, storageObject3.getName()));
Assert.assertEquals(expected, latest);
}
use of com.google.api.client.util.DateTime in project beam by apache.
the class GcsFileSystem method toMetadata.
private Metadata toMetadata(StorageObject storageObject) {
// TODO: Address https://issues.apache.org/jira/browse/BEAM-1494
// It is incorrect to set IsReadSeekEfficient true for files with content encoding set to gzip.
Metadata.Builder ret = Metadata.builder().setIsReadSeekEfficient(true).setResourceId(GcsResourceId.fromGcsPath(GcsPath.fromObject(storageObject)));
if (storageObject.getMd5Hash() != null) {
ret.setChecksum(storageObject.getMd5Hash());
}
BigInteger size = firstNonNull(storageObject.getSize(), BigInteger.ZERO);
ret.setSizeBytes(size.longValue());
DateTime lastModified = firstNonNull(storageObject.getUpdated(), new DateTime(0L));
ret.setLastModifiedMillis(lastModified.getValue());
return ret.build();
}
use of com.google.api.client.util.DateTime in project incubator-gobblin by apache.
the class GoogleDriveFsHelperTest method testPagination.
public void testPagination() throws IOException, FileBasedHelperException {
State state = new State();
state.appendToSetProp(GoogleDriveFileSystem.PAGE_SIZE, Integer.toString(1));
GoogleDriveFsHelper fsHelper = new GoogleDriveFsHelper(state, client, Closer.create());
List listRequest = mock(List.class);
when(files.list()).thenReturn(listRequest);
when(listRequest.setPageSize(anyInt())).thenReturn(listRequest);
when(listRequest.setFields(anyString())).thenReturn(listRequest);
when(listRequest.setQ(anyString())).thenReturn(listRequest);
when(listRequest.setPageToken(anyString())).thenReturn(listRequest);
int paginatedCalls = 5;
final MutableInt i = new MutableInt(paginatedCalls);
final File file = new File();
file.setId("testId");
file.setModifiedTime(new DateTime(System.currentTimeMillis()));
when(listRequest.execute()).thenAnswer(new Answer<FileList>() {
@Override
public FileList answer(InvocationOnMock invocation) throws Throwable {
FileList fileList = new FileList();
fileList.setFiles(ImmutableList.of(file));
if (i.intValue() > 0) {
fileList.setNextPageToken("token");
i.decrement();
}
return fileList;
}
});
fsHelper.ls("test");
int expectedCalls = 1 + paginatedCalls;
verify(listRequest, times(expectedCalls)).execute();
}
use of com.google.api.client.util.DateTime in project incubator-gobblin by apache.
the class GoogleDriveFsHelperTest method createFileList.
private FileList createFileList(java.util.List<String> fileIds, String folderId) {
FileList fileList = new FileList();
java.util.List<File> list = Lists.newArrayList();
for (String fileId : fileIds) {
File f = new File();
f.setId(fileId);
f.setModifiedTime(new DateTime(System.currentTimeMillis()));
list.add(f);
}
if (folderId != null) {
File f = new File();
f.setMimeType(FOLDER_MIME_TYPE);
f.setId(folderId);
f.setModifiedTime(new DateTime(System.currentTimeMillis()));
list.add(f);
}
fileList.setFiles(list);
return fileList;
}
Aggregations