Esempio n. 1
0
func TestComputeServicesMetrics(t *testing.T) {
	defer resetMetrics()

	instMetrics := make(map[string]data.MetricData)
	instMetrics["instance1_1"] = data.MetricData{
		BaseMetrics: map[string]float64{
			enum.METRIC_CPU_AVG.ToString(): 0.4,
			enum.METRIC_MEM_AVG.ToString(): 0.4,
		},
	}
	instMetrics["instance1_2"] = data.MetricData{
		BaseMetrics: map[string]float64{
			enum.METRIC_CPU_AVG.ToString(): 0.6,
			enum.METRIC_MEM_AVG.ToString(): 0.6,
		},
	}
	instMetrics["instance2_1"] = data.MetricData{
		BaseMetrics: map[string]float64{
			enum.METRIC_CPU_AVG.ToString(): 0.5,
			enum.METRIC_MEM_AVG.ToString(): 0.5,
		},
	}

	servicesMetrics["service1"].UserMetrics["response_time"] = []float64{1000, 2000, 3000, 4000, 5000}
	servicesMetrics["service2"].UserMetrics["response_time"] = []float64{1000, 2000, 3000, 4000, 5000}

	serviceMet := computeServicesMetrics(instMetrics)
	assert.NotEmpty(t, serviceMet)
	assert.InEpsilon(t, 0.5, serviceMet["service1"].BaseMetrics[enum.METRIC_CPU_AVG.ToString()], 0.0001)
	assert.InEpsilon(t, 0.5, serviceMet["service2"].BaseMetrics[enum.METRIC_CPU_AVG.ToString()], 0.0001)
	assert.Equal(t, 0.0, serviceMet["service3"].BaseMetrics[enum.METRIC_CPU_AVG.ToString()])
	assert.Equal(t, 0.0, serviceMet["service3"].BaseMetrics[enum.METRIC_MEM_AVG.ToString()])
	assert.Equal(t, 3000.0, serviceMet["service1"].UserMetrics["response_time"])
	assert.Equal(t, 3000.0, serviceMet["service2"].UserMetrics["response_time"])
}
Esempio n. 2
0
func TestAvailableResources(t *testing.T) {
	setResources(6, "8G", 6, "8G")
	assert.Equal(t, 0.0, AvailableResources())
	setResources(6, "8G", 4, "6G")
	assert.InEpsilon(t, 0.3, AvailableResources(), c_EPSILON)
	setResources(6, "8G", 3, "4G")
	assert.InEpsilon(t, 0.5, AvailableResources(), c_EPSILON)
	setResources(6, "8G", 2, "2G")
	assert.InEpsilon(t, 0.7, AvailableResources(), c_EPSILON)
	setResources(6, "8G", 0, "0G")
	assert.InEpsilon(t, 1.0, AvailableResources(), c_EPSILON)
}
Esempio n. 3
0
func TestComputeSysMetrics(t *testing.T) {
	defer resetMetrics()

	instMetrics := make(map[string]data.MetricData)
	instMetrics["instance1_1"] = data.MetricData{
		BaseMetrics: map[string]float64{
			enum.METRIC_CPU_AVG.ToString(): 0.4,
			enum.METRIC_MEM_AVG.ToString(): 0.4,
		},
	}
	instMetrics["instance1_2"] = data.MetricData{
		BaseMetrics: map[string]float64{
			enum.METRIC_CPU_AVG.ToString(): 0.6,
			enum.METRIC_MEM_AVG.ToString(): 0.6,
		},
	}
	instMetrics["instance2_1"] = data.MetricData{
		BaseMetrics: map[string]float64{
			enum.METRIC_CPU_AVG.ToString(): 0.8,
			enum.METRIC_MEM_AVG.ToString(): 0.8,
		},
	}

	res.CreateMockResources(4, "1G", 0, "0G")
	sysMet := computeSysMetrics(instMetrics)
	assert.NotEmpty(t, sysMet)
	assert.InEpsilon(t, 0.65, sysMet.BaseMetrics[enum.METRIC_CPU_AVG.ToString()], 0.0001)
}