Search in sources :

Example 1 with DLInputStream

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();
}
Also used : DLInputStream(org.apache.heron.dlog.DLInputStream) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) DLInputStream(org.apache.heron.dlog.DLInputStream) InputStream(java.io.InputStream) LogReader(org.apache.distributedlog.api.LogReader) Namespace(org.apache.distributedlog.api.namespace.Namespace) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with DLInputStream

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);
}
Also used : StatefulStorageException(org.apache.heron.spi.statefulstorage.StatefulStorageException) Checkpoint(org.apache.heron.spi.statefulstorage.Checkpoint) DLInputStream(org.apache.heron.dlog.DLInputStream) DLInputStream(org.apache.heron.dlog.DLInputStream) InputStream(java.io.InputStream) CheckpointManager(org.apache.heron.proto.ckptmgr.CheckpointManager) IOException(java.io.IOException)

Example 3 with DLInputStream

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);
}
Also used : Checkpoint(org.apache.heron.spi.statefulstorage.Checkpoint) DLInputStream(org.apache.heron.dlog.DLInputStream) CheckpointManager(org.apache.heron.proto.ckptmgr.CheckpointManager) CheckpointInfo(org.apache.heron.spi.statefulstorage.CheckpointInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

DLInputStream (org.apache.heron.dlog.DLInputStream)3 InputStream (java.io.InputStream)2 CheckpointManager (org.apache.heron.proto.ckptmgr.CheckpointManager)2 Checkpoint (org.apache.heron.spi.statefulstorage.Checkpoint)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 IOException (java.io.IOException)1 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)1 LogReader (org.apache.distributedlog.api.LogReader)1 Namespace (org.apache.distributedlog.api.namespace.Namespace)1 CheckpointInfo (org.apache.heron.spi.statefulstorage.CheckpointInfo)1 StatefulStorageException (org.apache.heron.spi.statefulstorage.StatefulStorageException)1