Search in sources :

Example 36 with DateTime

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);
}
Also used : Pattern(java.util.regex.Pattern) StorageObject(com.google.api.services.storage.model.StorageObject) URI(java.net.URI) DateTime(com.google.api.client.util.DateTime) Test(org.junit.Test)

Example 37 with DateTime

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);
}
Also used : Pattern(java.util.regex.Pattern) StorageObject(com.google.api.services.storage.model.StorageObject) URI(java.net.URI) DateTime(com.google.api.client.util.DateTime) Test(org.junit.Test)

Example 38 with DateTime

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();
}
Also used : Metadata(org.apache.beam.sdk.io.fs.MatchResult.Metadata) BigInteger(java.math.BigInteger) DateTime(com.google.api.client.util.DateTime)

Example 39 with DateTime

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();
}
Also used : FileList(com.google.api.services.drive.model.FileList) State(org.apache.gobblin.configuration.State) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MutableInt(org.apache.commons.lang.mutable.MutableInt) FileList(com.google.api.services.drive.model.FileList) ImmutableList(com.google.common.collect.ImmutableList) File(com.google.api.services.drive.model.File) DateTime(com.google.api.client.util.DateTime)

Example 40 with DateTime

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;
}
Also used : FileList(com.google.api.services.drive.model.FileList) File(com.google.api.services.drive.model.File) DateTime(com.google.api.client.util.DateTime)

Aggregations

DateTime (com.google.api.client.util.DateTime)41 Event (com.google.api.services.calendar.model.Event)13 EventDateTime (com.google.api.services.calendar.model.EventDateTime)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)10 Date (java.util.Date)9 Calendar (com.google.api.services.calendar.Calendar)8 Events (com.google.api.services.calendar.model.Events)7 File (com.google.api.services.drive.model.File)7 CalendarData (com.cloudcraftgaming.discal.api.object.calendar.CalendarData)6 SimpleDateFormat (java.text.SimpleDateFormat)6 Test (org.junit.Test)6 Map (java.util.Map)5 ParseException (java.text.ParseException)4 GuildSettings (com.cloudcraftgaming.discal.api.object.GuildSettings)3 EventData (com.cloudcraftgaming.discal.api.object.event.EventData)3 Recurrence (com.cloudcraftgaming.discal.api.object.event.Recurrence)3 WebGuild (com.cloudcraftgaming.discal.api.object.web.WebGuild)3 FileList (com.google.api.services.drive.model.FileList)3 StorageObject (com.google.api.services.storage.model.StorageObject)3