public long getBytesInMemory() { return out.getBytesInMemory(); }
public long getBytesOnDisk() { return out.getBytesOnDisk(); }
@VisibleForTesting public long getFilesCreated() { return out.getCreatedFiles().size(); } }
private void recycle() throws IOException { synchronized (recyclingMonitor) { if (out != null && !out.isEmpty()) { out.close(); } out = new StreamyBytesPersistentOutputStream(basePath, prefix, inputBuffer, deleteFilesOnClose); smileGenerator = smileFactory.createJsonGenerator(out, JsonEncoding.UTF8); // Drop the Smile header smileGenerator.flush(); out.reset(); samplesforTimestampWritten.set(0); } }
private void flushUnderlyingBufferAndReset() { synchronized (inputBuffer) { if (inputBuffer.available() == 0) { // Somebody beat you to it return; } final String pathname = getFileName(); createdFiles.add(pathname); log.debug("Flushing in-memory buffer to disk: {}", pathname); try { final File out = new File(pathname); flushToFile(out); } catch (IOException e) { log.warn("Error flushing data", e); } finally { reset(); } } }
@Test(groups = "slow") public void testOrdering() throws Exception { Assert.assertTrue(basePath.mkdir()); final List<String> filePathsCreated = new ArrayList<String>(); final List<File> filesCreated = new ArrayList<File>(); final int expected = 50; for (int i = 0; i < expected; i++) { filePathsCreated.add(outputStream.getFileName()); Thread.sleep(17); } // Create the files in the opposite ordering to make sure we can re-read them in order for (int i = expected - 1; i >= 0; i--) { final File file = new File(filePathsCreated.get(i)); Assert.assertTrue(file.createNewFile()); filesCreated.add(file); } final MockReplayer replayer = new MockReplayer(basePath.toString(), Lists.reverse(filesCreated)); replayer.readAll(); Assert.assertEquals(replayer.getSeen(), expected); } }
public long getInMemoryAvailableSpace() { return out.getInMemoryAvailableSpace(); }
@Override public void write(final byte[] data, final int off, final int len) throws IOException { if (!inputBuffer.tryAppend(data, off, len)) { // Buffer full - need to flush // TODO sync with HTTP call, performance hit? flushUnderlyingBufferAndReset(); if (!inputBuffer.tryAppend(data, off, len)) { log.warn("Unable to append data: 1 byte lost"); } } }