mirror of
https://github.com/google/nomulus.git
synced 2025-06-30 08:13:32 +02:00
Add option --non_live_versions to set_num_instances command
This commit introduced a new flag to enable SetNumInstancesCommand to be able to set the number of instances for all non-live versions for a given service or for all deployed services. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=222826003
This commit is contained in:
parent
19b7a7b3ec
commit
d20b83c820
16 changed files with 582 additions and 85 deletions
|
@ -20,6 +20,8 @@ import static org.mockito.Mockito.times;
|
|||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import com.beust.jcommander.ParameterException;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import google.registry.testing.AppEngineAdminApiHelper;
|
||||
import google.registry.testing.InjectRule;
|
||||
import google.registry.util.AppEngineServiceUtils;
|
||||
import org.junit.Before;
|
||||
|
@ -34,18 +36,22 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
|
|||
|
||||
@Mock AppEngineServiceUtils appEngineServiceUtils;
|
||||
|
||||
private final String projectId = "domain-registry-test";
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
command = new SetNumInstancesCommand();
|
||||
command.appEngineServiceUtils = appEngineServiceUtils;
|
||||
command.projectId = projectId;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_missingService_throwsException() {
|
||||
ParameterException thrown =
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
ParameterException.class, () -> runCommand("--version=version", "--numInstances=5"));
|
||||
assertThat(thrown).hasMessageThat().contains("The following option is required: --service");
|
||||
IllegalArgumentException.class,
|
||||
() -> runCommand("--versions=version", "--num_instances=5"));
|
||||
assertThat(thrown).hasMessageThat().contains("Service must be specified");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -53,35 +59,47 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
|
|||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> runCommand("--service=", "--version=version", "--numInstances=5"));
|
||||
assertThat(thrown).hasMessageThat().contains("Service must be specified");
|
||||
() -> runCommand("--services=", "--versions=version", "--num_instances=5"));
|
||||
assertThat(thrown).hasMessageThat().contains("Invalid service(s): []");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_invalidService_throwsException() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
runCommand(
|
||||
"--services=INVALID,DEFAULT", "--versions=version", "--num_instances=5"));
|
||||
assertThat(thrown).hasMessageThat().contains("Invalid service(s): [INVALID]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_missingVersion_throwsException() {
|
||||
ParameterException thrown =
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
ParameterException.class, () -> runCommand("--service=service", "--numInstances=5"));
|
||||
assertThat(thrown).hasMessageThat().contains("The following option is required: --version");
|
||||
IllegalArgumentException.class,
|
||||
() -> runCommand("--services=DEFAULT", "--num_instances=5"));
|
||||
assertThat(thrown).hasMessageThat().contains("Version must be specified");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_emptyVersion_throwsException() {
|
||||
IllegalArgumentException thrown =
|
||||
ParameterException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> runCommand("--service=service", "--version=", "--numInstances=5"));
|
||||
assertThat(thrown).hasMessageThat().contains("Version must be specified");
|
||||
ParameterException.class,
|
||||
() -> runCommand("--services=DEFAULT", "--num_instances=5", "--versions"));
|
||||
assertThat(thrown).hasMessageThat().contains("Expected a value after parameter --versions");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_missingNumInstances_throwsException() {
|
||||
ParameterException thrown =
|
||||
assertThrows(
|
||||
ParameterException.class, () -> runCommand("--service=service", "--version=version"));
|
||||
ParameterException.class, () -> runCommand("--services=DEFAULT", "--versions=version"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("The following option is required: --numInstances");
|
||||
.contains("The following option is required: --num_instances");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -89,13 +107,111 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
|
|||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> runCommand("--service=service", "--version=version", "--numInstances=-5"));
|
||||
() -> runCommand("--services=DEFAULT", "--versions=version", "--num_instances=-5"));
|
||||
assertThat(thrown).hasMessageThat().contains("Number of instances must be greater than zero");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_versionNotNullWhenSettingAllNonLiveVersions_throwsException() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> runCommand("--services=DEFAULT", "--versions=version", "--num_instances=-5"));
|
||||
assertThat(thrown).hasMessageThat().contains("Number of instances must be greater than zero");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_settingNonManualScalingVersions_throwsException() {
|
||||
command.appengine =
|
||||
new AppEngineAdminApiHelper.Builder()
|
||||
.setAppId(projectId)
|
||||
.setManualScalingVersionsMap(ImmutableMultimap.of("default", "version1"))
|
||||
.build()
|
||||
.getAppengine();
|
||||
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
runCommand(
|
||||
"--non_live_versions=true",
|
||||
"--services=DEFAULT",
|
||||
"--versions=version",
|
||||
"--num_instances=10"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("--versions cannot be set if --non_live_versions is set");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_validParameters_succeeds() throws Exception {
|
||||
runCommand("--service=service", "--version=version", "--numInstances=10");
|
||||
verify(appEngineServiceUtils, times(1)).setNumInstances("service", "version", 10L);
|
||||
command.appengine =
|
||||
new AppEngineAdminApiHelper.Builder()
|
||||
.setAppId(projectId)
|
||||
.setManualScalingVersionsMap(ImmutableMultimap.of("default", "version"))
|
||||
.build()
|
||||
.getAppengine();
|
||||
|
||||
runCommand("--services=DEFAULT", "--versions=version", "--num_instances=10");
|
||||
verify(appEngineServiceUtils, times(1)).setNumInstances("default", "version", 10L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_settingMultipleServicesAndVersions_succeeds() throws Exception {
|
||||
command.appengine =
|
||||
new AppEngineAdminApiHelper.Builder()
|
||||
.setAppId(projectId)
|
||||
.setManualScalingVersionsMap(
|
||||
ImmutableMultimap.of(
|
||||
"default", "version1",
|
||||
"default", "version2",
|
||||
"backend", "version1",
|
||||
"backend", "version2"))
|
||||
.build()
|
||||
.getAppengine();
|
||||
|
||||
runCommand("--services=DEFAULT,BACKEND", "--versions=version1,version2", "--num_instances=10");
|
||||
verify(appEngineServiceUtils, times(1)).setNumInstances("default", "version1", 10L);
|
||||
verify(appEngineServiceUtils, times(1)).setNumInstances("default", "version2", 10L);
|
||||
verify(appEngineServiceUtils, times(1)).setNumInstances("backend", "version1", 10L);
|
||||
verify(appEngineServiceUtils, times(1)).setNumInstances("backend", "version2", 10L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_settingAllNonLiveVersions_succeeds() throws Exception {
|
||||
command.appengine =
|
||||
new AppEngineAdminApiHelper.Builder()
|
||||
.setAppId(projectId)
|
||||
.setManualScalingVersionsMap(
|
||||
ImmutableMultimap.of(
|
||||
"default", "version1", "default", "version2", "default", "version3"))
|
||||
.setLiveVersionsMap(ImmutableMultimap.of("default", "version2"))
|
||||
.build()
|
||||
.getAppengine();
|
||||
|
||||
runCommand("--non_live_versions=true", "--services=DEFAULT", "--num_instances=10");
|
||||
verify(appEngineServiceUtils, times(1)).setNumInstances("default", "version1", 10L);
|
||||
verify(appEngineServiceUtils, times(0)).setNumInstances("default", "version2", 10L);
|
||||
verify(appEngineServiceUtils, times(1)).setNumInstances("default", "version3", 10L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_noNonLiveVersions_succeeds() throws Exception {
|
||||
command.appengine =
|
||||
new AppEngineAdminApiHelper.Builder()
|
||||
.setAppId(projectId)
|
||||
.setManualScalingVersionsMap(
|
||||
ImmutableMultimap.of(
|
||||
"default", "version1", "default", "version2", "default", "version3"))
|
||||
.setLiveVersionsMap(
|
||||
ImmutableMultimap.of(
|
||||
"default", "version1", "default", "version2", "default", "version3"))
|
||||
.build()
|
||||
.getAppengine();
|
||||
|
||||
runCommand("--non_live_versions=true", "--services=DEFAULT", "--num_instances=10");
|
||||
verify(appEngineServiceUtils, times(0)).setNumInstances("default", "version1", 10L);
|
||||
verify(appEngineServiceUtils, times(0)).setNumInstances("default", "version2", 10L);
|
||||
verify(appEngineServiceUtils, times(0)).setNumInstances("default", "version3", 10L);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue