Skip to content

Commit 2fd0e20

Browse files
committed
Merge branch 'master' into logging-label
2 parents f9f862c + 3919d63 commit 2fd0e20

File tree

20 files changed

+757
-202
lines changed

20 files changed

+757
-202
lines changed

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public abstract class JobConfiguration implements Serializable {
3636
/**
3737
* Type of a BigQuery Job.
3838
*/
39-
enum Type {
39+
public enum Type {
4040
/**
4141
* A Copy Job copies an existing table to another new or existing table. Instances of
4242
* {@code JobConfiguration} for this type are implemented by {@link CopyJobConfiguration}.

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/CopyJobConfigurationTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ public void testSetProjectId() {
118118
}
119119
}
120120

121+
@Test
122+
public void testGetType() {
123+
assertEquals(JobConfiguration.Type.COPY, COPY_JOB_CONFIGURATION.getType());
124+
assertEquals(JobConfiguration.Type.COPY, COPY_JOB_CONFIGURATION_MULTIPLE_TABLES.getType());
125+
}
126+
121127
private void compareCopyJobConfiguration(CopyJobConfiguration expected,
122128
CopyJobConfiguration value) {
123129
assertEquals(expected, value);

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ExtractJobConfigurationTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ public void testSetProjectId() {
125125
assertEquals("p", configuration.getSourceTable().getProject());
126126
}
127127

128+
@Test
129+
public void testGetType() {
130+
assertEquals(JobConfiguration.Type.EXTRACT, EXTRACT_CONFIGURATION.getType());
131+
assertEquals(JobConfiguration.Type.EXTRACT, EXTRACT_CONFIGURATION_ONE_URI.getType());
132+
}
133+
128134
private void compareExtractJobConfiguration(ExtractJobConfiguration expected,
129135
ExtractJobConfiguration value) {
130136
assertEquals(expected, value);

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/LoadJobConfigurationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ public void testSetProjectId() {
109109
assertEquals("p", configuration.getDestinationTable().getProject());
110110
}
111111

112+
@Test
113+
public void testGetType() {
114+
assertEquals(JobConfiguration.Type.LOAD, LOAD_CONFIGURATION.getType());
115+
}
116+
112117
private void compareLoadJobConfiguration(LoadJobConfiguration expected,
113118
LoadJobConfiguration value) {
114119
assertEquals(expected, value);

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryJobConfigurationTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,15 @@
1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertNotNull;
2121
import static org.junit.Assert.assertNull;
22-
import static org.junit.Assert.assertTrue;
2322

2423
import com.google.cloud.bigquery.JobInfo.CreateDisposition;
2524
import com.google.cloud.bigquery.JobInfo.WriteDisposition;
2625
import com.google.cloud.bigquery.QueryJobConfiguration.Priority;
2726
import com.google.common.collect.ImmutableList;
2827
import com.google.common.collect.ImmutableMap;
29-
30-
import org.junit.Test;
31-
3228
import java.util.List;
3329
import java.util.Map;
30+
import org.junit.Test;
3431

3532
public class QueryJobConfigurationTest {
3633

@@ -134,6 +131,11 @@ public void testSetProjectId() {
134131
assertEquals("p", configuration.getDestinationTable().getProject());
135132
}
136133

134+
@Test
135+
public void testGetType() {
136+
assertEquals(JobConfiguration.Type.QUERY, QUERY_JOB_CONFIGURATION.getType());
137+
}
138+
137139
private void compareQueryJobConfiguration(QueryJobConfiguration expected,
138140
QueryJobConfiguration value) {
139141
assertEquals(expected, value);

google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProvider.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.google.common.base.MoreObjects;
3434
import com.google.common.base.Throwables;
3535
import com.google.common.collect.AbstractIterator;
36+
import com.google.common.net.UrlEscapers;
3637
import com.google.common.primitives.Ints;
3738

3839
import java.io.BufferedInputStream;
@@ -48,6 +49,7 @@
4849
import java.nio.file.DirectoryStream.Filter;
4950
import java.nio.file.FileAlreadyExistsException;
5051
import java.nio.file.FileStore;
52+
import java.nio.file.Files;
5153
import java.nio.file.LinkOption;
5254
import java.nio.file.NoSuchFileException;
5355
import java.nio.file.OpenOption;
@@ -209,6 +211,12 @@ public CloudStoragePath getPath(URI uri) {
209211
getFileSystem(CloudStorageUtil.stripPathFromUri(uri)), uri.getPath());
210212
}
211213

214+
/** Convenience method: replaces spaces with "%20", builds a URI, and calls getPath(uri). */
215+
public CloudStoragePath getPath(String uriInStringForm) {
216+
String escaped = UrlEscapers.urlFragmentEscaper().escape(uriInStringForm);
217+
return getPath(URI.create(escaped));
218+
}
219+
212220
@Override
213221
public SeekableByteChannel newByteChannel(
214222
Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {
@@ -351,6 +359,15 @@ public boolean deleteIfExists(Path path) throws IOException {
351359
initStorage();
352360
CloudStoragePath cloudPath = CloudStorageUtil.checkPath(path);
353361
if (cloudPath.seemsLikeADirectoryAndUsePseudoDirectories()) {
362+
// if the "folder" is empty then we're fine, otherwise complain
363+
// that we cannot act on folders.
364+
try (DirectoryStream<Path> paths = Files.newDirectoryStream(path)) {
365+
if (!paths.iterator().hasNext()) {
366+
// "folder" isn't actually there in the first place, so: success!
367+
// (we must return true so delete doesn't freak out)
368+
return true;
369+
}
370+
}
354371
throw new CloudStoragePseudoDirectoryException(cloudPath);
355372
}
356373
return storage.delete(cloudPath.getBlobId());

0 commit comments

Comments
 (0)