Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add additional IT for create instance with autoscaling #1115

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.google.cloud.bigtable.test_helpers.env.PrefixGenerator;
import com.google.cloud.bigtable.test_helpers.env.TestEnvRule;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
Expand Down Expand Up @@ -285,6 +284,43 @@ public void basicInstanceOperationTest() {
assertThat(client.listInstances()).contains(instance);
}

@Test
public void createInstanceWithAutoscalingTest() {
String newInstanceId = prefixGenerator.newPrefix();
String newClusterId = newInstanceId + "-c1";

try {
ClusterAutoscalingConfig clusterAutoscalingConfig =
ClusterAutoscalingConfig.of(newInstanceId, newClusterId)
.setMaxNodes(3)
.setMinNodes(1)
.setCpuUtilizationTargetPercent(30);
client.createInstance(
CreateInstanceRequest.of(newInstanceId)
.addCluster(
newClusterId,
testEnvRule.env().getPrimaryZone(),
clusterAutoscalingConfig,
StorageType.HDD)
.setDisplayName("Multi-Cluster-Instance-Test")
.addLabel("state", "readytodelete")
.setType(Type.PRODUCTION));

Cluster cluster = client.getCluster(newInstanceId, newClusterId);
assertThat(cluster.getId()).contains(newClusterId);
assertThat(cluster.getServeNodes()).isEqualTo(1);
assertThat(cluster.getAutoscalingMinServeNodes()).isEqualTo(1);
assertThat(cluster.getAutoscalingMaxServeNodes()).isEqualTo(3);
assertThat(cluster.getAutoscalingCpuPercentageTarget()).isEqualTo(30);
} catch (Exception e) {
throw new AssertionError(e);
} finally {
if (client.exists(newInstanceId)) {
client.deleteInstance(newInstanceId);
}
}
}

@Test
public void createClusterWithAutoscalingTest() {
String newInstanceId = prefixGenerator.newPrefix();
Expand Down Expand Up @@ -316,9 +352,11 @@ public void createClusterWithAutoscalingTest() {
assertThat(cluster.getAutoscalingMaxServeNodes()).isEqualTo(4);
assertThat(cluster.getAutoscalingCpuPercentageTarget()).isEqualTo(20);
} catch (Exception e) {
Assert.fail("error in the test" + e.getMessage());
throw new AssertionError(e);
} finally {
client.deleteInstance(newInstanceId);
if (client.exists(newInstanceId)) {
client.deleteInstance(newInstanceId);
}
}
}

Expand Down Expand Up @@ -383,9 +421,11 @@ public void createClusterWithAutoscalingAndPartialUpdateTest() {
assertThat(updatedCluster.getAutoscalingMaxServeNodes()).isEqualTo(5);
assertThat(updatedCluster.getAutoscalingCpuPercentageTarget()).isEqualTo(45);
} catch (Exception e) {
Assert.fail("error in the test: " + e.getMessage());
throw new AssertionError(e);
} finally {
client.deleteInstance(newInstanceId);
if (client.exists(newInstanceId)) {
client.deleteInstance(newInstanceId);
}
}
}

Expand Down Expand Up @@ -415,9 +455,11 @@ public void createClusterWithManualScalingTest() {
assertThat(cluster.getAutoscalingMinServeNodes()).isEqualTo(0);
assertThat(cluster.getAutoscalingCpuPercentageTarget()).isEqualTo(0);
} catch (Exception e) {
Assert.fail("error in the test: " + e.getMessage());
throw new AssertionError(e);
} finally {
client.deleteInstance(newInstanceId);
if (client.exists(newInstanceId)) {
client.deleteInstance(newInstanceId);
}
}
}

Expand Down