Esempio n. 1
0
func TestPushValues(t *testing.T) {
	values := []float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0}
	var b Buffer
	var res []float64

	b = BuildBuffer(10)
	res = b.PushValues(values)
	assert.Nil(t, res)
	assert.Len(t, b.values, len(values))

	b = BuildBuffer(6)
	res = b.PushValues(values)
	assert.NotNil(t, res)
	assert.Len(t, res, len(values))
	assert.Empty(t, b.values)

	b = BuildBuffer(2)
	res = b.PushValues(values)
	assert.NotNil(t, res)
	assert.Len(t, res, len(values))
	assert.Empty(t, b.values)

	b = BuildBuffer(4)
	res = b.PushValues(values)
	assert.NotNil(t, res)
	assert.Len(t, res, b.capacity)
	assert.Len(t, b.values, len(values)-b.capacity)
}
Esempio n. 2
0
func TestDeleteAllData(t *testing.T) {
	intern := 0
	key := "test"
	data := []byte("pippo")
	var value map[string][]byte
	var err error

	//INTERNAL
	dataStore = intern
	Initialize()
	StoreData(key, data, enum.STATS)
	StoreData(key, data, enum.ANALYTICS)
	StoreData(key, data, enum.POLICIES)
	StoreData(key, data, enum.SHARED)

	err = DeleteAllData(enum.STATS)
	assert.NoError(t, err)
	value, _ = GetAllData(enum.STATS)
	assert.Empty(t, value)
	err = DeleteAllData(enum.ANALYTICS)
	assert.NoError(t, err)
	value, _ = GetAllData(enum.ANALYTICS)
	assert.Empty(t, value)
	err = DeleteAllData(enum.POLICIES)
	assert.NoError(t, err)
	value, _ = GetAllData(enum.POLICIES)
	assert.Empty(t, value)
	err = DeleteAllData(enum.SHARED)
	assert.NoError(t, err)
	value, _ = GetAllData(enum.SHARED)
	assert.Empty(t, value)
}
Esempio n. 3
0
func TestCreatePortBindings(t *testing.T) {
	service1 := "service1"
	ports1 := map[string]string{
		"50100": "50100",
	}
	service2 := "service2"
	ports2 := map[string]string{
		"50200": "50200",
	}
	service3 := "service3"
	resources.InitializeServiceAvailablePorts(service1, ports1)
	resources.InitializeServiceAvailablePorts(service2, ports2)

	bindings1 := createPortBindings(service1)
	assert.Len(t, bindings1, 1)
	assert.NotEmpty(t, bindings1["50100/tcp"])
	assert.Equal(t, "50100", bindings1["50100/tcp"][0].HostPort)

	bindings2 := createPortBindings(service2)
	assert.Len(t, bindings2, 1)
	assert.NotEmpty(t, bindings2["50200/tcp"])
	assert.Equal(t, "50200", bindings2["50200/tcp"][0].HostPort)

	bindings3 := createPortBindings(service3)
	assert.Empty(t, bindings3)
}
Esempio n. 4
0
func TestRequestPortsForService(t *testing.T) {
	defer clearServicePorts()
	var err error
	createServicePorts()
	service := "pippo"
	port1 := "50100"
	port2 := "50200"

	result, err := RequestPortsForService(service)
	assert.NoError(t, err)
	assert.Len(t, result, 2)
	assert.Len(t, resources.Network.ServicePorts[service].LastRequested, 2)
	available1 := resources.Network.ServicePorts[service].Status[port1].Available
	occupied1 := resources.Network.ServicePorts[service].Status[port1].Occupied
	assert.Len(t, available1, 4)
	assert.Len(t, occupied1, 0)
	available2 := resources.Network.ServicePorts[service].Status[port2].Available
	occupied2 := resources.Network.ServicePorts[service].Status[port2].Occupied
	assert.Len(t, available2, 2)
	assert.Len(t, occupied2, 0)

	ports := resources.Network.ServicePorts[service]
	status := ports.Status[port1]
	status.Available = []string{}
	ports.Status[port1] = status
	resources.Network.ServicePorts[service] = ports
	_, err = RequestPortsForService(service)
	assert.Error(t, err)
	assert.Empty(t, resources.Network.ServicePorts[service].LastRequested)
}
Esempio n. 5
0
func TestRemoveValues(t *testing.T) {
	b := BuildBuffer(10)
	values := []float64{1, 2, 3}
	b.values = append(b.values, values...)
	res := b.RemoveValues()
	assert.Len(t, res, len(values))
	assert.Empty(t, b.values)
}
Esempio n. 6
0
func TestClear(t *testing.T) {
	b := BuildBuffer(5)
	values := []float64{1, 2, 3, 4, 5}
	b.values = append(b.values, values...)

	b.Clear()
	assert.Empty(t, b.values)
}
Esempio n. 7
0
func TestRemoveInstance(t *testing.T) {
	id := "id1"
	instancesMetrics[id] = Metric{
		BaseMetrics: make(map[string][]float64),
	}

	RemoveInstance(id)
	assert.Empty(t, instancesMetrics)
}
Esempio n. 8
0
func TestResetMetrics(t *testing.T) {
	id := "id1"
	defer delete(instancesMetrics, id)

	instancesMetrics[id] = Metric{
		BaseMetrics: make(map[string][]float64),
	}
	instancesMetrics[id].BaseMetrics[enum.METRIC_CPU_INST.ToString()] = []float64{10000, 20000, 30000, 40000, 50000, 60000}
	instancesMetrics[id].BaseMetrics[enum.METRIC_CPU_SYS.ToString()] = []float64{1000000, 1100000, 1200000, 1300000, 1400000, 1500000}
	servicesMetrics["service1"].UserMetrics["response_time"] = []float64{1000, 2000, 3000, 4000, 5000}
	servicesMetrics["service2"].UserMetrics["response_time"] = []float64{1000, 2000, 3000, 4000, 5000}

	resetMetrics()
	assert.Len(t, servicesMetrics, len(srv.List()))
	assert.Empty(t, servicesMetrics["service1"].UserMetrics["response_time"])
	assert.Empty(t, servicesMetrics["service2"].UserMetrics["response_time"])
	assert.Empty(t, servicesMetrics["service3"].UserMetrics["response_time"])
	assert.Len(t, instancesMetrics, 1)
	assert.Empty(t, instancesMetrics[id].BaseMetrics[enum.METRIC_CPU_INST.ToString()])
	assert.Empty(t, instancesMetrics[id].BaseMetrics[enum.METRIC_CPU_SYS.ToString()])

}
Esempio n. 9
0
func TestInitializeServiceAvailablePorts(t *testing.T) {
	defer clearServicePorts()

	service1 := "service1"
	ports1 := map[string]string{
		"50100": "50100-50103",
	}
	InitializeServiceAvailablePorts(service1, ports1)
	servicePorts1 := resources.Network.ServicePorts[service1]
	assert.NotNil(t, servicePorts1)
	status1 := servicePorts1.Status["50100"]
	assert.NotNil(t, status1)
	assert.Empty(t, status1.Occupied)
	assert.Len(t, status1.Available, 4)

	service2 := "service2"
	ports2 := map[string]string{
		"50200": "50200",
	}
	InitializeServiceAvailablePorts(service2, ports2)
	servicePorts2 := resources.Network.ServicePorts[service2]
	assert.NotNil(t, servicePorts2)
	status2 := servicePorts2.Status["50200"]
	assert.NotNil(t, status2)
	assert.Empty(t, status2.Occupied)
	assert.Len(t, status2.Available, 1)

	service3 := "service3"
	ports3 := map[string]string{
		"50300": "pippo",
	}
	InitializeServiceAvailablePorts(service3, ports3)
	servicePorts3 := resources.Network.ServicePorts[service3]
	assert.NotNil(t, servicePorts3)
	status3 := servicePorts3.Status["50300"]
	assert.NotNil(t, status3)
	assert.Empty(t, status3.Occupied)
	assert.Empty(t, status3.Available)
}
Esempio n. 10
0
func TestPushValue(t *testing.T) {
	value := 1.0
	var b Buffer
	var res []float64

	b = BuildBuffer(10)
	res = b.PushValue(value)
	res = b.PushValue(value)
	res = b.PushValue(value)
	assert.Nil(t, res)
	assert.Len(t, b.values, 3)

	b = BuildBuffer(1)
	res = b.PushValue(value)
	assert.NotNil(t, res)
	assert.Empty(t, b.values)
}
Esempio n. 11
0
func TestCreateContainerConfig(t *testing.T) {
	defer cfg.CleanServices()
	services := service.CreateMockServices()
	cfg.SetServices(services)
	resources.CreateMockResources(2, "1G", 0, "0G")
	service1 := "service1"
	id1 := "pippo"
	availablePorts1 := map[string]string{
		"50100": "50100",
	}
	ports1 := map[string][]string{
		"50100": []string{"50100"},
	}
	resources.InitializeServiceAvailablePorts(service1, availablePorts1)
	resources.AssignSpecifiPortsToService(service1, id1, ports1)
	srv1, _ := service.GetServiceByName(service1)

	containerConfigStop := createContainerConfig(srv1, enum.STOP)
	assert.Empty(t, containerConfigStop.ExposedPorts)
	containerConfigStart := createContainerConfig(srv1, enum.START)
	assert.NotEmpty(t, containerConfigStart.ExposedPorts)
}