Search in sources :

Example 11 with Checkpoint

use of com.twitter.heron.spi.statefulstorage.Checkpoint in project incubator-heron by apache.

the class LocalFileSystemStorageTest method testStore.

@Test
public void testStore() throws Exception {
    PowerMockito.spy(FileUtils.class);
    PowerMockito.doReturn(true).when(FileUtils.class, "createDirectory", anyString());
    PowerMockito.doReturn(true).when(FileUtils.class, "isFileExists", anyString());
    PowerMockito.doReturn(true).when(FileUtils.class, "isDirectoryExists", anyString());
    PowerMockito.doReturn(true).when(FileUtils.class, "writeToFile", anyString(), any(byte[].class), anyBoolean());
    Checkpoint mockCheckpoint = mock(Checkpoint.class);
    when(mockCheckpoint.getCheckpoint()).thenReturn(checkpoint);
    localFileSystemStorage.store(mockCheckpoint);
    PowerMockito.verifyStatic(times(1));
    FileUtils.writeToFile(anyString(), eq(checkpoint.toByteArray()), eq(true));
}
Also used : InstanceStateCheckpoint(com.twitter.heron.proto.ckptmgr.CheckpointManager.InstanceStateCheckpoint) Checkpoint(com.twitter.heron.spi.statefulstorage.Checkpoint) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with Checkpoint

use of com.twitter.heron.spi.statefulstorage.Checkpoint in project incubator-heron by apache.

the class HDFSStorage method restore.

@Override
public Checkpoint restore(String topologyName, String checkpointId, PhysicalPlans.Instance instanceInfo) throws StatefulStorageException {
    Path path = new Path(getCheckpointPath(topologyName, checkpointId, instanceInfo.getInfo().getComponentName(), instanceInfo.getInfo().getTaskId()));
    FSDataInputStream in = null;
    CheckpointManager.InstanceStateCheckpoint state = null;
    try {
        in = fileSystem.open(path);
        state = CheckpointManager.InstanceStateCheckpoint.parseFrom(in);
    } catch (IOException e) {
        throw new StatefulStorageException("Failed to read", e);
    } finally {
        SysUtils.closeIgnoringExceptions(in);
    }
    return new Checkpoint(topologyName, instanceInfo, state);
}
Also used : Path(org.apache.hadoop.fs.Path) StatefulStorageException(com.twitter.heron.spi.statefulstorage.StatefulStorageException) Checkpoint(com.twitter.heron.spi.statefulstorage.Checkpoint) CheckpointManager(com.twitter.heron.proto.ckptmgr.CheckpointManager) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) IOException(java.io.IOException)

Example 13 with Checkpoint

use of com.twitter.heron.spi.statefulstorage.Checkpoint in project incubator-heron by apache.

the class HDFSStorageTest method testStore.

@Test
public void testStore() throws Exception {
    PowerMockito.mockStatic(CheckpointManager.InstanceStateCheckpoint.class);
    CheckpointManager.InstanceStateCheckpoint mockCheckpointState = mock(CheckpointManager.InstanceStateCheckpoint.class);
    Checkpoint checkpoint = new Checkpoint(StatefulStorageTestContext.TOPOLOGY_NAME, instance, mockCheckpointState);
    FSDataOutputStream mockFSDateOutputStream = mock(FSDataOutputStream.class);
    when(mockFileSystem.create(any(Path.class))).thenReturn(mockFSDateOutputStream);
    doNothing().when(hdfsStorage).createDir(anyString());
    hdfsStorage.store(checkpoint);
    verify(mockCheckpointState).writeTo(mockFSDateOutputStream);
}
Also used : Path(org.apache.hadoop.fs.Path) Checkpoint(com.twitter.heron.spi.statefulstorage.Checkpoint) CheckpointManager(com.twitter.heron.proto.ckptmgr.CheckpointManager) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Checkpoint (com.twitter.heron.spi.statefulstorage.Checkpoint)13 CheckpointManager (com.twitter.heron.proto.ckptmgr.CheckpointManager)9 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 StatefulStorageException (com.twitter.heron.spi.statefulstorage.StatefulStorageException)5 ByteString (com.google.protobuf.ByteString)3 Path (org.apache.hadoop.fs.Path)3 InstanceStateCheckpoint (com.twitter.heron.proto.ckptmgr.CheckpointManager.InstanceStateCheckpoint)2 Common (com.twitter.heron.proto.system.Common)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Message (com.google.protobuf.Message)1 HeronClient (com.twitter.heron.common.network.HeronClient)1 StatusCode (com.twitter.heron.common.network.StatusCode)1 HeronServerTester (com.twitter.heron.common.testhelpers.HeronServerTester)1 DLInputStream (com.twitter.heron.dlog.DLInputStream)1 PhysicalPlans (com.twitter.heron.proto.system.PhysicalPlans)1 AppendOnlyStreamWriter (org.apache.distributedlog.AppendOnlyStreamWriter)1