Exemplo n.º 1
0
func (stringSetSuite) TestUninitialized(c *C) {
	var uninitialized set.Strings
	c.Assert(uninitialized.Size(), Equals, 0)
	c.Assert(uninitialized.IsEmpty(), Equals, true)
	// You can get values and sorted values from an unitialized set.
	AssertValues(c, uninitialized)
	// All contains checks are false
	c.Assert(uninitialized.Contains("foo"), Equals, false)
	// Remove works on an uninitialized Strings
	uninitialized.Remove("foo")

	var other set.Strings
	// Union returns a new set that is empty but initialized.
	c.Assert(uninitialized.Union(other), DeepEquals, set.NewStrings())
	c.Assert(uninitialized.Intersection(other), DeepEquals, set.NewStrings())
	c.Assert(uninitialized.Difference(other), DeepEquals, set.NewStrings())

	other = set.NewStrings("foo", "bar")
	c.Assert(uninitialized.Union(other), DeepEquals, other)
	c.Assert(uninitialized.Intersection(other), DeepEquals, set.NewStrings())
	c.Assert(uninitialized.Difference(other), DeepEquals, set.NewStrings())
	c.Assert(other.Union(uninitialized), DeepEquals, other)
	c.Assert(other.Intersection(uninitialized), DeepEquals, set.NewStrings())
	c.Assert(other.Difference(uninitialized), DeepEquals, other)

	// Once something is added, the set becomes initialized.
	uninitialized.Add("foo")
	AssertValues(c, uninitialized, "foo")
}
Exemplo n.º 2
0
func (w *minUnitsWatcher) merge(serviceNames *set.Strings, change watcher.Change) error {
	serviceName := change.Id.(string)
	if change.Revno == -1 {
		delete(w.known, serviceName)
		serviceNames.Remove(serviceName)
		return nil
	}
	doc := minUnitsDoc{}
	if err := w.st.minUnits.FindId(serviceName).One(&doc); err != nil {
		return err
	}
	revno, known := w.known[serviceName]
	w.known[serviceName] = doc.Revno
	if !known || doc.Revno > revno {
		serviceNames.Add(serviceName)
	}
	return nil
}