]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
log: Add optional msg parameter to create_entry and test with it
authorAdam C. Emerson <aemerson@redhat.com>
Thu, 5 Oct 2017 22:27:37 +0000 (18:27 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Fri, 6 Oct 2017 21:29:06 +0000 (17:29 -0400)
The tests should, really, get their time from the same source as the
log, and also probably use the same interface to creating entries that
other people do. So add an optional message argument and have the
tests use that rather than using the new operator directly.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/log/Log.cc
src/log/Log.h
src/log/test.cc

index bf219d379fadf4c5f5e1dc80ad052328d12844c4..e8d7ec00e8e506eb6a2812f925e70d49c707dcc1 100644 (file)
@@ -222,12 +222,12 @@ void Log::submit_entry(Entry *e)
 }
 
 
-Entry *Log::create_entry(int level, int subsys)
+Entry *Log::create_entry(int level, int subsys, const char* msg)
 {
   if (true) {
     return new Entry(ceph_clock_now(),
                     pthread_self(),
-                    level, subsys);
+                    level, subsys, msg);
   } else {
     // kludge for perf testing
     Entry *e = m_recent.dequeue();
index ce77daabc41fd4db38ed1a0490724d571dce9100..c977ee8e358ede6688602f099053d9320892f0fe 100644 (file)
@@ -82,7 +82,7 @@ public:
 
   shared_ptr<Graylog> graylog() { return m_graylog; }
 
-  Entry *create_entry(int level, int subsys);
+  Entry *create_entry(int level, int subsys, const char* msg = nullptr);
   Entry *create_entry(int level, int subsys, size_t* expected_size);
   void submit_entry(Entry *e);
 
index e11505af4561158d7c91d11dd65b0deb2bef888e..d423e4125b9e30781bd52125b85e2f34f911f78c 100644 (file)
@@ -29,11 +29,7 @@ TEST(Log, Simple)
     int sys = i % 4;
     int l = 5 + (i%4);
     if (subs.should_gather(sys, l)) {
-      Entry *e = new Entry(ceph_clock_now(),
-                          pthread_self(),
-                          l,
-                          sys,
-                          "hello world");
+      Entry *e = log.create_entry(l, sys, "hello world");
       log.submit_entry(e);
     }
   }
@@ -58,7 +54,7 @@ TEST(Log, ManyNoGather)
   for (int i=0; i<many; i++) {
     int l = 10;
     if (subs.should_gather(1, l))
-      log.submit_entry(new Entry(ceph_clock_now(), pthread_self(), l, 1));
+      log.submit_entry(log.create_entry(l, 1));
   }
   log.flush();
   log.stop();
@@ -76,8 +72,8 @@ TEST(Log, ManyGatherLog)
   for (int i=0; i<many; i++) {
     int l = 10;
     if (subs.should_gather(1, l))
-      log.submit_entry(new Entry(ceph_clock_now(), pthread_self(), l, 1,
-                                "this is a long string asdf asdf asdf asdf asdf asdf asd fasd fasdf "));
+      log.submit_entry(log.create_entry(l, 1,
+                                       "this is a long string asdf asdf asdf asdf asdf asdf asd fasd fasdf "));
   }
   log.flush();
   log.stop();
@@ -94,7 +90,7 @@ TEST(Log, ManyGatherLogStringAssign)
   for (int i=0; i<many; i++) {
     int l = 10;
     if (subs.should_gather(1, l)) {
-      Entry *e = new Entry(ceph_clock_now(), pthread_self(), l, 1);
+      Entry *e = log.create_entry(l, 1);
       ostringstream oss;
       oss << "this i a long stream asdf asdf asdf asdf asdf asdf asdf asdf asdf as fd";
       e->set_str(oss.str());
@@ -115,7 +111,7 @@ TEST(Log, ManyGatherLogStringAssignWithReserve)
   for (int i=0; i<many; i++) {
     int l = 10;
     if (subs.should_gather(1, l)) {
-      Entry *e = new Entry(ceph_clock_now(), pthread_self(), l, 1);
+      Entry *e = log.create_entry(l, 1);
       ostringstream oss;
       oss.str().reserve(80);
       oss << "this i a long stream asdf asdf asdf asdf asdf asdf asdf asdf asdf as fd";
@@ -138,7 +134,7 @@ TEST(Log, ManyGatherLogPrebuf)
   for (int i=0; i<many; i++) {
     int l = 10;
     if (subs.should_gather(1, l)) {
-      Entry *e = new Entry(ceph_clock_now(), pthread_self(), l, 1);
+      Entry *e = log.create_entry(l, 1);
       PrebufferedStreambuf psb(e->m_static_buf, sizeof(e->m_static_buf));
       ostream oss(&psb);
       oss << "this i a long stream asdf asdf asdf asdf asdf asdf asdf asdf asdf as fd";
@@ -161,7 +157,7 @@ TEST(Log, ManyGatherLogPrebufOverflow)
   for (int i=0; i<many; i++) {
     int l = 10;
     if (subs.should_gather(1, l)) {
-      Entry *e = new Entry(ceph_clock_now(), pthread_self(), l, 1);
+      Entry *e = log.create_entry(l, 1);
       PrebufferedStreambuf psb(e->m_static_buf, sizeof(e->m_static_buf));
       ostream oss(&psb);
       oss << "this i a long stream asdf asdf asdf asdf asdf asdf asdf asdf asdf as fd"
@@ -185,7 +181,7 @@ TEST(Log, ManyGather)
   for (int i=0; i<many; i++) {
     int l = 10;
     if (subs.should_gather(1, l))
-      log.submit_entry(new Entry(ceph_clock_now(), pthread_self(), l, 1));
+      log.submit_entry(log.create_entry(l, 1));
   }
   log.flush();
   log.stop();
@@ -201,7 +197,7 @@ void do_segv()
   log.reopen_log_file();
 
   log.inject_segv();
-  Entry *e = new Entry(ceph_clock_now(), pthread_self(), 10, 1);
+  Entry *e = log.create_entry(10, 1);
   {
     PrCtl unset_dumpable;
     log.submit_entry(e);  // this should segv
@@ -225,7 +221,7 @@ TEST(Log, LargeLog)
   log.set_log_file("/tmp/big");
   log.reopen_log_file();
   int l = 10;
-  Entry *e = new Entry(ceph_clock_now(), pthread_self(), l, 1);
+  Entry *e = log.create_entry(l, 1);
 
   std::string msg(10000000, 0);
   e->set_str(msg);