use of com.netflix.titus.runtime.store.v3.memory.InMemoryPolicyStore in project titus-control-plane by Netflix.
the class DefaultAppScaleManagerTest method checkV3LiveStreamTargetUpdates.
@Test
public void checkV3LiveStreamTargetUpdates() throws Exception {
String jobIdOne = UUID.randomUUID().toString();
String jobIdTwo = UUID.randomUUID().toString();
InMemoryPolicyStore policyStore = new InMemoryPolicyStore();
V3JobOperations v3JobOperations = mockV3Operations(jobIdOne, jobIdTwo);
AppScaleClientWithScalingPolicyConstraints appScalingClient = new AppScaleClientWithScalingPolicyConstraints();
DefaultAppScaleManager appScaleManager = new DefaultAppScaleManager(policyStore, new AutoScalingPolicyTests.MockAlarmClient(), appScalingClient, v3JobOperations, new DefaultRegistry(), AutoScalingPolicyTests.mockAppScaleManagerConfiguration(), Schedulers.immediate(), mock(TitusRuntime.class));
List<String> refIds = submitTwoJobs(appScaleManager, jobIdOne, jobIdTwo, policyStore);
Assertions.assertThat(refIds.size()).isEqualTo(2);
CountDownLatch latch = new CountDownLatch(1);
Observable<String> jobIdTargetUpdates = appScaleManager.v3LiveStreamTargetUpdates();
List<String> targetsUpdated = new ArrayList<>();
jobIdTargetUpdates.subscribe(targetUpdated -> {
log.info("Got ScalableTarget to be updated {}", targetUpdated);
Assertions.assertThat(targetUpdated).isEqualTo(jobIdTwo);
targetsUpdated.add(targetUpdated);
latch.countDown();
}, e -> log.error("Error in v2 live stream for scalable target update", e), () -> log.info("Completed"));
latch.await(60, TimeUnit.SECONDS);
AutoScalingPolicyTests.waitForCondition(() -> {
JobScalingConstraints jpc = appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdTwo);
return jpc != null && jpc.getMinCapacity() == 5 && jpc.getMaxCapacity() == 15;
});
Assertions.assertThat(targetsUpdated.size()).isEqualTo(1);
Assertions.assertThat(appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdOne).getMinCapacity()).isEqualTo(1);
Assertions.assertThat(appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdOne).getMaxCapacity()).isEqualTo(10);
Assertions.assertThat(appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdTwo).getMinCapacity()).isEqualTo(5);
Assertions.assertThat(appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdTwo).getMaxCapacity()).isEqualTo(15);
}
use of com.netflix.titus.runtime.store.v3.memory.InMemoryPolicyStore in project titus-control-plane by Netflix.
the class DefaultAppScaleManagerTest method submitTwoJobs.
private List<String> submitTwoJobs(DefaultAppScaleManager appScaleManager, String jobIdOne, String jobIdTwo, InMemoryPolicyStore policyStore) throws Exception {
// call - createAutoScalingPolicy
AutoScalingPolicy autoScalingPolicyOne = AutoScalingPolicyTests.buildStepScalingPolicy(jobIdOne);
appScaleManager.createAutoScalingPolicy(autoScalingPolicyOne).toBlocking().single();
// call - createAutoScalingPolicy
AutoScalingPolicy autoScalingPolicyTwo = AutoScalingPolicyTests.buildStepScalingPolicy(jobIdTwo);
appScaleManager.createAutoScalingPolicy(autoScalingPolicyTwo).toBlocking().single();
// call - processPendingPolicies
List<AutoScalingPolicy> savedPolicies = policyStore.retrievePolicies(false).toList().toBlocking().first();
AutoScalingPolicyTests.waitForCondition(() -> savedPolicies.size() == 2);
Assertions.assertThat(savedPolicies.size()).isEqualTo(2);
return savedPolicies.stream().map(policy -> policy.getRefId()).collect(Collectors.toList());
}
use of com.netflix.titus.runtime.store.v3.memory.InMemoryPolicyStore in project titus-control-plane by Netflix.
the class DefaultAppScaleManagerTest method checkBulkPolicyCreations.
@Test
public void checkBulkPolicyCreations() {
AutoScalingPolicyTests.MockAlarmClient mockAlarmClient = new AutoScalingPolicyTests.MockAlarmClient();
AutoScalingPolicyTests.MockAppAutoScalingClient mockAppAutoScalingClient = new AutoScalingPolicyTests.MockAppAutoScalingClient();
InMemoryPolicyStore policyStore = new InMemoryPolicyStore();
final int totalJobs = 300;
List<String> jobIds = new ArrayList<>(totalJobs);
for (int i = 0; i < totalJobs; i++) {
String jobId = UUID.randomUUID().toString();
jobIds.add(jobId);
}
V3JobOperations v3JobOperations = mockV3OperationsForJobs(jobIds);
DefaultAppScaleManager appScaleManager = new DefaultAppScaleManager(policyStore, mockAlarmClient, mockAppAutoScalingClient, v3JobOperations, new DefaultRegistry(), AutoScalingPolicyTests.mockAppScaleManagerConfiguration(), Schedulers.computation(), mock(TitusRuntime.class));
final CountDownLatch latch = new CountDownLatch(totalJobs);
for (int i = 0; i < totalJobs; i++) {
final AutoScalingPolicy autoScalingPolicy = AutoScalingPolicyTests.buildStepScalingPolicy(jobIds.get(i));
appScaleManager.createAutoScalingPolicy(autoScalingPolicy).subscribe(pid -> {
log.info("Policy created {}", pid);
latch.countDown();
});
}
await().timeout(30, TimeUnit.SECONDS).until(() -> mockAppAutoScalingClient.getNumPolicies() == totalJobs);
}
use of com.netflix.titus.runtime.store.v3.memory.InMemoryPolicyStore in project titus-control-plane by Netflix.
the class DefaultAppScaleManagerTest method checkCreatePolicyFlow.
private void checkCreatePolicyFlow(PolicyType policyType) throws Exception {
// create instance of DefaultAppScaleManager
AutoScalingPolicyTests.MockAlarmClient mockAlarmClient = new AutoScalingPolicyTests.MockAlarmClient();
AutoScalingPolicyTests.MockAppAutoScalingClient mockAppAutoScalingClient = new AutoScalingPolicyTests.MockAppAutoScalingClient();
InMemoryPolicyStore policyStore = new InMemoryPolicyStore();
String jobIdOne = UUID.randomUUID().toString();
String jobIdTwo = UUID.randomUUID().toString();
V3JobOperations v3JobOperations = mockV3Operations(jobIdOne, jobIdTwo);
DefaultAppScaleManager appScaleManager = new DefaultAppScaleManager(policyStore, mockAlarmClient, mockAppAutoScalingClient, v3JobOperations, new DefaultRegistry(), AutoScalingPolicyTests.mockAppScaleManagerConfiguration(), Schedulers.immediate(), mock(TitusRuntime.class));
AutoScalingPolicy autoScalingPolicyOne;
AutoScalingPolicy autoScalingPolicyTwo;
if (policyType == PolicyType.StepScaling) {
autoScalingPolicyOne = AutoScalingPolicyTests.buildStepScalingPolicy(jobIdOne);
autoScalingPolicyTwo = AutoScalingPolicyTests.buildStepScalingPolicy(jobIdTwo);
} else {
autoScalingPolicyOne = AutoScalingPolicyTests.buildTargetTrackingPolicy(jobIdOne);
autoScalingPolicyTwo = AutoScalingPolicyTests.buildTargetTrackingPolicy(jobIdTwo);
}
// call - createAutoScalingPolicy
appScaleManager.createAutoScalingPolicy(autoScalingPolicyOne).toBlocking().single();
String policyRefIdTwo = appScaleManager.createAutoScalingPolicy(autoScalingPolicyTwo).toBlocking().single();
AutoScalingPolicyTests.waitForCondition(() -> {
List<AutoScalingPolicy> policies = policyStore.retrievePolicies(false).toList().toBlocking().first();
return policies.size() == 2 && mockAppAutoScalingClient.getNumPolicies() == 2 && mockAppAutoScalingClient.getNumScalableTargets() == 2;
});
// verify counts in CloudAlarmClient, AppAutoScaleClient and AppScalePolicyStore
List<AutoScalingPolicy> policiesStored = policyStore.retrievePolicies(false).toList().toBlocking().first();
Assertions.assertThat(policiesStored.size()).isEqualTo(2);
Assertions.assertThat(mockAppAutoScalingClient.getNumPolicies()).isEqualTo(2);
Assertions.assertThat(mockAppAutoScalingClient.getNumScalableTargets()).isEqualTo(2);
if (policyType == PolicyType.StepScaling) {
Assertions.assertThat(mockAlarmClient.getNumOfAlarmsCreated()).isEqualTo(2);
}
appScaleManager.removeAutoScalingPolicy(policyRefIdTwo).await();
AutoScalingPolicyTests.waitForCondition(() -> {
List<AutoScalingPolicy> policies = policyStore.retrievePolicies(false).toList().toBlocking().first();
return policies.size() == 1 && mockAppAutoScalingClient.getNumPolicies() == 1 && mockAppAutoScalingClient.getNumScalableTargets() == 1;
});
// verify counts in CloudAlarmClient, AppAutoScaleClient and AppScalePolicyStore
policiesStored = policyStore.retrievePolicies(false).toList().toBlocking().first();
Assertions.assertThat(policiesStored.size()).isEqualTo(1);
Assertions.assertThat(mockAppAutoScalingClient.getNumPolicies()).isEqualTo(1);
Assertions.assertThat(mockAppAutoScalingClient.getNumScalableTargets()).isEqualTo(1);
if (policyType == PolicyType.StepScaling) {
Assertions.assertThat(mockAlarmClient.getNumOfAlarmsCreated()).isEqualTo(1);
}
}
Aggregations