1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
|
#include <TestSupport.h>
#include <UnionStation/Core.h>
#include <UnionStation/Transaction.h>
#include <MessageClient.h>
#include <agents/LoggingAgent/LoggingServer.h>
#include <Utils/MessageIO.h>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <oxt/thread.hpp>
#include <set>
using namespace Passenger;
using namespace Passenger::UnionStation;
using namespace std;
using namespace oxt;
namespace tut {
struct UnionStationTest {
static const unsigned long long YESTERDAY = 1263299017000000ull; // January 12, 2009, 12:23:37 UTC
static const unsigned long long TODAY = 1263385422000000ull; // January 13, 2009, 12:23:42 UTC
static const unsigned long long TOMORROW = 1263471822000000ull; // January 14, 2009, 12:23:42 UTC
#define TODAY_TXN_ID "cjb8n-abcd"
#define TODAY_TIMESTAMP_STR "cftz90m3k0"
ServerInstanceDirPtr serverInstanceDir;
ServerInstanceDir::GenerationPtr generation;
string socketFilename;
string socketAddress;
string dumpFile;
AccountsDatabasePtr accountsDatabase;
ev::dynamic_loop eventLoop;
FileDescriptor serverFd;
LoggingServerPtr server;
boost::shared_ptr<oxt::thread> serverThread;
CorePtr core, core2, core3, core4;
UnionStationTest() {
createServerInstanceDirAndGeneration(serverInstanceDir, generation);
socketFilename = generation->getPath() + "/logging.socket";
socketAddress = "unix:" + socketFilename;
dumpFile = generation->getPath() + "/log.txt";
accountsDatabase = ptr(new AccountsDatabase());
accountsDatabase->add("test", "1234", false);
setLogLevel(-1);
startLoggingServer();
core = make_shared<Core>(socketAddress, "test", "1234",
"localhost");
core2 = make_shared<Core>(socketAddress, "test", "1234",
"localhost");
core3 = make_shared<Core>(socketAddress, "test", "1234",
"localhost");
core4 = make_shared<Core>(socketAddress, "test", "1234",
"localhost");
}
~UnionStationTest() {
stopLoggingServer();
SystemTime::releaseAll();
setLogLevel(0);
}
void startLoggingServer(const boost::function<void ()> &initFunc = boost::function<void ()>()) {
VariantMap options;
options.set("analytics_dump_file", dumpFile);
serverFd = createUnixServer(socketFilename.c_str());
server = ptr(new LoggingServer(eventLoop,
serverFd, accountsDatabase, options));
if (initFunc) {
initFunc();
}
serverThread = ptr(new oxt::thread(
boost::bind(&UnionStationTest::runLoop, this)
));
}
void stopLoggingServer(bool destroy = true) {
if (serverThread != NULL) {
MessageClient client;
client.connect(socketAddress, "test", "1234");
client.write("exit", "immediately", NULL);
joinLoggingServer(destroy);
}
}
void joinLoggingServer(bool destroy = true) {
serverThread->join();
serverThread.reset();
if (destroy) {
server.reset();
}
unlink(socketFilename.c_str());
}
void runLoop() {
eventLoop.loop();
serverFd.close();
}
string timestampString(unsigned long long timestamp) {
char str[2 * sizeof(unsigned long long) + 1];
integerToHexatri<unsigned long long>(timestamp, str);
return str;
}
MessageClient createConnection(bool sendInitCommand = true) {
MessageClient client;
vector<string> args;
client.connect(socketAddress, "test", "1234");
if (sendInitCommand) {
client.write("init", "localhost", NULL);
client.read(args);
}
return client;
}
string readDumpFile() {
return readAll(dumpFile);
}
};
DEFINE_TEST_GROUP(UnionStationTest);
/*********** Logging interface tests ***********/
TEST_METHOD(1) {
// Test logging of new transaction.
SystemTime::forceAll(YESTERDAY);
TransactionPtr log = core->newTransaction("foobar");
log->message("hello");
log->message("world");
log->flushToDiskAfterClose(true);
ensure(!core->isNull());
ensure(!log->isNull());
log.reset();
string data = readDumpFile();
ensure(data.find("hello\n") != string::npos);
ensure(data.find("world\n") != string::npos);
}
TEST_METHOD(2) {
// Test logging of existing transaction.
SystemTime::forceAll(YESTERDAY);
TransactionPtr log = core->newTransaction("foobar");
log->message("message 1");
log->flushToDiskAfterClose(true);
TransactionPtr log2 = core2->continueTransaction(log->getTxnId(),
log->getGroupName(), log->getCategory());
log2->message("message 2");
log2->flushToDiskAfterClose(true);
log.reset();
log2.reset();
string data = readDumpFile();
ensure("(1)", data.find("message 1\n") != string::npos);
ensure("(2)", data.find("message 2\n") != string::npos);
}
TEST_METHOD(3) {
// Test logging with different points in time.
SystemTime::forceAll(YESTERDAY);
TransactionPtr log = core->newTransaction("foobar");
log->message("message 1");
SystemTime::forceAll(TODAY);
log->message("message 2");
log->flushToDiskAfterClose(true);
SystemTime::forceAll(TOMORROW);
TransactionPtr log2 = core2->continueTransaction(log->getTxnId(),
log->getGroupName(), log->getCategory());
log2->message("message 3");
log2->flushToDiskAfterClose(true);
TransactionPtr log3 = core3->newTransaction("foobar");
log3->message("message 4");
log3->flushToDiskAfterClose(true);
log.reset();
log2.reset();
log3.reset();
string data = readDumpFile();
ensure("(1)", data.find(timestampString(YESTERDAY) + " 1 message 1\n") != string::npos);
ensure("(2)", data.find(timestampString(TODAY) + " 2 message 2\n") != string::npos);
ensure("(3)", data.find(timestampString(TOMORROW) + " 4 message 3\n") != string::npos);
ensure("(4)", data.find(timestampString(TOMORROW) + " 1 message 4\n") != string::npos);
}
TEST_METHOD(4) {
// newTransaction() and continueTransaction() write an ATTACH message
// to the log file, while UnionStation::Transaction writes a DETACH message upon
// destruction.
SystemTime::forceAll(YESTERDAY);
TransactionPtr log = core->newTransaction("foobar");
SystemTime::forceAll(TODAY);
TransactionPtr log2 = core2->continueTransaction(log->getTxnId(),
log->getGroupName(), log->getCategory());
log2->flushToDiskAfterClose(true);
log2.reset();
SystemTime::forceAll(TOMORROW);
log->flushToDiskAfterClose(true);
log.reset();
string data = readDumpFile();
ensure("(1)", data.find(timestampString(YESTERDAY) + " 0 ATTACH\n") != string::npos);
ensure("(2)", data.find(timestampString(TODAY) + " 1 ATTACH\n") != string::npos);
ensure("(3)", data.find(timestampString(TODAY) + " 2 DETACH\n") != string::npos);
ensure("(4)", data.find(timestampString(TOMORROW) + " 3 DETACH\n") != string::npos);
}
TEST_METHOD(5) {
// newTransaction() generates a new ID, while continueTransaction()
// reuses the ID.
TransactionPtr log = core->newTransaction("foobar");
TransactionPtr log2 = core2->newTransaction("foobar");
TransactionPtr log3 = core3->continueTransaction(log->getTxnId(),
log->getGroupName(), log->getCategory());
TransactionPtr log4 = core4->continueTransaction(log2->getTxnId(),
log2->getGroupName(), log2->getCategory());
ensure_equals(log->getTxnId(), log3->getTxnId());
ensure_equals(log2->getTxnId(), log4->getTxnId());
ensure(log->getTxnId() != log2->getTxnId());
}
TEST_METHOD(6) {
// An empty UnionStation::Transaction doesn't do anything.
UnionStation::Transaction log;
ensure(log.isNull());
log.message("hello world");
ensure_equals(getFileType(dumpFile), FT_NONEXISTANT);
}
TEST_METHOD(7) {
// An empty UnionStation::Core doesn't do anything.
UnionStation::Core core;
ensure(core.isNull());
TransactionPtr log = core.newTransaction("foo");
ensure(log->isNull());
log->message("hello world");
ensure_equals(getFileType(dumpFile), FT_NONEXISTANT);
}
TEST_METHOD(11) {
// newTransaction() does not reconnect to the server for a short
// period of time if connecting failed
core->setReconnectTimeout(60 * 1000000);
SystemTime::forceAll(TODAY);
stopLoggingServer();
ensure(core->newTransaction("foobar")->isNull());
SystemTime::forceAll(TODAY + 30 * 1000000);
startLoggingServer();
ensure(core->newTransaction("foobar")->isNull());
SystemTime::forceAll(TODAY + 61 * 1000000);
ensure(!core->newTransaction("foobar")->isNull());
}
TEST_METHOD(12) {
// If the logging server crashed and was restarted then
// newTransaction() and continueTransaction() print a warning and return
// a null log object. One of the next newTransaction()/continueTransaction()
// calls will reestablish the connection when the connection timeout
// has passed.
SystemTime::forceAll(TODAY);
TransactionPtr log, log2;
log = core->newTransaction("foobar");
core2->continueTransaction(log->getTxnId(), "foobar");
log.reset(); // Check connection back into the pool.
stopLoggingServer();
startLoggingServer();
log = core->newTransaction("foobar");
ensure("(1)", log->isNull());
log2 = core2->continueTransaction("some-id", "foobar");
ensure("(2)", log2->isNull());
SystemTime::forceAll(TODAY + 60000000);
log = core->newTransaction("foobar");
ensure("(3)", !log->isNull());
log2 = core2->continueTransaction(log->getTxnId(), "foobar");
ensure("(4)", !log2->isNull());
log2->message("hello");
log2->flushToDiskAfterClose(true);
log.reset();
log2.reset();
EVENTUALLY(3,
result = readDumpFile().find("hello\n") != string::npos;
);
}
TEST_METHOD(13) {
// continueTransaction() does not reconnect to the server for a short
// period of time if connecting failed
core->setReconnectTimeout(60 * 1000000);
core2->setReconnectTimeout(60 * 1000000);
SystemTime::forceAll(TODAY);
TransactionPtr log = core->newTransaction("foobar");
core2->continueTransaction(log->getTxnId(), "foobar");
stopLoggingServer();
ensure(core2->continueTransaction(log->getTxnId(), "foobar")->isNull());
SystemTime::forceAll(TODAY + 30 * 1000000);
startLoggingServer();
ensure(core2->continueTransaction(log->getTxnId(), "foobar")->isNull());
SystemTime::forceAll(TODAY + 61 * 1000000);
ensure(!core2->continueTransaction(log->getTxnId(), "foobar")->isNull());
}
TEST_METHOD(14) {
// If a client disconnects from the logging server then all its
// transactions that are no longer referenced and have crash protection enabled
// will be closed and written to the sink.
MessageClient client1 = createConnection();
MessageClient client2 = createConnection();
MessageClient client3 = createConnection();
vector<string> args;
SystemTime::forceAll(TODAY);
client1.write("openTransaction",
TODAY_TXN_ID, "foobar", "", "requests", TODAY_TIMESTAMP_STR,
"-", "true", "true", NULL);
client1.read(args);
client2.write("openTransaction",
TODAY_TXN_ID, "foobar", "", "requests", TODAY_TIMESTAMP_STR,
"-", "true", NULL);
client2.write("log", TODAY_TXN_ID, "1000", NULL);
client2.writeScalar("hello world");
client2.write("flush", NULL);
client2.read(args);
client2.disconnect();
SHOULD_NEVER_HAPPEN(100,
// Transaction still has references open, so should not yet be written to sink.
result = readDumpFile().find("hello world") != string::npos;
);
client1.disconnect();
client3.write("flush", NULL);
client3.read(args);
EVENTUALLY(5,
result = readDumpFile().find("hello world") != string::npos;
);
}
TEST_METHOD(15) {
// If a client disconnects from the logging server then all its
// transactions that are no longer referenced and don't have crash
// protection enabled will be closed and discarded.
MessageClient client1 = createConnection();
MessageClient client2 = createConnection();
MessageClient client3 = createConnection();
vector<string> args;
SystemTime::forceAll(TODAY);
client1.write("openTransaction",
TODAY_TXN_ID, "foobar", "", "requests", TODAY_TIMESTAMP_STR,
"-", "false", "true", NULL);
client1.read(args);
client2.write("openTransaction",
TODAY_TXN_ID, "foobar", "", "requests", TODAY_TIMESTAMP_STR,
"-", "false", NULL);
client2.write("flush", NULL);
client2.read(args);
client2.disconnect();
client1.disconnect();
client3.write("flush", NULL);
client3.read(args);
SHOULD_NEVER_HAPPEN(500,
result = fileExists(dumpFile) && !readDumpFile().empty();
);
}
TEST_METHOD(16) {
// Upon server shutdown, all transaction that have crash protection enabled
// will be closed and written to to the sink.
MessageClient client1 = createConnection();
MessageClient client2 = createConnection();
vector<string> args;
SystemTime::forceAll(TODAY);
client1.write("openTransaction",
TODAY_TXN_ID, "foobar", "", "requests", TODAY_TIMESTAMP_STR,
"-", "true", "true", NULL);
client1.read(args);
client2.write("openTransaction",
TODAY_TXN_ID, "foobar", "", "requests", TODAY_TIMESTAMP_STR,
"-", "true", NULL);
client2.write("flush", NULL);
client2.read(args);
stopLoggingServer();
EVENTUALLY(5,
result = fileExists(dumpFile) && !readDumpFile().empty();
);
}
TEST_METHOD(17) {
// Upon server shutdown, all transaction that don't have crash protection
// enabled will be discarded.
MessageClient client1 = createConnection();
MessageClient client2 = createConnection();
vector<string> args;
SystemTime::forceAll(TODAY);
client1.write("openTransaction",
TODAY_TXN_ID, "foobar", "", "requests", TODAY_TIMESTAMP_STR,
"-", "false", "true", NULL);
client1.read(args);
client2.write("openTransaction",
TODAY_TXN_ID, "foobar", "", "requests", TODAY_TIMESTAMP_STR,
"-", "false", NULL);
client2.write("flush", NULL);
client2.read(args);
stopLoggingServer();
SHOULD_NEVER_HAPPEN(200,
result = fileExists(dumpFile) && !readDumpFile().empty();
);
}
TEST_METHOD(18) {
// Test DataStoreId
{
// Empty construction.
DataStoreId id;
ensure_equals(id.getGroupName(), "");
ensure_equals(id.getNodeName(), "");
ensure_equals(id.getCategory(), "");
}
{
// Normal construction.
DataStoreId id("ab", "cd", "ef");
ensure_equals(id.getGroupName(), "ab");
ensure_equals(id.getNodeName(), "cd");
ensure_equals(id.getCategory(), "ef");
}
{
// Copy constructor.
DataStoreId id("ab", "cd", "ef");
DataStoreId id2(id);
ensure_equals(id2.getGroupName(), "ab");
ensure_equals(id2.getNodeName(), "cd");
ensure_equals(id2.getCategory(), "ef");
}
{
// Assignment operator.
DataStoreId id("ab", "cd", "ef");
DataStoreId id2;
id2 = id;
ensure_equals(id2.getGroupName(), "ab");
ensure_equals(id2.getNodeName(), "cd");
ensure_equals(id2.getCategory(), "ef");
DataStoreId id3("gh", "ij", "kl");
id3 = id;
ensure_equals(id3.getGroupName(), "ab");
ensure_equals(id3.getNodeName(), "cd");
ensure_equals(id3.getCategory(), "ef");
}
{
// < operator
DataStoreId id, id2;
ensure(!(id < id2));
id = DataStoreId("ab", "cd", "ef");
id2 = DataStoreId("ab", "cd", "ef");
ensure(!(id < id2));
id = DataStoreId("ab", "cd", "ef");
id2 = DataStoreId("bb", "cd", "ef");
ensure(id < id2);
id = DataStoreId("ab", "cd", "ef");
id2 = DataStoreId();
ensure(id2 < id);
id = DataStoreId();
id2 = DataStoreId("ab", "cd", "ef");
ensure(id < id2);
}
{
// == operator
ensure(DataStoreId() == DataStoreId());
ensure(DataStoreId("ab", "cd", "ef") == DataStoreId("ab", "cd", "ef"));
ensure(!(DataStoreId("ab", "cd", "ef") == DataStoreId()));
ensure(!(DataStoreId("ab", "cd", "ef") == DataStoreId("ab", "cd", "e")));
ensure(!(DataStoreId("ab", "cd", "ef") == DataStoreId("ab", "c", "ef")));
ensure(!(DataStoreId("ab", "cd", "ef") == DataStoreId("a", "cd", "ef")));
}
}
TEST_METHOD(22) {
// The destructor flushes all data.
TransactionPtr log = core->newTransaction("foobar");
log->message("hello world");
log.reset();
stopLoggingServer();
struct stat buf;
ensure_equals(stat(dumpFile.c_str(), &buf), 0);
ensure(buf.st_size > 0);
}
TEST_METHOD(23) {
// The 'flush' command flushes all data.
SystemTime::forceAll(YESTERDAY);
TransactionPtr log = core->newTransaction("foobar");
log->message("hello world");
log.reset();
ConnectionPtr connection = core->checkoutConnection();
vector<string> args;
writeArrayMessage(connection->fd, "flush", NULL);
ensure(readArrayMessage(connection->fd, args));
ensure_equals(args.size(), 1u);
ensure_equals(args[0], "ok");
struct stat buf;
ensure_equals(stat(dumpFile.c_str(), &buf), 0);
ensure(buf.st_size > 0);
}
TEST_METHOD(24) {
// A transaction's data is not written out by the server
// until the transaction is fully closed.
SystemTime::forceAll(YESTERDAY);
vector<string> args;
TransactionPtr log = core->newTransaction("foobar");
log->message("hello world");
TransactionPtr log2 = core2->continueTransaction(log->getTxnId(),
log->getGroupName(), log->getCategory());
log2->message("message 2");
log2.reset();
ConnectionPtr connection = core->checkoutConnection();
writeArrayMessage(connection->fd, "flush", NULL);
ensure(readArrayMessage(connection->fd, args));
connection = core2->checkoutConnection();
writeArrayMessage(connection->fd, "flush", NULL);
ensure(readArrayMessage(connection->fd, args));
struct stat buf;
ensure_equals(stat(dumpFile.c_str(), &buf), 0);
ensure_equals(buf.st_size, (off_t) 0);
}
TEST_METHOD(25) {
// The 'exit' command causes the logging server to exit some time after
// the last client has disconnected. New clients are still accepted
// as long as the server hasn't exited.
SystemTime::forceAll(YESTERDAY);
vector<string> args;
MessageClient client = createConnection();
MessageClient client2 = createConnection();
client2.write("exit", NULL);
ensure("(1)", client2.read(args));
ensure_equals(args.size(), 1u);
ensure_equals(args[0], "Passed security");
ensure("(2)", client2.read(args));
ensure_equals(args.size(), 1u);
ensure_equals(args[0], "exit command received");
client2.disconnect();
// Not exited yet: there is still a client.
client2 = createConnection();
client2.write("ping", NULL);
ensure("(3)", client2.read(args));
client2.disconnect();
client.disconnect();
setLogLevel(-2);
usleep(25000); // Give server some time to process the connection closes.
// No clients now, but we can still connect because the timeout
// hasn't passed yet.
SystemTime::forceAll(YESTERDAY + 1000000);
SHOULD_NEVER_HAPPEN(250,
try {
close(connectToUnixServer(socketFilename));
result = false;
} catch (const SystemException &) {
result = true;
}
);
usleep(50000); // Give server some time to process the connection closes.
// It'll be gone in a few seconds.
SystemTime::forceAll(YESTERDAY + 1000000 + 5000000);
usleep(100000); // Give server some time to run the timer.
try {
close(connectToUnixServer(socketFilename));
fail("(4)");
} catch (const SystemException &) {
// Success
}
joinLoggingServer();
}
TEST_METHOD(26) {
// The 'exit semi-gracefully' command causes the logging server to
// refuse new clients while exiting some time after the last client has
// disconnected.
SystemTime::forceAll(YESTERDAY);
vector<string> args;
MessageClient client = createConnection();
MessageClient client2 = createConnection();
client2.write("exit", "semi-gracefully", NULL);
client2.disconnect();
// New connections are refused.
client2 = createConnection();
ensure("(1)", !client2.read(args));
client.disconnect();
setLogLevel(-2);
usleep(50000); // Give server some time to process the connection closes.
// It'll be gone in a few seconds.
SystemTime::forceAll(YESTERDAY + 1000000 + 5000000);
usleep(100000); // Give server some time to run the timer.
try {
close(connectToUnixServer(socketFilename));
fail("(2)");
} catch (const SystemException &) {
// Success
}
joinLoggingServer();
}
TEST_METHOD(27) {
// The 'exit immediately' command causes the logging server to
// immediately exit. Open transactions are not automatically
// closed and written out, even those with crash protection
// turned on.
SystemTime::forceAll(YESTERDAY);
TransactionPtr log = core->newTransaction("foobar");
log->message("hello world");
log.reset();
MessageClient client = createConnection();
client.write("exit", "immediately", NULL);
client.disconnect();
// Assertion: the following doesn't block.
joinLoggingServer();
}
TEST_METHOD(28) {
// UnionStation::Core treats a server that's semi-gracefully exiting as
// one that's refusing connections.
SystemTime::forceAll(YESTERDAY);
MessageClient client = createConnection();
client.write("exit", "semi-gracefully", NULL);
client.disconnect();
TransactionPtr log = core->newTransaction("foobar");
ensure(log->isNull());
}
TEST_METHOD(29) {
// One can supply a custom node name per openTransaction command.
MessageClient client1 = createConnection();
vector<string> args;
SystemTime::forceAll(TODAY);
client1.write("openTransaction",
TODAY_TXN_ID, "foobar", "remote", "requests", TODAY_TIMESTAMP_STR,
"-", "true", NULL);
client1.write("closeTransaction", TODAY_TXN_ID, TODAY_TIMESTAMP_STR, NULL);
client1.write("flush", NULL);
client1.read(args);
client1.disconnect();
ensure(fileExists(dumpFile));
}
TEST_METHOD(30) {
// A transaction is only written to the sink if it passes all given filters.
// Test logging of new transaction.
SystemTime::forceAll(YESTERDAY);
TransactionPtr log = core->newTransaction("foobar", "requests", "-",
"uri == \"/foo\""
"\1"
"uri != \"/bar\"");
log->message("URI: /foo");
log->message("transaction 1");
log->flushToDiskAfterClose(true);
log.reset();
log = core->newTransaction("foobar", "requests", "-",
"uri == \"/foo\""
"\1"
"uri == \"/bar\"");
log->message("URI: /foo");
log->message("transaction 2");
log->flushToDiskAfterClose(true);
log.reset();
string data = readDumpFile();
ensure("(1)", data.find("transaction 1\n") != string::npos);
ensure("(2)", data.find("transaction 2\n") == string::npos);
}
/************************************/
}
|