blob: 209c83c016cf9da03db61eb0eda5f28a409e575b [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COBALT_SRC_LOCAL_AGGREGATION_TEST_UTILS_TEST_EVENT_AGGREGATOR_MGR_H_
#define COBALT_SRC_LOCAL_AGGREGATION_TEST_UTILS_TEST_EVENT_AGGREGATOR_MGR_H_
#include "src/lib/util/not_null.h"
#include "src/local_aggregation/event_aggregator_mgr.h"
namespace cobalt::local_aggregation {
// Class to be used in testing to access the internal state of the tested objects.
class TestEventAggregatorManager : public EventAggregatorManager {
public:
TestEventAggregatorManager(const CobaltConfig& cfg, util::FileSystem& fs,
const logger::Encoder& encoder,
const logger::ObservationWriter* observation_writer,
MetadataBuilder& metadata_builder)
: EventAggregatorManager(cfg, fs, encoder, observation_writer, metadata_builder) {}
// Triggers an out of schedule run of GenerateObservations(). This does not change the schedule
// of future runs.
Status GenerateObservations(uint32_t day_index_utc, uint32_t day_index_local = 0u) {
return EventAggregatorManager::aggregate_store_.GenerateObservations(day_index_utc,
day_index_local);
}
// Triggers an out of schedule run of GarbageCollect(). This does not change the schedule of
// future runs.
Status GarbageCollect(uint32_t day_index_utc, uint32_t day_index_local = 0u) {
return EventAggregatorManager::aggregate_store_.GarbageCollect(day_index_utc, day_index_local);
}
// Returns the number of aggregates of type per_device_numeric_aggregates.
size_t NumPerDeviceNumericAggregatesInStore() {
size_t count = 0;
for (const auto& aggregates :
EventAggregatorManager::aggregate_store_.protected_aggregate_store_.lock()
->local_aggregate_store.by_report_key()) {
if (aggregates.second.has_numeric_aggregates()) {
count += aggregates.second.numeric_aggregates().by_component().size();
}
}
return count;
}
// Sets the EventAggregatorManager's SteadyClockInterface.
void SetSteadyClock(util::NotNullUniquePtr<util::SteadyClockInterface> clock) {
steady_clock_ = std::move(clock);
}
};
} // namespace cobalt::local_aggregation
#endif // COBALT_SRC_LOCAL_AGGREGATION_TEST_UTILS_TEST_EVENT_AGGREGATOR_MGR_H_