mirror of https://github.com/apache/jclouds.git
worked around guice issue where auth failures were retried
This commit is contained in:
parent
ca5312d849
commit
8940e1cc03
|
@ -87,6 +87,7 @@ import com.google.inject.Provides;
|
|||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
public class EC2RestClientModule extends AbstractModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("RUNNING")
|
||||
|
@ -146,11 +147,25 @@ public class EC2RestClientModule extends AbstractModule {
|
|||
return region;
|
||||
}
|
||||
|
||||
private RuntimeException regionException = null;
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@EC2
|
||||
Map<String, URI> provideRegions(AvailabilityZoneAndRegionClient client) {
|
||||
return client.describeRegions();
|
||||
// http://code.google.com/p/google-guice/issues/detail?id=483
|
||||
// guice doesn't remember when singleton providers throw exceptions.
|
||||
// in this case, if describeRegions fails, it is called again for
|
||||
// each provider method that depends on it. To short-circuit this,
|
||||
// we remember the last exception trusting that guice is single-threaded
|
||||
if (regionException != null)
|
||||
throw regionException;
|
||||
try {
|
||||
return client.describeRegions();
|
||||
} catch (RuntimeException e) {
|
||||
this.regionException = e;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -60,6 +60,5 @@ public interface AvailabilityZoneAndRegionClient {
|
|||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeRegions.html"
|
||||
* />
|
||||
*/
|
||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||
Map<String, URI> describeRegions(DescribeRegionsOptions... options);
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
return new JschSshClientModule();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(enabled = true, dependsOnMethods = "testCorrectAuthException")
|
||||
public void testExtendedOptionsAndLogin() throws Exception {
|
||||
SecurityGroupClient securityGroupClient = EC2Client.class.cast(
|
||||
context.getProviderSpecificContext().getApi()).getSecurityGroupServices();
|
||||
|
@ -128,7 +128,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(enabled = true, dependsOnMethods = "testCorrectAuthException")
|
||||
public void testExtendedOptionsNoKeyPair() throws Exception {
|
||||
SecurityGroupClient securityGroupClient = EC2Client.class.cast(
|
||||
context.getProviderSpecificContext().getApi()).getSecurityGroupServices();
|
||||
|
@ -179,7 +179,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(enabled = true, dependsOnMethods = "testCorrectAuthException")
|
||||
public void testLoadBalanceNodesMatching() throws Exception {
|
||||
|
||||
ElasticLoadBalancerClient elbClient = EC2Client.class.cast(
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.aws.handlers;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
|
||||
import org.jclouds.aws.util.AWSUtils;
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code AWSClientErrorRetryHandler}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "s3.AWSClientErrorRetryHandlerTest")
|
||||
public class AWSClientErrorRetryHandlerTest {
|
||||
@Test
|
||||
public void test401DoesNotRetry() {
|
||||
|
||||
AWSUtils utils = createMock(AWSUtils.class);
|
||||
HttpCommand command = createMock(HttpCommand.class);
|
||||
HttpResponse response = createMock(HttpResponse.class);
|
||||
|
||||
expect(command.getFailureCount()).andReturn(0);
|
||||
expect(response.getStatusCode()).andReturn(401).atLeastOnce();
|
||||
|
||||
replay(utils);
|
||||
replay(command);
|
||||
replay(response);
|
||||
|
||||
AWSClientErrorRetryHandler retry = new AWSClientErrorRetryHandler(utils);
|
||||
|
||||
assert !retry.shouldRetryRequest(command, response);
|
||||
|
||||
verify(utils);
|
||||
verify(command);
|
||||
verify(response);
|
||||
|
||||
}
|
||||
}
|
|
@ -146,9 +146,11 @@ public abstract class BaseComputeServiceLiveTest {
|
|||
|
||||
abstract protected Module getSshModule();
|
||||
|
||||
// wait up to 5 seconds for an auth exception
|
||||
@Test(enabled = true, expectedExceptions = AuthorizationException.class)
|
||||
public void testCorrectAuthException() throws Exception {
|
||||
new ComputeServiceContextFactory().createContext(service, "MOMMA", "MIA").close();
|
||||
new ComputeServiceContextFactory().createContext(service, "MOMMA", "MIA",
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule())).close();
|
||||
}
|
||||
|
||||
@Test(enabled = true, dependsOnMethods = "testCorrectAuthException")
|
||||
|
@ -163,7 +165,8 @@ public abstract class BaseComputeServiceLiveTest {
|
|||
@Test(enabled = true, dependsOnMethods = "testImagesCache")
|
||||
public void testTemplateMatch() throws Exception {
|
||||
template = buildTemplate(client.templateBuilder());
|
||||
Template toMatch = client.templateBuilder().imageId(template.getImage().getProviderId()).build();
|
||||
Template toMatch = client.templateBuilder().imageId(template.getImage().getProviderId())
|
||||
.build();
|
||||
assertEquals(toMatch, template);
|
||||
}
|
||||
|
||||
|
@ -223,7 +226,7 @@ public abstract class BaseComputeServiceLiveTest {
|
|||
assertEquals(node.getImage(), template.getImage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(enabled = true, dependsOnMethods = "testCorrectAuthException")
|
||||
public void testScriptExecutionAfterBootWithBasicTemplate() throws Exception {
|
||||
String tag = this.tag + "run";
|
||||
TemplateOptions options = client.templateOptions().blockOnPort(22, 120);
|
||||
|
|
Loading…
Reference in New Issue