Example #1
0
TEST(DurationTest, OutputFormat)
{
  EXPECT_EQ("1ns", stringify(Nanoseconds(1)));
  EXPECT_EQ("2ns", stringify(Nanoseconds(2)));

  // Truncated. Seconds in 15 digits of precision, max of double
  // type's precise digits.
  EXPECT_EQ("3.141592653secs",
            stringify(Duration::create(3.14159265358979).get()));
  EXPECT_EQ("3140ms", stringify(Duration::create(3.14).get()));
  EXPECT_EQ("10hrs", stringify(Hours(10)));
  EXPECT_EQ("-10hrs", stringify(Hours(-10)));

  // "10days" reads better than "1.42857142857143weeks" so it is
  // printed out in the lower unit.
  EXPECT_EQ("10days", stringify(Days(10)));
  // We go one-level down and it is still not a whole number so we
  // print it out using the higher unit.
  EXPECT_EQ("1.1875days", stringify(Days(1) + Hours(4) + Minutes(30)));
  // "2weeks" reads better than "14days" so we use the higher unit
  // here.
  EXPECT_EQ("2weeks", stringify(Days(14)));

  // Boundary cases.
  EXPECT_EQ("0ns", stringify(Duration::zero()));
  EXPECT_EQ("15250.2844524715weeks", stringify(Duration::max()));
  EXPECT_EQ("-15250.2844524715weeks", stringify(Duration::min()));
}
Example #2
0
int TradingPeriod::Now(Time now, Time *remaining, Time delayed) { 
    int ret = NONE, wall_st_hours_from_gmt, hours_to_wall_st = WallStHoursFromLocal(&wall_st_hours_from_gmt);
    Time days_away = Time(0);
    struct tm t;

    for (;; days_away += Hours(24)) {

        // Find next trading day
        for (;; days_away += Hours(24)) {
            WallStTime(now + days_away, &t, hours_to_wall_st);
            bool week_day = t.tm_wday >= 1 && t.tm_wday <= 5;
            if (week_day && !TradingHoliday(t.tm_year+1900, t.tm_mon+1, t.tm_mday)) break;
        }
        if (days_away != Time(0)) days_away -= SinceDayBegan(now + days_away, wall_st_hours_from_gmt);
        Time trading_day_elapsed = SinceDayBegan(now + days_away, wall_st_hours_from_gmt);

        // Find next trading period
        static int  trading_period_id  [] = { NONE,     PRE_MARKET,           MARKET,    AFTER_MARKET };
        static Time trading_period_time[] = { Hours(4), Hours(9)+Minutes(30), Hours(16), Hours(20),   };
        for (int i=0, l=sizeofarray(trading_period_id); i<l; i++) 
            if (trading_day_elapsed < (trading_period_time[i] + delayed)) {
                if (remaining) *remaining = (trading_period_time[i] + delayed - trading_day_elapsed) + days_away;
                return trading_period_id[i];
            }
    }
}
Example #3
0
TEST(DurationTest, ParseAndTry)
{
  EXPECT_SOME_EQ(Hours(3), Duration::parse("3hrs"));
  EXPECT_SOME_EQ(Hours(3) + Minutes(30), Duration::parse("3.5hrs"));

  EXPECT_SOME_EQ(Nanoseconds(3141592653), Duration::create(3.141592653));
  // Duration can hold only 9.22337e9 seconds.
  EXPECT_ERROR(Duration::create(10 * 1e9));
  EXPECT_ERROR(Duration::create(-10 * 1e9));
}
Example #4
0
/* 
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
void CFakeSMSSender::AppendPDUDataL(TMsvId aEntryId, const TDesC& aRecipient,TBool aUnicodeMsg,const TDesC& aBody)
{
 	CMsvEntry* entry = iMsvSession->GetEntryL(aEntryId);
    CleanupStack::PushL(entry);				
	
	CMsvStore* srore= entry->EditStoreL();
	CleanupStack::PushL(srore);
	if(srore)
	{	
		CSmsBuffer* smsBuffer = CSmsBuffer::NewL();	
		CSmsMessage* smsMsg = CSmsMessage::NewL(iFsSession,CSmsPDU::ESmsDeliver, smsBuffer);
		
		CleanupStack::PushL(smsMsg);
				
		smsMsg->SetTime(entry->Entry().iDate);
		
		if(aRecipient.Length() > 20)
			smsMsg->SetToFromAddressL(aRecipient.Left(20));
		else
			smsMsg->SetToFromAddressL(aRecipient);
		
		smsBuffer->InsertL(0,aBody);	
		
		CSmsDeliver& DSMSPDU = STATIC_CAST(CSmsDeliver&,smsMsg->SmsPDU());
		DSMSPDU.SetMoreMessagesToSend(EFalse);
		DSMSPDU.SetReplyPath(EFalse);
		DSMSPDU.SetStatusReportIndication(EFalse);

		TInt Hours(0x20);
		DSMSPDU.SetServiceCenterTimeStamp(entry->Entry().iDate,Hours);
		DSMSPDU.SetTextCompressed(EFalse);
		DSMSPDU.SetPIDType(TSmsProtocolIdentifier::ESmsPIDShortMessageType);	
		
		//DSMSPDU.SetTextCompressed(TBool aCompressed);
		//DSMSPDU.SetAlphabet(TSmsDataCodingScheme::TSmsAlphabet aAlphabet);
		
		CSmsHeader* MyHeader = CSmsHeader::NewL(smsMsg);
		CleanupStack::Pop(1);//smsMsg
		CleanupStack::PushL(MyHeader);
		
		CSmsSettings*  MySetting = CSmsSettings::NewL();
		CleanupStack::PushL(MySetting);
		
		if(aUnicodeMsg)
			MySetting->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabetUCS2);
		else
			MySetting->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabet7Bit);
			
		//MySetting->StoreL(*srore);//InternalizeL
		MyHeader->SetSmsSettingsL(*MySetting);
			
		MyHeader->StoreL(*srore);
		srore->CommitL();
		
		CleanupStack::PopAndDestroy(2);//MySetting,MyHeader,
	}	

	CleanupStack::PopAndDestroy(2);//entry,srore
}
Example #5
0
SOM_Scope void   SOMLINK WPSamFolder_wpInitData (WPSamF *somSelf)
{
    WPSamFData *somThis = WPSamFGetData (somSelf);
    WPSamFMethodDebug ("WPSamF","WPSamFolder_wpInitData");

    parent_wpInitData (somSelf); /* Parent method must be called prior own method */

    _ulZeitpunkt1 = _ulZeitpunkt2 = Hours ();
    _ulFlag       = SHUTDOWNENABLE | LOCKUPENABLE | ORIGDESKENABLE;
    _bCheckShare  = TRUE;

    DebugULx (D_SOM, "_wpInitData", "_ulZeitPunkt1", _ulZeitpunkt1);
}
Example #6
0
namespace slave {

const Duration EXECUTOR_REGISTRATION_TIMEOUT = Minutes(1);
const Duration EXECUTOR_SHUTDOWN_GRACE_PERIOD = Seconds(5);
const Duration EXECUTOR_REREGISTER_TIMEOUT = Seconds(2);
const Duration EXECUTOR_SIGNAL_ESCALATION_TIMEOUT = Seconds(3);
const Duration STATUS_UPDATE_RETRY_INTERVAL_MIN = Seconds(10);
const Duration STATUS_UPDATE_RETRY_INTERVAL_MAX = Minutes(10);
const Duration REGISTRATION_BACKOFF_FACTOR = Seconds(1);
const Duration REGISTER_RETRY_INTERVAL_MAX = Minutes(1);
const Duration GC_DELAY = Weeks(1);
const double GC_DISK_HEADROOM = 0.1;
const Duration DISK_WATCH_INTERVAL = Minutes(1);
const Duration RECOVERY_TIMEOUT = Minutes(15);
const Duration RESOURCE_MONITORING_INTERVAL = Seconds(1);
const uint32_t MAX_COMPLETED_FRAMEWORKS = 50;
const uint32_t MAX_COMPLETED_EXECUTORS_PER_FRAMEWORK = 150;
const uint32_t MAX_COMPLETED_TASKS_PER_EXECUTOR = 200;
const double DEFAULT_CPUS = 1;
const Bytes DEFAULT_MEM = Gigabytes(1);
const Bytes DEFAULT_DISK = Gigabytes(10);
const std::string DEFAULT_PORTS = "[31000-32000]";
#ifdef WITH_NETWORK_ISOLATOR
const uint16_t DEFAULT_EPHEMERAL_PORTS_PER_CONTAINER = 1024;
#endif
const Duration DOCKER_REMOVE_DELAY = Hours(6);
const Duration DOCKER_INSPECT_DELAY = Seconds(1);
// TODO(tnachen): Make this a flag.
const Duration DOCKER_VERSION_WAIT_TIMEOUT = Seconds(5);
const std::string DEFAULT_AUTHENTICATEE = "crammd5";

Duration DEFAULT_MASTER_PING_TIMEOUT()
{
  return master::DEFAULT_SLAVE_PING_TIMEOUT *
    master::DEFAULT_MAX_SLAVE_PING_TIMEOUTS;
}

} // namespace slave {
Example #7
0
TEST(DurationTest, Comparison)
{
  EXPECT_EQ(Duration::zero(), Seconds(0));
  EXPECT_EQ(Minutes(180), Hours(3));
  EXPECT_EQ(Seconds(10800), Hours(3));
  EXPECT_EQ(Milliseconds(10800000), Hours(3));

  EXPECT_EQ(Milliseconds(1), Microseconds(1000));
  EXPECT_EQ(Milliseconds(1000), Seconds(1));

  EXPECT_GT(Weeks(1), Days(6));

  EXPECT_LT(Hours(23), Days(1));

  EXPECT_LE(Hours(24), Days(1));
  EXPECT_GE(Hours(24), Days(1));

  EXPECT_NE(Minutes(59), Hours(1));

  // Maintains precision for a 100 year duration.
  EXPECT_GT(Weeks(5217) + Nanoseconds(1), Weeks(5217));
  EXPECT_LT(Weeks(5217) - Nanoseconds(1), Weeks(5217));
}
Example #8
0
inline std::ostream& operator<<(std::ostream& stream, const Duration& duration_)
{
  // Output the duration in full double precision and save the old precision.
  std::streamsize precision =
    stream.precision(std::numeric_limits<double>::digits10);

  // Parse the duration as the sign and the absolute value.
  Duration duration = duration_;
  if (duration_ < Duration::zero()) {
    stream << "-";

    // Duration::min() may not be representable as a positive Duration.
    if (duration_ == Duration::min()) {
      duration = Duration::max();
    } else {
      duration = duration_ * -1;
    }
  }

  // First determine which bucket of time unit the duration falls into
  // then check whether the duration can be represented as a whole
  // number with this time unit or a smaller one.
  // e.g. 1.42857142857143weeks falls into the 'Weeks' bucket but
  // reads better with a smaller unit: '10days'. So we use 'days'
  // instead of 'weeks' to output the duration.
  int64_t nanoseconds = duration.ns();
  if (duration < Microseconds(1)) {
    stream << duration.ns() << Nanoseconds::units();
  } else if (duration < Milliseconds(1)) {
    if (nanoseconds % Duration::MICROSECONDS != 0) {
      // We can't get a whole number using this unit but we can at
      // one level down.
      stream << duration.ns() << Nanoseconds::units();
    } else {
      stream << duration.us() << Microseconds::units();
    }
  } else if (duration < Seconds(1)) {
    if (nanoseconds % Duration::MILLISECONDS != 0 &&
        nanoseconds % Duration::MICROSECONDS == 0) {
      stream << duration.us() << Microseconds::units();
    } else {
      stream << duration.ms() << Milliseconds::units();
    }
  } else if (duration < Minutes(1)) {
    if (nanoseconds % Duration::SECONDS != 0 &&
        nanoseconds % Duration::MILLISECONDS == 0) {
      stream << duration.ms() << Milliseconds::units();
    } else {
      stream << duration.secs() << Seconds::units();
    }
  } else if (duration < Hours(1)) {
    if (nanoseconds % Duration::MINUTES != 0 &&
        nanoseconds % Duration::SECONDS == 0) {
      stream << duration.secs() << Seconds::units();
    } else {
      stream << duration.mins() << Minutes::units();
    }
  } else if (duration < Days(1)) {
    if (nanoseconds % Duration::HOURS != 0 &&
        nanoseconds % Duration::MINUTES == 0) {
      stream << duration.mins() << Minutes::units();
    } else {
      stream << duration.hrs() << Hours::units();
    }
  } else if (duration < Weeks(1)) {
    if (nanoseconds % Duration::DAYS != 0 &&
        nanoseconds % Duration::HOURS == 0) {
      stream << duration.hrs() << Hours::units();
    } else {
      stream << duration.days() << Days::units();
    }
  } else {
    if (nanoseconds % Duration::WEEKS != 0 &&
        nanoseconds % Duration::DAYS == 0) {
      stream << duration.days() << Days::units();
    } else {
      stream << duration.weeks() << Weeks::units();
    }
  }

  // Return the stream to original formatting state.
  stream.precision(precision);

  return stream;
}
Example #9
0
void WallStTime(Time t, struct tm *out, int hours_to_wall_st) {
    if (!hours_to_wall_st) hours_to_wall_st = WallStHoursFromLocal();
    localtm(Time2time_t(t + Hours(hours_to_wall_st)), out);
}
Example #10
0
Time SinceDayBegan(Time t, int gmt_offset_hrs) {
    Time ret = (t % Hours(24)) + Hours(gmt_offset_hrs);
    return ret < Time(0) ? ret + Hours(24) : ret;
}
Example #11
0
	/// The current minute of the period <0-24)
	int Hour(void) const
	{
		return int(Hours()) % 24;
	}
Example #12
0
SOM_Scope HWND   SOMLINK WPSamFolder_wpOpen (WPSamF *somSelf,
                HWND hwndCnr,
                ULONG ulView,
                ULONG param)
    {
    ULONG    ul;

    WPSamFData *somThis = WPSamFGetData (somSelf);
    WPSamFMethodDebug ("WPSamF","WPSamFolder_wpOpen");

    if (_wpIsCurrentDesktop (somSelf) && _bCheckShare)
        {
        SOMClass *Metaclass = SOM_GetClass (somSelf);

        DosResetEventSem(hevPrfResetLock, &ul);
        DebugULd (D_SOM, "_wpOpen", "hevPrfResetLock Lock count", ul);
        DebugE (D_SOM, "_wpOpen", "PrfReset locked");

        _bCheckShare = FALSE;
        DebugE (D_SOM, "_wpOpen", "clsIsShareware rufen");

        if (WPSamFM_clsIsShareware (Metaclass))
            {
            if (Hours () <  _ulZeitpunkt2 ||
                Hours () > (_ulZeitpunkt1 + 444) ||
                _ulZeitpunkt1 > _ulZeitpunkt2)
                {
                /* Shareware-Zeit abgelaufen */
                DebugE (D_SOM, "_wpOpen", "Shareware time expired");
                DebugULx (D_SOM, "_wpOpen", "_ulZeitPunkt1", _ulZeitpunkt1);
                DebugULx (D_SOM, "_wpOpen", "_ulZeitPunkt2", _ulZeitpunkt2);
                DebugULx (D_SOM, "_wpOpen", "Hours ()", Hours ());

                WPSamFM_clsAbout (Metaclass);

                if (WPSamFM_clsIsShareware (Metaclass))
                   {
                   DosResetEventSem(hevPrfResetLock, &ul);
                   DebugULd (D_SOM, "_wpOpen", "hevPrfResetLock Lock count", ul);
                   DebugE (D_SOM, "_wpOpen", "PrfReset locked");

                   _RootDesktop(somSelf);
                   }
                }
            else
                {
                /* Shareware-Zeit noch nicht abgelaufen */
                DebugE (D_SOM, "_wpOpen", "Shareware time isn't expired");

                _ulZeitpunkt2 = Hours ();
                _wpSaveDeferred (somSelf);
                }
            }
        }

    /* ok => Desktop kann ge�ffnet werden */

    switch (ulView)
        {
        #ifdef DEBUG
        case PRIMARY_DEBUG:
            DebugE (D_SOM, "wpsam_wpOpen", "Begin Debug");
                {
                }
            DebugE (D_SOM, "wpsam_wpOpen", "End Debug");
            break;
        #endif

        case PRIMARY_ORIGDESK:
            if (!_wpSwitchTo (somSelf, ulView))
               {
               DebugE (D_SOM, "_wpOpen", "Original Desktop");
               _RootDesktop (somSelf);
               }
            break;

        default:
            DebugE (D_SOM, "_wpOpen", "parent_wpOpen will be called");
            return parent_wpOpen (somSelf, hwndCnr, ulView,param);
        }

    DebugE (D_SOM, "_wpOpen", "Normal exit");

    return NULLHANDLE;   /* Nothing opened */
    }
Example #13
0
namespace slave {

// TODO(jieyu): Use static functions for all the constants. See more
// details in MESOS-1023.

constexpr Duration EXECUTOR_REGISTRATION_TIMEOUT = Minutes(1);
constexpr Duration EXECUTOR_REREGISTRATION_TIMEOUT = Seconds(2);

// The maximum timeout within which an executor can re-register.
// Note that this value has to be << 'MIN_AGENT_REREGISTER_TIMEOUT'
// declared in 'master/constants.hpp'; since agent recovery will only
// complete after this timeout has elapsed, this ensures that the
// agent can re-register with the master before it is marked
// unreachable and its tasks are transitioned to TASK_UNREACHABLE or
// TASK_LOST.
constexpr Duration MAX_EXECUTOR_REREGISTRATION_TIMEOUT = Seconds(15);

// The default amount of time to wait for the executor to
// shut down before destroying the container.
constexpr Duration DEFAULT_EXECUTOR_SHUTDOWN_GRACE_PERIOD = Seconds(5);

constexpr Duration RECOVERY_TIMEOUT = Minutes(15);

// TODO(gkleiman): Move this to a different file once `TaskStatusUpdateManager`
// uses `StatusUpdateManagerProcess`. See MESOS-8296.
constexpr Duration STATUS_UPDATE_RETRY_INTERVAL_MIN = Seconds(10);
constexpr Duration STATUS_UPDATE_RETRY_INTERVAL_MAX = Minutes(10);

// Default backoff interval used by the slave to wait before registration.
constexpr Duration DEFAULT_REGISTRATION_BACKOFF_FACTOR = Seconds(1);

// The maximum interval the slave waits before retrying registration.
// Note that this value has to be << 'MIN_SLAVE_REREGISTER_TIMEOUT'
// declared in 'master/constants.hpp'. This helps the slave to retry
// (re-)registration multiple times between when the master finishes
// recovery and when it times out slave re-registration.
constexpr Duration REGISTER_RETRY_INTERVAL_MAX = Minutes(1);

// The maximum interval the slave waits before retrying authentication.
constexpr Duration AUTHENTICATION_RETRY_INTERVAL_MAX = Minutes(1);

// Default backoff interval used by the slave to wait after failed
// authentication.
constexpr Duration DEFAULT_AUTHENTICATION_BACKOFF_FACTOR = Seconds(1);

constexpr Duration GC_DELAY = Weeks(1);
constexpr Duration DISK_WATCH_INTERVAL = Minutes(1);

// Minimum free disk capacity enforced by the garbage collector.
constexpr double GC_DISK_HEADROOM = 0.1;

// Maximum number of completed frameworks to store in memory.
constexpr size_t MAX_COMPLETED_FRAMEWORKS = 50;

// Default maximum number of completed executors per framework
// to store in memory.
constexpr size_t DEFAULT_MAX_COMPLETED_EXECUTORS_PER_FRAMEWORK = 150;

// Maximum number of completed tasks per executor to store in memory.
//
// NOTE: This should be greater than zero because the agent looks
// for completed tasks to determine (with false positives) whether
// an executor ever received tasks. See MESOS-8411.
//
// TODO(mzhu): Remove this note once we can determine whether an
// executor ever received tasks without looking through the
// completed tasks.
constexpr size_t MAX_COMPLETED_TASKS_PER_EXECUTOR = 200;

// Default cpus offered by the slave.
constexpr double DEFAULT_CPUS = 1;

// Default memory offered by the slave.
constexpr Bytes DEFAULT_MEM = Gigabytes(1);

// Default disk space offered by the slave.
constexpr Bytes DEFAULT_DISK = Gigabytes(10);

// Default ports range offered by the slave.
constexpr char DEFAULT_PORTS[] = "[31000-32000]";

// Default cpu resource given to a command executor.
constexpr double DEFAULT_EXECUTOR_CPUS = 0.1;

// Default memory resource given to a command executor.
constexpr Bytes DEFAULT_EXECUTOR_MEM = Megabytes(32);

#ifdef ENABLE_PORT_MAPPING_ISOLATOR
// Default number of ephemeral ports allocated to a container by the
// network isolator.
constexpr uint16_t DEFAULT_EPHEMERAL_PORTS_PER_CONTAINER = 1024;
#endif

// Default UNIX socket (Linux) or Named Pipe (Windows) resource that provides
// CLI access to the Docker daemon.
#ifdef __WINDOWS__
constexpr char DEFAULT_DOCKER_HOST_RESOURCE[] = "//./pipe/docker_engine";
#else
constexpr char DEFAULT_DOCKER_HOST_RESOURCE[] = "/var/run/docker.sock";
#endif // __WINDOWS__

// Default duration that docker containers will be removed after exit.
constexpr Duration DOCKER_REMOVE_DELAY = Hours(6);

// Default duration to wait before retry inspecting a docker
// container.
constexpr Duration DOCKER_INSPECT_DELAY = Seconds(1);

// Default maximum number of docker inspect calls docker ps will invoke
// in parallel to prevent hitting system's open file descriptor limit.
constexpr size_t DOCKER_PS_MAX_INSPECT_CALLS = 100;

// Default duration that docker containerizer will wait to check
// docker version.
// TODO(tnachen): Make this a flag.
constexpr Duration DOCKER_VERSION_WAIT_TIMEOUT = Seconds(5);

// Additional duration that docker containerizer will wait beyond the
// configured `docker_stop_timeout` for docker stop to succeed, before
// trying to kill the process by itself.
constexpr Duration DOCKER_FORCE_KILL_TIMEOUT = Seconds(1);

// Name of the default, CRAM-MD5 authenticatee.
constexpr char DEFAULT_AUTHENTICATEE[] = "crammd5";

// Name of the default, local authorizer.
constexpr char DEFAULT_AUTHORIZER[] = "local";

// Name of the agent HTTP authentication realm for read-only endpoints.
constexpr char READONLY_HTTP_AUTHENTICATION_REALM[] = "mesos-agent-readonly";

// Name of the agent HTTP authentication realm for read-write endpoints.
constexpr char READWRITE_HTTP_AUTHENTICATION_REALM[] = "mesos-agent-readwrite";

// Name of the agent HTTP authentication realm for HTTP executors.
constexpr char EXECUTOR_HTTP_AUTHENTICATION_REALM[] = "mesos-agent-executor";

// Default maximum storage space to be used by the fetcher cache.
constexpr Bytes DEFAULT_FETCHER_CACHE_SIZE = Gigabytes(2);

// If no pings received within this timeout, then the slave will
// trigger a re-detection of the master to cause a re-registration.
Duration DEFAULT_MASTER_PING_TIMEOUT();

// Name of the executable for default executor.
#ifdef __WINDOWS__
constexpr char MESOS_DEFAULT_EXECUTOR[] = "mesos-default-executor.exe";
#else
constexpr char MESOS_DEFAULT_EXECUTOR[] = "mesos-default-executor";
#endif // __WINDOWS__

// Virtual path on which agent logs are mounted in `/files/` endpoint.
constexpr char AGENT_LOG_VIRTUAL_PATH[] = "/slave/log";

std::vector<SlaveInfo::Capability> AGENT_CAPABILITIES();

} // namespace slave {