Search in sources :

Example 11 with AppendOnlyStreamWriter

use of org.apache.distributedlog.AppendOnlyStreamWriter in project incubator-heron by apache.

the class DLOutputStreamTest method testClose.

/**
 * Test Case: close output stream.
 */
@Test
public void testClose() throws Exception {
    DistributedLogManager dlm = mock(DistributedLogManager.class);
    AppendOnlyStreamWriter writer = mock(AppendOnlyStreamWriter.class);
    DLOutputStream out = new DLOutputStream(dlm, writer);
    out.close();
    verify(writer, times(1)).markEndOfStream();
    verify(writer, times(1)).close();
    verify(dlm, times(1)).close();
}
Also used : DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) AppendOnlyStreamWriter(org.apache.distributedlog.AppendOnlyStreamWriter) Test(org.junit.Test)

Example 12 with AppendOnlyStreamWriter

use of org.apache.distributedlog.AppendOnlyStreamWriter in project incubator-heron by apache.

the class DLOutputStreamTest method testFlush.

/**
 * Test Case: flush should force writing the data.
 */
@Test
public void testFlush() throws Exception {
    DistributedLogManager dlm = mock(DistributedLogManager.class);
    AppendOnlyStreamWriter writer = mock(AppendOnlyStreamWriter.class);
    DLOutputStream out = new DLOutputStream(dlm, writer);
    out.flush();
    verify(writer, times(1)).force(eq(false));
}
Also used : DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) AppendOnlyStreamWriter(org.apache.distributedlog.AppendOnlyStreamWriter) Test(org.junit.Test)

Example 13 with AppendOnlyStreamWriter

use of org.apache.distributedlog.AppendOnlyStreamWriter in project incubator-pulsar by apache.

the class Utils method uploadToBookeeper.

public static void uploadToBookeeper(Namespace dlogNamespace, InputStream uploadedInputStream, String destPkgPath) throws IOException {
    // if the dest directory does not exist, create it.
    if (dlogNamespace.logExists(destPkgPath)) {
        // if the destination file exists, write a log message
        log.info(String.format("Target function file already exists at '%s'. Overwriting it now", destPkgPath));
        dlogNamespace.deleteLog(destPkgPath);
    }
    // copy the topology package to target working directory
    log.info(String.format("Uploading function package to '%s'", destPkgPath));
    try (DistributedLogManager dlm = dlogNamespace.openLog(destPkgPath)) {
        try (AppendOnlyStreamWriter writer = dlm.getAppendOnlyStreamWriter()) {
            try (OutputStream out = new DLOutputStream(dlm, writer)) {
                int read = 0;
                byte[] bytes = new byte[1024];
                while ((read = uploadedInputStream.read(bytes)) != -1) {
                    out.write(bytes, 0, read);
                }
                out.flush();
            }
        }
    }
}
Also used : DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) AppendOnlyStreamWriter(org.apache.distributedlog.AppendOnlyStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DLOutputStream(org.apache.pulsar.functions.worker.dlog.DLOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) DLOutputStream(org.apache.pulsar.functions.worker.dlog.DLOutputStream)

Aggregations

AppendOnlyStreamWriter (org.apache.distributedlog.AppendOnlyStreamWriter)13 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)13 Test (org.junit.Test)6 OutputStream (java.io.OutputStream)3 Test (org.testng.annotations.Test)3 DLOutputStream (com.twitter.heron.dlog.DLOutputStream)2 Namespace (org.apache.distributedlog.api.namespace.Namespace)2 CheckpointManager (com.twitter.heron.proto.ckptmgr.CheckpointManager)1 Checkpoint (com.twitter.heron.spi.statefulstorage.Checkpoint)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 DLOutputStream (org.apache.pulsar.functions.worker.dlog.DLOutputStream)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1