Skip to content

Commit

Permalink
test case for failure in beginCreate
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft committed Jan 30, 2022
1 parent 8e5fbb5 commit 88c7561
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -77,7 +78,9 @@ protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile

@Override
protected void cleanUpResources() {
resourceManager.resourceGroups().beginDeleteByName(rgName);
if (rgName != null) {
resourceManager.resourceGroups().beginDeleteByName(rgName);
}
}

@Test
Expand Down Expand Up @@ -196,6 +199,43 @@ public void canCreateVirtualMachine() throws Exception {
computeManager.virtualMachines().deleteById(foundVM.id());
}

@Test
public void cannotCreateVirtualMachineSyncPoll() throws Exception {
final String mySqlInstallScript = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/4397e808d07df60ff3cdfd1ae40999f0130eb1b3/mysql-standalone-server-ubuntu/scripts/install_mysql_server_5.6.sh";
final String installCommand = "bash install_mysql_server_5.6.sh Abc.123x(";

Assertions.assertThrows(IllegalStateException.class, () -> {
Accepted<VirtualMachine> acceptedVirtualMachine =
this.computeManager.virtualMachines()
.define(vmName)
.withRegion(region)
.withNewResourceGroup(rgName)
.withNewPrimaryNetwork("10.0.0.0/28")
.withPrimaryPrivateIPAddressDynamic()
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_18_04_LTS)
.withRootUsername("Foo12")
.withSsh(sshPublicKey())
// virtual machine extensions is not compatible with "beginCreate" method
.defineNewExtension("CustomScriptForLinux")
.withPublisher("Microsoft.OSTCExtensions")
.withType("CustomScriptForLinux")
.withVersion("1.4")
.withMinorVersionAutoUpgrade()
.withPublicSetting("fileUris", Collections.singletonList(mySqlInstallScript))
.withPublicSetting("commandToExecute", installCommand)
.attach()
.beginCreate();
});

// verify dependent resources is not created in the case of above failed "beginCreate" method
boolean dependentResourceCreated = computeManager.resourceManager().serviceClient().getResourceGroups().checkExistence(rgName);

This comment has been minimized.

Copy link
@weidongxu-microsoft

weidongxu-microsoft Jan 30, 2022

Author Member

We should add a checkExistence to resource group convenient layer. Another PR.

Assertions.assertFalse(dependentResourceCreated);

// skip cleanup
rgName = null;
}

@Test
public void canCreateVirtualMachineSyncPoll() throws Exception {
final long defaultDelayInMillis = 10 * 1000;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"networkCallRecords" : [ {
"Method" : "HEAD",
"Uri" : "http://localhost:1234/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/javacsmrg32776?api-version=2021-01-01",
"Headers" : {
"User-Agent" : "azsdk-java-com.azure.resourcemanager.resources/2.12.0-beta.1 (17.0.1; Windows 11; 10.0)",
"x-ms-client-request-id" : "b72068f8-3aee-44e4-99c0-e8a09162516f",
"Content-Type" : "application/json"
},
"Response" : {
"content-length" : "106",
"X-Content-Type-Options" : "nosniff",
"Pragma" : "no-cache",
"retry-after" : "0",
"x-ms-ratelimit-remaining-subscription-reads" : "11999",
"StatusCode" : "404",
"x-ms-correlation-request-id" : "3bb17bcb-79a8-4571-a431-6c31c105548a",
"Date" : "Sun, 30 Jan 2022 08:50:24 GMT",
"Strict-Transport-Security" : "max-age=31536000; includeSubDomains",
"Cache-Control" : "no-cache",
"x-ms-failure-cause" : "gateway",
"x-ms-routing-request-id" : "SOUTHEASTASIA:20220130T085024Z:3bb17bcb-79a8-4571-a431-6c31c105548a",
"Expires" : "-1",
"x-ms-request-id" : "3bb17bcb-79a8-4571-a431-6c31c105548a",
"Body" : "",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
} ],
"variables" : [ "javacsmrg32776", "javacsmrg232702", "nic6346912fda1", "vnet74848d334a" ]
}

0 comments on commit 88c7561

Please sign in to comment.