public static ICollection <ReconfigurationUtil.PropertyChange> GetChangedProperties (Configuration newConf, Configuration oldConf) { IDictionary <string, ReconfigurationUtil.PropertyChange> changes = new Dictionary < string, ReconfigurationUtil.PropertyChange>(); // iterate over old configuration foreach (KeyValuePair <string, string> oldEntry in oldConf) { string prop = oldEntry.Key; string oldVal = oldEntry.Value; string newVal = newConf.GetRaw(prop); if (newVal == null || !newVal.Equals(oldVal)) { changes[prop] = new ReconfigurationUtil.PropertyChange(prop, newVal, oldVal); } } // now iterate over new configuration // (to look for properties not present in old conf) foreach (KeyValuePair <string, string> newEntry in newConf) { string prop = newEntry.Key; string newVal = newEntry.Value; if (oldConf.Get(prop) == null) { changes[prop] = new ReconfigurationUtil.PropertyChange(prop, newVal, null); } } return(changes.Values); }
public virtual void TestAsyncReconfigure() { TestReconfiguration.AsyncReconfigurableDummy dummy = Org.Mockito.Mockito.Spy(new TestReconfiguration.AsyncReconfigurableDummy(conf1)); IList <ReconfigurationUtil.PropertyChange> changes = Lists.NewArrayList(); changes.AddItem(new ReconfigurationUtil.PropertyChange("name1", "new1", "old1")); changes.AddItem(new ReconfigurationUtil.PropertyChange("name2", "new2", "old2")); changes.AddItem(new ReconfigurationUtil.PropertyChange("name3", "new3", "old3")); Org.Mockito.Mockito.DoReturn(changes).When(dummy).GetChangedProperties(Matchers.Any <Configuration>(), Matchers.Any <Configuration>()); Org.Mockito.Mockito.DoReturn(true).When(dummy).IsPropertyReconfigurable(Matchers.Eq ("name1")); Org.Mockito.Mockito.DoReturn(false).When(dummy).IsPropertyReconfigurable(Matchers.Eq ("name2")); Org.Mockito.Mockito.DoReturn(true).When(dummy).IsPropertyReconfigurable(Matchers.Eq ("name3")); Org.Mockito.Mockito.DoNothing().When(dummy).ReconfigurePropertyImpl(Matchers.Eq("name1" ), Matchers.AnyString()); Org.Mockito.Mockito.DoNothing().When(dummy).ReconfigurePropertyImpl(Matchers.Eq("name2" ), Matchers.AnyString()); Org.Mockito.Mockito.DoThrow(new ReconfigurationException("NAME3", "NEW3", "OLD3", new IOException("io exception"))).When(dummy).ReconfigurePropertyImpl(Matchers.Eq ("name3"), Matchers.AnyString()); dummy.StartReconfigurationTask(); WaitAsyncReconfigureTaskFinish(dummy); ReconfigurationTaskStatus status = dummy.GetReconfigurationTaskStatus(); Assert.Equal(3, status.GetStatus().Count); foreach (KeyValuePair <ReconfigurationUtil.PropertyChange, Optional <string> > result in status.GetStatus()) { ReconfigurationUtil.PropertyChange change = result.Key; if (change.prop.Equals("name1")) { NUnit.Framework.Assert.IsFalse(result.Value.IsPresent()); } else { if (change.prop.Equals("name2")) { MatcherAssert.AssertThat(result.Value.Get(), CoreMatchers.ContainsString("Property name2 is not reconfigurable" )); } else { if (change.prop.Equals("name3")) { MatcherAssert.AssertThat(result.Value.Get(), CoreMatchers.ContainsString("io exception" )); } else { NUnit.Framework.Assert.Fail("Unknown property: " + change.prop); } } } } }