}
}
+void
+ConfigBase::merge(const ConfigBase& other) {
+ // Merge logging info.
+ if (!other.logging_info_.empty()) {
+ logging_info_ = other.logging_info_;
+ }
+
+ // Merge the config control info
+ if (other.config_ctl_info_) {
+ if (config_ctl_info_) {
+ config_ctl_info_->merge(*other.config_ctl_info_);
+ } else {
+ config_ctl_info_ = other.config_ctl_info_;
+ }
+ }
+}
+
ElementPtr
ConfigBase::toElement() const {
ElementPtr result = Element::createMap();
/// @param other the other configuration to compare to
bool equals(const ConfigBase& other) const;
+ /// @brief Merges specified configuration into this configuration.
+ ///
+ /// This method merges logging and config control configuration into
+ /// this configuration. The new logging configuration replaces the
+ /// existing configuration if the new logging configuration is
+ /// non-empty. The new config control configuration replaces the
+ /// existing configuration if the new logging configuration is
+ /// non-null and non-empty.
+ ///
+ /// @param other the other configuration to be merged into this
+ /// configuration.
+ virtual void merge(const ConfigBase& other);
+
/// @brief Converts to Element representation
///
/// This creates a Map element with the following content (expressed
/// @brief Empties the contents of the class, including the database list
void clear();
+ /// @brief Merges specified configuration into this configuration.
+ ///
+ /// If the other configuration is non-empty it completely replaces
+ /// this configuration.
+ ///
+ /// @param other the other configuration to be merged into this
+ /// configuration.
+ void merge(const ConfigControlInfo& other);
+
/// @brief Unparse a configuration object
///
/// @return a pointer to unparsed configuration
// They should be equal again.
EXPECT_TRUE(base1.equals(base2));
}
+
+// Verifies that logging information can be merged to another.
+TEST(ConfigBase, mergeLoggingInfo) {
+ // Create first logging info.
+ LoggingInfo log_info1;
+ log_info1.name_ = "foo";
+
+ // Create second logging info.
+ LoggingInfo log_info2;
+ log_info2.name_ = "bar";
+
+ // Create first config base instance.
+ ConfigBaseImpl base1;
+ base1.addLoggingInfo(log_info1);
+
+ // Copy the first instance to keep it as reference.
+ ConfigBaseImpl base1_copy;
+ base1_copy.copy(base1);
+
+ // Create second config base instance.
+ ConfigBaseImpl base2;
+ ASSERT_NO_THROW(base1.merge(base2));
+ EXPECT_TRUE(base1.equals(base1_copy));
+
+ // Set some data for the second config.
+ base2.addLoggingInfo(log_info2);
+
+ // This time the merge should replace the original config.
+ ASSERT_NO_THROW(base1.merge(base2));
+ EXPECT_TRUE(base1.equals(base2));
+}
+
+// Verifies that config control can be merged to another.
+TEST(ConfigBase, mergeConfigControl) {
+ // Create first config control info.
+ ConfigControlInfoPtr ctl_info1(new ConfigControlInfo());
+ ctl_info1->addConfigDatabase("type=mysql host=example.com");
+ ctl_info1->addConfigDatabase("type=mysql host=example2.com");
+
+ // Create second config control info.
+ ConfigControlInfoPtr ctl_info2(new ConfigControlInfo());
+ ctl_info2->addConfigDatabase("type=pgsql host=example.com");
+ ctl_info2->addConfigDatabase("type=pgsql host=example2.com");
+
+ // Create first config base instance.
+ ConfigBaseImpl base1;
+ base1.setConfigControlInfo(ctl_info1);
+
+ // Copy the first instance to keep it as reference.
+ ConfigBaseImpl base1_copy;
+ base1_copy.copy(base1);
+
+ // Create second config base instance.
+ ConfigBaseImpl base2;
+
+ // Merged base is empty, so the original should be preserved.
+ ASSERT_NO_THROW(base1.merge(base2));
+ EXPECT_TRUE(base1.equals(base1_copy));
+
+ // Set some data for the second config.
+ base2.setConfigControlInfo(ctl_info2);
+
+ // This time the merge should replace the original config.
+ ASSERT_NO_THROW(base1.merge(base2));
+ EXPECT_TRUE(base1.equals(base2));
+}