use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testUpdateBlobs.
@Test
public void testUpdateBlobs() {
String sourceBlobName1 = "test-update-blobs-1";
String sourceBlobName2 = "test-update-blobs-2";
BlobInfo sourceBlob1 = BlobInfo.newBuilder(BUCKET, sourceBlobName1).build();
BlobInfo sourceBlob2 = BlobInfo.newBuilder(BUCKET, sourceBlobName2).build();
Blob remoteBlob1 = storage.create(sourceBlob1);
Blob remoteBlob2 = storage.create(sourceBlob2);
assertNotNull(remoteBlob1);
assertNotNull(remoteBlob2);
List<Blob> updatedBlobs = storage.update(remoteBlob1.toBuilder().setContentType(CONTENT_TYPE).build(), remoteBlob2.toBuilder().setContentType(CONTENT_TYPE).build());
assertEquals(sourceBlob1.getBucket(), updatedBlobs.get(0).getBucket());
assertEquals(sourceBlob1.getName(), updatedBlobs.get(0).getName());
assertEquals(CONTENT_TYPE, updatedBlobs.get(0).getContentType());
assertEquals(sourceBlob2.getBucket(), updatedBlobs.get(1).getBucket());
assertEquals(sourceBlob2.getName(), updatedBlobs.get(1).getName());
assertEquals(CONTENT_TYPE, updatedBlobs.get(1).getContentType());
assertTrue(updatedBlobs.get(0).delete());
assertTrue(updatedBlobs.get(1).delete());
}
use of com.google.cloud.storage.BlobInfo in project spring-cloud-gcp by spring-cloud.
the class GcsMessageHandlerTests method testNewFiles.
@Test
public void testNewFiles() throws IOException {
File testFile = this.temporaryFolder.newFile("benfica");
BlobInfo expectedCreateBlobInfo = BlobInfo.newBuilder(BlobId.of("testGcsBucket", "benfica.writing")).build();
WriteChannel writeChannel = mock(WriteChannel.class);
willAnswer(invocationOnMock -> writeChannel).given(GCS).writer(eq(expectedCreateBlobInfo));
willAnswer(invocationOnMock -> 10).given(writeChannel).write(isA(ByteBuffer.class));
CopyWriter copyWriter = mock(CopyWriter.class);
ArgumentCaptor<Storage.CopyRequest> copyRequestCaptor = ArgumentCaptor.forClass(Storage.CopyRequest.class);
willAnswer(invocationOnMock -> copyWriter).given(GCS).copy(isA(Storage.CopyRequest.class));
willAnswer(invocationOnMock -> true).given(GCS).delete(eq(BlobId.of("testGcsBucket", "benfica.writing")));
this.channel.send(new GenericMessage<Object>(testFile));
verify(GCS, times(1)).writer(eq(expectedCreateBlobInfo));
verify(GCS, times(1)).copy(copyRequestCaptor.capture());
verify(GCS, times(1)).delete(eq(BlobId.of("testGcsBucket", "benfica.writing")));
Storage.CopyRequest expectedCopyRequest = copyRequestCaptor.getValue();
assertThat(expectedCopyRequest.getSource()).isEqualTo(BlobId.of("testGcsBucket", "benfica.writing"));
assertThat(expectedCopyRequest.getTarget().getBlobId()).isEqualTo(BlobId.of("testGcsBucket", "benfica"));
}
use of com.google.cloud.storage.BlobInfo in project flink by apache.
the class GSBlobStorageImpl method createBlob.
@Override
public void createBlob(GSBlobIdentifier blobIdentifier) {
LOGGER.trace("Creating empty blob {}", blobIdentifier);
Preconditions.checkNotNull(blobIdentifier);
BlobInfo blobInfo = BlobInfo.newBuilder(blobIdentifier.getBlobId()).build();
storage.create(blobInfo);
}
use of com.google.cloud.storage.BlobInfo in project flink by apache.
the class GSBlobStorageImpl method writeBlob.
@Override
public GSBlobStorage.WriteChannel writeBlob(GSBlobIdentifier blobIdentifier) {
LOGGER.trace("Creating writeable blob for identifier {}", blobIdentifier);
Preconditions.checkNotNull(blobIdentifier);
BlobInfo blobInfo = BlobInfo.newBuilder(blobIdentifier.getBlobId()).build();
com.google.cloud.WriteChannel writeChannel = storage.writer(blobInfo);
return new WriteChannel(blobIdentifier, writeChannel);
}
use of com.google.cloud.storage.BlobInfo in project flink by apache.
the class GSBlobStorageImpl method compose.
@Override
public void compose(List<GSBlobIdentifier> sourceBlobIdentifiers, GSBlobIdentifier targetBlobIdentifier) {
LOGGER.trace("Composing blobs {} to blob {}", sourceBlobIdentifiers, targetBlobIdentifier);
Preconditions.checkNotNull(sourceBlobIdentifiers);
Preconditions.checkArgument(sourceBlobIdentifiers.size() > 0);
Preconditions.checkArgument(sourceBlobIdentifiers.size() <= BlobUtils.COMPOSE_MAX_BLOBS);
Preconditions.checkNotNull(targetBlobIdentifier);
// build a request to compose all the source blobs into the target blob
Storage.ComposeRequest.Builder builder = Storage.ComposeRequest.newBuilder();
BlobInfo targetBlobInfo = BlobInfo.newBuilder(targetBlobIdentifier.getBlobId()).build();
builder.setTarget(targetBlobInfo);
for (GSBlobIdentifier blobIdentifier : sourceBlobIdentifiers) {
builder.addSource(blobIdentifier.objectName);
}
Storage.ComposeRequest request = builder.build();
storage.compose(request);
}
Aggregations