Exemplo n.º 1
0
void CachedFileTest::VerifyContent(wstring const & expectedContent, TimeSpan const & waitTimeMax)
{
    TimeSpan waitTime = TimeSpan::Zero;
    TimeSpan retryDelay = TimeSpan::FromMilliseconds(300);

    for(;;)
    {
        wstring actualContent = L"";
        ReadFromCache(actualContent);
        if (actualContent == expectedContent)
        {
            break;
        }

        waitTime = waitTime + retryDelay;
        if (waitTime > waitTimeMax)
        {
            FAIL_TEST(
                "Actual Content '{0}' does not match expected Content '{1}'", 
                actualContent, 
                expectedContent);
        }
        else
        {
            Trace.WriteInfo(
                TraceType,
                "Sleep to wait for notifications to be processed");

            Sleep(static_cast<DWORD>(retryDelay.TotalMilliseconds()));
        }
    }
}
Exemplo n.º 2
0
void DecayAverage::Update(TimeSpan const & value)
{
    uint millisecondsValue;
    StopwatchTime now = Stopwatch::Now();

    if (value.TotalMilliseconds() > MAX_VALUE)
    {
        millisecondsValue = MAX_VALUE;
    }
    else
    {
        millisecondsValue = static_cast<uint>(value.TotalMilliseconds());
    }

    if (decayFactor_ == 0.0)
    {
        weightedSumMilliSeconds_ = static_cast<double>(millisecondsValue);
        sumOfWeightMilliSeconds_ = 1.0;
    }
    else
    {
        TimeSpan interval = now - lastUpdatedTime_;
        double power = interval / decayInterval_;
        double coefficient = pow(decayFactor_, power);
        
        if (coefficient > MinCoefficient &&
            MAX_DOUBLE - weightedSumMilliSeconds_ > millisecondsValue)  // Protect against overflow here
        {
            weightedSumMilliSeconds_ = weightedSumMilliSeconds_ * coefficient + static_cast<double>(millisecondsValue);
            sumOfWeightMilliSeconds_ = sumOfWeightMilliSeconds_ * coefficient + 1.0;
        }
        else
        {
            weightedSumMilliSeconds_ = static_cast<double>(millisecondsValue);
            sumOfWeightMilliSeconds_ = 1.0;
        }
    }

    lastValueMilliSeconds_ = millisecondsValue;
    lastUpdatedTime_ = now;
}
Exemplo n.º 3
0
	/**
	 * Signals the current thread to stop processing for the specified time span.
	 *
	 * @param timeSpan The amount of time to stop processing.
	 */
	static void Sleep(const TimeSpan& timeSpan) { StackTrace trace(__METHOD__, __FILE__, __LINE__);
		if (timeSpan > TimeSpan::Zero()) {
			msleep((uint32_t) timeSpan.TotalMilliseconds());
			Idle += timeSpan;
		}
	}
Exemplo n.º 4
0
	/**
	 * Returns the thread utilization.
	 *
	 * @return A value in between zero and one, where zero means the thread was completely idle, and one means the thread was completely busy.
	 */
	static double Utilization() { StackTrace trace(__METHOD__, __FILE__, __LINE__);
		double duration = (DateTime::Utc() - Started).TotalMilliseconds();
		return (duration - Idle.TotalMilliseconds()) / duration;
	}