RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 /* endpoint_test.cc 00002 Jeremy Barnes, 31 January 2011 00003 Copyright (c) 2011 Datacratic. All rights reserved. 00004 00005 Tests for the endpoints. 00006 */ 00007 00008 #define BOOST_TEST_MAIN 00009 #define BOOST_TEST_DYN_LINK 00010 00011 #include <boost/test/unit_test.hpp> 00012 #include "soa/logger/multi_output.h" 00013 #include "soa/logger/file_output.h" 00014 #include <sys/socket.h> 00015 #include "jml/utils/guard.h" 00016 #include "jml/arch/exception_handler.h" 00017 #include "jml/utils/testing/watchdog.h" 00018 #include "jml/utils/testing/fd_exhauster.h" 00019 #include "jml/arch/timers.h" 00020 00021 using namespace std; 00022 using namespace ML; 00023 using namespace Datacratic; 00024 00025 00026 BOOST_AUTO_TEST_CASE( test_remote_logger ) 00027 { 00028 vector<string> filesOpened; 00029 00030 ML::Call_Guard guard([&] () { for (auto file: filesOpened) unlink(file.c_str());}); 00031 00032 00033 // We try to stream a whole stack of messages through and check that they all 00034 // get to the other end. 00035 00036 MultiOutput output; 00037 00038 auto createOutput = [&] (string key) -> std::shared_ptr<LogOutput> 00039 { 00040 cerr << "creating output for " << key << endl; 00041 filesOpened.push_back(key); 00042 return make_shared<FileOutput>(key); 00043 }; 00044 00045 output.logTo("", "tmp/logs-$(0)-$(1).txt", 00046 createOutput); 00047 00048 output.logMessage("HELLO", "dogs\tone"); 00049 output.logMessage("HELLO", "dogs\ttwo"); 00050 00051 BOOST_CHECK_EQUAL(filesOpened, vector<string>({"tmp/logs-HELLO-dogs.txt"})); 00052 BOOST_CHECK_EQUAL(filesOpened, vector<string>({"tmp/logs-HELLO-dogs.txt"})); 00053 00054 output.logMessage("HELLO", "cats\tone"); 00055 output.logMessage("HELLO", "cats\ttwo"); 00056 00057 BOOST_CHECK_EQUAL(filesOpened, vector<string>({"tmp/logs-HELLO-dogs.txt", 00058 "tmp/logs-HELLO-cats.txt"})); 00059 00060 #if 0 00061 output.connect(port, "localhost"); 00062 00063 for (int i = 0; i < 1000; ++i) { 00064 output.logMessage("channelname", "blah blah this is another message"); 00065 output.barrier(); 00066 } 00067 00068 //output.close(); 00069 00070 output.shutdown(); 00071 input.shutdown(); 00072 #endif 00073 }