|
| 1 | +#include <ydb/core/config/validation/validators.h> |
| 2 | +#include <ydb/core/protos/config.pb.h> |
| 3 | +#include <ydb/core/protos/flat_scheme_op.pb.h> |
| 4 | + |
| 5 | +#include <library/cpp/testing/unittest/registar.h> |
| 6 | + |
| 7 | +#include <vector> |
| 8 | + |
| 9 | +using namespace NKikimr::NConfig; |
| 10 | + |
| 11 | +Y_UNIT_TEST_SUITE(ColumnShardConfigValidation) { |
| 12 | + Y_UNIT_TEST(AcceptDefaultCompression) { |
| 13 | + NKikimrConfig::TColumnShardConfig CSConfig; |
| 14 | + std::vector<TString> error; |
| 15 | + EValidationResult result = ValidateColumnShardConfig(CSConfig, error); |
| 16 | + UNIT_ASSERT_EQUAL(result, EValidationResult::Ok); |
| 17 | + UNIT_ASSERT_C(error.empty(), "Should not be errors"); |
| 18 | + } |
| 19 | + |
| 20 | + Y_UNIT_TEST(NotAcceptDefaultCompression) { |
| 21 | + NKikimrConfig::TColumnShardConfig CSConfig; |
| 22 | + std::vector<TString> error; |
| 23 | + CSConfig.SetDefaultCompressionLevel(2); |
| 24 | + EValidationResult result = ValidateColumnShardConfig(CSConfig, error); |
| 25 | + UNIT_ASSERT_EQUAL(result, EValidationResult::Error); |
| 26 | + UNIT_ASSERT_VALUES_EQUAL(error.size(), 1); |
| 27 | + UNIT_ASSERT_STRINGS_EQUAL(error.front(), "ColumnShardConfig: compression level is set without compression type"); |
| 28 | + } |
| 29 | + |
| 30 | + Y_UNIT_TEST(CorrectPlainCompression) { |
| 31 | + NKikimrConfig::TColumnShardConfig CSConfig; |
| 32 | + std::vector<TString> error; |
| 33 | + CSConfig.SetDefaultCompression(NKikimrSchemeOp::EColumnCodec::ColumnCodecPlain); |
| 34 | + EValidationResult result = ValidateColumnShardConfig(CSConfig, error); |
| 35 | + UNIT_ASSERT_EQUAL(result, EValidationResult::Ok); |
| 36 | + UNIT_ASSERT_C(error.empty(), "Should not be errors"); |
| 37 | + } |
| 38 | + |
| 39 | + Y_UNIT_TEST(NotCorrectPlainCompression) { |
| 40 | + NKikimrConfig::TColumnShardConfig CSConfig; |
| 41 | + std::vector<TString> error; |
| 42 | + CSConfig.SetDefaultCompression(NKikimrSchemeOp::EColumnCodec::ColumnCodecPlain); |
| 43 | + CSConfig.SetDefaultCompressionLevel(1); |
| 44 | + EValidationResult result = ValidateColumnShardConfig(CSConfig, error); |
| 45 | + UNIT_ASSERT_EQUAL(result, EValidationResult::Error); |
| 46 | + UNIT_ASSERT_VALUES_EQUAL(error.size(), 1); |
| 47 | + UNIT_ASSERT_STRINGS_EQUAL(error.front(), "ColumnShardConfig: compression `uncompressed` does not support compression level"); |
| 48 | + } |
| 49 | + |
| 50 | + Y_UNIT_TEST(CorrectLZ4Compression) { |
| 51 | + NKikimrConfig::TColumnShardConfig CSConfig; |
| 52 | + std::vector<TString> error; |
| 53 | + CSConfig.SetDefaultCompression(NKikimrSchemeOp::EColumnCodec::ColumnCodecLZ4); |
| 54 | + EValidationResult result = ValidateColumnShardConfig(CSConfig, error); |
| 55 | + UNIT_ASSERT_EQUAL(result, EValidationResult::Ok); |
| 56 | + UNIT_ASSERT_C(error.empty(), "Should not be errors"); |
| 57 | + } |
| 58 | + |
| 59 | + Y_UNIT_TEST(NotCorrectLZ4Compression) { |
| 60 | + NKikimrConfig::TColumnShardConfig CSConfig; |
| 61 | + std::vector<TString> error; |
| 62 | + CSConfig.SetDefaultCompression(NKikimrSchemeOp::EColumnCodec::ColumnCodecLZ4); |
| 63 | + CSConfig.SetDefaultCompressionLevel(1); |
| 64 | + EValidationResult result = ValidateColumnShardConfig(CSConfig, error); |
| 65 | + UNIT_ASSERT_EQUAL(result, EValidationResult::Error); |
| 66 | + UNIT_ASSERT_VALUES_EQUAL(error.size(), 1); |
| 67 | + UNIT_ASSERT_STRINGS_EQUAL(error.front(), "ColumnShardConfig: compression `lz4` does not support compression level"); |
| 68 | + } |
| 69 | + |
| 70 | + Y_UNIT_TEST(CorrectZSTDCompression) { |
| 71 | + NKikimrConfig::TColumnShardConfig CSConfig; |
| 72 | + std::vector<TString> error; |
| 73 | + CSConfig.SetDefaultCompression(NKikimrSchemeOp::EColumnCodec::ColumnCodecZSTD); |
| 74 | + EValidationResult result = ValidateColumnShardConfig(CSConfig, error); |
| 75 | + UNIT_ASSERT_EQUAL(result, EValidationResult::Ok); |
| 76 | + UNIT_ASSERT_C(error.empty(), "Should not be errors"); |
| 77 | + CSConfig.SetDefaultCompressionLevel(0); |
| 78 | + result = ValidateColumnShardConfig(CSConfig, error); |
| 79 | + UNIT_ASSERT_EQUAL(result, EValidationResult::Ok); |
| 80 | + UNIT_ASSERT_C(error.empty(), "Should not be errors"); |
| 81 | + CSConfig.SetDefaultCompressionLevel(-100); |
| 82 | + result = ValidateColumnShardConfig(CSConfig, error); |
| 83 | + UNIT_ASSERT_EQUAL(result, EValidationResult::Ok); |
| 84 | + UNIT_ASSERT_C(error.empty(), "Should not be errors"); |
| 85 | + } |
| 86 | + |
| 87 | + Y_UNIT_TEST(NotCorrectZSTDCompression) { |
| 88 | + NKikimrConfig::TColumnShardConfig CSConfig; |
| 89 | + std::vector<TString> error; |
| 90 | + CSConfig.SetDefaultCompression(NKikimrSchemeOp::EColumnCodec::ColumnCodecZSTD); |
| 91 | + CSConfig.SetDefaultCompressionLevel(100); |
| 92 | + EValidationResult result = ValidateColumnShardConfig(CSConfig, error); |
| 93 | + UNIT_ASSERT_EQUAL(result, EValidationResult::Error); |
| 94 | + UNIT_ASSERT_VALUES_EQUAL(error.size(), 1); |
| 95 | + UNIT_ASSERT_STRINGS_EQUAL(error.front(), "ColumnShardConfig: compression `zstd` does not support compression level = 100"); |
| 96 | + } |
| 97 | +} |
0 commit comments