TEST_F(ShardConnFixture, KilledGoodConnShouldNotClearPool) { ShardConnection conn1(TARGET_HOST, "test.user"); ShardConnection conn2(TARGET_HOST, "test.user"); ShardConnection conn3(TARGET_HOST, "test.user"); const uint64_t upperBoundCreationTime = conn3.get()->getSockCreationMicroSec(); conn3.done(); const uint64_t badCreationTime = conn1.get()->getSockCreationMicroSec(); conn1.kill(); conn2.done(); ShardConnection conn4(TARGET_HOST, "test.user"); ShardConnection conn5(TARGET_HOST, "test.user"); ASSERT_GREATER_THAN(conn4.get()->getSockCreationMicroSec(), badCreationTime); ASSERT_LESS_THAN_OR_EQUALS(conn4.get()->getSockCreationMicroSec(), upperBoundCreationTime); ASSERT_GREATER_THAN(conn5.get()->getSockCreationMicroSec(), badCreationTime); ASSERT_LESS_THAN_OR_EQUALS(conn5.get()->getSockCreationMicroSec(), upperBoundCreationTime); checkNewConns(assertGreaterThan, upperBoundCreationTime, 10); }
TEST(ConnectXTest, consCheck) //Check possible condition cases for constructor. { ConnectX conn1(4,5,3); ConnectX conn2(-4,5,2); ConnectX conn3(4,-5,3); ConnectX conn4(4,5,-3); }
TEST_F(DummyServerFixture, DontReturnKnownBadConnToPool) { ScopedDbConnection conn1(TARGET_HOST); ScopedDbConnection conn2(TARGET_HOST); ScopedDbConnection conn3(TARGET_HOST); conn1.done(); mongo::getGlobalFailPointRegistry()->getFailPoint("throwSockExcep")-> setMode(FailPoint::alwaysOn); try { conn3->query("test.user", mongo::Query()); } catch (const mongo::SocketException&) { } mongo::getGlobalFailPointRegistry()->getFailPoint("throwSockExcep")-> setMode(FailPoint::off); const uint64_t badCreationTime = conn3->getSockCreationMicroSec(); conn3.done(); // attempting to put a 'bad' connection back to the pool conn2.done(); checkNewConns(assertGreaterThan, badCreationTime, 10); }
TEST_F(DummyServerFixture, InvalidateBadConnEvenWhenPoolIsFull) { mongo::pool.setMaxPoolSize(2); ScopedDbConnection conn1(TARGET_HOST); ScopedDbConnection conn2(TARGET_HOST); ScopedDbConnection conn3(TARGET_HOST); conn1.done(); conn3.done(); const uint64_t badCreationTime = mongo::curTimeMicros64(); mongo::getGlobalFailPointRegistry()->getFailPoint("throwSockExcep")-> setMode(FailPoint::alwaysOn); try { conn2->query("test.user", mongo::Query()); } catch (const mongo::SocketException&) { } mongo::getGlobalFailPointRegistry()->getFailPoint("throwSockExcep")-> setMode(FailPoint::off); conn2.done(); checkNewConns(assertGreaterThan, badCreationTime, 2); }
TEST_F(DummyServerFixture, InvalidateBadConnInPool) { scoped_ptr<ScopedDbConnection> conn1( ScopedDbConnection::getScopedDbConnection(TARGET_HOST)); scoped_ptr<ScopedDbConnection> conn2( ScopedDbConnection::getScopedDbConnection(TARGET_HOST)); scoped_ptr<ScopedDbConnection> conn3( ScopedDbConnection::getScopedDbConnection(TARGET_HOST)); conn1->done(); conn3->done(); const uint64_t badCreationTime = mongo::curTimeMicros64(); mongo::getGlobalFailPointRegistry()->getFailPoint("throwSockExcep")-> setMode(FailPoint::alwaysOn); try { conn2->get()->query("test.user", mongo::Query()); } catch (const mongo::SocketException&) { } mongo::getGlobalFailPointRegistry()->getFailPoint("throwSockExcep")-> setMode(FailPoint::off); conn2->done(); checkNewConns(assertGreaterThan, badCreationTime, 10); }
TEST_F(DummyServerFixture, DontReturnConnGoneBadToPool) { ScopedDbConnection conn1(TARGET_HOST); const uint64_t conn1CreationTime = conn1->getSockCreationMicroSec(); uint64_t conn2CreationTime = 0; { ScopedDbConnection conn2(TARGET_HOST); conn2CreationTime = conn2->getSockCreationMicroSec(); conn1.done(); // conn2 gets out of scope without calling done() } // conn2 should not have been put back into the pool but it should // also not invalidate older connections since it didn't encounter // a socket exception. ScopedDbConnection conn1Again(TARGET_HOST); ASSERT_EQUALS(conn1CreationTime, conn1Again->getSockCreationMicroSec()); checkNewConns(assertNotEqual, conn2CreationTime, 10); conn1Again.done(); }
TEST(ConnectXTest, placePieceCheck) // Check if piece value in board is updated. { ConnectX conn1(10,10,5); conn1.showBoard(); conn1.placePiece(0); ASSERT_EQ(0,conn1.at(0,0)); conn1.placePiece(5); conn1.placePiece(3); }
TEST(ConnectXTest, boardDisplayCheck) //Check if pieces are placed properly. { ConnectX conn1(4,5,3); conn1.showBoard(); conn1.placePiece(3); conn1.showBoard(); conn1.placePiece(2); conn1.showBoard(); }
TEST(ConnectXTest, atCheck) //Checking validity of pieces placed at various locations. { ConnectX conn1(10,10,5); ASSERT_EQ(0,conn1.at(7,8)); conn1.placePiece(7); ASSERT_EQ(-1,conn1.at(0,-1)); conn1.placePiece(5); ASSERT_EQ(1,conn1.at(10,5)); }
//============================================================================== void initialise (const String& commandLine) override { // This method is where you should put your application's initialisation code.. try { const char* headers[] = { "Connection", "close", "Content-type", "application/x-www-form-urlencoded", "Accept", "text/plain", 0 }; const char* body = "answer=42&name=Bubba"; happyhttp::Connection conn1( "posttestserver.com", 80 ); conn1.setcallbacks( OnBegin, OnData, OnComplete, 0 ); conn1.request( "PUT", "/post.php", headers, (const unsigned char*)body, strlen(body) ); while( conn1.outstanding() ) { conn1.pump(); } const char* cbliteHeaders[] = { "Connection", "close", "Authorization", "Basic Y2JsaXRlOnBhc3N3b3Jk", 0 }; happyhttp::Connection conn2( "localhost", 5984 ); conn2.setcallbacks( OnBegin, OnData, OnComplete, 0 ); conn2.request( "GET", "/", cbliteHeaders, 0, 0 ); while( conn2.outstanding() ) conn2.pump(); } catch( happyhttp::Wobbly& e ) { DBG ("Exception:\n" << e.what() ); } mainWindow = new MainWindow (getApplicationName()); }
TEST_F(DummyServerFixture, BasicScopedDbConnection) { ScopedDbConnection conn1(TARGET_HOST); ScopedDbConnection conn2(TARGET_HOST); DBClientBase* conn1Ptr = conn1.get(); conn1.done(); ScopedDbConnection conn3(TARGET_HOST); ASSERT_EQUALS(conn1Ptr, conn3.get()); conn2.done(); conn3.done(); }
TEST_F(ShardConnFixture, BasicShardConnection) { ShardConnection conn1(TARGET_HOST, "test.user"); ShardConnection conn2(TARGET_HOST, "test.user"); DBClientBase* conn1Ptr = conn1.get(); conn1.done(); ShardConnection conn3(TARGET_HOST, "test.user"); ASSERT_EQUALS(conn1Ptr, conn3.get()); conn2.done(); conn3.done(); }
TEST_F(DummyServerFixture, BasicScopedDbConnection) { scoped_ptr<ScopedDbConnection> conn1( ScopedDbConnection::getScopedDbConnection(TARGET_HOST)); scoped_ptr<ScopedDbConnection> conn2( ScopedDbConnection::getScopedDbConnection(TARGET_HOST)); DBClientBase* conn1Ptr = conn1->get(); conn1->done(); scoped_ptr<ScopedDbConnection> conn3( ScopedDbConnection::getScopedDbConnection(TARGET_HOST)); ASSERT_EQUALS(conn1Ptr, conn3->get()); conn2->done(); conn3->done(); }
CASE_TEST(happ_connection, basic) { AutoPtr<hiredis::happ::connection> conn1(new hiredis::happ::connection()); AutoPtr<hiredis::happ::connection> conn2(new hiredis::happ::connection()); CASE_EXPECT_EQ(conn1->get_sequence() + 1, conn2->get_sequence()); hiredis::happ::holder_t h; redisAsyncContext vir_context; conn1->init(h, "127.0.0.2", 1234); conn2->init(h, "127.0.0.3", 1234); CASE_EXPECT_TRUE("127.0.0.2" == conn1->get_key().ip); CASE_EXPECT_TRUE(1234 == conn1->get_key().port); CASE_EXPECT_TRUE("127.0.0.2:1234" == conn1->get_key().name); CASE_EXPECT_EQ(hiredis::happ::connection::status::DISCONNECTED, conn1->conn_status); hiredis::happ::cmd_exec* cmd = hiredis::happ::cmd_exec::create(h, NULL, &vir_context, 0); int res = conn1->redis_cmd(cmd, NULL); CASE_EXPECT_EQ(hiredis::happ::error_code::REDIS_HAPP_CREATE, res); conn1->set_connecting(&vir_context); CASE_EXPECT_EQ(conn1->get_context(), &vir_context); CASE_EXPECT_EQ(hiredis::happ::connection::status::CONNECTING, conn1->conn_status); conn1->set_connected(); CASE_EXPECT_EQ(hiredis::happ::connection::status::CONNECTED, conn1->conn_status); CASE_EXPECT_EQ(conn1->get_context(), &vir_context); cmd->pri_data = conn2.get(); conn2->set_connecting(&vir_context); conn1->release(false); conn2->release(false); CASE_EXPECT_EQ(conn1->get_context(), NULL); CASE_EXPECT_EQ(conn2->get_context(), NULL); hiredis::happ::cmd_exec::destroy(cmd); }
TEST_F(ShardConnFixture, InvalidateBadConnInPool) { ShardConnection conn1(TARGET_HOST, "test.user"); ShardConnection conn2(TARGET_HOST, "test.user"); ShardConnection conn3(TARGET_HOST, "test.user"); conn1.done(); conn3.done(); const uint64_t badCreationTime = mongo::curTimeMicros64(); killServer(); try { conn2.get()->query("test.user", mongo::Query()); } catch (const mongo::SocketException&) { } conn2.done(); restartServer(); checkNewConns(assertGreaterThan, badCreationTime, 10); }
void Conn::run() { debug("%s: start", info); conn1(); conn0(); const unsigned siz = 32 * 1024; for (int i = 0; i < 2; i++) { Copy& copy = this->copy[i]; copy.rfd = sockfd[i]; copy.wfd = sockfd[1-i]; copy.buf = new unsigned char[siz]; copy.bufsiz = siz; sprintf(copy.info, "copy %d-%d", this->node[i]->id, this->node[1-i]->id); copy.thread = NdbThread_Create(copyrun_C, (void**)©, 8192, "copyrun", NDB_THREAD_PRIO_LOW); if (copy.thread == 0) { fatal("%s: create thread %d failed errno=%d", i, errno); } } debug("%s: stop", info); }
TEST_F(ShardConnFixture, BadConnClearsPoolWhenKilled) { ShardConnection conn1(TARGET_HOST, "test.user"); ShardConnection conn2(TARGET_HOST, "test.user"); ShardConnection conn3(TARGET_HOST, "test.user"); conn1.done(); killServer(); try { conn3.get()->query("test.user", mongo::Query()); } catch (const mongo::SocketException&) { } restartServer(); const uint64_t badCreationTime = conn3.get()->getSockCreationMicroSec(); conn3.kill(); // attempting to put a 'bad' connection back to the pool conn2.done(); checkNewConns(assertGreaterThan, badCreationTime, 10); }
TEST(MockDBClientConnTest, Restart) { MockRemoteDBServer server("test"); server.setCommandReply("serverStatus", BSON("ok" << 1)); MockDBClientConnection conn1(&server); // Do some queries and commands then check the counters later that // new instance still has it conn1.query("test.user"); BSONObj response; conn1.runCommand("test.user", BSON("serverStatus" << 1), response); server.shutdown(); ASSERT_THROWS(conn1.query("test.user"), mongo::SocketException); // New connections shouldn't work either MockDBClientConnection conn2(&server); ASSERT_THROWS(conn2.query("test.user"), mongo::SocketException); ASSERT_EQUALS(1U, server.getQueryCount()); ASSERT_EQUALS(1U, server.getCmdCount()); server.reboot(); ASSERT(server.isRunning()); { MockDBClientConnection conn(&server); conn.query("test.user"); } // Old connections still shouldn't work ASSERT_THROWS(conn1.query("test.user"), mongo::SocketException); ASSERT_THROWS(conn2.query("test.user"), mongo::SocketException); ASSERT_EQUALS(2U, server.getQueryCount()); ASSERT_EQUALS(1U, server.getCmdCount()); }
TEST(ConnectXTest, placePieceCheck2) // Check for height =1 { ConnectX conn1(10,1,5); conn1.placePiece(0); conn1.placePiece(0); }