forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-16191][state backends] Improve error message on Windows when R…
…ocksDB is give a too long path.
- Loading branch information
1 parent
333e374
commit e3cbe8b
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
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
88 changes: 88 additions & 0 deletions
88
...db/src/test/java/org/apache/flink/contrib/streaming/state/RocksDBOperationsUtilsTest.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,88 @@ | ||
/* | ||
* 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:https://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.flink.contrib.streaming.state; | ||
|
||
import org.apache.flink.util.OperatingSystem; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.rocksdb.ColumnFamilyOptions; | ||
import org.rocksdb.DBOptions; | ||
import org.rocksdb.NativeLibraryLoader; | ||
import org.rocksdb.RocksDB; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.Collections; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
/** | ||
* Tests for the {@link RocksDBOperationUtils}. | ||
*/ | ||
public class RocksDBOperationsUtilsTest { | ||
|
||
@ClassRule | ||
public static final TemporaryFolder TMP_DIR = new TemporaryFolder(); | ||
|
||
@BeforeClass | ||
public static void loadRocksLibrary() throws Exception { | ||
NativeLibraryLoader.getInstance().loadLibrary(TMP_DIR.newFolder().getAbsolutePath()); | ||
} | ||
|
||
@Test | ||
public void testPathExceptionOnWindows() throws Exception { | ||
assumeTrue(OperatingSystem.isWindows()); | ||
|
||
final File folder = TMP_DIR.newFolder(); | ||
final File rocksDir = new File(folder, getLongString(247 - folder.getAbsolutePath().length())); | ||
|
||
Files.createDirectories(rocksDir.toPath()); | ||
|
||
try (DBOptions dbOptions = new DBOptions().setCreateIfMissing(true); | ||
ColumnFamilyOptions colOptions = new ColumnFamilyOptions()) { | ||
|
||
RocksDB rocks = RocksDBOperationUtils.openDB( | ||
rocksDir.getAbsolutePath(), | ||
Collections.emptyList(), | ||
Collections.emptyList(), | ||
colOptions, dbOptions); | ||
rocks.close(); | ||
|
||
// do not provoke a test failure if this passes, because some setups may actually | ||
// support long paths, in which case: great! | ||
} | ||
catch (IOException e) { | ||
assertThat(e.getMessage(), containsString("longer than the directory path length limit for Windows")); | ||
} | ||
} | ||
|
||
private static String getLongString(int numChars) { | ||
final StringBuilder builder = new StringBuilder(); | ||
for (int i = numChars; i > 0; --i) { | ||
builder.append('a'); | ||
} | ||
return builder.toString(); | ||
} | ||
} |