InstanceFailureStepDefinitions implements EC2StepFunctions { @Given("^EC2 \"([^\"]*)\"$") public InstanceFailureStepDefinitions givenEC2InstanceName(String name) { executionStateCache.addInstances(findInstancesByName(name)); executionStateCache.setEc2Tag(name); return this; } InstanceFailureStepDefinitions(); ExecutionStateCache getExecutionStateCache(); void setExecutionStateCache(ExecutionStateCache executionStateCache); @Given("^EC2 \"([^\"]*)\"$") InstanceFailureStepDefinitions givenEC2InstanceName(String name); @Given("^EC2 with a tag \"([^\"]*)\"$") InstanceFailureStepDefinitions givenEC2InstanceTags(String tag); @Given("^EC2 instances filtered by \"([^\"]*)\"$") InstanceFailureStepDefinitions givenFilteredEC2(String filters); @Given("^EC2 with a tags \"([^\"]*)\"$") InstanceFailureStepDefinitions givenEC2InstanceTags(String... tags); void terminateProcessGivenInstance(String processName, String instanceID, String instanceIP); @When("^terminate process \"([^\"]*)\"$") InstanceFailureStepDefinitions terminateProcessOnAllHealthyInstances(String processName); @When("^terminate process \"([^\"]*)\" on instance with id \"([^\"]*)\" and ip \"([^\"]*)\"$") InstanceFailureStepDefinitions terminateProcessGivenInstanceCucumber(String processName, String instanceID, String instanceIP); @When("^terminate process \"([^\"]*)\" on (\\d+) instance$") InstanceFailureStepDefinitions terminateProcessOnHealthyInstances(String processName, int numHosts); @When("^terminate process \"([^\"]*)\" on (\\d+) instance in zone \"([^\"]*)\"$") InstanceFailureStepDefinitions terminateProcessInAvailabilityZone(String processName, int numHosts, String zoneId); void spikeCPUGivenInstance(int cores, String instanceID, String instanceIP); @When("^CPU spike for (\\d+) cores on instance with id \"([^\"]*)\" and ip \"([^\"]*)\"$") InstanceFailureStepDefinitions spikeCPUGivenInstanceCucumber(int cores, String instanceID, String instanceIP); @When("^CPU spike on (\\d+) instances for (\\d+) cores$") InstanceFailureStepDefinitions spikeCPUOnHealthyInstances(int numHosts, int cores); @When("^terminate all instances$") InstanceFailureStepDefinitions terminateAllInstances(); void terminateGivenInstance(String instanceID, String instanceIP); @When("^terminate instance with id \"([^\"]*)\" and ip \"([^\"]*)\"$") InstanceFailureStepDefinitions terminateGivenInstanceCucumber(String instanceID, String instanceIP); @When("^terminate (\\d+) instance$") InstanceFailureStepDefinitions terminateInstanceOnNumInstances(int numInstances); @When("^terminate (\\d+) instance with tags \"([^\"]*)\"$") InstanceFailureStepDefinitions terminateInstanceOnNumInstancesWithTags(int numInstances, String compulsoryTagsString); @When("^stop (\\d+) instance$") InstanceFailureStepDefinitions stopInstanceOnNumInstances(int numInstances ); @Then("^start (\\d+) instance$") InstanceFailureStepDefinitions startInstanceOnNumInstances(int numInstances ); void diskFullGivenInstance(String volumeType, int size, String instanceID, String instanceIP); @When("^\"([^\"]*)\" disk full with (\\d+) GB on instance with id \"([^\"]*)\" and ip \"([^\"]*)\"$") InstanceFailureStepDefinitions diskFullGivenInstanceCucumber(String volumeType, int size, String instanceID, String instanceIP); @When("^\"([^\"]*)\" disk full with (\\d+) GB on (\\d+) instance$") InstanceFailureStepDefinitions diskFullOnInstance(String volumeType, int size, int instanceCount); @When("^block domain \"([^\"]*)\" on (\\d+) instances$") InstanceFailureStepDefinitions blockDomain(String domainName, int numInstances); void blockPortGivenInstance(int portNum, String instanceID, String instanceIP); @When("^block port (\\d+) on instance with id \"([^\"]*)\" and ip \"([^\"]*)\"$") InstanceFailureStepDefinitions blockPortGivenInstanceCucumber(int portNum, String instanceID, String instanceIP); @When("^block port (\\d+) on (\\d+) instances$") InstanceFailureStepDefinitions blockPort(int portNum, int numInstances); @When("^block DynamoDB on (\\d+) instances$") InstanceFailureStepDefinitions blockDynamoDb(int numInstances); @When("^block S3 on (\\d+) instances$") InstanceFailureStepDefinitions blockS3(int numInstances); @When("^stop (service|process) \"([^\"]*)\" on (\\d+) instance$") InstanceFailureStepDefinitions stopProcessOnHealthyInstances(String serviceOrProcessType, String processName, int numHosts); @When("^start (service|process) \"([^\"]*)\" on (\\d+) instance$") InstanceFailureStepDefinitions startProcessOnHealthyInstances(String serviceOrProcessType, String processName, int numHosts); void injectNetworkLatencyGivenInstance(int lowerBound, int upperBound, String instanceID, String instanceIP); @When("^inject network latency (\\d+) ms to (\\d+) ms on instance with id \"([^\"]*)\" and ip \"([^\"]*)\"$") InstanceFailureStepDefinitions injectNetworkLatencyGivenInstanceCucumber(int lowerBound, int upperBound, String instanceID, String instanceIP); @When("^inject network latency (\\d+) ms to (\\d+) ms on (\\d+) instances$") InstanceFailureStepDefinitions injectNetworkLatency(int lowerBound, int upperBound, int numInstances); @When("^inject domain network latency \"([^\"]*)\" for (\\d+) ms to (\\d+) ms on (\\d+) instances$") InstanceFailureStepDefinitions injectNetworkLatency(String domainName, int lowerBound, int upperBound, int numInstances); List<EC2InstanceTO> findInstancesByName(String name); List<EC2InstanceTO> findAllInstancesByTag(String tagString); EC2InstanceTO getInstanceFromID(String id);  }
@Test public void testGivenEC2WithTag() throws Exception { PowerMockito.when(ec2Raider.getInstancesByName("test")).thenReturn(createInstances()); instanceFailureStepDefinitions.givenEC2InstanceName("test"); Assert.assertEquals(executionStateCache.getEc2Tag(), "test"); Assert.assertTrue(executionStateCache.getInstances().size()>0); }