Search in sources :

Example 1 with StateValueSerdeFactory

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));
}
Also used : Serde(org.apache.samza.serializers.Serde) StateValue(org.apache.beam.runners.samza.runtime.SamzaStoreStateInternals.StateValue) StateValueSerdeFactory(org.apache.beam.runners.samza.runtime.SamzaStoreStateInternals.StateValueSerdeFactory) Test(org.junit.Test)

Aggregations

StateValue (org.apache.beam.runners.samza.runtime.SamzaStoreStateInternals.StateValue)1 StateValueSerdeFactory (org.apache.beam.runners.samza.runtime.SamzaStoreStateInternals.StateValueSerdeFactory)1 Serde (org.apache.samza.serializers.Serde)1 Test (org.junit.Test)1