opentelemetry-cpp/sdk/test/metrics/metric_reader_test.cc

35 lines
1.3 KiB
C++

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#include <gtest/gtest.h>
#include <memory>
#include <utility>
#include "common.h"
#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
#include "opentelemetry/sdk/metrics/export/metric_producer.h"
#include "opentelemetry/sdk/metrics/instruments.h"
#include "opentelemetry/sdk/metrics/meter_context.h"
#include "opentelemetry/sdk/metrics/metric_reader.h"
#include "opentelemetry/sdk/metrics/state/metric_collector.h"
using namespace opentelemetry;
using namespace opentelemetry::sdk::instrumentationscope;
using namespace opentelemetry::sdk::metrics;
TEST(MetricReaderTest, BasicTests)
{
std::unique_ptr<MetricReader> metric_reader1(new MockMetricReader());
EXPECT_EQ(metric_reader1->GetAggregationTemporality(InstrumentType::kCounter),
AggregationTemporality::kCumulative);
std::shared_ptr<MeterContext> meter_context1(new MeterContext());
meter_context1->AddMetricReader(std::move(metric_reader1));
std::unique_ptr<MetricReader> metric_reader2(new MockMetricReader());
std::shared_ptr<MeterContext> meter_context2(new MeterContext());
std::shared_ptr<MetricProducer> metric_producer{
new MetricCollector(meter_context2.get(), std::move(metric_reader2))};
metric_producer->Produce();
}