def run(columnFamily): """ Loop accepting input from stdin and writing it to the log server """ scribbleWriter = scribble_lib.scribble_writer() try: while True: logMessage = sys.stdin.readline().rstrip() if logMessage: write_to_server(scribbleWriter, logMessage, columnFamily) except KeyboardInterrupt: return
def test_basic_buffering(self): """Test that basic buffer works""" baseLogMessage = "This is log record {0}" # Override the max buffer size so that we know when it should flush self.server.maxLogBufferSize = 5 scribbleWriter = scribble_lib.scribble_writer() for idx in range(0, 4): scribble_client.write_to_server(scribbleWriter, baseLogMessage.format(idx), "Users") self.server.do_work() # There should be no buffered output yet self.assertEqual(0, len(self.bufferedOutput), "Premature dumping of log buffer") scribble_client.write_to_server(scribbleWriter, baseLogMessage.format(4), "Users") # Manually 'run' the server for a bit [self.server.do_work() for i in range(15)] # Shutdown the server self.server.shutdown() rowCount = 0 # Count the rows for colFam in self.bufferedOutput: for col in self.bufferedOutput[colFam].values(): rowCount += len(col.values()) # There should be buffered output now self.assertTrue(rowCount > 0, "Buffered log data not dumped as expected") self.assertEqual(rowCount, 5, "The expected amount of log data was not dumped")