Search in sources :

Example 1 with ConsumerWorkingSet

use of io.cdap.cdap.api.dataset.lib.partitioned.ConsumerWorkingSet in project cdap by caskdata.

the class ConsumerWorkingSetTest method testByteSerialization.

@Test
public void testByteSerialization() {
    ConsumerWorkingSet workingSet = new ConsumerWorkingSet();
    // test with empty partitions lists
    testSerDe(workingSet);
    // test with two elements in AVAILABLE and none in IN_PROGRESS
    workingSet.getPartitions().add(new DefaultConsumablePartition(generateUniqueKey()));
    workingSet.getPartitions().add(new DefaultConsumablePartition(generateUniqueKey()));
    testSerDe(workingSet);
    // test with three elements in partitions and none in inProgressPartitions
    workingSet.getPartitions().add(new DefaultConsumablePartition(generateUniqueKey()));
    testSerDe(workingSet);
    // mark the first element as IN_PROGRESS
    workingSet.getPartitions().get(0).take();
    workingSet.getPartitions().get(0).setTimestamp(System.currentTimeMillis());
    testSerDe(workingSet);
}
Also used : DefaultConsumablePartition(io.cdap.cdap.api.dataset.lib.partitioned.DefaultConsumablePartition) ConsumerWorkingSet(io.cdap.cdap.api.dataset.lib.partitioned.ConsumerWorkingSet) Test(org.junit.Test)

Example 2 with ConsumerWorkingSet

use of io.cdap.cdap.api.dataset.lib.partitioned.ConsumerWorkingSet in project cdap by caskdata.

the class ConsumerWorkingSetTest method testSerDe.

private void testSerDe(ConsumerWorkingSet stateToSerialize) {
    byte[] bytes = stateToSerialize.toBytes();
    // Assert that the serialization format version is 0
    Assert.assertEquals(0, bytes[0]);
    ConsumerWorkingSet deserializedState = ConsumerWorkingSet.fromBytes(bytes);
    Assert.assertEquals(stateToSerialize, deserializedState);
}
Also used : ConsumerWorkingSet(io.cdap.cdap.api.dataset.lib.partitioned.ConsumerWorkingSet)

Aggregations

ConsumerWorkingSet (io.cdap.cdap.api.dataset.lib.partitioned.ConsumerWorkingSet)2 DefaultConsumablePartition (io.cdap.cdap.api.dataset.lib.partitioned.DefaultConsumablePartition)1 Test (org.junit.Test)1