Beispiel #1
0
func TestSpreadPlaceContainerHuge(t *testing.T) {
	s := &SpreadPlacementStrategy{}

	nodes := []*node.Node{}
	for i := 0; i < 100; i++ {
		nodes = append(nodes, createNode(fmt.Sprintf("node-%d", i), 1, 1))
	}

	// add 100 container 1CPU
	for i := 0; i < 100; i++ {
		node := selectTopNode(t, s, createConfig(0, 1), nodes)
		assert.NoError(t, node.AddContainer(createContainer(fmt.Sprintf("c%d", i), createConfig(0, 1))))
	}

	// try to add another container 1CPU
	_, err := s.RankAndSort(createConfig(0, 1), nodes)
	assert.Error(t, err)

	// add 100 container 1G
	for i := 100; i < 200; i++ {
		node := selectTopNode(t, s, createConfig(1, 0), nodes)
		assert.NoError(t, node.AddContainer(createContainer(fmt.Sprintf("c%d", i), createConfig(1, 0))))
	}

	// try to add another container 1G
	_, err = s.RankAndSort(createConfig(1, 0), nodes)
	assert.Error(t, err)
}
Beispiel #2
0
func TestSpreadPlaceEqualWeight(t *testing.T) {
	s := &SpreadPlacementStrategy{}

	nodes := []*node.Node{}
	for i := 0; i < 2; i++ {
		nodes = append(nodes, createNode(fmt.Sprintf("node-%d", i), 4, 0))
	}

	// add 1 container 2G on node1
	config := createConfig(2, 0)
	assert.NoError(t, nodes[0].AddContainer(createContainer("c1", config)))
	assert.Equal(t, nodes[0].UsedMemory, int64(2*1024*1024*1024))

	// add 2 containers 1G on node2
	config = createConfig(1, 0)
	assert.NoError(t, nodes[1].AddContainer(createContainer("c2", config)))
	assert.NoError(t, nodes[1].AddContainer(createContainer("c3", config)))
	assert.Equal(t, nodes[1].UsedMemory, int64(2*1024*1024*1024))

	// add another container 1G
	config = createConfig(1, 0)
	node := selectTopNode(t, s, config, nodes)
	assert.NoError(t, node.AddContainer(createContainer("c4", config)))
	assert.Equal(t, node.UsedMemory, int64(3*1024*1024*1024))

	// check that the last container ended on the node with the lowest number of containers
	assert.Equal(t, node.ID, nodes[0].ID)
	assert.Equal(t, len(nodes[0].Containers), len(nodes[1].Containers))

}
Beispiel #3
0
// listNodes returns all validated engines in the cluster, excluding pendingEngines.
func (c *Cluster) listNodes() []*node.Node {
	c.RLock()
	defer c.RUnlock()

	out := make([]*node.Node, 0, len(c.engines))
	for _, e := range c.engines {
		node := node.NewNode(e)
		for _, c := range c.pendingContainers {
			if c.Engine.ID == e.ID && node.Container(c.Config.SwarmID()) == nil {
				node.AddContainer(c.ToContainer())
			}
		}
		out = append(out, node)
	}

	return out
}
Beispiel #4
0
func TestSpreadPlaceDifferentNodeSizeCPUs(t *testing.T) {
	s := &SpreadPlacementStrategy{}

	nodes := []*node.Node{
		createNode(fmt.Sprintf("node-0"), 64, 21),
		createNode(fmt.Sprintf("node-1"), 128, 42),
	}

	// add 60 containers 1CPU
	for i := 0; i < 60; i++ {
		config := createConfig(0, 1)
		node := selectTopNode(t, s, config, nodes)
		assert.NoError(t, node.AddContainer(createContainer(fmt.Sprintf("c%d", i), config)))
	}

	assert.Equal(t, len(nodes[0].Containers), 20)
	assert.Equal(t, len(nodes[1].Containers), 40)
}