Exemple #1
0
func runStorageTest(f func(test.TestStorageDriver, *testing.T), t *testing.T, bufferCount int) {
	machineName := "machineA"
	table := "cadvisor_table"
	database := "cadvisor_test"
	username := "******"
	password := "******"
	hostname := "localhost:8086"
	//percentilesDuration := 10 * time.Minute

	config := influxdb.Config{
		URL:      url.URL{Scheme: "http", Host: hostname},
		Username: username,
		Password: password,
	}
	client, err := influxdb.NewClient(config)
	if err != nil {
		t.Fatal(err)
	}

	// Re-create the database first.
	if err := prepareDatabase(client, database); err != nil {
		t.Fatal(err)
	}

	// Delete all data by the end of the call.
	//defer client.Query(influxdb.Query{Command: fmt.Sprintf("drop database \"%v\"", database)})

	driver, err := newStorage(machineName,
		table,
		database,
		username,
		password,
		hostname,
		false,
		time.Duration(bufferCount))
	if err != nil {
		t.Fatal(err)
	}
	defer driver.Close()
	testDriver := &influxDbTestStorageDriver{buffer: bufferCount}
	driver.OverrideReadyToFlush(testDriver.readyToFlush)
	testDriver.base = driver

	// Generate another container's data on same machine.
	test.StorageDriverFillRandomStatsFunc("containerOnSameMachine", 100, testDriver, t)

	// Generate another container's data on another machine.
	driverForAnotherMachine, err := newStorage("machineB",
		table,
		database,
		username,
		password,
		hostname,
		false,
		time.Duration(bufferCount))
	if err != nil {
		t.Fatal(err)
	}
	defer driverForAnotherMachine.Close()
	testDriverOtherMachine := &influxDbTestStorageDriver{buffer: bufferCount}
	driverForAnotherMachine.OverrideReadyToFlush(testDriverOtherMachine.readyToFlush)
	testDriverOtherMachine.base = driverForAnotherMachine

	test.StorageDriverFillRandomStatsFunc("containerOnAnotherMachine", 100, testDriverOtherMachine, t)
	f(testDriver, t)
}
Exemple #2
0
func runStorageTest(f func(test.TestStorageDriver, *testing.T), t *testing.T) {
	machineName := "machineA"
	tablename := "t"
	database := "cadvisor"
	username := "******"
	password := "******"
	hostname := "localhost:8086"
	percentilesDuration := 10 * time.Minute
	rootConfig := &influxdb.ClientConfig{
		Host:     hostname,
		Username: username,
		Password: password,
		IsSecure: false,
	}
	rootClient, err := influxdb.NewClient(rootConfig)
	if err != nil {
		t.Fatal(err)
	}
	// create the data base first.
	rootClient.CreateDatabase(database)
	config := &influxdb.ClientConfig{
		Host:     hostname,
		Username: username,
		Password: password,
		Database: database,
		IsSecure: false,
	}
	client, err := influxdb.NewClient(config)
	if err != nil {
		t.Fatal(err)
	}
	client.DisableCompression()
	deleteAll := fmt.Sprintf("drop series %v", tablename)
	_, err = client.Query(deleteAll)
	if err != nil {
		t.Fatal(err)
	}
	// delete all data by the end of the call
	defer client.Query(deleteAll)

	driver, err := New(machineName,
		tablename,
		database,
		username,
		password,
		hostname,
		false,
		percentilesDuration)
	if err != nil {
		t.Fatal(err)
	}

	testDriver := test.TestStorageDriver{Driver: driver, StatsEq: StatsEq}
	// generate another container's data on same machine.
	test.StorageDriverFillRandomStatsFunc("containerOnSameMachine", 100, testDriver, t)

	// generate another container's data on another machine.
	driverForAnotherMachine, err := New("machineB",
		tablename,
		database,
		username,
		password,
		hostname,
		false,
		percentilesDuration)
	if err != nil {
		t.Fatal(err)
	}
	defer driverForAnotherMachine.Close()
	testDriverOtherMachine := test.TestStorageDriver{Driver: driverForAnotherMachine, StatsEq: StatsEq}
	test.StorageDriverFillRandomStatsFunc("containerOnAnotherMachine", 100, testDriverOtherMachine, t)
	f(testDriver, t)
}