Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LocalDataSegmentPusher: Fix for Hadoop + relative paths. #1761

Merged
merged 1 commit into from
Sep 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public LocalDataSegmentPusher(
@Override
public String getPathForHadoop(String dataSource)
{
return String.format("file://%s/%s", config.getStorageDirectory(), dataSource);
return new File(config.getStorageDirectory().getAbsoluteFile(), dataSource).toURI().toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ public class LocalDataSegmentPusherTest
@Before
public void setUp() throws IOException
{
dataSegment = new DataSegment("",
new Interval(0, 1),
"",
null,
null,
null,
new NoneShardSpec(),
null,
-1);
dataSegment = new DataSegment(
"",
new Interval(0, 1),
"",
null,
null,
null,
new NoneShardSpec(),
null,
-1
);
localDataSegmentPusher = new LocalDataSegmentPusher(new LocalDataSegmentPusherConfig(), new ObjectMapper());
dataSegmentFiles = Files.createTempDir();
ByteStreams.write(
Expand All @@ -72,16 +74,47 @@ public void testPush() throws IOException
DataSegment returnSegment = localDataSegmentPusher.push(dataSegmentFiles, dataSegment);
Assert.assertNotNull(returnSegment);
Assert.assertEquals(dataSegment, returnSegment);
outDir = new File(new LocalDataSegmentPusherConfig().getStorageDirectory(), DataSegmentPusherUtil.getStorageDir(returnSegment));
outDir = new File(
new LocalDataSegmentPusherConfig().getStorageDirectory(),
DataSegmentPusherUtil.getStorageDir(returnSegment)
);
File versionFile = new File(outDir, "index.zip");
File descriptorJson = new File(outDir, "descriptor.json");
Assert.assertTrue(versionFile.exists());
Assert.assertTrue(descriptorJson.exists());
}

@Test
public void testPathForHadoopAbsolute()
{
LocalDataSegmentPusherConfig config = new LocalDataSegmentPusherConfig();
config.storageDirectory = new File("/druid");

Assert.assertEquals(
"file:/druid/foo",
new LocalDataSegmentPusher(config, new ObjectMapper()).getPathForHadoop("foo")
);
}

@Test
public void testPathForHadoopRelative()
{
LocalDataSegmentPusherConfig config = new LocalDataSegmentPusherConfig();
config.storageDirectory = new File("druid");

Assert.assertEquals(
String.format("file:%s/druid/foo", System.getProperty("user.dir")),
new LocalDataSegmentPusher(config, new ObjectMapper()).getPathForHadoop("foo")
);
}

@After
public void tearDown() throws IOException{
public void tearDown() throws IOException
{
FileUtils.deleteDirectory(dataSegmentFiles);
FileUtils.deleteDirectory(outDir);

if (outDir != null) {
FileUtils.deleteDirectory(outDir);
}
}
}