Ejemplo n.º 1
0
func TestDeltaElement(t *testing.T) {
	var plc *data.Policy
	var threshold float64
	var policies []data.Policy

	targets := []string{"pippo"}
	actions := map[string][]enum.Action{
		"pippo": []enum.Action{enum.START},
	}

	policies = []data.Policy{
		data.CreateMockPolicy("p1", 0.1, targets, actions),
		data.CreateMockPolicy("p2", 0.4, targets, actions),
		data.CreateMockPolicy("p3", 0.6, targets, actions),
		data.CreateMockPolicy("p4", 0.2, targets, actions),
	}

	threshold = 0.4
	plc = deltaElement(policies, threshold)
	assert.Equal(t, "p3", plc.Name)

	threshold = 0.8
	plc = deltaElement(policies, threshold)
	assert.Equal(t, "p3", plc.Name)
}
Ejemplo n.º 2
0
func TestMakeDecision(t *testing.T) {
	var plc *data.Policy
	targets := []string{"pippo"}
	actions := map[string][]enum.Action{
		"pippo": []enum.Action{enum.START},
	}

	// ----- DUMMY ----- //

	policies := []data.Policy{
		data.CreateMockPolicy("p", 0.0, targets, actions),
		data.CreateMockPolicy("p", 0.2, targets, actions),
		data.CreateMockPolicy("p", 0.5, targets, actions),
		data.CreateMockPolicy("p", 0.8, targets, actions),
		data.CreateMockPolicy("p", 1.0, targets, actions),
	}

	New("dummy")
	plc = MakeDecision(policies)
	assert.Equal(t, plc.Weight, 1.0)
}
Ejemplo n.º 3
0
func TestUpdateMetrics(t *testing.T) {
	cfg.SetServices(service.CreateMockServices())

	updateMetrics()
	assert.Equal(t, 0.0, Metrics().Service["service1"].Stats.BaseMetrics[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, 0.0, Metrics().Service["service2"].Analytics.BaseAnalytics[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, "noaction", Metrics().Policy.Name)

	data.SaveMockStats()
	data.SaveMockAnalytics()
	data.SaveSharedCluster(data.CreateMockShared())
	plc := data.CreateMockPolicy("policy", 1.0, []string{"pippo"}, map[string][]enum.Action{})
	data.SavePolicy(plc)
	updateMetrics()
	assert.Equal(t, 0.6, Metrics().Service["service1"].Stats.BaseMetrics[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, 0.1, Metrics().Service["service2"].Analytics.BaseAnalytics[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, 0.6, metrics.Service["service1"].Shared.BaseShared[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, "policy", Metrics().Policy.Name)
}