2 Copyright (c) 2018-2019 Nokia.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
22 #include <gtest/gtest.h>
23 #include <gmock/gmock.h>
25 #include <boost/property_tree/ptree.hpp>
26 #include <boost/property_tree/json_parser.hpp>
27 #include "private/configurationreader.hpp"
28 #include "private/createlogger.hpp"
29 #include "private/logger.hpp"
30 #include "private/tst/databaseconfigurationmock.hpp"
31 #include "private/tst/gettopsrcdir.hpp"
32 #include "private/tst/namespaceconfigurationsmock.hpp"
33 #include "private/tst/systemmock.hpp"
35 using namespace shareddatalayer;
36 using namespace shareddatalayer::tst;
37 using namespace testing;
41 class ConfigurationReaderBaseTest: public testing::Test
44 const std::string someKnownInputSource;
45 const Directories noDirectories;
46 DatabaseConfigurationMock databaseConfigurationMock;
47 NamespaceConfigurationsMock namespaceConfigurationsMock;
48 std::unique_ptr<ConfigurationReader> configurationReader;
49 SystemMock systemMock;
50 std::shared_ptr<Logger> logger;
52 ConfigurationReaderBaseTest(std::string inputSourceName):
53 someKnownInputSource(inputSourceName),
54 logger(createLogger(SDL_LOG_PREFIX))
56 EXPECT_CALL(databaseConfigurationMock, isEmpty()).WillRepeatedly(Return(true));
57 EXPECT_CALL(namespaceConfigurationsMock, isEmpty()).WillRepeatedly(Return(true));
60 void expectDbTypeConfigurationCheckAndApply(const std::string& type)
62 EXPECT_CALL(databaseConfigurationMock, checkAndApplyDbType(type));
65 void expectGetDbTypeAndWillOnceReturn(DatabaseConfiguration::DbType type)
67 EXPECT_CALL(databaseConfigurationMock, getDbType())
68 .WillOnce(Return(type));
71 void expectDBServerAddressConfigurationCheckAndApply(const std::string& address)
73 EXPECT_CALL(databaseConfigurationMock, checkAndApplyServerAddress(address));
76 void expectSentinelAddressConfigurationCheckAndApply(const std::string& address)
78 EXPECT_CALL(databaseConfigurationMock, checkAndApplySentinelAddress(address));
81 void expectSentinelMasterNameConfigurationCheckAndApply(const std::string& address)
83 EXPECT_CALL(databaseConfigurationMock, checkAndApplySentinelMasterName(address));
86 void expectDatabaseConfigurationIsEmpty_returnFalse()
88 EXPECT_CALL(databaseConfigurationMock, isEmpty()).
89 WillOnce(Return(false));
92 void tryToReadDatabaseConfigurationToNonEmptyContainer()
94 expectDatabaseConfigurationIsEmpty_returnFalse();
95 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
98 void expectNamespaceConfigurationIsEmpty_returnFalse()
100 EXPECT_CALL(namespaceConfigurationsMock, isEmpty()).
101 WillOnce(Return(false));
104 void tryToReadNamespaceConfigurationToNonEmptyContainer()
106 expectNamespaceConfigurationIsEmpty_returnFalse();
107 configurationReader->readNamespaceConfigurations(namespaceConfigurationsMock);
110 void expectAddNamespaceConfiguration(const std::string& namespacePrefix, bool useDbBackend,
111 bool enableNotifications)
113 NamespaceConfiguration expectedNamespaceConfiguration{namespacePrefix, useDbBackend,
115 someKnownInputSource};
116 EXPECT_CALL(namespaceConfigurationsMock, addNamespaceConfiguration(expectedNamespaceConfiguration));
119 void expectGetEnvironmentString(const char* returnValue)
121 EXPECT_CALL(systemMock, getenv(_))
122 .WillOnce(Return(returnValue));
125 void initializeReaderWithoutDirectories()
127 configurationReader.reset(new ConfigurationReader(noDirectories, systemMock, logger));
130 void initializeReaderWithSDLconfigFileDirectory()
132 configurationReader.reset(new ConfigurationReader({getTopSrcDir() + "/conf"}, systemMock, logger));
136 class ConfigurationReaderSDLConfigFileTest: public ConfigurationReaderBaseTest
140 ConfigurationReaderSDLConfigFileTest():
141 ConfigurationReaderBaseTest("ConfFileFromSDLrepo")
143 expectGetEnvironmentString(nullptr);
144 initializeReaderWithSDLconfigFileDirectory();
148 class ConfigurationReaderInputStreamTest: public ConfigurationReaderBaseTest
152 ConfigurationReaderInputStreamTest():
153 ConfigurationReaderBaseTest("<istream>")
155 expectGetEnvironmentString(nullptr);
156 initializeReaderWithoutDirectories();
159 void readConfigurationAndExpectJsonParserException(const std::istringstream& is)
161 const std::string expectedError("error in SDL configuration <istream> at line 7: expected ':'");
166 configurationReader->readConfigurationFromInputStream(is);
167 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
168 configurationReader->readNamespaceConfigurations(namespaceConfigurationsMock);
170 catch (const std::exception& e)
172 EXPECT_EQ(expectedError, e.what());
178 void readConfigurationAndExpectBadValueException(const std::istringstream& is,
179 const std::string& param)
181 std::ostringstream os;
182 os << "Configuration error in " << someKnownInputSource << ": "
183 << "invalid \"" << param << "\": \"bad-value\"";
188 configurationReader->readConfigurationFromInputStream(is);
189 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
190 configurationReader->readNamespaceConfigurations(namespaceConfigurationsMock);
192 catch (const std::exception& e)
194 EXPECT_EQ(os.str(), e.what());
200 void readConfigurationAndExpectDbTypeException(const std::istringstream& is)
202 std::ostringstream os;
203 os << "Configuration error in " << someKnownInputSource << ": some error";
205 EXPECT_CALL(databaseConfigurationMock, checkAndApplyDbType(_))
206 .WillOnce(Throw(Exception("some error")));
211 configurationReader->readConfigurationFromInputStream(is);
212 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
214 catch (const std::exception& e)
216 EXPECT_EQ(os.str(), e.what());
222 void readConfigurationAndExpectAddressException(const std::istringstream& is,
223 const std::string& addressValue)
225 std::ostringstream os;
226 os << "Configuration error in " << someKnownInputSource << ": "
227 << "invalid \"address\": \"" << addressValue << "\" some error";
229 EXPECT_CALL(databaseConfigurationMock, checkAndApplyServerAddress(_))
230 .WillOnce(Throw(Exception("some error")));
235 configurationReader->readConfigurationFromInputStream(is);
236 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
238 catch (const std::exception& e)
240 EXPECT_EQ(os.str(), e.what());
246 void readConfigurationAndExpectMissingParameterException(const std::istringstream& is, const std::string& param)
248 std::ostringstream os;
249 os << "Configuration error in " << someKnownInputSource << ": "
250 << "missing \"" << param << "\"";
255 configurationReader->readConfigurationFromInputStream(is);
256 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
257 configurationReader->readNamespaceConfigurations(namespaceConfigurationsMock);
259 catch (const std::exception& e)
261 EXPECT_EQ(os.str(), e.what());
267 void readConfigurationAndExpectNamespacePrefixValidationException(const std::istringstream& is,
268 const std::string& namespacePrefix)
270 std::ostringstream os;
271 os << "Configuration error in " << someKnownInputSource << ": "
272 << "\"namespacePrefix\": \"" << namespacePrefix << "\""
273 << " contains some of these disallowed characters: ,{}";
278 configurationReader->readConfigurationFromInputStream(is);
279 configurationReader->readNamespaceConfigurations(namespaceConfigurationsMock);
281 catch (const std::exception& e)
283 EXPECT_EQ(os.str(), e.what() );
289 void readConfigurationAndExpectEnableNotificationsValidationException(const std::istringstream& is)
291 std::ostringstream os;
292 os << "Configuration error in " << someKnownInputSource << ": "
293 << "\"enableNotifications\" cannot be true, when \"useDbBackend\" is false";
298 configurationReader->readConfigurationFromInputStream(is);
299 configurationReader->readNamespaceConfigurations(namespaceConfigurationsMock);
301 catch (const std::exception& e)
303 EXPECT_EQ(os.str(), e.what() );
312 TEST_F(ConfigurationReaderInputStreamTest, CanReadJSONDatabaseConfiguration)
315 std::istringstream is(R"JSON(
319 "type": "redis-standalone",
323 "address": "someKnownDbAddress:65535"
328 expectDbTypeConfigurationCheckAndApply("redis-standalone");
329 expectDBServerAddressConfigurationCheckAndApply("someKnownDbAddress:65535");
330 configurationReader->readConfigurationFromInputStream(is);
331 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
334 TEST_F(ConfigurationReaderInputStreamTest, CanReadJSONDatabaseConfigurationWithMultipleServerAddresses)
337 std::istringstream is(R"JSON(
341 "type": "redis-cluster",
345 "address": "10.20.30.40:50000"
348 "address": "10.20.30.50:50001"
354 expectDbTypeConfigurationCheckAndApply("redis-cluster");
355 expectDBServerAddressConfigurationCheckAndApply("10.20.30.40:50000");
356 expectDBServerAddressConfigurationCheckAndApply("10.20.30.50:50001");
357 configurationReader->readConfigurationFromInputStream(is);
358 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
361 TEST_F(ConfigurationReaderInputStreamTest, CanReadJSONDatabaseConfigurationWithMultipleReadOperations)
364 std::istringstream isOne(R"JSON(
368 "type": "redis-cluster",
372 "address": "10.20.30.40:50000"
377 std::istringstream isTwo(R"JSON(
381 "type": "redis-cluster",
385 "address": "10.20.30.50:50001"
391 expectDbTypeConfigurationCheckAndApply("redis-cluster");
392 expectDBServerAddressConfigurationCheckAndApply("10.20.30.40:50000");
393 expectDbTypeConfigurationCheckAndApply("redis-cluster");
394 expectDBServerAddressConfigurationCheckAndApply("10.20.30.50:50001");
395 configurationReader->readConfigurationFromInputStream(isOne);
396 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
397 configurationReader->readConfigurationFromInputStream(isTwo);
398 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
401 TEST_F(ConfigurationReaderInputStreamTest, CanCatchAndThrowMisingMandatoryDatabaseTypeParameter)
404 std::istringstream is(R"JSON(
411 "address": "10.20.30.50:50001"
417 readConfigurationAndExpectMissingParameterException(is, "type");
420 TEST_F(ConfigurationReaderInputStreamTest, CanCatchAndThrowMisingMandatoryDatabaseServersArray)
423 std::istringstream is(R"JSON(
427 "type": "redis-standalone"
431 expectDbTypeConfigurationCheckAndApply("redis-standalone");
432 readConfigurationAndExpectMissingParameterException(is, "servers");
435 TEST_F(ConfigurationReaderInputStreamTest, CanCatchAndThrowMisingMandatoryDatabaseServerAddressParameter)
438 std::istringstream is(R"JSON(
442 "type": "redis-standalone",
451 expectDbTypeConfigurationCheckAndApply("redis-standalone");
452 readConfigurationAndExpectMissingParameterException(is, "address");
455 TEST_F(ConfigurationReaderInputStreamTest, CanCatchAndThrowDatabaseConfigurationDbTypeError)
458 std::istringstream is(R"JSON(
462 "type": "someBadType",
466 "address": "10.20.30.50:50001"
472 readConfigurationAndExpectDbTypeException(is);
475 TEST_F(ConfigurationReaderInputStreamTest, CanCatchAndThrowDatabaseConfigurationAddressError)
478 std::istringstream is(R"JSON(
482 "type": "redis-standalone",
486 "address": "someBadAddress"
492 expectDbTypeConfigurationCheckAndApply("redis-standalone");
493 readConfigurationAndExpectAddressException(is, "someBadAddress");
496 TEST_F(ConfigurationReaderInputStreamTest, CanHandleJSONWithoutAnyConfiguration)
499 std::istringstream is(R"JSON(
503 EXPECT_CALL(databaseConfigurationMock, checkAndApplyServerAddress(_))
505 EXPECT_CALL(namespaceConfigurationsMock, addNamespaceConfiguration(_))
507 configurationReader->readConfigurationFromInputStream(is);
510 TEST_F(ConfigurationReaderInputStreamTest, CanReadJSONSharedDataLayerConfiguration)
513 std::istringstream is(R"JSON(
518 "namespacePrefix": "someKnownNamespacePrefix",
519 "useDbBackend": true,
520 "enableNotifications": true
523 "namespacePrefix": "anotherKnownNamespace",
524 "useDbBackend": false,
525 "enableNotifications": false
530 expectAddNamespaceConfiguration("anotherKnownNamespace", false, false);
531 expectAddNamespaceConfiguration("someKnownNamespacePrefix", true, true);
532 configurationReader->readConfigurationFromInputStream(is);
533 configurationReader->readNamespaceConfigurations(namespaceConfigurationsMock);
536 TEST_F(ConfigurationReaderInputStreamTest, CanReadJSONSharedDataLayerConfigurationWithMultipleReadOperations)
539 std::istringstream isOne(R"JSON(
544 "namespacePrefix": "someKnownNamespacePrefix",
545 "useDbBackend": true,
546 "enableNotifications": true
551 std::istringstream isTwo(R"JSON(
556 "namespacePrefix": "anotherKnownNamespace",
557 "useDbBackend": false,
558 "enableNotifications": false
563 expectAddNamespaceConfiguration("someKnownNamespacePrefix", true, true);
564 expectAddNamespaceConfiguration("anotherKnownNamespace", false, false);
565 configurationReader->readConfigurationFromInputStream(isOne);
566 configurationReader->readNamespaceConfigurations(namespaceConfigurationsMock);
567 configurationReader->readConfigurationFromInputStream(isTwo);
568 configurationReader->readNamespaceConfigurations(namespaceConfigurationsMock);
571 TEST_F(ConfigurationReaderInputStreamTest, CanReadJSONSharedDataLayerConfigurationWithEmptyNamespacePrefixValue)
574 std::istringstream is(R"JSON(
579 "namespacePrefix": "",
580 "useDbBackend": false,
581 "enableNotifications": false
586 expectAddNamespaceConfiguration("", false, false);
587 configurationReader->readConfigurationFromInputStream(is);
588 configurationReader->readNamespaceConfigurations(namespaceConfigurationsMock);
591 TEST_F(ConfigurationReaderInputStreamTest, CanCatchAndThrowJSONSyntaxError)
594 std::istringstream is(R"JSON(
604 readConfigurationAndExpectJsonParserException(is);
607 TEST_F(ConfigurationReaderInputStreamTest, CanCatchAndThrowParameterUseDbBackendBadValue)
610 std::istringstream is(R"JSON(
615 "namespacePrefix": "someKnownNamespacePrefix",
616 "useDbBackend": "bad-value",
617 "enableNotifications": false
622 readConfigurationAndExpectBadValueException(is, "useDbBackend");
625 TEST_F(ConfigurationReaderInputStreamTest, CanCatchAndThrowParameterEnableNotificationsBadValue)
628 std::istringstream is(R"JSON(
633 "namespacePrefix": "someKnownNamespacePrefix",
634 "useDbBackend": true,
635 "enableNotifications": "bad-value"
640 readConfigurationAndExpectBadValueException(is, "enableNotifications");
643 TEST_F(ConfigurationReaderInputStreamTest, CanCatchAndThrowMisingMandatoryNamespacePrefixParameter)
646 std::istringstream is(R"JSON(
651 "useDbBackend": true,
652 "enableNotifications": true
657 readConfigurationAndExpectMissingParameterException(is, "namespacePrefix");
660 TEST_F(ConfigurationReaderInputStreamTest, CanCatchAndThrowMisingMandatoryUseDbBackendParameter)
663 std::istringstream is(R"JSON(
668 "namespacePrefix": "someKnownNamespacePrefix",
669 "enableNotifications": true
674 readConfigurationAndExpectMissingParameterException(is, "useDbBackend");
677 TEST_F(ConfigurationReaderInputStreamTest, CanCatchAndThrowMisingMandatoryEnableNotificationsParameter)
680 std::istringstream is(R"JSON(
685 "namespacePrefix": "someKnownNamespacePrefix",
691 readConfigurationAndExpectMissingParameterException(is, "enableNotifications");
694 TEST_F(ConfigurationReaderInputStreamTest, CanThrowValidationErrorForNamespacePrefixWithDisallowedCharacters)
697 std::istringstream is(R"JSON(
702 "namespacePrefix": "a,b{c}",
703 "useDbBackend": true,
704 "enableNotifications": true
709 readConfigurationAndExpectNamespacePrefixValidationException(is, "a,b{c}");
712 TEST_F(ConfigurationReaderInputStreamTest, CanThrowValidationErrorForEnableNotificationsWithNoDbBackend)
715 std::istringstream is(R"JSON(
720 "namespacePrefix": "someKnownNamespacePrefix",
721 "useDbBackend": false,
722 "enableNotifications": true
727 readConfigurationAndExpectEnableNotificationsValidationException(is);
730 TEST_F(ConfigurationReaderInputStreamTest, WillNotReadDatabaseConfigurationToNonEmptyContainer)
732 EXPECT_EXIT(tryToReadDatabaseConfigurationToNonEmptyContainer(),
733 KilledBySignal(SIGABRT), "ABORT.*configurationreader\\.cpp");
736 TEST_F(ConfigurationReaderInputStreamTest, WillNotReadNamespaceConfigurationToNonEmptyContainer)
738 EXPECT_EXIT(tryToReadNamespaceConfigurationToNonEmptyContainer(),
739 KilledBySignal(SIGABRT), "ABORT.*configurationreader\\.cpp");
742 class ConfigurationReaderEnvironmentVariableTest: public ConfigurationReaderBaseTest
745 std::string dbHostEnvVariableValue;
746 std::string dbPortEnvVariableValue;
747 std::string sentinelPortEnvVariableValue;
748 std::string sentinelMasterNameEnvVariableValue;
749 std::string dbClusterAddrListEnvVariableValue;
750 std::istringstream is{R"JSON(
754 "type": "redis-cluster",
758 "address": "10.20.30.40:50000"
761 "address": "10.20.30.50:50001"
767 ConfigurationReaderEnvironmentVariableTest():
768 ConfigurationReaderBaseTest(DB_HOST_ENV_VAR_NAME)
772 void readEnvironmentConfigurationAndExpectConfigurationErrorException(const std::string& msg,
775 std::ostringstream os;
776 os << "Configuration error in " << someKnownInputSource << ": " << msg;
779 EXPECT_CALL(databaseConfigurationMock, checkAndApplyDbType(_))
780 .WillOnce(Throw(Exception("some error")));
785 EXPECT_CALL(systemMock, getenv(_))
787 .WillOnce(Return(dbHostEnvVariableValue.c_str()))
788 .WillOnce(Return(nullptr))
789 .WillOnce(Return(nullptr))
790 .WillOnce(Return(nullptr))
791 .WillOnce(Return(nullptr));
792 initializeReaderWithoutDirectories();
793 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
795 catch (const std::exception& e)
797 EXPECT_EQ(os.str(), e.what());
804 TEST_F(ConfigurationReaderEnvironmentVariableTest, EnvironmentConfigurationCanOverrideJSONDatabaseConfiguration)
807 dbHostEnvVariableValue = "unknownAddress.local";
808 expectGetEnvironmentString(dbHostEnvVariableValue.c_str());
809 dbPortEnvVariableValue = "12345";
810 expectGetEnvironmentString(dbPortEnvVariableValue.c_str());
811 expectGetEnvironmentString(nullptr); //SENTINEL_PORT_ENV_VAR_NAME
812 expectGetEnvironmentString(nullptr); //SENTINEL_MASTER_NAME_ENV_VAR_NAME
813 expectGetEnvironmentString(nullptr); //DB_CLUSTER_ENV_VAR_NAME
815 expectDbTypeConfigurationCheckAndApply("redis-standalone");
816 expectDBServerAddressConfigurationCheckAndApply("unknownAddress.local:12345");
817 expectGetDbTypeAndWillOnceReturn(DatabaseConfiguration::DbType::REDIS_STANDALONE);
818 initializeReaderWithSDLconfigFileDirectory();
819 configurationReader->readConfigurationFromInputStream(is);
820 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
823 TEST_F(ConfigurationReaderEnvironmentVariableTest, EnvironmentConfigurationWithoutPortIsAccepted)
826 dbHostEnvVariableValue = "server.local";
827 expectGetEnvironmentString(dbHostEnvVariableValue.c_str());
828 expectGetEnvironmentString(nullptr); //DB_PORT_ENV_VAR_NAME
829 expectGetEnvironmentString(nullptr); //SENTINEL_PORT_ENV_VAR_NAME
830 expectGetEnvironmentString(nullptr); //SENTINEL_MASTER_NAME_ENV_VAR_NAME
831 expectGetEnvironmentString(nullptr); //DB_CLUSTER_ENV_VAR_NAME
833 expectDbTypeConfigurationCheckAndApply("redis-standalone");
834 expectDBServerAddressConfigurationCheckAndApply("server.local");
835 expectGetDbTypeAndWillOnceReturn(DatabaseConfiguration::DbType::REDIS_STANDALONE);
836 initializeReaderWithoutDirectories();
837 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
840 TEST_F(ConfigurationReaderEnvironmentVariableTest, EmptyEnvironmentVariableThrows)
842 dbHostEnvVariableValue = "";
843 readEnvironmentConfigurationAndExpectConfigurationErrorException("Missing environment variable configuration!",
847 TEST_F(ConfigurationReaderEnvironmentVariableTest, IllegalCharacterInEnvironmentVariableThrows)
849 dbHostEnvVariableValue = "@";
850 readEnvironmentConfigurationAndExpectConfigurationErrorException("some error", true);
853 TEST_F(ConfigurationReaderEnvironmentVariableTest, EnvironmentConfigurationAcceptIPv6Address)
856 dbHostEnvVariableValue = "[2001::123]:12345";
857 expectGetEnvironmentString(dbHostEnvVariableValue.c_str());
858 expectGetEnvironmentString(nullptr); //DB_PORT_ENV_VAR_NAME
859 expectGetEnvironmentString(nullptr); //SENTINEL_PORT_ENV_VAR_NAME
860 expectGetEnvironmentString(nullptr); //SENTINEL_MASTER_NAME_ENV_VAR_NAME
861 expectGetEnvironmentString(nullptr); //DB_CLUSTER_ENV_VAR_NAME
863 expectDbTypeConfigurationCheckAndApply("redis-standalone");
864 expectDBServerAddressConfigurationCheckAndApply("[2001::123]:12345");
865 expectGetDbTypeAndWillOnceReturn(DatabaseConfiguration::DbType::REDIS_STANDALONE);
866 initializeReaderWithoutDirectories();
867 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
870 TEST_F(ConfigurationReaderEnvironmentVariableTest, EnvironmentConfigurationWithSentinel)
873 dbHostEnvVariableValue = "sentinelAddress.local";
874 expectGetEnvironmentString(dbHostEnvVariableValue.c_str());
875 dbPortEnvVariableValue = "1111";
876 expectGetEnvironmentString(dbPortEnvVariableValue.c_str());
877 sentinelPortEnvVariableValue = "2222";
878 expectGetEnvironmentString(sentinelPortEnvVariableValue.c_str());
879 sentinelMasterNameEnvVariableValue = "mymaster";
880 expectGetEnvironmentString(sentinelMasterNameEnvVariableValue.c_str());
881 expectGetEnvironmentString(nullptr); //DB_CLUSTER_ENV_VAR_NAME
883 expectDbTypeConfigurationCheckAndApply("redis-sentinel");
884 expectDBServerAddressConfigurationCheckAndApply("sentinelAddress.local:1111");
885 expectGetDbTypeAndWillOnceReturn(DatabaseConfiguration::DbType::REDIS_SENTINEL);
886 expectSentinelAddressConfigurationCheckAndApply("sentinelAddress.local:2222");
887 expectSentinelMasterNameConfigurationCheckAndApply(sentinelMasterNameEnvVariableValue);
888 initializeReaderWithoutDirectories();
889 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
892 TEST_F(ConfigurationReaderEnvironmentVariableTest, EnvironmentConfigurationWithSentinelAndClusterConfiguration)
895 dbHostEnvVariableValue = "address-0.local";
896 expectGetEnvironmentString(dbHostEnvVariableValue.c_str());
897 expectGetEnvironmentString(nullptr); //DB_PORT_ENV_VAR_NAME
898 sentinelPortEnvVariableValue = "2222";
899 expectGetEnvironmentString(sentinelPortEnvVariableValue.c_str());
900 sentinelMasterNameEnvVariableValue = "mymaster";
901 expectGetEnvironmentString(sentinelMasterNameEnvVariableValue.c_str());
902 dbClusterAddrListEnvVariableValue = "address-0.local,address-1.local,address-2.local";
903 expectGetEnvironmentString(dbClusterAddrListEnvVariableValue.c_str());
905 expectDbTypeConfigurationCheckAndApply("sdl-sentinel-cluster");
906 expectDBServerAddressConfigurationCheckAndApply("address-0.local");
907 expectDBServerAddressConfigurationCheckAndApply("address-1.local");
908 expectDBServerAddressConfigurationCheckAndApply("address-2.local");
909 expectGetDbTypeAndWillOnceReturn(DatabaseConfiguration::DbType::SDL_SENTINEL_CLUSTER);
910 expectSentinelAddressConfigurationCheckAndApply("address-0.local:2222");
911 expectSentinelMasterNameConfigurationCheckAndApply(sentinelMasterNameEnvVariableValue);
912 initializeReaderWithoutDirectories();
913 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
916 TEST_F(ConfigurationReaderEnvironmentVariableTest, EnvironmentConfigurationWithoutSentinelAndWithClusterConfiguration)
919 dbHostEnvVariableValue = "address-0.local";
920 expectGetEnvironmentString(dbHostEnvVariableValue.c_str());
921 expectGetEnvironmentString(nullptr); //DB_PORT_ENV_VAR_NAME
922 expectGetEnvironmentString(nullptr); //SENTINEL_PORT_ENV_VAR_NAME
923 expectGetEnvironmentString(nullptr); //SENTINEL_MASTER_NAME_ENV_VAR_NAME
924 dbClusterAddrListEnvVariableValue = "address-0.local,address-1.local,address-2.local";
925 expectGetEnvironmentString(dbClusterAddrListEnvVariableValue.c_str());
927 expectDbTypeConfigurationCheckAndApply("sdl-standalone-cluster");
928 expectDBServerAddressConfigurationCheckAndApply("address-0.local");
929 expectDBServerAddressConfigurationCheckAndApply("address-1.local");
930 expectDBServerAddressConfigurationCheckAndApply("address-2.local");
931 expectGetDbTypeAndWillOnceReturn(DatabaseConfiguration::DbType::SDL_STANDALONE_CLUSTER);
932 initializeReaderWithoutDirectories();
933 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);
936 TEST_F(ConfigurationReaderEnvironmentVariableTest, EnvironmentConfigurationWithoutSentinelAndWithClusterConfigurationAndDbPort)
939 dbHostEnvVariableValue = "address-0.local";
940 expectGetEnvironmentString(dbHostEnvVariableValue.c_str());
941 dbPortEnvVariableValue = "1111";
942 expectGetEnvironmentString(dbPortEnvVariableValue.c_str());
943 expectGetEnvironmentString(nullptr); //SENTINEL_PORT_ENV_VAR_NAME
944 expectGetEnvironmentString(nullptr); //SENTINEL_MASTER_NAME_ENV_VAR_NAME
945 dbClusterAddrListEnvVariableValue = "address-0.local,address-1.local,address-2.local";
946 expectGetEnvironmentString(dbClusterAddrListEnvVariableValue.c_str());
948 expectDbTypeConfigurationCheckAndApply("sdl-standalone-cluster");
949 expectDBServerAddressConfigurationCheckAndApply("address-0.local:1111");
950 expectDBServerAddressConfigurationCheckAndApply("address-1.local:1111");
951 expectDBServerAddressConfigurationCheckAndApply("address-2.local:1111");
952 expectGetDbTypeAndWillOnceReturn(DatabaseConfiguration::DbType::SDL_STANDALONE_CLUSTER);
953 initializeReaderWithoutDirectories();
954 configurationReader->readDatabaseConfiguration(databaseConfigurationMock);