Add SetNumInstancesCommand in Nomulus tool to adjust the number of instances

for a given service and version at runtime.

Note that this CL only supports the adjustment for a given service and version. I will add another functionality to let this command be able to detect all non-live versions automatically and apply the adjustment.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=221092001
This commit is contained in:
shicong 2018-11-12 07:59:00 -08:00 committed by jianglai
parent 557984bb75
commit 66d98c8d66
7 changed files with 216 additions and 0 deletions

View file

@ -19,6 +19,8 @@ import static google.registry.testing.JUnitBackports.assertThrows;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.appengine.api.modules.ModulesService;
@ -75,4 +77,37 @@ public class AppEngineServiceUtilsImplTest {
() -> appEngineServiceUtils.getVersionHostname("servicename", null));
assertThat(thrown).hasMessageThat().isEqualTo("Must specify the version");
}
@Test
public void test_setNumInstances_worksWithValidParameters() {
appEngineServiceUtils.setNumInstances("service", "version", 10L);
verify(modulesService, times(1)).setNumInstances("service", "version", 10L);
}
@Test
public void test_setNumInstances_throwsWhenServiceIsNull() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> appEngineServiceUtils.setNumInstances(null, "version", 10L));
assertThat(thrown).hasMessageThat().isEqualTo("Must specify the service");
}
@Test
public void test_setNumInstances_throwsWhenVersionIsNull() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> appEngineServiceUtils.setNumInstances("service", null, 10L));
assertThat(thrown).hasMessageThat().isEqualTo("Must specify the version");
}
@Test
public void test_setNumInstances_throwsWhenNumInstancesIsInvalid() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> appEngineServiceUtils.setNumInstances("service", "version", -10L));
assertThat(thrown).hasMessageThat().isEqualTo("Number of instances must be greater than 0");
}
}