NCBI C++ ToolKit
conn_test_thread.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: conn_test_thread.cpp 26247 2012-08-10 14:53:46Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 #include <corelib/ncbitime.hpp>
36 
38 
40 
41 CConnTestThread::CConnTestThread(unsigned int timeout) : m_Timeout(timeout), m_GoodConnection(false)
42 {
43 }
44 
46 {
48 
49  try {
50  STimeout tmo;
51  tmo.sec = (unsigned int)m_Timeout;
52  tmo.usec = (unsigned int)0;
53 
54  CNcbiOstrstream ostr;
55  CConnTest conn_test(&tmo, &ostr);
56  conn_test.SetCanceledCallback(this);
57 
58  conn_test.SetEmail("gbench-bugs@ncbi.nlm.nih.gov");
60 
61  SetDiagFilter(eDiagFilter_Trace, "!/corelib !/objmgr");
62 
65  EIO_Status status = conn_test.Execute(everything);
66  if (status != eIO_Success) {
68  m_GoodConnection = false;
70  }
71  else {
72  m_GoodConnection = true;
73  m_ConnInfo = "No problems with connection found";
74  }
75  }
76  catch (const std::exception&) { // Exception should only be thrown if cancelled
77  m_GoodConnection = false;
78  m_ConnInfo = "Connection test cancelled";
79  }
80 
81  SetDiagFilter(eDiagFilter_Trace, "!/corelib !/connect !/objmgr");
82  sw.Stop();
83 
84  m_Finished.Set(1);
85  LOG_POST(Info << "ConnTest took: " << sw.AsSmartString(CTimeSpan::eSSP_Millisecond));
86 
87  return 0;
88 }
89 
#define false
Definition: bool.h:36
CConnTestThread(unsigned int timeout)
unsigned int m_Timeout
virtual void * Main(void)
Do job delegated processing to the main class.
CAtomicCounter_WithAutoInit m_Finished
Guard for collecting diag messages (affects the current thread only).
Definition: ncbidiag.hpp:1300
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CStopWatch –.
Definition: ncbitime.hpp:1938
void Set(TValue new_value) THROWS_NONE
Set atomic counter value.
Definition: ncbicntr.hpp:185
void Release(void)
Release the guard.
Definition: ncbidiag.cpp:575
void SetDiagFilter(EDiagFilter what, const char *filter_str)
Set diagnostic filter.
Definition: ncbidiag.cpp:7670
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
@ ePrint
Print all collected messages as is.
Definition: ncbidiag.hpp:1304
@ eDiag_Trace
Trace message.
Definition: ncbidiag.hpp:657
@ eDiag_Info
Informational message.
Definition: ncbidiag.hpp:651
@ eDiagFilter_Trace
for TRACEs only
Definition: ncbidiag.hpp:2529
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
void Stop(void)
Suspend the timer.
Definition: ncbitime.hpp:2793
string AsSmartString(CTimeSpan::ESmartStringPrecision precision, ERound rounding, CTimeSpan::ESmartStringZeroMode zero_mode=CTimeSpan::eSSZ_SkipZero) const
Transform elapsed time to "smart" string.
Definition: ncbitime.hpp:2851
@ eStart
Start timer immediately after creating.
Definition: ncbitime.hpp:1942
@ eSSP_Millisecond
Definition: ncbitime.hpp:1511
EIO_Status
I/O status.
Definition: ncbi_core.h:132
unsigned int usec
microseconds (modulo 1,000,000)
Definition: ncbi_types.h:78
unsigned int sec
seconds
Definition: ncbi_types.h:77
@ eIO_Success
everything is fine, no error occurred
Definition: ncbi_core.h:133
@ eDebugPrintout_Data
EStage
Note that each stage has a previous one as a prerequisite, with the only exception for the stateful s...
void SetDebugPrintout(EDebugPrintout debug_printout)
virtual EIO_Status Execute(EStage &stage, string *reason=0)
Execute the test suite from the very first (eHttp) up to and including the requested "stage".
void SetEmail(const string &email)
void SetCanceledCallback(const ICanceled *canceled)
@ eStatefulService
Check whether NCBI stateful service works.
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
static CStopWatch sw
Defines: CTimeFormat - storage class for time format.
Timeout structure.
Definition: ncbi_types.h:76
Modified on Wed Dec 06 07:14:20 2023 by modify_doxy.py rev. 669887