use of com.google.cloud.WriteChannel in project google-cloud-java by GoogleCloudPlatform.
the class BigQueryImplTest method testWriter.
@Test
public void testWriter() {
WriteChannelConfiguration writeChannelConfiguration = WriteChannelConfiguration.of(TABLE_ID);
EasyMock.expect(bigqueryRpcMock.open(WriteChannelConfiguration.of(TABLE_ID_WITH_PROJECT).toPb())).andReturn("upload-id");
EasyMock.replay(bigqueryRpcMock);
bigquery = options.getService();
WriteChannel channel = bigquery.writer(writeChannelConfiguration);
assertNotNull(channel);
assertTrue(channel.isOpen());
}
use of com.google.cloud.WriteChannel in project google-cloud-java by GoogleCloudPlatform.
the class StorageImplTest method testWriterWithOptions.
@Test
public void testWriterWithOptions() {
BlobInfo info = BLOB_INFO1.toBuilder().setMd5(CONTENT_MD5).setCrc32c(CONTENT_CRC32C).build();
EasyMock.expect(storageRpcMock.open(info.toPb(), BLOB_TARGET_OPTIONS_CREATE)).andReturn("upload-id");
EasyMock.replay(storageRpcMock);
initializeService();
WriteChannel channel = storage.writer(info, BLOB_WRITE_METAGENERATION, BLOB_WRITE_NOT_EXIST, BLOB_WRITE_PREDEFINED_ACL, BLOB_WRITE_CRC2C, BLOB_WRITE_MD5_HASH);
assertNotNull(channel);
assertTrue(channel.isOpen());
}
use of com.google.cloud.WriteChannel in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testReadAndWriteChannels.
@Test
public void testReadAndWriteChannels() throws IOException {
String blobName = "test-read-and-write-channels-blob";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build();
byte[] stringBytes;
try (WriteChannel writer = storage.writer(blob)) {
stringBytes = BLOB_STRING_CONTENT.getBytes(UTF_8);
writer.write(ByteBuffer.wrap(BLOB_BYTE_CONTENT));
writer.write(ByteBuffer.wrap(stringBytes));
}
ByteBuffer readBytes;
ByteBuffer readStringBytes;
try (ReadChannel reader = storage.reader(blob.getBlobId())) {
readBytes = ByteBuffer.allocate(BLOB_BYTE_CONTENT.length);
readStringBytes = ByteBuffer.allocate(stringBytes.length);
reader.read(readBytes);
reader.read(readStringBytes);
}
assertArrayEquals(BLOB_BYTE_CONTENT, readBytes.array());
assertEquals(BLOB_STRING_CONTENT, new String(readStringBytes.array(), UTF_8));
assertTrue(storage.delete(BUCKET, blobName));
}
use of com.google.cloud.WriteChannel in project google-cloud-java by GoogleCloudPlatform.
the class StorageImplTest method testWriter.
@Test
public void testWriter() {
BlobInfo.Builder infoBuilder = BLOB_INFO1.toBuilder();
BlobInfo infoWithHashes = infoBuilder.setMd5(CONTENT_MD5).setCrc32c(CONTENT_CRC32C).build();
BlobInfo infoWithoutHashes = infoBuilder.setMd5(null).setCrc32c(null).build();
EasyMock.expect(storageRpcMock.open(infoWithoutHashes.toPb(), EMPTY_RPC_OPTIONS)).andReturn("upload-id");
EasyMock.replay(storageRpcMock);
initializeService();
WriteChannel channel = storage.writer(infoWithHashes);
assertNotNull(channel);
assertTrue(channel.isOpen());
}
use of com.google.cloud.WriteChannel in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testWriteChannelFail.
@Test
public void testWriteChannelFail() throws IOException {
String blobName = "test-write-channel-blob-fail";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName, -1L).build();
try {
try (WriteChannel writer = storage.writer(blob, Storage.BlobWriteOption.generationMatch())) {
writer.write(ByteBuffer.allocate(42));
}
fail("StorageException was expected");
} catch (StorageException ex) {
// expected
}
}
Aggregations