### Question:
FileTxnLog implements TxnLog, Closeable { public synchronized long getCurrentLogSize() { if (logFileWrite != null) { return logFileWrite.length(); } return 0; } FileTxnLog(File logDir); static void setPreallocSize(long size); @Override synchronized void setServerStats(ServerStats serverStats); static void setTxnLogSizeLimit(long size); synchronized long getCurrentLogSize(); synchronized void setTotalLogSize(long size); synchronized long getTotalLogSize(); synchronized void rollLog(); synchronized void close(); synchronized boolean append(TxnHeader hdr, Record txn); @Override synchronized boolean append(TxnHeader hdr, Record txn, TxnDigest digest); static File[] getLogFiles(File[] logDirList, long snapshotZxid); long getLastLoggedZxid(); synchronized void commit(); long getTxnLogSyncElapsedTime(); TxnIterator read(long zxid); TxnIterator read(long zxid, boolean fastForward); boolean truncate(long zxid); long getDbId(); boolean isForceSync(); static final int TXNLOG_MAGIC; static final int VERSION; static final String LOG_FILE_PREFIX; }### Answer:
@Test public void testGetCurrentLogSize() throws Exception { FileTxnLog.setTxnLogSizeLimit(-1); File tmpDir = ClientBase.createTmpDir(); FileTxnLog log = new FileTxnLog(tmpDir); FileTxnLog.setPreallocSize(PREALLOCATE); CreateRequest record = new CreateRequest(null, new byte[NODE_SIZE], ZooDefs.Ids.OPEN_ACL_UNSAFE, 0); int zxid = 1; for (int i = 0; i < 4; i++) { log.append(new TxnHeader(0, 0, zxid++, 0, 0), record); LOG.debug("Current log size: {}", log.getCurrentLogSize()); } log.commit(); LOG.info("Current log size: {}", log.getCurrentLogSize()); assertTrue(log.getCurrentLogSize() > (zxid - 1) * NODE_SIZE); for (int i = 0; i < 4; i++) { log.append(new TxnHeader(0, 0, zxid++, 0, 0), record); LOG.debug("Current log size: {}", log.getCurrentLogSize()); } log.commit(); LOG.info("Current log size: " + log.getCurrentLogSize()); assertTrue(log.getCurrentLogSize() > (zxid - 1) * NODE_SIZE); }