Beispiel #1
0
// Creates a new bucket reader with the given context.
// Param enableStats is generally used for integration tests.
// Enabling stats in production can cause high memory usage,
// so keep that off unless you're trying to diagnose specific problems.
func NewAPTBucketReader(context *context.Context, enableStats bool) *APTBucketReader {
	reader := &APTBucketReader{
		Context:           context,
		Institutions:      make(map[string]*models.Institution),
		RecentIngestItems: make(map[string]*models.WorkItem),
		statsEnabled:      enableStats,
	}
	if enableStats {
		reader.stats = stats.NewAPTBucketReaderStats()
	}
	return reader
}
func TestNewAPTBucketReaderStats(t *testing.T) {
	_stats := stats.NewAPTBucketReaderStats()
	require.NotNil(t, _stats)
	assert.NotNil(t, _stats.InstitutionsCached)
	assert.NotNil(t, _stats.WorkItemsCached)
	assert.NotNil(t, _stats.WorkItemsFetched)
	assert.NotNil(t, _stats.WorkItemsCreated)
	assert.NotNil(t, _stats.WorkItemsQueued)
	assert.NotNil(t, _stats.WorkItemsMarkedAsQueued)
	assert.NotNil(t, _stats.S3Items)
	assert.NotNil(t, _stats.Errors)
	assert.NotNil(t, _stats.Warnings)
}
// Create a stats object with 5 of everything, no errors and no warnings.
func makeAPTBucketReaderStats() *stats.APTBucketReaderStats {
	_stats := stats.NewAPTBucketReaderStats()
	for i := 1; i <= 5; i++ {
		inst := testutil.MakeInstitution()
		inst.Identifier = fmt.Sprintf("inst_%d", i)
		_stats.AddToInstitutionsCached(inst)

		workItem := testutil.MakeWorkItem()
		workItem.Id = i
		workItem.Name = fmt.Sprintf("item_%d.tar", i)
		workItem.ETag = fmt.Sprintf("etag_%d", i)
		_stats.AddWorkItem("WorkItemsCached", workItem)
		_stats.AddWorkItem("WorkItemsFetched", workItem)
		_stats.AddWorkItem("WorkItemsCreated", workItem)
		_stats.AddWorkItem("WorkItemsQueued", workItem)
		_stats.AddWorkItem("WorkItemsMarkedAsQueued", workItem)
		_stats.AddS3Item(fmt.Sprintf("test.edu/test_item_%d", i))
	}
	return _stats
}