fix npe with gs uri having underscores (#14107)

* fix npe with gs uri having underscores

* compile fix
This commit is contained in:
Parag Jain 2023-04-19 11:26:18 +05:30 committed by GitHub
parent 9436ee8a63
commit e8674e2a60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 2 deletions

View File

@ -83,14 +83,14 @@ public class GoogleDataSegmentPuller implements URIDataPuller
public InputStream getInputStream(URI uri) throws IOException
{
String path = StringUtils.maybeRemoveLeadingSlash(uri.getPath());
return storage.get(uri.getHost(), path);
return storage.get(uri.getHost() != null ? uri.getHost() : uri.getAuthority(), path);
}
@Override
public String getVersion(URI uri) throws IOException
{
String path = StringUtils.maybeRemoveLeadingSlash(uri.getPath());
return storage.version(uri.getHost(), path);
return storage.version(uri.getHost() != null ? uri.getHost() : uri.getAuthority(), path);
}
@Override

View File

@ -23,6 +23,7 @@ import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.googleapis.testing.json.GoogleJsonResponseExceptionFactoryTesting;
import com.google.api.client.json.jackson2.JacksonFactory;
import org.apache.druid.java.util.common.FileUtils;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.segment.loading.SegmentLoadingException;
import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
@ -31,6 +32,8 @@ import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
public class GoogleDataSegmentPullerTest extends EasyMockSupport
{
@ -64,4 +67,38 @@ public class GoogleDataSegmentPullerTest extends EasyMockSupport
FileUtils.deleteDirectory(outDir);
}
}
@Test
public void testGetVersionBucketNameWithUnderscores() throws IOException
{
String bucket = "bucket_test";
String prefix = "prefix/";
String version = "0";
GoogleStorage storage = createMock(GoogleStorage.class);
EasyMock.expect(storage.version(EasyMock.eq(bucket), EasyMock.eq(prefix))).andReturn("0");
EasyMock.replay(storage);
GoogleDataSegmentPuller puller = new GoogleDataSegmentPuller(storage);
String actual = puller.getVersion(URI.create(StringUtils.format("gs://%s/%s", bucket, prefix)));
Assert.assertEquals(version, actual);
EasyMock.verify(storage);
}
@Test
public void testGetInputStreamBucketNameWithUnderscores() throws IOException
{
String bucket = "bucket_test";
String prefix = "prefix/";
GoogleStorage storage = createMock(GoogleStorage.class);
EasyMock.expect(storage.get(EasyMock.eq(bucket), EasyMock.eq(prefix))).andReturn(EasyMock.createMock(InputStream.class));
EasyMock.replay(storage);
GoogleDataSegmentPuller puller = new GoogleDataSegmentPuller(storage);
puller.getInputStream(URI.create(StringUtils.format("gs://%s/%s", bucket, prefix)));
EasyMock.verify(storage);
}
}