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);
}
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();
}
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;
}
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)));
}
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);
}
Aggregations