1 // Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 
6 package org.rocksdb;
7 
8 import org.junit.ClassRule;
9 import org.junit.Rule;
10 import org.junit.Test;
11 import org.junit.rules.TemporaryFolder;
12 
13 import static java.nio.charset.StandardCharsets.UTF_8;
14 
15 public class HdfsEnvTest {
16 
17   @ClassRule
18   public static final RocksNativeLibraryResource ROCKS_NATIVE_LIBRARY_RESOURCE =
19       new RocksNativeLibraryResource();
20 
21   @Rule
22   public TemporaryFolder dbFolder = new TemporaryFolder();
23 
24   // expect org.rocksdb.RocksDBException: Not compiled with hdfs support
25   @Test(expected = RocksDBException.class)
construct()26   public void construct() throws RocksDBException {
27     try (final Env env = new HdfsEnv("hdfs://localhost:5000")) {
28       // no-op
29     }
30   }
31 
32   // expect org.rocksdb.RocksDBException: Not compiled with hdfs support
33   @Test(expected = RocksDBException.class)
construct_integration()34   public void construct_integration() throws RocksDBException {
35     try (final Env env = new HdfsEnv("hdfs://localhost:5000");
36          final Options options = new Options()
37              .setCreateIfMissing(true)
38              .setEnv(env);
39     ) {
40       try (final RocksDB db = RocksDB.open(options, dbFolder.getRoot().getPath())) {
41         db.put("key1".getBytes(UTF_8), "value1".getBytes(UTF_8));
42       }
43     }
44   }
45 }
46