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();
}
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));
}
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();
}
}
}
}
Aggregations