-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
processing/src/main/java/org/apache/druid/storage/local/LocalTmpStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.storage.local; | ||
|
||
import com.google.inject.Provider; | ||
import org.apache.druid.java.util.common.FileUtils; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* LocalTmpStorage is a provider for temporary directories. A default implementation is binded in all services except | ||
* Peon. For peons, a custom implementation is binded in CliPeon which uses the working directory of the peon to create | ||
* a temporary storage. This interface will be guice injectable in all services. | ||
* The cleaning up of the temporary files/directories created in this storage is handled by the caller. | ||
*/ | ||
public interface LocalTmpStorage | ||
{ | ||
/** | ||
* Get a temporary directory. | ||
* | ||
* @return a temporary directory | ||
*/ | ||
File getTmpDir(); | ||
|
||
class DefaultLocalTmpStorageProvider implements Provider<LocalTmpStorage> | ||
{ | ||
private final String prefix; | ||
|
||
public DefaultLocalTmpStorageProvider(String prefix) | ||
{ | ||
this.prefix = prefix; | ||
} | ||
|
||
@Override | ||
public LocalTmpStorage get() | ||
{ | ||
File tmpStorage = FileUtils.createTempDir(prefix); | ||
return () -> tmpStorage; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
processing/src/test/java/org/apache/druid/storage/local/LocalTmpStorageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.storage.local; | ||
|
||
import org.apache.druid.java.util.common.FileUtils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.nio.file.Paths; | ||
|
||
public class LocalTmpStorageTest | ||
{ | ||
@Test | ||
public void testDefaultLocalTmpStorage() | ||
{ | ||
LocalTmpStorage localTmpStorage = new LocalTmpStorage.DefaultLocalTmpStorageProvider("test").get(); | ||
String prefixPath = | ||
Paths.get(FileUtils.getTempDir().toAbsolutePath().toString(), "test").toAbsolutePath().toString(); | ||
if (!localTmpStorage.getTmpDir().getAbsolutePath().startsWith(prefixPath)) { | ||
Assert.fail("Temporary directory path does not start with the expected prefix"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters