Beispiel #1
0
func TestNoExportInTime(t *testing.T) {
	timeout := 3 * time.Second

	sink1 := util.NewDummySink("s1", 30*time.Second)
	sink2 := util.NewDummySink("s2", 30*time.Second)
	manager, _ := NewDataSinkManager([]core.DataSink{sink1, sink2}, timeout, timeout)

	now := time.Now()
	batch := core.DataBatch{
		Timestamp:  now,
		MetricSets: map[string]*core.MetricSet{},
	}

	manager.ExportData(&batch)
	manager.ExportData(&batch)
	manager.ExportData(&batch)

	elapsed := time.Now().Sub(now)
	if elapsed > 2*timeout+2*time.Second {
		t.Fatalf("3xExportData took too long: %s", elapsed)
	}
	if elapsed < 2*timeout-1*time.Second {
		t.Fatalf("3xExportData took too short: %s", elapsed)
	}

	time.Sleep(time.Second)
	assert.Equal(t, 1, sink1.GetExportCount())
	assert.Equal(t, 1, sink2.GetExportCount())
}
Beispiel #2
0
func TestStop(t *testing.T) {
	timeout := 3 * time.Second

	sink1 := util.NewDummySink("s1", 30*time.Second)
	sink2 := util.NewDummySink("s2", 30*time.Second)
	manager, _ := NewDataSinkManager([]core.DataSink{sink1, sink2}, timeout, timeout)

	now := time.Now()
	manager.Stop()
	elapsed := time.Now().Sub(now)
	if elapsed > time.Second {
		t.Fatalf("stop too long: %s", elapsed)
	}
	time.Sleep(time.Second)

	assert.Equal(t, true, sink1.IsStopped())
	assert.Equal(t, true, sink2.IsStopped())
}
Beispiel #3
0
func TestThrottling(t *testing.T) {
	source := util.NewDummyMetricsSource("src", time.Millisecond)
	sink := util.NewDummySink("sink", 4*time.Second)
	processor := util.NewDummyDataProcessor(5 * time.Millisecond)

	manager, _ := NewManager(source, []core.DataProcessor{processor}, sink, time.Second, time.Millisecond, 1)
	manager.Start()

	// 4-5 cycles
	time.Sleep(time.Millisecond * 9500)
	manager.Stop()

	if sink.GetExportCount() < 2 || sink.GetExportCount() > 3 {
		t.Fatalf("Wrong number of exports executed: %d", sink.GetExportCount())
	}
}