Search in sources :

Example 1 with BoundedList

use of org.apache.samza.diagnostics.BoundedList in project samza by apache.

the class TestMetricsSnapshotSerdeV2 method metricsSnapshot.

private static MetricsSnapshot metricsSnapshot(Exception exception, boolean includeSamzaEpochId) {
    MetricsHeader metricsHeader;
    if (includeSamzaEpochId) {
        metricsHeader = new MetricsHeader("jobName", "i001", "container 0", "test container ID", Optional.of("epoch-123"), "source", "300.14.25.1", "1", "1", 1, 1);
    } else {
        metricsHeader = new MetricsHeader("jobName", "i001", "container 0", "test container ID", "source", "300.14.25.1", "1", "1", 1, 1);
    }
    BoundedList<DiagnosticsExceptionEvent> boundedList = new BoundedList<>("exceptions");
    DiagnosticsExceptionEvent diagnosticsExceptionEvent = new DiagnosticsExceptionEvent(1, exception, new HashMap<>());
    boundedList.add(diagnosticsExceptionEvent);
    Map<String, Map<String, Object>> metricMessage = new HashMap<>();
    Map<String, Object> samzaContainerMetrics = new HashMap<>();
    samzaContainerMetrics.put("commit-calls", 1);
    metricMessage.put("org.apache.samza.container.SamzaContainerMetrics", samzaContainerMetrics);
    Map<String, Object> exceptions = new HashMap<>();
    exceptions.put("exceptions", boundedList.getValues());
    metricMessage.put("org.apache.samza.exceptions", exceptions);
    return new MetricsSnapshot(metricsHeader, new Metrics(metricMessage));
}
Also used : HashMap(java.util.HashMap) MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) MetricsHeader(org.apache.samza.metrics.reporter.MetricsHeader) Metrics(org.apache.samza.metrics.reporter.Metrics) DiagnosticsExceptionEvent(org.apache.samza.diagnostics.DiagnosticsExceptionEvent) HashMap(java.util.HashMap) Map(java.util.Map) BoundedList(org.apache.samza.diagnostics.BoundedList)

Example 2 with BoundedList

use of org.apache.samza.diagnostics.BoundedList in project samza by apache.

the class TestBoundedList method testSizeEnforcement.

@Test
public void testSizeEnforcement() {
    BoundedList boundedList = getBoundedListForTest();
    for (int i = 15; i > 0; i--) {
        boundedList.add("v" + i);
    }
    Assert.assertEquals("List sizes should be as configured at creation time", boundedList.getValues().size(), 10);
    int valueIndex = 10;
    Collection<String> currentList = boundedList.getValues();
    Iterator iterator = currentList.iterator();
    while (iterator.hasNext()) {
        String gaugeValue = (String) iterator.next();
        Assert.assertTrue(gaugeValue.equals("v" + valueIndex));
        valueIndex--;
    }
}
Also used : Iterator(java.util.Iterator) BoundedList(org.apache.samza.diagnostics.BoundedList) Test(org.junit.Test)

Aggregations

BoundedList (org.apache.samza.diagnostics.BoundedList)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 DiagnosticsExceptionEvent (org.apache.samza.diagnostics.DiagnosticsExceptionEvent)1 Metrics (org.apache.samza.metrics.reporter.Metrics)1 MetricsHeader (org.apache.samza.metrics.reporter.MetricsHeader)1 MetricsSnapshot (org.apache.samza.metrics.reporter.MetricsSnapshot)1 Test (org.junit.Test)1