mirror of https://github.com/apache/druid.git
Better error message when LocalDataSegmentPusher cannot create its directory.
This commit is contained in:
parent
e75c2a407d
commit
f2c271e500
|
@ -78,7 +78,9 @@ public class LocalDataSegmentPusher implements DataSegmentPusher
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
outDir.mkdirs();
|
if (!outDir.mkdirs() && !outDir.isDirectory()) {
|
||||||
|
throw new IOException(String.format("Cannot create directory[%s]", outDir));
|
||||||
|
}
|
||||||
File outFile = new File(outDir, "index.zip");
|
File outFile = new File(outDir, "index.zip");
|
||||||
log.info("Compressing files from[%s] to [%s]", dataSegmentFile, outFile);
|
log.info("Compressing files from[%s] to [%s]", dataSegmentFile, outFile);
|
||||||
long size = CompressionUtils.zip(dataSegmentFile, outFile);
|
long size = CompressionUtils.zip(dataSegmentFile, outFile);
|
||||||
|
|
|
@ -20,35 +20,37 @@
|
||||||
package io.druid.segment.loading;
|
package io.druid.segment.loading;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Ints;
|
||||||
import io.druid.timeline.DataSegment;
|
import io.druid.timeline.DataSegment;
|
||||||
import io.druid.timeline.partition.NoneShardSpec;
|
import io.druid.timeline.partition.NoneShardSpec;
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.joda.time.Interval;
|
import org.joda.time.Interval;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class LocalDataSegmentPusherTest
|
public class LocalDataSegmentPusherTest
|
||||||
{
|
{
|
||||||
DataSegment dataSegment;
|
@Rule
|
||||||
LocalDataSegmentPusher localDataSegmentPusher;
|
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
File dataSegmentFiles;
|
|
||||||
File outDir;
|
|
||||||
|
|
||||||
@Before
|
@Rule
|
||||||
public void setUp() throws IOException
|
public ExpectedException exception = ExpectedException.none();
|
||||||
{
|
|
||||||
dataSegment = new DataSegment(
|
LocalDataSegmentPusher localDataSegmentPusher;
|
||||||
"",
|
LocalDataSegmentPusherConfig config;
|
||||||
|
File dataSegmentFiles;
|
||||||
|
DataSegment dataSegment = new DataSegment(
|
||||||
|
"ds",
|
||||||
new Interval(0, 1),
|
new Interval(0, 1),
|
||||||
"",
|
"v1",
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
@ -56,26 +58,42 @@ public class LocalDataSegmentPusherTest
|
||||||
null,
|
null,
|
||||||
-1
|
-1
|
||||||
);
|
);
|
||||||
localDataSegmentPusher = new LocalDataSegmentPusher(new LocalDataSegmentPusherConfig(), new ObjectMapper());
|
|
||||||
dataSegmentFiles = Files.createTempDir();
|
|
||||||
ByteStreams.write(
|
|
||||||
Ints.toByteArray(0x9),
|
|
||||||
Files.newOutputStreamSupplier(new File(dataSegmentFiles, "version.bin"))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws IOException
|
||||||
|
{
|
||||||
|
config = new LocalDataSegmentPusherConfig();
|
||||||
|
config.storageDirectory = temporaryFolder.newFolder();
|
||||||
|
localDataSegmentPusher = new LocalDataSegmentPusher(config, new ObjectMapper());
|
||||||
|
dataSegmentFiles = temporaryFolder.newFolder();
|
||||||
|
Files.asByteSink(new File(dataSegmentFiles, "version.bin")).write(Ints.toByteArray(0x9));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPush() throws IOException
|
public void testPush() throws IOException
|
||||||
{
|
{
|
||||||
/* DataSegment segment - Used to create LoadSpec and Create outDir (Local Deep Storage location in this case)
|
/* DataSegment - Used to create LoadSpec and Create outDir (Local Deep Storage location in this case)
|
||||||
File dataSegmentFile - Used to get location of segment files like version.bin, meta.smoosh and xxxxx.smoosh
|
File dataSegmentFile - Used to get location of segment files like version.bin, meta.smoosh and xxxxx.smoosh
|
||||||
*/
|
*/
|
||||||
DataSegment returnSegment = localDataSegmentPusher.push(dataSegmentFiles, dataSegment);
|
final DataSegment dataSegment2 = dataSegment.withVersion("v2");
|
||||||
Assert.assertNotNull(returnSegment);
|
|
||||||
Assert.assertEquals(dataSegment, returnSegment);
|
DataSegment returnSegment1 = localDataSegmentPusher.push(dataSegmentFiles, dataSegment);
|
||||||
outDir = new File(
|
DataSegment returnSegment2 = localDataSegmentPusher.push(dataSegmentFiles, dataSegment2);
|
||||||
new LocalDataSegmentPusherConfig().getStorageDirectory(),
|
|
||||||
|
Assert.assertNotNull(returnSegment1);
|
||||||
|
Assert.assertEquals(dataSegment, returnSegment1);
|
||||||
|
|
||||||
|
Assert.assertNotNull(returnSegment2);
|
||||||
|
Assert.assertEquals(dataSegment2, returnSegment2);
|
||||||
|
|
||||||
|
Assert.assertNotEquals(
|
||||||
|
DataSegmentPusherUtil.getStorageDir(dataSegment),
|
||||||
|
DataSegmentPusherUtil.getStorageDir(dataSegment2)
|
||||||
|
);
|
||||||
|
|
||||||
|
for (DataSegment returnSegment : ImmutableList.of(returnSegment1, returnSegment2)) {
|
||||||
|
File outDir = new File(
|
||||||
|
config.getStorageDirectory(),
|
||||||
DataSegmentPusherUtil.getStorageDir(returnSegment)
|
DataSegmentPusherUtil.getStorageDir(returnSegment)
|
||||||
);
|
);
|
||||||
File versionFile = new File(outDir, "index.zip");
|
File versionFile = new File(outDir, "index.zip");
|
||||||
|
@ -83,11 +101,22 @@ public class LocalDataSegmentPusherTest
|
||||||
Assert.assertTrue(versionFile.exists());
|
Assert.assertTrue(versionFile.exists());
|
||||||
Assert.assertTrue(descriptorJson.exists());
|
Assert.assertTrue(descriptorJson.exists());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPushCannotCreateDirectory() throws IOException
|
||||||
|
{
|
||||||
|
exception.expect(IOException.class);
|
||||||
|
exception.expectMessage("Cannot create directory");
|
||||||
|
config.storageDirectory = new File(config.storageDirectory, "xxx");
|
||||||
|
Assert.assertTrue(config.storageDirectory.mkdir());
|
||||||
|
config.storageDirectory.setWritable(false);
|
||||||
|
localDataSegmentPusher.push(dataSegmentFiles, dataSegment);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPathForHadoopAbsolute()
|
public void testPathForHadoopAbsolute()
|
||||||
{
|
{
|
||||||
LocalDataSegmentPusherConfig config = new LocalDataSegmentPusherConfig();
|
|
||||||
config.storageDirectory = new File("/druid");
|
config.storageDirectory = new File("/druid");
|
||||||
|
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
|
@ -99,7 +128,6 @@ public class LocalDataSegmentPusherTest
|
||||||
@Test
|
@Test
|
||||||
public void testPathForHadoopRelative()
|
public void testPathForHadoopRelative()
|
||||||
{
|
{
|
||||||
LocalDataSegmentPusherConfig config = new LocalDataSegmentPusherConfig();
|
|
||||||
config.storageDirectory = new File("druid");
|
config.storageDirectory = new File("druid");
|
||||||
|
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
|
@ -107,14 +135,4 @@ public class LocalDataSegmentPusherTest
|
||||||
new LocalDataSegmentPusher(config, new ObjectMapper()).getPathForHadoop("foo")
|
new LocalDataSegmentPusher(config, new ObjectMapper()).getPathForHadoop("foo")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() throws IOException
|
|
||||||
{
|
|
||||||
FileUtils.deleteDirectory(dataSegmentFiles);
|
|
||||||
|
|
||||||
if (outDir != null) {
|
|
||||||
FileUtils.deleteDirectory(outDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue