use of org.apache.beam.runners.samza.runtime.SamzaStoreStateInternals.StateValueSerdeFactory in project beam by apache.
the class SamzaStoreStateInternalsTest method testStateValueSerde.
@Test
public void testStateValueSerde() throws IOException {
StateValueSerdeFactory stateValueSerdeFactory = new StateValueSerdeFactory();
Serde<StateValue<Integer>> serde = (Serde) stateValueSerdeFactory.getSerde("Test", null);
int value = 123;
Coder<Integer> coder = VarIntCoder.of();
byte[] valueBytes = serde.toBytes(StateValue.of(value, coder));
StateValue<Integer> stateValue1 = serde.fromBytes(valueBytes);
StateValue<Integer> stateValue2 = StateValue.of(valueBytes);
assertEquals(stateValue1.getValue(coder).intValue(), value);
assertEquals(stateValue2.getValue(coder).intValue(), value);
Integer nullValue = null;
byte[] nullBytes = serde.toBytes(StateValue.of(nullValue, coder));
StateValue<Integer> nullStateValue = serde.fromBytes(nullBytes);
assertNull(nullBytes);
assertNull(nullStateValue.getValue(coder));
}
Aggregations