TEST(QoSPipelineTest, FiltersNotProperlyFed) { uint64_t WINDOWS_SIZE = 10; uint64_t CONTENTION_COOLDOWN = 10; double_t RELATIVE_THRESHOLD = 0.5; Try<mesos::FixtureResourceUsage> usages = JsonUsage::ReadJson("tests/fixtures/pipeline/insufficient_metrics.json"); if (usages.isError()) { LOG(ERROR) << "JsonSource failed: " << usages.error() << std::endl; } ResourceUsage usage; usage.CopyFrom(usages.get().resource_usage(0)); QoSControllerPipeline* pipeline = new CpuQoSPipeline<RollingChangePointDetector>( QoSPipelineConf( ChangePointDetectionState::createForRollingDetector( WINDOWS_SIZE, CONTENTION_COOLDOWN, RELATIVE_THRESHOLD), ema::DEFAULT_ALPHA, false, true)); Result<QoSCorrections> corrections = pipeline->run(usage); EXPECT_NONE(corrections); delete pipeline; }
TEST(QoSPipelineTest, FiltersNotProperlyFed) { uint64_t WINDOWS_SIZE = 10; uint64_t CONTENTION_COOLDOWN = 10; double_t FRATIONAL_THRESHOLD = 0.5; Try<mesos::FixtureResourceUsage> usages = JsonUsage::ReadJson("tests/fixtures/pipeline/insufficient_metrics.json"); if (usages.isError()) { LOG(ERROR) << "JsonSource failed: " << usages.error() << std::endl; } ResourceUsage usage; usage.CopyFrom(usages.get().resource_usage(0)); SerenityConfig conf; conf["Detector"] = createAssuranceDetectorCfg( WINDOWS_SIZE, CONTENTION_COOLDOWN, FRATIONAL_THRESHOLD); conf.set(ENABLED_VISUALISATION, false); conf.set(VALVE_OPENED, true); QoSControllerPipeline* pipeline = new CpuQoSPipeline(conf); Result<QoSCorrections> corrections = pipeline->run(usage); EXPECT_NONE(corrections); delete pipeline; }
/** * In this test we generate stable load with drop and * test the RollingChangePointDetector. We expect one * contention. */ TEST(DropFilterRollingDetectorTest, StableLoadWithDrop) { const uint64_t WINDOWS_SIZE = 10; const uint64_t CONTENTION_COOLDOWN = 10; const double_t RELATIVE_THRESHOLD = 5; const uint64_t LOAD_ITERATIONS = 200; // End of pipeline. MockSink<Contentions> mockSink; EXPECT_CALL(mockSink, consume(_)) .Times(LOAD_ITERATIONS); DropFilter<RollingChangePointDetector> dropFilter( &mockSink, usage::getIpc, ChangePointDetectionState::createForRollingDetector( WINDOWS_SIZE, CONTENTION_COOLDOWN, RELATIVE_THRESHOLD)); // Fake slave ResourceUsage source. MockSource<ResourceUsage> usageSource(&dropFilter); Try<mesos::FixtureResourceUsage> usages = JsonUsage::ReadJson("tests/fixtures/start_json_test.json"); if (usages.isError()) { LOG(ERROR) << "JsonSource failed: " << usages.error() << std::endl; } ResourceUsage usage; usage.CopyFrom(usages.get().resource_usage(0)); const double_t DROP_PROGRES = 1; LoadGenerator loadGen( [](double_t iter) { return 10; }, new ZeroNoise(), LOAD_ITERATIONS); bool dropped = false; for (; loadGen.end(); loadGen++) { usage.mutable_executors(0)->CopyFrom( generateIPC(usage.executors(0), (*loadGen)(), (*loadGen).timestamp)); // Run pipeline iteration. usageSource.produce(usage); if (dropped) { dropped = false; mockSink.expectContentionWithVictim("serenity2"); } else { mockSink.expectContentions(0); } if (loadGen.iteration >= 100 && loadGen.iteration < 110) { // After 6 iterations of 1 drop progress value should be below // threshold (4). if (loadGen.iteration == 105) dropped = true; loadGen.modifier -= DROP_PROGRES; } } }
/** * In this test we generate load with noise and * test the CpuUsageEMAfilter output in every iteration. */ TEST(EMATest, CpuUsageEMATestNoisyConstSample) { // End of pipeline. MockSink<ResourceUsage> mockSink; // Third component in pipeline. EMAFilter cpuUsageEMAFilter( &mockSink, usage::getCpuUsage, usage::setEmaCpuUsage, 0.2); // Second component in pipeline. // We need that for cumulative metrics. CumulativeFilter cumulativeFilter( &cpuUsageEMAFilter); // First component in pipeline. MockSource<ResourceUsage> source(&cumulativeFilter); Try<mesos::FixtureResourceUsage> usages = JsonUsage::ReadJson("tests/fixtures/start_json_test.json"); if (usages.isError()) { LOG(ERROR) << "JsonSource failed: " << usages.error() << std::endl; } ResourceUsage usage; usage.CopyFrom(usages.get().resource_usage(0)); const double_t CPU_USAGE_VALUE = 10; const double_t THRESHOLD = 1.2; const double_t MAX_NOISE = 5; const int32_t ITERATIONS = 100; SignalScenario signalGen = SignalScenario(ITERATIONS) .use(math::const10Function) .use(new SymetricNoiseGenerator(MAX_NOISE)); ITERATE_SIGNAL(signalGen) { usage.mutable_executors(0)->CopyFrom( generateCpuUsage(usage.executors(0), (uint64_t)(*signalGen).cumulative(), signalGen->timestamp)); // Run pipeline iteration source.produce(usage); if (signalGen.iteration > 0) mockSink.expectCpuUsage(0, CPU_USAGE_VALUE, THRESHOLD); } EXPECT_EQ(99, mockSink.numberOfMessagesConsumed); }
/** * In this test we generate stable load and * test the RollingChangePointDetector. We don't expect * any contention. */ TEST(DropFilterRollingDetectorTest, StableLoad) { const uint64_t WINDOWS_SIZE = 10; const uint64_t CONTENTION_COOLDOWN = 10; const double_t RELATIVE_THRESHOLD = 0.5; const uint64_t LOAD_ITERATIONS = 100; // End of pipeline. MockSink<Contentions> mockSink; EXPECT_CALL(mockSink, consume(_)) .Times(LOAD_ITERATIONS); DropFilter<RollingChangePointDetector> dropFilter( &mockSink, usage::getIpc, ChangePointDetectionState::createForRollingDetector( WINDOWS_SIZE, CONTENTION_COOLDOWN, RELATIVE_THRESHOLD)); // Fake slave ResourceUsage source. MockSource<ResourceUsage> usageSource(&dropFilter); Try<mesos::FixtureResourceUsage> usages = JsonUsage::ReadJson("tests/fixtures/start_json_test.json"); if (usages.isError()) { LOG(ERROR) << "JsonSource failed: " << usages.error() << std::endl; } ResourceUsage usage; usage.CopyFrom(usages.get().resource_usage(0)); LoadGenerator loadGen( [](double_t iter) { return 10; }, new ZeroNoise(), LOAD_ITERATIONS); for (; loadGen.end(); loadGen++) { usage.mutable_executors(0)->CopyFrom( generateIPC(usage.executors(0), (*loadGen)(), (*loadGen).timestamp)); // Run pipeline iteration. usageSource.produce(usage); if (loadGen.iteration > 0) mockSink.expectContentions(0); } }
TEST(EstimatorPipelineTest, FiltersNotProperlyFed) { Try<mesos::FixtureResourceUsage> usages = JsonUsage::ReadJson("tests/fixtures/pipeline/insufficient_metrics.json"); if (usages.isError()) { LOG(ERROR) << "JsonSource failed: " << usages.error() << std::endl; ASSERT_FALSE(usages.isError()); // test failure. } ResourceUsage usage; usage.CopyFrom(usages.get().resource_usage(0)); ResourceEstimatorPipeline* pipeline = new CpuEstimatorPipeline(); Result<Resources> slack = pipeline->run(usage); EXPECT_NONE(slack); delete pipeline; }
/** * Check if getRevocableExecutors function properly filters out PR executors. * * TODO(skonefal): Does it really work? */ TEST(HelperFunctionsTest, getRevocableExecutors) { Try<mesos::FixtureResourceUsage> usages = JsonUsage::ReadJson(QOS_FIXTURE); if (usages.isError()) { LOG(ERROR) << "JsonSource failed: " << usages.error() << std::endl; } ResourceUsage usage; usage.CopyFrom(usages.get().resource_usage(0)); std::list<ResourceUsage_Executor> ret = ResourceUsageHelper::getRevocableExecutors(usage); ASSERT_EQ(3u, ret.size()); // Expected only BE executors. for (auto executor : ret) { Resources allocated(executor.allocated()); EXPECT_FALSE(allocated.revocable().empty()); } }