You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rm...@apache.org on 2022/08/28 15:25:42 UTC
[logging-log4cxx] branch LOGCXX-527_TS updated (38039220 -> f37ee15f)
This is an automated email from the ASF dual-hosted git repository.
rmiddleton pushed a change to branch LOGCXX-527_TS
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
omit 38039220 Some former assumptions didn't hold anymore. Some tests use generic file names and if those exist during rollover, their last write time is used as new file name. That last write time might be arbitrary in the past and therefore broke existing checks about expected file names. Hence, those files have been deleted.
omit b5db5f0a LOGCXX-527: mock the clock for tests
new f37ee15f LOGCXX-527: mock the clock for tests
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (38039220)
\
N -- N -- N refs/heads/LOGCXX-527_TS (f37ee15f)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
[logging-log4cxx] 01/01: LOGCXX-527: mock the clock for tests
Posted by rm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rmiddleton pushed a commit to branch LOGCXX-527_TS
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit f37ee15f3b6029e193ad403f938cca8d8630215a
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Thu Mar 24 21:23:14 2022 -0400
LOGCXX-527: mock the clock for tests
Mock the clock for unit tests to make them more reliable and configurable.
This also cleans up some APR calls to make us less dependent on APR and
more on standard C++ features
Some former assumptions didn't hold anymore. Some tests use generic file
names and if those exist during rollover, their last write time is used as
new file name. That last write time might be arbitrary in the past and
therefore broke existing checks about expected file names. Hence, those files have been deleted.
That deletion was based on some naming convention and the number of the
executed tests. But some tests simply didn't follow that convention and
because some tests where commented, the expected numbers didn't work as
well. So I've changed the implementation so that each test method needs
to delete the file, as only each method knows which name is used.
Additionally, I centralized things into an individual directory, as that
is done for the corresponding witnesses as well already. Some witness
file contents needed to be adjusted to what I think is the new behaviour,
but not too sure who is correct, the former witness or the test implementation.
---
src/examples/cpp/delayedloop.cpp | 1 +
src/main/cpp/aprinitializer.cpp | 3 +-
src/main/cpp/date.cpp | 25 +-
src/main/cpp/filewatchdog.cpp | 1 -
src/main/cpp/hierarchy.cpp | 1 +
src/main/cpp/htmllayout.cpp | 4 +-
src/main/cpp/loggingevent.cpp | 4 +-
src/main/cpp/propertyconfigurator.cpp | 1 +
src/main/cpp/timebasedrollingpolicy.cpp | 21 +-
src/main/include/log4cxx/helpers/aprinitializer.h | 5 +-
src/main/include/log4cxx/helpers/date.h | 22 +-
.../log4cxx/rolling/timebasedrollingpolicy.h | 1 +
src/test/cpp/rolling/timebasedrollingtest.cpp | 474 +++++++++++----------
src/test/resources/witness/rolling/tbr-test4.0 | 1 +
src/test/resources/witness/rolling/tbr-test4.3 | 1 +
src/test/resources/witness/rolling/tbr-test5.0 | 1 +
src/test/resources/witness/rolling/tbr-test5.3 | 1 +
src/test/resources/witness/rolling/tbr-test6.0 | 1 +
src/test/resources/witness/rolling/tbr-test6.3 | 1 -
19 files changed, 309 insertions(+), 260 deletions(-)
diff --git a/src/examples/cpp/delayedloop.cpp b/src/examples/cpp/delayedloop.cpp
index 194473a8..d1768135 100644
--- a/src/examples/cpp/delayedloop.cpp
+++ b/src/examples/cpp/delayedloop.cpp
@@ -20,6 +20,7 @@
#include <log4cxx/propertyconfigurator.h>
#include <apr_general.h>
#include <apr_time.h>
+#include <apr.h>
#include <iostream>
#include <log4cxx/stream.h>
#include <exception>
diff --git a/src/main/cpp/aprinitializer.cpp b/src/main/cpp/aprinitializer.cpp
index 0bd91d22..cbaeb77d 100644
--- a/src/main/cpp/aprinitializer.cpp
+++ b/src/main/cpp/aprinitializer.cpp
@@ -26,6 +26,7 @@
#include <apr_thread_mutex.h>
#include <apr_thread_proc.h>
#include <log4cxx/helpers/filewatchdog.h>
+#include <log4cxx/helpers/date.h>
using namespace log4cxx::helpers;
using namespace log4cxx;
@@ -46,7 +47,7 @@ APRInitializer::APRInitializer() : p(0), startTime(0), tlsKey(0)
apr_initialize();
apr_pool_create(&p, NULL);
apr_atomic_init(p);
- startTime = apr_time_now();
+ startTime = Date::currentTime();
#if APR_HAS_THREADS
apr_status_t stat = apr_threadkey_private_create(&tlsKey, tlsDestruct, p);
assert(stat == APR_SUCCESS);
diff --git a/src/main/cpp/date.cpp b/src/main/cpp/date.cpp
index a1ea7cec..1fb3a836 100644
--- a/src/main/cpp/date.cpp
+++ b/src/main/cpp/date.cpp
@@ -17,7 +17,7 @@
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/date.h>
-#include <apr_time.h>
+#define LOG4CXX_USEC_PER_SEC 1000000LL
#ifndef INT64_C
#define INT64_C(x) x ## LL
#endif
@@ -27,7 +27,10 @@ using namespace log4cxx::helpers;
IMPLEMENT_LOG4CXX_OBJECT(Date)
-Date::Date() : time(apr_time_now())
+
+Date::GetCurrentTimeFn Date::getCurrentTimeFn = Date::getCurrentTimeStd;
+
+Date::Date() : time(getCurrentTimeFn())
{
}
@@ -41,16 +44,28 @@ Date::~Date()
log4cxx_time_t Date::getMicrosecondsPerDay()
{
- return APR_INT64_C(86400000000);
+ return 86400000000ull;
}
log4cxx_time_t Date::getMicrosecondsPerSecond()
{
- return APR_USEC_PER_SEC;
+ return LOG4CXX_USEC_PER_SEC;
}
log4cxx_time_t Date::getNextSecond() const
{
- return ((time / APR_USEC_PER_SEC) + 1) * APR_USEC_PER_SEC;
+ return ((time / LOG4CXX_USEC_PER_SEC) + 1) * LOG4CXX_USEC_PER_SEC;
+}
+
+void Date::setGetCurrentTimeFunction(GetCurrentTimeFn fn){
+ getCurrentTimeFn = fn;
+}
+
+log4cxx_time_t Date::currentTime(){
+ return getCurrentTimeFn();
+}
+
+log4cxx_time_t Date::getCurrentTimeStd(){
+ return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}
diff --git a/src/main/cpp/filewatchdog.cpp b/src/main/cpp/filewatchdog.cpp
index f9d0d7f0..42576bb3 100644
--- a/src/main/cpp/filewatchdog.cpp
+++ b/src/main/cpp/filewatchdog.cpp
@@ -18,7 +18,6 @@
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/filewatchdog.h>
#include <log4cxx/helpers/loglog.h>
-#include <apr_time.h>
#include <apr_thread_proc.h>
#include <apr_atomic.h>
#include <log4cxx/helpers/transcoder.h>
diff --git a/src/main/cpp/hierarchy.cpp b/src/main/cpp/hierarchy.cpp
index 22caa895..91dee598 100644
--- a/src/main/cpp/hierarchy.cpp
+++ b/src/main/cpp/hierarchy.cpp
@@ -38,6 +38,7 @@
#include <log4cxx/defaultconfigurator.h>
#include <log4cxx/spi/rootlogger.h>
#include <mutex>
+#include <apr.h>
#include "assert.h"
diff --git a/src/main/cpp/htmllayout.cpp b/src/main/cpp/htmllayout.cpp
index f63e78ee..8c18d950 100644
--- a/src/main/cpp/htmllayout.cpp
+++ b/src/main/cpp/htmllayout.cpp
@@ -24,8 +24,8 @@
#include <log4cxx/helpers/iso8601dateformat.h>
#include <log4cxx/helpers/stringhelper.h>
#include <log4cxx/helpers/transcoder.h>
+#include <log4cxx/helpers/date.h>
-#include <apr_time.h>
#include <apr_strings.h>
#include <string.h>
@@ -185,7 +185,7 @@ void HTMLLayout::appendHeader(LogString& output, Pool& p)
output.append(LOG4CXX_EOL);
output.append(LOG4CXX_STR("Log session start time "));
- dateFormat.format(output, apr_time_now(), p);
+ dateFormat.format(output, Date::currentTime(), p);
output.append(LOG4CXX_STR("<br>"));
output.append(LOG4CXX_EOL);
diff --git a/src/main/cpp/loggingevent.cpp b/src/main/cpp/loggingevent.cpp
index eb59e2fb..46a7f671 100644
--- a/src/main/cpp/loggingevent.cpp
+++ b/src/main/cpp/loggingevent.cpp
@@ -29,7 +29,6 @@
#include <log4cxx/helpers/threadspecificdata.h>
#include <log4cxx/helpers/transcoder.h>
-#include <apr_time.h>
#include <apr_portable.h>
#include <apr_strings.h>
#include <log4cxx/helpers/stringhelper.h>
@@ -37,6 +36,7 @@
#include <log4cxx/helpers/bytebuffer.h>
#include <log4cxx/logger.h>
#include <log4cxx/private/log4cxx_private.h>
+#include <log4cxx/helpers/date.h>
using namespace log4cxx;
using namespace log4cxx::spi;
@@ -75,7 +75,7 @@ LoggingEvent::LoggingEvent(
ndcLookupRequired(true),
mdcCopyLookupRequired(true),
message(message1),
- timeStamp(apr_time_now()),
+ timeStamp(Date::currentTime()),
locationInfo(locationInfo1),
threadName(getCurrentThreadName()),
threadUserName(getCurrentThreadUserName())
diff --git a/src/main/cpp/propertyconfigurator.cpp b/src/main/cpp/propertyconfigurator.cpp
index 65efadc2..1edd2e45 100644
--- a/src/main/cpp/propertyconfigurator.cpp
+++ b/src/main/cpp/propertyconfigurator.cpp
@@ -40,6 +40,7 @@
#define LOG4CXX 1
#include <log4cxx/helpers/aprinitializer.h>
+#include <apr.h>
using namespace log4cxx;
diff --git a/src/main/cpp/timebasedrollingpolicy.cpp b/src/main/cpp/timebasedrollingpolicy.cpp
index c81f09d5..cd1fe908 100644
--- a/src/main/cpp/timebasedrollingpolicy.cpp
+++ b/src/main/cpp/timebasedrollingpolicy.cpp
@@ -34,12 +34,6 @@
#include <log4cxx/rolling/rollingfileappenderskeleton.h>
#include<iostream>
-#ifndef INT64_C
- #define INT64_C(x) x ## LL
-#endif
-
-#include <apr_time.h>
-
using namespace log4cxx;
using namespace log4cxx::rolling;
using namespace log4cxx::helpers;
@@ -202,9 +196,8 @@ void TimeBasedRollingPolicy::activateOptions(log4cxx::helpers::Pool& pool)
throw IllegalStateException();
}
- apr_time_t n = apr_time_now();
LogString buf;
- ObjectPtr obj(new Date(n));
+ ObjectPtr obj(new Date());
formatFileName(obj, buf, pool);
lastFileName = buf;
@@ -268,8 +261,9 @@ RolloverDescriptionPtr TimeBasedRollingPolicy::initialize(
const bool append,
Pool& pool)
{
- apr_time_t n = apr_time_now();
- nextCheck = ((n / APR_USEC_PER_SEC) + 1) * APR_USEC_PER_SEC;
+ Date now;
+ log4cxx_time_t n = now.getTime();
+ nextCheck = now.getNextSecond();
File currentFile(currentActiveFile);
@@ -299,8 +293,9 @@ RolloverDescriptionPtr TimeBasedRollingPolicy::rollover(
const bool append,
Pool& pool)
{
- apr_time_t n = apr_time_now();
- nextCheck = ((n / APR_USEC_PER_SEC) + 1) * APR_USEC_PER_SEC;
+ Date now;
+ log4cxx_time_t n = now.getTime();
+ nextCheck = now.getNextSecond();
LogString buf;
ObjectPtr obj(new Date(n));
@@ -419,6 +414,6 @@ bool TimeBasedRollingPolicy::isTriggeringEvent(
return ((apr_time_now()) > nextCheck) || (!bAlreadyInitialized);
#else
- return apr_time_now() > nextCheck;
+ return Date::currentTime() > nextCheck;
#endif
}
diff --git a/src/main/include/log4cxx/helpers/aprinitializer.h b/src/main/include/log4cxx/helpers/aprinitializer.h
index fccd18e0..9fcdd5ca 100644
--- a/src/main/include/log4cxx/helpers/aprinitializer.h
+++ b/src/main/include/log4cxx/helpers/aprinitializer.h
@@ -23,13 +23,14 @@
#endif
#include <list>
+#include <log4cxx/helpers/date.h>
extern "C" {
typedef struct apr_thread_mutex_t apr_thread_mutex_t;
typedef struct apr_threadkey_t apr_threadkey_t;
+ struct apr_pool_t;
}
-#include <apr_time.h>
#include <mutex>
namespace log4cxx
@@ -61,7 +62,7 @@ class APRInitializer
apr_pool_t* p;
std::mutex mutex;
std::list<FileWatchdog*> watchdogs;
- apr_time_t startTime;
+ log4cxx_time_t startTime;
apr_threadkey_t* tlsKey;
static APRInitializer& getInstance();
diff --git a/src/main/include/log4cxx/helpers/date.h b/src/main/include/log4cxx/helpers/date.h
index facace72..c031531d 100644
--- a/src/main/include/log4cxx/helpers/date.h
+++ b/src/main/include/log4cxx/helpers/date.h
@@ -20,7 +20,7 @@
#include <log4cxx/helpers/object.h>
#include <log4cxx/log4cxx.h>
-
+#include <functional>
namespace log4cxx
{
@@ -36,6 +36,13 @@ class LOG4CXX_EXPORT Date : public Object
{
const log4cxx_time_t time;
+ /**
+ * A function that will return the current time(in microseconds) when called
+ */
+ typedef std::function<log4cxx_time_t()> GetCurrentTimeFn;
+
+ static log4cxx_time_t getCurrentTimeStd();
+
public:
DECLARE_LOG4CXX_OBJECT(Date)
BEGIN_LOG4CXX_CAST_MAP()
@@ -60,6 +67,19 @@ class LOG4CXX_EXPORT Date : public Object
static log4cxx_time_t getMicrosecondsPerDay();
static log4cxx_time_t getMicrosecondsPerSecond();
+ static log4cxx_time_t currentTime();
+
+ static GetCurrentTimeFn getCurrentTimeFn;
+
+ /**
+ * Set the function that is used to get the current time.
+ * This is used only for testing purposes and should never be called
+ * under normal circumstances.
+ *
+ * @param fn
+ */
+ static void setGetCurrentTimeFunction(GetCurrentTimeFn fn);
+
};
LOG4CXX_PTR_DEF(Date);
diff --git a/src/main/include/log4cxx/rolling/timebasedrollingpolicy.h b/src/main/include/log4cxx/rolling/timebasedrollingpolicy.h
index ddeacf5e..7c82e3d8 100755
--- a/src/main/include/log4cxx/rolling/timebasedrollingpolicy.h
+++ b/src/main/include/log4cxx/rolling/timebasedrollingpolicy.h
@@ -25,6 +25,7 @@
#include <log4cxx/writerappender.h>
#include <log4cxx/helpers/outputstream.h>
#include <apr_mmap.h>
+#include <functional>
#if defined(_MSC_VER)
#pragma warning ( push )
diff --git a/src/test/cpp/rolling/timebasedrollingtest.cpp b/src/test/cpp/rolling/timebasedrollingtest.cpp
index 706cb3df..7825d947 100644
--- a/src/test/cpp/rolling/timebasedrollingtest.cpp
+++ b/src/test/cpp/rolling/timebasedrollingtest.cpp
@@ -24,6 +24,7 @@
#include <log4cxx/patternlayout.h>
#include <log4cxx/rolling/timebasedrollingpolicy.h>
#include <log4cxx/helpers/simpledateformat.h>
+#include <log4cxx/helpers/date.h>
#include <iostream>
#include <log4cxx/helpers/stringhelper.h>
#include "../util/compare.h"
@@ -40,9 +41,12 @@
// into other string literals or as an object. While macros are hard to debug, embedding into string
// literals is easier this way, because the compiler can automatically collaps them, and if we have
// one macro already, a second for a similar purpose shouldn't hurt as well.
-#define DATE_PATTERN "yyyy-MM-dd_HH_mm_ss"
-#define DATE_PATTERN_STR LogString(LOG4CXX_STR("yyyy-MM-dd_HH_mm_ss"))
-#define PATTERN_LAYOUT LOG4CXX_STR("%c{1} - %m%n")
+#define DATE_PATTERN "yyyy-MM-dd_HH_mm_ss"
+#define DATE_PATTERN_STR LogString(LOG4CXX_STR("yyyy-MM-dd_HH_mm_ss"))
+#define PATTERN_LAYOUT LOG4CXX_STR("%c{1} - %m%n")
+
+#define DIR_PRE_OUTPUT "output/rolling/tbr-"
+#define DIR_PRE_WITNESS "witness/rolling/tbr-"
using namespace log4cxx;
using namespace log4cxx::helpers;
@@ -77,19 +81,12 @@ LOGUNIT_CLASS(TimeBasedRollingTest)
LOGUNIT_TEST(test5);
LOGUNIT_TEST(test6);
LOGUNIT_TEST(test7);
-// LOGUNIT_TEST(create_directories);
+ LOGUNIT_TEST(rollIntoDir);
LOGUNIT_TEST_SUITE_END();
private:
- static LoggerPtr logger;
-
- /**
- * Currently running test.
- * <p>
- * Number of currently running test, used e.g. for some generic code in {@link setUp()}.
- * </p>
- */
- size_t num_test;
+ static LoggerPtr logger;
+ log4cxx_time_t current_time;
/**
* Build file names with timestamps.
@@ -113,30 +110,31 @@ private:
* therefore "now" could have easily past and the first file name will never be found, because
* the rolling appender creates it with a newer "now", at least one second in the future.
* </p>
- * @param[in,out] pool
- * @param[in] prefix
- * @param[in] fileNames
- * param[in,opt] withCompression
- * param[in,opt] startInFuture
+ * @param[in,out] pool
+ * @param[in] prefix
+ * @param[in] fnames
+ * @param[in,opt] compressed
+ * @param[in,opt] startInFuture
*/
template<size_t N>
- void buildTsFileNames( Pool & pool,
- const logchar * prefix,
- LogString (&fileNames)[N],
- bool withCompression = false,
- bool startInFuture = false)
+ void buildTsFnames(
+ Pool& pool,
+ const logchar* prefix,
+ LogString (&fnames)[N],
+ bool compressed = false,
+ bool startInFuture = false)
{
- SimpleDateFormat sdf(DATE_PATTERN_STR);
- apr_time_t now(apr_time_now());
- LogString ext(withCompression ? LOG4CXX_STR(".gz") : LOG4CXX_STR(""));
+ SimpleDateFormat sdf(DATE_PATTERN_STR);
+ log4cxx_time_t now(current_time);
+ LogString ext(compressed ? LOG4CXX_STR(".gz") : LOG4CXX_STR(""));
now += startInFuture ? APR_USEC_PER_SEC : 0;
for (size_t i = 0; i < N; ++i)
{
- fileNames[i].assign(LogString(LOG4CXX_STR("output/")) + prefix);
- sdf.format(fileNames[i], now, pool);
- fileNames[i].append(ext);
+ fnames[i].assign(LogString(LOG4CXX_STR("" DIR_PRE_OUTPUT)) + prefix);
+ sdf.format(fnames[i], now, pool);
+ fnames[i].append(ext);
now += APR_USEC_PER_SEC;
}
@@ -170,25 +168,26 @@ private:
* We had macro wrappers around this method dealing with such things in the past, but as args
* where added, those become more and more difficult to maintain properly and therefore removed.
* </p>
- * @param[in,out] pool
- * @param[in] howOften
- * @param[in] srcFunc
- * @param[in] srcLine
- * @param[in,opt] startWith
- * @param[in] waitFactor
+ * @param[in,out] pool
+ * @param[in] howOften
+ * @param[in] srcFunc
+ * @param[in] srcLine
+ * @param[in,opt] startWith
+ * @param[in] waitFactor
*/
- void logMsgAndSleep(Pool & pool,
- size_t howOften,
- std::string srcFunc,
- size_t srcLine,
- size_t startWith = 0,
- float waitFactor = 0.5)
+ void logMsgAndSleep(
+ Pool& pool,
+ size_t howOften,
+ std::string srcFunc,
+ size_t srcLine,
+ size_t startWith = 0,
+ float waitFactor = 0.5)
{
#undef LOG4CXX_LOCATION
-#define LOG4CXX_LOCATION ::log4cxx::spi::LocationInfo( \
- __FILE__, \
- __FILE__, \
- srcFunc.c_str(), \
+#define LOG4CXX_LOCATION ::log4cxx::spi::LocationInfo( \
+ __FILE__, \
+ __FILE__, \
+ srcFunc.c_str(), \
srcLine)
for (size_t i = startWith; i < startWith + howOften; ++i)
@@ -197,14 +196,14 @@ private:
message.append(pool.itoa(i));
LOG4CXX_DEBUG(logger, message);
- apr_sleep(APR_USEC_PER_SEC * waitFactor);
+ current_time += (APR_USEC_PER_SEC * waitFactor);
}
#undef LOG4CXX_LOCATION
-#define LOG4CXX_LOCATION ::log4cxx::spi::LocationInfo( \
- __FILE__, \
- __FILE__, \
- __LOG4CXX_FUNC__, \
+#define LOG4CXX_LOCATION ::log4cxx::spi::LocationInfo( \
+ __FILE__, \
+ __FILE__, \
+ __LOG4CXX_FUNC__, \
__LINE__)
}
@@ -220,23 +219,26 @@ private:
* We don't use a wrapper macro this time because the src line should have the same name in all
* compilers and is easily to add for the caller.
* </p>
- * @param[in,out] pool
- * @param[in] prefix
- * @param[in] fileName
- * @param[in] witnessIdx
- * @param[in] srcLine
+ * @param[in,out] pool
+ * @param[in] prefix
+ * @param[in] fname
+ * @param[in] witnessIdx
+ * @param[in] srcLine
*/
- void compareWitness( Pool & pool,
- const logchar * prefix,
- const LogString & fileName,
- size_t witnessIdx,
- size_t srcLine)
+ void compareWitness(
+ Pool& pool,
+ const logchar* prefix,
+ const LogString& fname,
+ size_t witnessIdx,
+ size_t srcLine)
{
- LogString witness(LOG4CXX_STR("witness/rolling/tbr-"));
+ LogString witness(LOG4CXX_STR("" DIR_PRE_WITNESS));
witness.append(prefix);
-
StringHelper::toString(witnessIdx, pool, witness);
- LOGUNIT_ASSERT_SRCL(Compare::compare(fileName, File(witness)), srcLine);
+
+ //std::wcerr << L"Comparing file: " << fname << L"\n";
+ //std::wcerr << L"Comparing witness: " << witness << L"\n";
+ LOGUNIT_ASSERT_SRCL(Compare::compare(fname, File(witness)), srcLine);
}
/**
@@ -245,20 +247,21 @@ private:
* This method is a wrapper around {@link compareWitness}, used to iterate over all files from a
* given test.
* </p>
- * @param[in,out] pool
- * @param[in] prefix
- * @param[in] fileNames
- * @param[in] srcLine
+ * @param[in,out] pool
+ * @param[in] prefix
+ * @param[in] fnames
+ * @param[in] srcLine
*/
template<size_t N>
- void compareWitnesses( Pool & pool,
- const logchar * prefix,
- LogString (&fileNames)[N],
- size_t srcLine)
+ void compareWitnesses(
+ Pool& pool,
+ const logchar* prefix,
+ LogString (&fnames)[N],
+ size_t srcLine)
{
for (int i = 0; i < N; ++i)
{
- this->compareWitness(pool, prefix, fileNames[i], i, srcLine);
+ this->compareWitness(pool, prefix, fnames[i], i, srcLine);
}
}
@@ -269,26 +272,30 @@ private:
* the last one by content to some witness.
* </p>
* <p>
- * We don't use a wrapper macro this time because the src line schould have the same name in all
+ * We don't use a wrapper macro this time because the src line should have the same name in all
* compilers and is easily to add for the caller.
* </p>
- * @param[in,out] pool
- * @param[in] prefix
- * @param[in] fileNames
- * @param[in] srcLine
+ * @param[in,out] pool
+ * @param[in] prefix
+ * @param[in] fnames
+ * @param[in] witnessIdx
+ * @param[in] srcLine
*/
template<size_t N>
- void checkFilesExist( Pool & pool,
- const logchar * prefix,
- LogString (&fileNames)[N],
- size_t srcLine)
+ void checkFilesExist(
+ Pool& pool,
+ const logchar* prefix,
+ LogString (&fnames)[N],
+ size_t witnessIdx,
+ size_t srcLine)
{
for (int i = 0; i < N - 1; ++i)
{
- LOGUNIT_ASSERT_EQUAL_SRCL(true, File(fileNames[0]).exists(pool), srcLine);
+ //std::wcerr << L"Check: " << fnames[i] << L"\n";
+ LOGUNIT_ASSERT_EQUAL_SRCL(true, File(fnames[i]).exists(pool), srcLine);
}
- this->compareWitness(pool, prefix, fileNames[N - 1], N - 1, srcLine);
+ this->compareWitness(pool, prefix, fnames[witnessIdx], witnessIdx, srcLine);
}
/**
@@ -299,12 +306,9 @@ private:
* </p>
* @param[in,opt] millis
*/
- void delayUntilNextSecond(size_t millis = 100)
+ void delayUntilNextSecond()
{
- apr_time_t now = apr_time_now();
- apr_time_t next = ((now / APR_USEC_PER_SEC) + 1) * APR_USEC_PER_SEC + millis * 1000L;
-
- apr_sleep(next - now);
+ current_time += APR_USEC_PER_SEC;
}
/**
@@ -315,74 +319,53 @@ private:
* </p>
* @param[in,opt] millis
*/
- void delayUntilNextSecondWithMsg(size_t millis = 100)
+ void delayUntilNextSecondWithMsg()
{
- std::cout << "Waiting until next second and " << millis << " millis.";
- delayUntilNextSecond(millis);
- std::cout << "Done waiting." << std::endl;
+ std::cout << "Advancing one second\n";
+ delayUntilNextSecond();
}
/**
- * Delete generic log files.
+ * Delete generic log file.
* <p>
* Some tests use generic log file names which may already be available during subsequent calls
* to the test and influence their behavior, e.g. because RollingFileAppender uses the last
- * modification time of already existing files to create their internal names. Such a date may
- * be from the arbitrary past, but ost of the test assumes operations like rollovers within few
- * seconds around "new". Thos assumptions will fail for older existing files. So this method can
- * be called during {@link setUp()} of an test to clear such generically named files for each
- * test. We currently only care about {@code output/testxy.log}.
+ * modification time of already existing files to create its internal name. Such a date might be
+ * from the arbitrary past, but most of the tests assume operations like rollovers within a few
+ * seconds around "new". Those assumptions will fail for older existing files. This method can
+ * be used to delete those files, while documenting the problem at the same time.
* </p>
- * @param[in] num_test
+ * @param[in,out] pool
+ * @param[in] path
*/
- void deleteGenericLogFilePerTest(size_t num_test)
+ void delGenericLogFile(
+ Pool& pool,
+ LogString path)
{
- Pool pool;
- LogString path(LOG4CXX_STR("output/test"));
-
- StringHelper::toString(num_test, pool, path);
- path.append(LOG4CXX_STR(".log"));
-
File(path).deleteFile(pool);
}
/**
- * Setup for internal test call.
- * <p>
- * This method has a similar intention like {@link setUp()}, only that it focusses on internal
- * calls of the tests, where we don't need to create some loggers and such, but may need to
- * delete some files etc. to make tests work.
- * </p>
- * @param[in] num_test
- */
- void internalSetUp(size_t num_test)
- {
- this->deleteGenericLogFilePerTest(num_test);
- }
-
- /**
- * Counterpart for {@like internalSetUp(size_t)}.
+ * Set the current time for each individual test methhod run.
* <p>
- * Counterpart for {@like internalSetUp(size_t)}.
+ * There's at least one test running multiple other tests WITHIN the same lifecycle of
+ * {@code setUp} and {@code tearDown}, but each of the test methods need the same current time
+ * to start with. So this method can be used to set that and is simply used by {@code setUp}
+ * as well.
* </p>
*/
- void internalTearDown()
+ void setUpCurrTime()
{
- // Nothing to do currently.
+ //current_time = log4cxx::helpers::Date::currentTime(); // Start at "about" now.
+ //current_time -= (current_time % APR_USEC_PER_SEC); // Go to the top of the second
+ //current_time++; // Need to not be at the top of a second for rollover logic to work correctly
+ current_time = 1; // Start at about unix epoch
}
public:
- /**
- * Extract number of current test.
- * <p>
- * {@code setUp()} needs the number of the current runnign test for some generic work and this
- * is the only place where we can extract and save it in the instance.
- * </p>
- */
- void setCase(abts_case * tc)
+ log4cxx_time_t currentTime()
{
- LogUnit::TestFixture::setCase(tc);
- this->num_test = tc->suite->num_test;
+ return current_time;
}
void setUp()
@@ -392,216 +375,240 @@ public:
ConsoleAppenderPtr(new ConsoleAppender(
PatternLayoutPtr(new PatternLayout(
LOG4CXX_STR("%d{ABSOLUTE} [%t] %level %c{2}#%M:%L - %m%n"))))));
- this->internalSetUp(this->num_test);
+
+ this->setUpCurrTime();
+ log4cxx::helpers::Date::setGetCurrentTimeFunction( std::bind( &TimeBasedRollingTest::currentTime, this ) );
}
void tearDown()
{
- this->internalTearDown();
LogManager::shutdown();
}
/**
- * Test rolling without compression, activeFileName left blank, no stop/start
+ * Test rolling without compression, activeFileName left blank, no stop/start.
*/
void test1()
{
- Pool pool;
- const size_t nrOfFileNames = 4;
- LogString fileNames[nrOfFileNames];
+ Pool pool;
+ const size_t nrOfFnames(4);
+ LogString fnames[nrOfFnames];
- PatternLayoutPtr layout( new PatternLayout(PATTERN_LAYOUT));
- RollingFileAppenderPtr rfa( new RollingFileAppender());
+ PatternLayoutPtr layout( new PatternLayout(PATTERN_LAYOUT));
+ RollingFileAppenderPtr rfa( new RollingFileAppender());
+ rfa->setAppend(false);
rfa->setLayout(layout);
TimeBasedRollingPolicyPtr tbrp(new TimeBasedRollingPolicy());
- tbrp->setFileNamePattern(LOG4CXX_STR("output/test1-%d{" DATE_PATTERN "}"));
+ tbrp->setFileNamePattern(LOG4CXX_STR("" DIR_PRE_OUTPUT "test1-%d{" DATE_PATTERN "}"));
tbrp->activateOptions(pool);
rfa->setRollingPolicy(tbrp);
rfa->activateOptions(pool);
logger->addAppender(rfa);
- this->buildTsFileNames(pool, LOG4CXX_STR("test1-"), fileNames);
+ this->buildTsFnames(pool, LOG4CXX_STR("test1-"), fnames);
this->delayUntilNextSecondWithMsg();
- this->logMsgAndSleep( pool, nrOfFileNames + 1, __LOG4CXX_FUNC__, __LINE__);
- this->compareWitnesses( pool, LOG4CXX_STR("test1."), fileNames, __LINE__);
+ this->logMsgAndSleep( pool, nrOfFnames + 1, __LOG4CXX_FUNC__, __LINE__);
+ this->compareWitnesses( pool, LOG4CXX_STR("test1."), fnames, __LINE__);
}
+
/**
- * No compression, with stop/restart, activeFileName left blank
+ * No compression, with stop/restart, activeFileName left blank.
*/
void test2()
{
- Pool pool;
- const size_t nrOfFileNames = 4;
- LogString fileNames[nrOfFileNames];
+ Pool pool;
+ const size_t nrOfFnames(4);
+ LogString fnames[nrOfFnames];
- PatternLayoutPtr layout1(new PatternLayout(PATTERN_LAYOUT));
- RollingFileAppenderPtr rfa1( new RollingFileAppender());
+ PatternLayoutPtr layout1(new PatternLayout(PATTERN_LAYOUT));
+ RollingFileAppenderPtr rfa1( new RollingFileAppender());
+ rfa1->setAppend(false);
rfa1->setLayout(layout1);
TimeBasedRollingPolicyPtr tbrp1(new TimeBasedRollingPolicy());
- tbrp1->setFileNamePattern(LOG4CXX_STR("output/test2-%d{" DATE_PATTERN "}"));
+ tbrp1->setFileNamePattern(LOG4CXX_STR("" DIR_PRE_OUTPUT "test2-%d{" DATE_PATTERN "}"));
tbrp1->activateOptions(pool);
rfa1->setRollingPolicy(tbrp1);
rfa1->activateOptions(pool);
logger->addAppender(rfa1);
- this->buildTsFileNames(pool, LOG4CXX_STR("test2-"), fileNames);
+ this->buildTsFnames(pool, LOG4CXX_STR("test2-"), fnames);
this->delayUntilNextSecondWithMsg();
this->logMsgAndSleep(pool, 3, __LOG4CXX_FUNC__, __LINE__);
logger->removeAppender(rfa1);
rfa1->close();
- PatternLayoutPtr layout2(new PatternLayout(PATTERN_LAYOUT));
- RollingFileAppenderPtr rfa2( new RollingFileAppender());
+ PatternLayoutPtr layout2(new PatternLayout(PATTERN_LAYOUT));
+ RollingFileAppenderPtr rfa2( new RollingFileAppender());
rfa2->setLayout(layout2);
TimeBasedRollingPolicyPtr tbrp2 = TimeBasedRollingPolicyPtr(new TimeBasedRollingPolicy());
- tbrp2->setFileNamePattern(LOG4CXX_STR("output/test2-%d{" DATE_PATTERN "}"));
+ tbrp2->setFileNamePattern(LOG4CXX_STR("" DIR_PRE_OUTPUT "test2-%d{" DATE_PATTERN "}"));
tbrp2->activateOptions(pool);
rfa2->setRollingPolicy(tbrp2);
rfa2->activateOptions(pool);
+ rfa2->setAppend(false);
logger->addAppender(rfa2);
- this->logMsgAndSleep( pool, 2, __LOG4CXX_FUNC__, __LINE__, 3);
- this->compareWitnesses( pool, LOG4CXX_STR("test2."), fileNames, __LINE__);
+ this->logMsgAndSleep( pool, 2, __LOG4CXX_FUNC__, __LINE__, 3);
+ this->compareWitnesses( pool, LOG4CXX_STR("test2."), fnames, __LINE__);
}
+
/**
- * With compression, activeFileName left blank, no stop/restart
+ * With compression, activeFileName left blank, no stop/restart.
*/
void test3()
{
- Pool pool;
- const size_t nrOfFileNames = 4;
- LogString fileNames[nrOfFileNames];
+ Pool pool;
+ const size_t nrOfFnames(4);
+ LogString fnames[nrOfFnames];
- PatternLayoutPtr layout( new PatternLayout(PATTERN_LAYOUT));
- RollingFileAppenderPtr rfa( new RollingFileAppender());
+ PatternLayoutPtr layout( new PatternLayout(PATTERN_LAYOUT));
+ RollingFileAppenderPtr rfa( new RollingFileAppender());
rfa->setAppend(false);
rfa->setLayout(layout);
TimeBasedRollingPolicyPtr tbrp = TimeBasedRollingPolicyPtr(new TimeBasedRollingPolicy());
- tbrp->setFileNamePattern(LogString(LOG4CXX_STR("output/test3-%d{" DATE_PATTERN "}.gz")));
+ tbrp->setFileNamePattern(LogString(LOG4CXX_STR("" DIR_PRE_OUTPUT "test3-%d{" DATE_PATTERN "}.gz")));
tbrp->activateOptions(pool);
rfa->setRollingPolicy(tbrp);
rfa->activateOptions(pool);
logger->addAppender(rfa);
- this->buildTsFileNames(pool, LOG4CXX_STR("test3-"), fileNames, true);
- fileNames[3].resize(fileNames[3].size() - 3);
+ this->buildTsFnames(pool, LOG4CXX_STR("test3-"), fnames, true);
+ fnames[nrOfFnames - 1].resize(fnames[nrOfFnames - 1].size() - 3);
this->delayUntilNextSecondWithMsg();
- this->logMsgAndSleep( pool, nrOfFileNames + 1, __LOG4CXX_FUNC__, __LINE__);
- this->checkFilesExist( pool, LOG4CXX_STR("test3."), fileNames, __LINE__);
+ this->logMsgAndSleep( pool, nrOfFnames + 1, __LOG4CXX_FUNC__, __LINE__);
+ this->checkFilesExist( pool, LOG4CXX_STR("test3."), fnames, nrOfFnames - 1, __LINE__);
}
/**
* Without compression, activeFileName set, with stop/restart
+ *
+ * Note: because this test stops and restarts, it is not possible to use the
+ * date pattern in the filenames, as log4cxx will use the file's last modified
+ * time when rolling over and determining the new filename.
*/
void test4()
{
- Pool pool;
- const size_t nrOfFileNames = 4;
- LogString fileNames[nrOfFileNames];
+ Pool pool;
+ const size_t nrOfFnames(4);
+ const size_t nrOfLogMsgs(((nrOfFnames - 1) * 2) - 1);
+ LogString fnames[nrOfFnames];
- PatternLayoutPtr layout1(new PatternLayout(PATTERN_LAYOUT));
- RollingFileAppenderPtr rfa1( new RollingFileAppender());
+ PatternLayoutPtr layout1(new PatternLayout(PATTERN_LAYOUT));
+ RollingFileAppenderPtr rfa1( new RollingFileAppender());
rfa1->setLayout(layout1);
TimeBasedRollingPolicyPtr tbrp1 = TimeBasedRollingPolicyPtr(new TimeBasedRollingPolicy());
- rfa1->setFile(LOG4CXX_STR("output/test4.log"));
- tbrp1->setFileNamePattern(LOG4CXX_STR("output/test4-%d{" DATE_PATTERN "}"));
+ tbrp1->setFileNamePattern(LOG4CXX_STR("" DIR_PRE_OUTPUT "test4-%d{" DATE_PATTERN "}"));
tbrp1->activateOptions(pool);
+ rfa1->setFile(LOG4CXX_STR("" DIR_PRE_OUTPUT "test4.log"));
rfa1->setRollingPolicy(tbrp1);
rfa1->activateOptions(pool);
logger->addAppender(rfa1);
- this->buildTsFileNames(pool, LOG4CXX_STR("test4-"), fileNames);
- fileNames[3].assign(rfa1->getFile());
+ this->delGenericLogFile(pool, rfa1->getFile());
+ this->buildTsFnames(pool, LOG4CXX_STR("test4-"), fnames);
+ fnames[0].assign(rfa1->getFile());
this->delayUntilNextSecondWithMsg();
- this->logMsgAndSleep(pool, 3, __LOG4CXX_FUNC__, __LINE__);
+ this->logMsgAndSleep(pool, nrOfLogMsgs, __LOG4CXX_FUNC__, __LINE__);
logger->removeAppender(rfa1);
rfa1->close();
- PatternLayoutPtr layout2(new PatternLayout(PATTERN_LAYOUT));
- RollingFileAppenderPtr rfa2( new RollingFileAppender());
+ PatternLayoutPtr layout2(new PatternLayout(PATTERN_LAYOUT));
+ RollingFileAppenderPtr rfa2( new RollingFileAppender());
rfa2->setLayout(layout2);
TimeBasedRollingPolicyPtr tbrp2 = TimeBasedRollingPolicyPtr(new TimeBasedRollingPolicy());
- tbrp2->setFileNamePattern(LOG4CXX_STR("output/test4-%d{" DATE_PATTERN "}"));
- rfa2->setFile(fileNames[3]);
+ tbrp2->setFileNamePattern(LOG4CXX_STR("" DIR_PRE_OUTPUT "test4-%d{" DATE_PATTERN "}"));
tbrp2->activateOptions(pool);
+ rfa2->setFile(rfa1->getFile());
rfa2->setRollingPolicy(tbrp2);
rfa2->activateOptions(pool);
logger->addAppender(rfa2);
- this->logMsgAndSleep( pool, 2, __LOG4CXX_FUNC__, __LINE__, 3);
- this->compareWitnesses( pool, LOG4CXX_STR("test4."), fileNames, __LINE__);
+ // The one file not checked is the active file from the old appender reused by the new one
+ // and rolled over afterwards. The problem is that because the reused file exists already,
+ // it doesn't get an expected fname, but the last write time instead. Though, should be safe
+ // enough to not check that special file.
+ this->logMsgAndSleep(pool, 2, __LOG4CXX_FUNC__, __LINE__, nrOfLogMsgs);
+ this->compareWitness(pool, LOG4CXX_STR("test4."), fnames[0], 0, __LINE__);
+ this->compareWitness(pool, LOG4CXX_STR("test4."), fnames[1], 1, __LINE__);
+ this->compareWitness(pool, LOG4CXX_STR("test4."), fnames[2], 2, __LINE__);
}
/**
- * No compression, activeFileName set, without stop/restart
+ * No compression, activeFileName set, without stop/restart.
*/
void test5()
{
- Pool pool;
- const size_t nrOfFileNames = 4;
- LogString fileNames[nrOfFileNames];
+ Pool pool;
+ const size_t nrOfFnames(4);
+ const size_t nrOfLogMsgs((nrOfFnames * 2) - 1);
+ LogString fnames[nrOfFnames];
- PatternLayoutPtr layout( new PatternLayout(PATTERN_LAYOUT));
- RollingFileAppenderPtr rfa( new RollingFileAppender());
+ PatternLayoutPtr layout( new PatternLayout(PATTERN_LAYOUT));
+ RollingFileAppenderPtr rfa( new RollingFileAppender());
rfa->setLayout(layout);
TimeBasedRollingPolicyPtr tbrp = TimeBasedRollingPolicyPtr(new TimeBasedRollingPolicy());
- tbrp->setFileNamePattern(LOG4CXX_STR("output/test5-%d{" DATE_PATTERN "}"));
- rfa->setFile(LOG4CXX_STR("output/test5.log"));
+ tbrp->setFileNamePattern(LOG4CXX_STR("" DIR_PRE_OUTPUT "test5-%d{" DATE_PATTERN "}"));
+ rfa->setFile(LOG4CXX_STR("" DIR_PRE_OUTPUT "test5.log"));
tbrp->activateOptions(pool);
rfa->setRollingPolicy(tbrp);
rfa->activateOptions(pool);
logger->addAppender(rfa);
- this->buildTsFileNames(pool, LOG4CXX_STR("test5-"), fileNames);
- fileNames[3].assign(rfa->getFile());
+ this->delGenericLogFile(pool, rfa->getFile());
+ this->buildTsFnames(pool, LOG4CXX_STR("test5-"), fnames);
+ fnames[0].assign(rfa->getFile());
+
this->delayUntilNextSecondWithMsg();
- this->logMsgAndSleep( pool, nrOfFileNames + 1, __LOG4CXX_FUNC__, __LINE__);
- this->compareWitnesses( pool, LOG4CXX_STR("test5."), fileNames, __LINE__);
+ this->logMsgAndSleep( pool, nrOfLogMsgs, __LOG4CXX_FUNC__, __LINE__);
+ this->compareWitnesses( pool, LOG4CXX_STR("test5."), fnames, __LINE__);
}
/**
- * With compression, activeFileName set, no stop/restart,
+ * With compression, activeFileName set, no stop/restart.
*/
void test6()
{
- Pool pool;
- const size_t nrOfFileNames = 4;
- LogString fileNames[nrOfFileNames];
+ Pool pool;
+ const size_t nrOfFnames(4);
+ const size_t nrOfLogMsgs((nrOfFnames * 2) - 1);
+ LogString fnames[nrOfFnames];
- PatternLayoutPtr layout( new PatternLayout(PATTERN_LAYOUT));
- RollingFileAppenderPtr rfa( new RollingFileAppender());
+ PatternLayoutPtr layout( new PatternLayout(PATTERN_LAYOUT));
+ RollingFileAppenderPtr rfa( new RollingFileAppender());
rfa->setAppend(false);
rfa->setLayout(layout);
TimeBasedRollingPolicyPtr tbrp = TimeBasedRollingPolicyPtr(new TimeBasedRollingPolicy());
- tbrp->setFileNamePattern(LogString(LOG4CXX_STR("output/test6-%d{" DATE_PATTERN "}.gz")));
- rfa->setFile(LOG4CXX_STR("output/test6.log"));
+ tbrp->setFileNamePattern(LogString(LOG4CXX_STR("" DIR_PRE_OUTPUT "test6-%d{" DATE_PATTERN "}.gz")));
+ rfa->setFile(LOG4CXX_STR("" DIR_PRE_OUTPUT "test6.log"));
tbrp->activateOptions(pool);
rfa->setRollingPolicy(tbrp);
rfa->activateOptions(pool);
logger->addAppender(rfa);
- this->buildTsFileNames(pool, LOG4CXX_STR("test6-"), fileNames, true);
- fileNames[3].assign(rfa->getFile());
+ this->delGenericLogFile(pool, rfa->getFile());
+ this->buildTsFnames(pool, LOG4CXX_STR("test6-"), fnames, true);
+ fnames[0].assign(rfa->getFile());
+
this->delayUntilNextSecondWithMsg();
- this->logMsgAndSleep( pool, nrOfFileNames + 1, __LOG4CXX_FUNC__, __LINE__);
- this->checkFilesExist( pool, LOG4CXX_STR("test6."), fileNames, __LINE__);
+ this->logMsgAndSleep( pool, nrOfLogMsgs, __LOG4CXX_FUNC__, __LINE__);
+ this->checkFilesExist( pool, LOG4CXX_STR("test6."), fnames, 0, __LINE__);
}
/**
- * Repeat some test with generic file name.s
+ * Repeat some tests with generic file names.
* <p>
* This test calls some tests which use generic file names and will only work properly if those
* got deleted before running the test during setup.
@@ -612,8 +619,8 @@ public:
typedef void (TimeBasedRollingTest::*Test)();
typedef std::vector<Test> Tests;
- Tests tests(10);
- size_t numTest = 0;
+ Tests tests(10);
+ size_t numTest = 0;
tests.at(4) = &TimeBasedRollingTest::test4;
tests.at(5) = &TimeBasedRollingTest::test5;
@@ -622,39 +629,40 @@ public:
for (size_t numTest = 1; numTest < tests.size(); ++numTest)
{
Test test(tests.at(numTest));
-
if (!test)
{
continue;
}
- this->internalSetUp(numTest);
+ this->setUpCurrTime();
(this->*test)();
- this->internalTearDown();
}
}
- void create_directories()
+ void rollIntoDir()
{
- Pool pool;
- const size_t nrOfFileNames = 4;
- LogString fileNames[nrOfFileNames];
+ Pool pool;
+ const size_t nrOfFnames(4);
+ const size_t nrOfLogMsgs((nrOfFnames * 2) - 1);
+ LogString fnames[nrOfFnames];
- PatternLayoutPtr layout( new PatternLayout(PATTERN_LAYOUT));
- RollingFileAppenderPtr rfa( new RollingFileAppender());
+ PatternLayoutPtr layout( new PatternLayout(PATTERN_LAYOUT));
+ RollingFileAppenderPtr rfa( new RollingFileAppender());
rfa->setLayout(layout);
- rfa->setFile(LOG4CXX_STR("output/timebasedrolling_create_dir.log"));
+ rfa->setFile(LOG4CXX_STR("" DIR_PRE_OUTPUT "rollIntoDir.log"));
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> dist(1,100000);
- LogString filenamePattern = LOG4CXX_STR("output/tbrolling-directory-");
+ LogString filenamePattern = LOG4CXX_STR("" DIR_PRE_OUTPUT);
#if LOG4CXX_LOGCHAR_IS_WCHAR
LogString dirNumber = std::to_wstring(dist(rng));
#else
LogString dirNumber = std::to_string(dist(rng));
#endif
- filenamePattern.append( dirNumber );
+ LogString directoryName = LOG4CXX_STR("tbr-rollIntoDir-");
+ directoryName.append( dirNumber );
+ filenamePattern.append( directoryName );
LogString filenamePatternPrefix = filenamePattern;
filenamePattern.append( LOG4CXX_STR("/file-%d{" DATE_PATTERN "}") );
@@ -665,15 +673,17 @@ public:
rfa->activateOptions(pool);
logger->addAppender(rfa);
- this->buildTsFileNames(pool, filenamePatternPrefix.append(LOG4CXX_STR("/file-")).data(), fileNames);
- this->delayUntilNextSecondWithMsg();
- this->logMsgAndSleep( pool, nrOfFileNames + 1, __LOG4CXX_FUNC__, __LINE__);
-// this->compareWitnesses( pool, LOG4CXX_STR("test1."), fileNames, __LINE__);
+ const logchar* prefix = directoryName.append(LOG4CXX_STR("/file-")).data();
- for( size_t x = 0; x < nrOfFileNames - 1; x++ ){
- LOGUNIT_ASSERT_EQUAL(true, File(fileNames[x]).exists(pool));
- }
+ this->delGenericLogFile(pool, rfa->getFile());
+ this->buildTsFnames(pool, prefix, fnames);
+ fnames[0].assign(rfa->getFile());
+
+ this->delayUntilNextSecondWithMsg();
+ this->logMsgAndSleep( pool, nrOfLogMsgs, __LOG4CXX_FUNC__, __LINE__);
+ this->checkFilesExist( pool, LOG4CXX_STR("test6."), fnames, 0, __LINE__);
}
+
};
LoggerPtr TimeBasedRollingTest::logger(Logger::getLogger("org.apache.log4j.TimeBasedRollingTest"));
diff --git a/src/test/resources/witness/rolling/tbr-test4.0 b/src/test/resources/witness/rolling/tbr-test4.0
index e69de29b..ae12f7ad 100644
--- a/src/test/resources/witness/rolling/tbr-test4.0
+++ b/src/test/resources/witness/rolling/tbr-test4.0
@@ -0,0 +1 @@
+TimeBasedRollingTest - Hello---6
diff --git a/src/test/resources/witness/rolling/tbr-test4.3 b/src/test/resources/witness/rolling/tbr-test4.3
index dfc095dc..9a81d949 100644
--- a/src/test/resources/witness/rolling/tbr-test4.3
+++ b/src/test/resources/witness/rolling/tbr-test4.3
@@ -1 +1,2 @@
TimeBasedRollingTest - Hello---4
+TimeBasedRollingTest - Hello---5
diff --git a/src/test/resources/witness/rolling/tbr-test5.0 b/src/test/resources/witness/rolling/tbr-test5.0
index e69de29b..ae12f7ad 100644
--- a/src/test/resources/witness/rolling/tbr-test5.0
+++ b/src/test/resources/witness/rolling/tbr-test5.0
@@ -0,0 +1 @@
+TimeBasedRollingTest - Hello---6
diff --git a/src/test/resources/witness/rolling/tbr-test5.3 b/src/test/resources/witness/rolling/tbr-test5.3
index dfc095dc..9a81d949 100644
--- a/src/test/resources/witness/rolling/tbr-test5.3
+++ b/src/test/resources/witness/rolling/tbr-test5.3
@@ -1 +1,2 @@
TimeBasedRollingTest - Hello---4
+TimeBasedRollingTest - Hello---5
diff --git a/src/test/resources/witness/rolling/tbr-test6.0 b/src/test/resources/witness/rolling/tbr-test6.0
new file mode 100644
index 00000000..ae12f7ad
--- /dev/null
+++ b/src/test/resources/witness/rolling/tbr-test6.0
@@ -0,0 +1 @@
+TimeBasedRollingTest - Hello---6
diff --git a/src/test/resources/witness/rolling/tbr-test6.3 b/src/test/resources/witness/rolling/tbr-test6.3
deleted file mode 100644
index dfc095dc..00000000
--- a/src/test/resources/witness/rolling/tbr-test6.3
+++ /dev/null
@@ -1 +0,0 @@
-TimeBasedRollingTest - Hello---4