use of org.apache.heron.spi.statefulstorage.Checkpoint in project heron by twitter.
the class HDFSStorage method restoreCheckpoint.
@Override
public Checkpoint restoreCheckpoint(CheckpointInfo info) throws StatefulStorageException {
Path path = new Path(getCheckpointPath(info.getCheckpointId(), info.getComponent(), info.getInstanceId()));
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(state);
}
use of org.apache.heron.spi.statefulstorage.Checkpoint in project heron by twitter.
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(mockCheckpointState);
FSDataOutputStream mockFSDateOutputStream = mock(FSDataOutputStream.class);
when(mockFileSystem.create(any(Path.class))).thenReturn(mockFSDateOutputStream);
doNothing().when(hdfsStorage).createDir(anyString());
final CheckpointInfo info = new CheckpointInfo(StatefulStorageTestContext.CHECKPOINT_ID, instance);
hdfsStorage.storeCheckpoint(info, checkpoint);
verify(mockCheckpointState).writeTo(mockFSDateOutputStream);
}
use of org.apache.heron.spi.statefulstorage.Checkpoint in project heron by twitter.
the class DlogStorage method restoreCheckpoint.
@Override
public Checkpoint restoreCheckpoint(CheckpointInfo info) throws StatefulStorageException {
String checkpointPath = getCheckpointPath(topologyName, info.getCheckpointId(), info.getComponent(), info.getInstanceId());
InputStream in = null;
CheckpointManager.InstanceStateCheckpoint state;
try {
in = openInputStream(checkpointPath);
state = CheckpointManager.InstanceStateCheckpoint.parseFrom(in);
} catch (IOException ioe) {
throw new StatefulStorageException("Failed to read checkpoint from " + checkpointPath, ioe);
} finally {
if (in != null) {
final long num = ((DLInputStream) in).getNumOfBytesRead();
LOG.info(() -> num + " bytes read");
}
SysUtils.closeIgnoringExceptions(in);
}
return new Checkpoint(state);
}
use of org.apache.heron.spi.statefulstorage.Checkpoint in project heron by twitter.
the class DlogStorageTest method testStore.
@Test
public void testStore() throws Exception {
PowerMockito.mockStatic(CheckpointManager.InstanceStateCheckpoint.class);
CheckpointManager.InstanceStateCheckpoint mockCheckpointState = mock(CheckpointManager.InstanceStateCheckpoint.class);
final CheckpointInfo info = new CheckpointInfo(StatefulStorageTestContext.CHECKPOINT_ID, instance);
Checkpoint checkpoint = new Checkpoint(mockCheckpointState);
DistributedLogManager mockDLM = mock(DistributedLogManager.class);
when(mockNamespace.openLog(anyString())).thenReturn(mockDLM);
AppendOnlyStreamWriter mockWriter = mock(AppendOnlyStreamWriter.class);
when(mockDLM.getAppendOnlyStreamWriter()).thenReturn(mockWriter);
dlogStorage.storeCheckpoint(info, checkpoint);
verify(mockWriter).markEndOfStream();
verify(mockWriter).close();
}
use of org.apache.heron.spi.statefulstorage.Checkpoint in project heron by twitter.
the class DlogStorageTest method testRestore.
@Test
public void testRestore() throws Exception {
DLInputStream mockInputStream = mock(DLInputStream.class);
doReturn(mockInputStream).when(dlogStorage).openInputStream(anyString());
PowerMockito.spy(CheckpointManager.InstanceStateCheckpoint.class);
PowerMockito.doReturn(checkpointPartition).when(CheckpointManager.InstanceStateCheckpoint.class, "parseFrom", mockInputStream);
final CheckpointInfo info = new CheckpointInfo(StatefulStorageTestContext.CHECKPOINT_ID, instance);
Checkpoint restoreCheckpoint = dlogStorage.restoreCheckpoint(info);
assertEquals(restoreCheckpoint.getCheckpoint(), checkpointPartition);
}
Aggregations