Search in sources :

Example 1 with DefaultBucket

use of org.apache.apex.malhar.lib.state.managed.Bucket.DefaultBucket in project apex-malhar by apache.

the class ManagedTimeStateImplTest method testRecovery.

@Test
public void testRecovery() throws ExecutionException, InterruptedException {
    Slice one = ManagedStateTestUtils.getSliceFor("1");
    testMeta.managedState.setup(testMeta.operatorContext);
    long time = System.currentTimeMillis();
    testMeta.managedState.beginWindow(0);
    testMeta.managedState.put(0, time, one, one);
    testMeta.managedState.endWindow();
    testMeta.managedState.beforeCheckpoint(0);
    testMeta.managedState.teardown();
    // there is a failure and the operator is re-deployed.
    testMeta.managedState.setStateTracker(new StateTracker());
    Attribute.AttributeMap.DefaultAttributeMap attributes = new Attribute.AttributeMap.DefaultAttributeMap();
    attributes.put(DAG.APPLICATION_PATH, testMeta.applicationPath);
    attributes.put(Context.OperatorContext.ACTIVATION_WINDOW_ID, 0L);
    OperatorContext operatorContext = mockOperatorContext(1, attributes);
    testMeta.managedState.setup(operatorContext);
    Bucket.DefaultBucket defaultBucket = (Bucket.DefaultBucket) testMeta.managedState.getBucket(0);
    Assert.assertEquals("value of one", one, defaultBucket.get(one, time, Bucket.ReadSource.MEMORY));
}
Also used : DefaultBucket(org.apache.apex.malhar.lib.state.managed.Bucket.DefaultBucket) Attribute(com.datatorrent.api.Attribute) DefaultBucket(org.apache.apex.malhar.lib.state.managed.Bucket.DefaultBucket) DefaultBucket(org.apache.apex.malhar.lib.state.managed.Bucket.DefaultBucket) Slice(com.datatorrent.netlet.util.Slice) OperatorContextTestHelper.mockOperatorContext(org.apache.apex.malhar.lib.helper.OperatorContextTestHelper.mockOperatorContext) OperatorContext(com.datatorrent.api.Context.OperatorContext) Test(org.junit.Test)

Aggregations

Attribute (com.datatorrent.api.Attribute)1 OperatorContext (com.datatorrent.api.Context.OperatorContext)1 Slice (com.datatorrent.netlet.util.Slice)1 OperatorContextTestHelper.mockOperatorContext (org.apache.apex.malhar.lib.helper.OperatorContextTestHelper.mockOperatorContext)1 DefaultBucket (org.apache.apex.malhar.lib.state.managed.Bucket.DefaultBucket)1 Test (org.junit.Test)1