Search in sources :

Example 11 with MetricsSnapshot

use of org.apache.samza.metrics.reporter.MetricsSnapshot in project samza by apache.

the class TestMetricsSnapshotSerdeV2 method testSerializeThenDeserializeEmptySamzaEpochIdInHeader.

@Test
public void testSerializeThenDeserializeEmptySamzaEpochIdInHeader() {
    SamzaException samzaException = new SamzaException("this is a samza exception", new RuntimeException("cause"));
    MetricsSnapshot metricsSnapshot = metricsSnapshot(samzaException, false);
    MetricsSnapshotSerdeV2 metricsSnapshotSerde = new MetricsSnapshotSerdeV2();
    byte[] serializedBytes = metricsSnapshotSerde.toBytes(metricsSnapshot);
    MetricsSnapshot deserializedMetricsSnapshot = metricsSnapshotSerde.fromBytes(serializedBytes);
    assertEquals(metricsSnapshot, deserializedMetricsSnapshot);
}
Also used : MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) MetricsSnapshotSerdeV2(org.apache.samza.serializers.MetricsSnapshotSerdeV2) SamzaException(org.apache.samza.SamzaException) Test(org.junit.Test)

Example 12 with MetricsSnapshot

use of org.apache.samza.metrics.reporter.MetricsSnapshot in project samza by apache.

the class TestMetricsSnapshotSerdeV2 method testSerializeThenDeserialize.

@Test
public void testSerializeThenDeserialize() {
    SamzaException samzaException = new SamzaException("this is a samza exception", new RuntimeException("cause"));
    MetricsSnapshot metricsSnapshot = metricsSnapshot(samzaException, true);
    MetricsSnapshotSerdeV2 metricsSnapshotSerde = new MetricsSnapshotSerdeV2();
    byte[] serializedBytes = metricsSnapshotSerde.toBytes(metricsSnapshot);
    MetricsSnapshot deserializedMetricsSnapshot = metricsSnapshotSerde.fromBytes(serializedBytes);
    assertEquals(metricsSnapshot, deserializedMetricsSnapshot);
}
Also used : MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) MetricsSnapshotSerdeV2(org.apache.samza.serializers.MetricsSnapshotSerdeV2) SamzaException(org.apache.samza.SamzaException) Test(org.junit.Test)

Example 13 with MetricsSnapshot

use of org.apache.samza.metrics.reporter.MetricsSnapshot in project samza by apache.

the class TestMetricsSnapshotSerde method testSerializeThenDeserializeEmptySamzaEpochIdInHeader.

@Test
public void testSerializeThenDeserializeEmptySamzaEpochIdInHeader() {
    MetricsSnapshot snapshot = metricsSnapshot(true);
    MetricsSnapshotSerde serde = new MetricsSnapshotSerde();
    byte[] bytes = serde.toBytes(snapshot);
    assertEquals(snapshot, serde.fromBytes(bytes));
}
Also used : MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) Test(org.junit.Test)

Example 14 with MetricsSnapshot

use of org.apache.samza.metrics.reporter.MetricsSnapshot in project samza by apache.

the class TestMetricsSnapshotSerde method testDeserializeRawEmptySamzaEpochIdInHeader.

/**
 * Helps for verifying compatibility when schemas evolve.
 */
@Test
public void testDeserializeRawEmptySamzaEpochIdInHeader() {
    MetricsSnapshot snapshot = metricsSnapshot(false);
    MetricsSnapshotSerde serde = new MetricsSnapshotSerde();
    assertEquals(snapshot, serde.fromBytes(expectedSeralizedSnapshot(false, false).getBytes(StandardCharsets.UTF_8)));
    assertEquals(snapshot, serde.fromBytes(expectedSeralizedSnapshot(false, true).getBytes(StandardCharsets.UTF_8)));
}
Also used : MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) Test(org.junit.Test)

Example 15 with MetricsSnapshot

use of org.apache.samza.metrics.reporter.MetricsSnapshot in project samza by apache.

the class TestDiagnosticsStreamMessage method serdeTest.

/**
 * Tests serialization and deserialization of a {@link DiagnosticsStreamMessage}
 */
@Test
public void serdeTest() {
    DiagnosticsStreamMessage diagnosticsStreamMessage = getDiagnosticsStreamMessage(Optional.of(SAMZA_EPOCH_ID));
    Collection<DiagnosticsExceptionEvent> exceptionEventList = getExceptionList();
    diagnosticsStreamMessage.addDiagnosticsExceptionEvents(exceptionEventList);
    diagnosticsStreamMessage.addProcessorStopEvents(getProcessorStopEventList());
    diagnosticsStreamMessage.addContainerModels(getSampleContainerModels());
    MetricsSnapshot metricsSnapshot = diagnosticsStreamMessage.convertToMetricsSnapshot();
    MetricsHeader expectedHeader = new MetricsHeader(JOB_NAME, JOB_ID, CONTAINER_NAME, EXECUTION_ENV_CONTAINER_ID, Optional.of(SAMZA_EPOCH_ID), DiagnosticsManager.class.getName(), TASK_CLASS_VERSION, SAMZA_VERSION, HOSTNAME, timestamp, resetTimestamp);
    Assert.assertEquals(metricsSnapshot.getHeader(), expectedHeader);
    Map<String, Map<String, Object>> metricsMap = metricsSnapshot.getMetrics().getAsMap();
    Assert.assertTrue(metricsMap.get("org.apache.samza.container.SamzaContainerMetrics").containsKey("exceptions"));
    Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("containerModels"));
    Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("numPersistentStores"));
    Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("containerNumCores"));
    Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("containerMemoryMb"));
    Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("stopEvents"));
    Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("config"));
    DiagnosticsStreamMessage convertedDiagnosticsStreamMessage = DiagnosticsStreamMessage.convertToDiagnosticsStreamMessage(metricsSnapshot);
    Assert.assertEquals(convertedDiagnosticsStreamMessage, diagnosticsStreamMessage);
}
Also used : MetricsHeader(org.apache.samza.metrics.reporter.MetricsHeader) MetricsSnapshot(org.apache.samza.metrics.reporter.MetricsSnapshot) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

MetricsSnapshot (org.apache.samza.metrics.reporter.MetricsSnapshot)17 Test (org.junit.Test)12 MetricsSnapshotSerdeV2 (org.apache.samza.serializers.MetricsSnapshotSerdeV2)9 MetricsHeader (org.apache.samza.metrics.reporter.MetricsHeader)6 HashMap (java.util.HashMap)4 SamzaException (org.apache.samza.SamzaException)4 Map (java.util.Map)3 Metrics (org.apache.samza.metrics.reporter.Metrics)2 OutgoingMessageEnvelope (org.apache.samza.system.OutgoingMessageEnvelope)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 BoundedList (org.apache.samza.diagnostics.BoundedList)1 DiagnosticsExceptionEvent (org.apache.samza.diagnostics.DiagnosticsExceptionEvent)1 LocalContainerRunner (org.apache.samza.runtime.LocalContainerRunner)1