/* * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/ #include"precompiled.hpp" #include"jvm.h" #include"logging/log.hpp" #include"logging/logAsyncWriter.hpp" #include"logging/logFileOutput.hpp" #include"logging/logMessage.hpp" #include"logTestFixture.hpp" #include"logTestUtils.inline.hpp" #include"unittest.hpp"
class AsyncLogTest : public LogTestFixture { public:
AsyncLogTest() { if(!LogConfiguration::is_async_mode()) {
fprintf(stderr, "Warning: asynclog is OFF.\n");
}
}
for (int i = 0; i < MULTI_LINES; ++i) {
msg.debug("nonbreakable log message line-%02d", i);
if (0 == (i % 4)) {
logger.debug("a noisy message from other logger");
}
}
logger.debug("a noisy message from other logger");
}
AsyncLogWriter::flush();
ResourceMark rm;
LogMessageBuffer buffer; constchar* strs[MULTI_LINES + 1];
strs[MULTI_LINES] = NULL; for (int i = 0; i < MULTI_LINES; ++i) {
stringStream ss;
ss.print_cr("nonbreakable log message line-%02d", i);
strs[i] = ss.as_string();
} // check nonbreakable log messages are consecutive
EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, strs));
EXPECT_TRUE(file_contains_substring(TestLogFileName, "a noisy message from other logger"));
}
while (buffer->push_back(output, Default, "0123456789abcdef")) {
line++;
}
EXPECT_GT(line, 2); while (it.hasNext()) {
e = it.next();
addr = reinterpret_cast<uintptr_t>(e);
EXPECT_EQ(0, (int)(addr & (sizeof(void*)-1)));
EXPECT_EQ(output, e->output());
EXPECT_STREQ("0123456789abcdef", e->message());
written = e->output()->write_blocking(e->decorations(), e->message());
EXPECT_GT(written, 0);
line--;
}
EXPECT_EQ(line, 2);
// last one, flush token. expect to succeed even buffer has been full.
buffer->push_flush_token();
EXPECT_TRUE(it.hasNext());
e = it.next();
EXPECT_EQ(e->output(), nullptr);
EXPECT_TRUE(e->is_token());
EXPECT_STREQ("", e->message());
EXPECT_FALSE(it.hasNext());
AsyncLogWriter::flush(); if (AsyncLogWriter::instance() != nullptr) {
EXPECT_TRUE(file_contains_substring(TestLogFileName, "messages dropped due to async logging"));
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.