YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rocksutil/rocksdb_encrypted_env-test.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#include <string>
15
16
#include "yb/gutil/casts.h"
17
18
#include "yb/rocksutil/rocksdb_encrypted_file_factory.h"
19
20
#include "yb/encryption/encryption_test_util.h"
21
#include "yb/encryption/header_manager.h"
22
#include "yb/encryption/header_manager_mock_impl.h"
23
24
#include "yb/util/random_util.h"
25
#include "yb/util/status.h"
26
#include "yb/util/test_util.h"
27
28
namespace yb {
29
30
constexpr uint32_t kDataSize = 1000;
31
32
class TestRocksDBEncryptedEnv : public YBTest {};
33
34
0
TEST_F(TestRocksDBEncryptedEnv, FileOps) {
35
0
  auto header_manager = encryption::GetMockHeaderManager();
36
0
  encryption::HeaderManager* hm_ptr = header_manager.get();
37
0
  auto env = yb::NewRocksDBEncryptedEnv(std::move(header_manager));
38
0
  auto fname = "test-file";
39
0
  auto bytes = RandomBytes(kDataSize);
40
0
  Slice data(bytes.data(), bytes.size());
41
42
0
  for (bool encrypted : {false, true}) {
43
0
    down_cast<encryption::HeaderManagerMockImpl*>(hm_ptr)->SetFileEncryption(encrypted);
44
45
0
    std::unique_ptr<rocksdb::WritableFile> writable_file;
46
0
    ASSERT_OK(env->NewWritableFile(fname, &writable_file, rocksdb::EnvOptions()));
47
0
    encryption::TestWrites(writable_file.get(), data);
48
49
0
    std::unique_ptr<rocksdb::RandomAccessFile> ra_file;
50
0
    ASSERT_OK(env->NewRandomAccessFile(fname, &ra_file, rocksdb::EnvOptions()));
51
0
    encryption::TestRandomAccessReads<uint8_t>(ra_file.get(), data);
52
53
0
    std::unique_ptr<rocksdb::SequentialFile> s_file;
54
0
    ASSERT_OK(env->NewSequentialFile(fname, &s_file, rocksdb::EnvOptions()));
55
0
    encryption::TestSequentialReads<uint8_t>(s_file.get(), data);
56
57
0
    ASSERT_OK(env->DeleteFile(fname));
58
0
  }
59
0
}
60
61
} // namespace yb