aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/vespa/streamingvisitors/tracing/SamplingTraceExporterTest.java
blob: f143efbf78696601cd90ef2af9591bf20be609f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.streamingvisitors.tracing;

import org.junit.jupiter.api.Test;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class SamplingTraceExporterTest {

    @Test
    void sampling_decision_is_deferred_to_provided_sampler() {
        var exporter = mock(TraceExporter.class);
        var sampler = mock(SamplingStrategy.class);
        when(sampler.shouldSample()).thenReturn(true, false);
        var samplingExporter = new SamplingTraceExporter(exporter, sampler);

        samplingExporter.maybeExport(() -> new TraceDescription(null, ""));
        verify(exporter, times(1)).maybeExport(any());

        samplingExporter.maybeExport(() -> new TraceDescription(null, ""));
        verify(exporter, times(1)).maybeExport(any()); // No further invocations since last
    }

}