Search in sources :

Example 6 with MetricsSnapshotSerdeV2

use of org.apache.samza.serializers.MetricsSnapshotSerdeV2 in project samza by apache.

the class TestMetricsSnapshotReporterFactory method testGetSerdeFallback.

@Test
public void testGetSerdeFallback() {
    Config config = new MapConfig(ImmutableMap.of("metrics.reporter.metrics-reporter.stream", "system0.stream0", "streams.stream0.samza.system", "system0"));
    assertTrue(this.factory.getSerde(REPORTER, config) instanceof MetricsSnapshotSerdeV2);
}
Also used : Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) MetricsSnapshotSerdeV2(org.apache.samza.serializers.MetricsSnapshotSerdeV2) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Example 7 with MetricsSnapshotSerdeV2

use of org.apache.samza.serializers.MetricsSnapshotSerdeV2 in project samza by apache.

the class TestMetricsSnapshotReporter method setup.

@Before
public void setup() {
    producer = mock(SystemProducer.class);
    clock = mock(Clock.class);
    Mockito.when(clock.currentTimeMillis()).thenReturn(RESET_TIME, SEND_TIME);
    serializer = new MetricsSnapshotSerdeV2();
}
Also used : SystemProducer(org.apache.samza.system.SystemProducer) MetricsSnapshotSerdeV2(org.apache.samza.serializers.MetricsSnapshotSerdeV2) Clock(org.apache.samza.util.Clock) Before(org.junit.Before)

Example 8 with MetricsSnapshotSerdeV2

use of org.apache.samza.serializers.MetricsSnapshotSerdeV2 in project samza by apache.

the class MetricsSnapshotReporterFactory method getSerde.

protected Serde<MetricsSnapshot> getSerde(String reporterName, Config config) {
    StreamConfig streamConfig = new StreamConfig(config);
    SystemConfig systemConfig = new SystemConfig(config);
    SystemStream systemStream = getSystemStream(reporterName, config);
    Optional<String> streamSerdeName = streamConfig.getStreamMsgSerde(systemStream);
    Optional<String> systemSerdeName = systemConfig.getSystemMsgSerde(systemStream.getSystem());
    String serdeName = streamSerdeName.orElse(systemSerdeName.orElse(null));
    SerializerConfig serializerConfig = new SerializerConfig(config);
    Serde<MetricsSnapshot> serde;
    if (serdeName != null) {
        Optional<String> serdeFactoryClass = serializerConfig.getSerdeFactoryClass(serdeName);
        if (serdeFactoryClass.isPresent()) {
            SerdeFactory<MetricsSnapshot> serdeFactory = ReflectionUtil.getObj(serdeFactoryClass.get(), SerdeFactory.class);
            serde = serdeFactory.getSerde(serdeName, config);
        } else {
            serde = null;
        }
    } else {
        serde = new MetricsSnapshotSerdeV2();
    }
    LOG.info("Got serde {}.", serde);
    return serde;
}
Also used : SystemConfig(org.apache.samza.config.SystemConfig) SerializerConfig(org.apache.samza.config.SerializerConfig) SystemStream(org.apache.samza.system.SystemStream) StreamConfig(org.apache.samza.config.StreamConfig) MetricsSnapshotSerdeV2(org.apache.samza.serializers.MetricsSnapshotSerdeV2)

Example 9 with MetricsSnapshotSerdeV2

use of org.apache.samza.serializers.MetricsSnapshotSerdeV2 in project samza by apache.

the class TestMetricsSnapshotSerdeV2 method testDeserializeRaw.

/**
 * Helps for verifying compatibility when schemas evolve.
 *
 * Maps have non-deterministic ordering when serialized, so it is difficult to check exact serialized results. It
 * isn't really necessary to check the serialized results anyways. We just need to make sure serialized data can be
 * read by old and new systems.
 */
@Test
public void testDeserializeRaw() {
    SamzaException samzaException = new SamzaException("this is a samza exception", new RuntimeException("cause"));
    MetricsSnapshot metricsSnapshot = metricsSnapshot(samzaException, true);
    MetricsSnapshotSerdeV2 metricsSnapshotSerde = new MetricsSnapshotSerdeV2();
    assertEquals(metricsSnapshot, metricsSnapshotSerde.fromBytes(expectedSeralizedSnapshot(samzaException, true, false).getBytes(StandardCharsets.UTF_8)));
    assertEquals(metricsSnapshot, metricsSnapshotSerde.fromBytes(expectedSeralizedSnapshot(samzaException, true, true).getBytes(StandardCharsets.UTF_8)));
}
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 10 with MetricsSnapshotSerdeV2

use of org.apache.samza.serializers.MetricsSnapshotSerdeV2 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)

Aggregations

MetricsSnapshotSerdeV2 (org.apache.samza.serializers.MetricsSnapshotSerdeV2)12 MetricsSnapshot (org.apache.samza.metrics.reporter.MetricsSnapshot)9 Test (org.junit.Test)7 SamzaException (org.apache.samza.SamzaException)4 MetricsHeader (org.apache.samza.metrics.reporter.MetricsHeader)2 OutgoingMessageEnvelope (org.apache.samza.system.OutgoingMessageEnvelope)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Config (org.apache.samza.config.Config)1 MapConfig (org.apache.samza.config.MapConfig)1 SerializerConfig (org.apache.samza.config.SerializerConfig)1 StreamConfig (org.apache.samza.config.StreamConfig)1 SystemConfig (org.apache.samza.config.SystemConfig)1 Metrics (org.apache.samza.metrics.reporter.Metrics)1 LocalContainerRunner (org.apache.samza.runtime.LocalContainerRunner)1 SystemProducer (org.apache.samza.system.SystemProducer)1 SystemStream (org.apache.samza.system.SystemStream)1 Clock (org.apache.samza.util.Clock)1 Before (org.junit.Before)1