use of org.apache.heron.dlog.DLInputStream in project heron by twitter.
the class DLDownloaderTest method testOpenInputStream.
@Test
public void testOpenInputStream() throws Exception {
Namespace ns = mock(Namespace.class);
DistributedLogManager dlm = mock(DistributedLogManager.class);
LogReader reader = mock(LogReader.class);
when(ns.openLog(anyString())).thenReturn(dlm);
when(dlm.getInputStream(eq(DLSN.InitialDLSN))).thenReturn(reader);
InputStream is = DLDownloader.openInputStream(ns, "test-open-inputstream");
assertTrue(is instanceof DLInputStream);
is.close();
verify(dlm, times(1)).close();
verify(reader, times(1)).close();
}
use of org.apache.heron.dlog.DLInputStream 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.dlog.DLInputStream 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