Skip to content

Commit

Permalink
LocalDataSegmentPusher: Fix for Hadoop + relative paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
gianm committed Sep 22, 2015
1 parent 6605a60 commit 4efbe64
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
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);
}
}
}

0 comments on commit 4efbe64

Please sign in to comment.