mirror of https://github.com/apache/jclouds.git
fixed tests to not taint static credential cache
This commit is contained in:
parent
8cf71adedf
commit
8a3712fb2f
|
@ -61,6 +61,7 @@ import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.CancellationException;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -83,12 +84,14 @@ import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.LoginCredentials;
|
import org.jclouds.domain.LoginCredentials;
|
||||||
|
import org.jclouds.io.CopyInputStreamInputSupplierMap;
|
||||||
import org.jclouds.logging.LoggingModules;
|
import org.jclouds.logging.LoggingModules;
|
||||||
import org.jclouds.logging.config.LoggingModule;
|
import org.jclouds.logging.config.LoggingModule;
|
||||||
import org.jclouds.net.IPSocket;
|
import org.jclouds.net.IPSocket;
|
||||||
import org.jclouds.predicates.RetryablePredicate;
|
import org.jclouds.predicates.RetryablePredicate;
|
||||||
import org.jclouds.predicates.SocketOpen;
|
import org.jclouds.predicates.SocketOpen;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
|
import org.jclouds.rest.config.CredentialStoreModule;
|
||||||
import org.jclouds.scriptbuilder.domain.SaveHttpResponseTo;
|
import org.jclouds.scriptbuilder.domain.SaveHttpResponseTo;
|
||||||
import org.jclouds.scriptbuilder.domain.Statements;
|
import org.jclouds.scriptbuilder.domain.Statements;
|
||||||
import org.jclouds.scriptbuilder.statements.java.InstallJDK;
|
import org.jclouds.scriptbuilder.statements.java.InstallJDK;
|
||||||
|
@ -107,6 +110,7 @@ import com.google.common.base.Stopwatch;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.io.InputSupplier;
|
||||||
import com.google.common.net.InetAddresses;
|
import com.google.common.net.InetAddresses;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
@ -130,7 +134,10 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv
|
||||||
|
|
||||||
protected Template template;
|
protected Template template;
|
||||||
protected Map<String, String> keyPair;
|
protected Map<String, String> keyPair;
|
||||||
|
// isolate tests from eachother, as default credentialStore is static
|
||||||
|
protected Module credentialStoreModule = new CredentialStoreModule(
|
||||||
|
new CopyInputStreamInputSupplierMap(new ConcurrentHashMap<String, InputSupplier<InputStream>>()));
|
||||||
|
|
||||||
@BeforeGroups(groups = { "integration", "live" })
|
@BeforeGroups(groups = { "integration", "live" })
|
||||||
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||||
setServiceDefaults();
|
setServiceDefaults();
|
||||||
|
@ -189,7 +196,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv
|
||||||
overrides.setProperty(provider + ".identity", "MOMMA");
|
overrides.setProperty(provider + ".identity", "MOMMA");
|
||||||
overrides.setProperty(provider + ".credential", "MIA");
|
overrides.setProperty(provider + ".credential", "MIA");
|
||||||
context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
|
context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
|
||||||
ImmutableSet.<Module> of(getLoggingModule()), overrides);
|
ImmutableSet.<Module> of(getLoggingModule(), credentialStoreModule), overrides);
|
||||||
context.getComputeService().listNodes();
|
context.getComputeService().listNodes();
|
||||||
} catch (AuthorizationException e) {
|
} catch (AuthorizationException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -22,11 +22,13 @@ import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
@ -40,10 +42,12 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.LoginCredentials;
|
import org.jclouds.domain.LoginCredentials;
|
||||||
|
import org.jclouds.io.CopyInputStreamInputSupplierMap;
|
||||||
import org.jclouds.json.Json;
|
import org.jclouds.json.Json;
|
||||||
import org.jclouds.json.config.GsonModule;
|
import org.jclouds.json.config.GsonModule;
|
||||||
import org.jclouds.logging.LoggingModules;
|
import org.jclouds.logging.LoggingModules;
|
||||||
import org.jclouds.logging.config.LoggingModule;
|
import org.jclouds.logging.config.LoggingModule;
|
||||||
|
import org.jclouds.rest.config.CredentialStoreModule;
|
||||||
import org.testng.annotations.AfterTest;
|
import org.testng.annotations.AfterTest;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
|
@ -55,6 +59,7 @@ import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import com.google.common.io.InputSupplier;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
|
||||||
|
@ -269,6 +274,10 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void tryOverrideUsingPropertyKey(String propertyKey) {
|
protected void tryOverrideUsingPropertyKey(String propertyKey) {
|
||||||
|
// isolate tests from eachother, as default credentialStore is static
|
||||||
|
Module credentialStoreModule = new CredentialStoreModule(
|
||||||
|
new CopyInputStreamInputSupplierMap(new ConcurrentHashMap<String, InputSupplier<InputStream>>()));
|
||||||
|
|
||||||
ComputeServiceContext context = null;
|
ComputeServiceContext context = null;
|
||||||
try {
|
try {
|
||||||
Properties overrides = setupProperties();
|
Properties overrides = setupProperties();
|
||||||
|
@ -278,7 +287,7 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi
|
||||||
overrides.setProperty(propertyKey + ".image.authenticate-sudo", auth + "");
|
overrides.setProperty(propertyKey + ".image.authenticate-sudo", auth + "");
|
||||||
|
|
||||||
context = new ComputeServiceContextFactory().createContext(provider,
|
context = new ComputeServiceContextFactory().createContext(provider,
|
||||||
ImmutableSet.<Module> of(getLoggingModule()), overrides);
|
ImmutableSet.<Module> of(getLoggingModule(), credentialStoreModule), overrides);
|
||||||
|
|
||||||
Iterable<String> userPass = Splitter.on(':').split(login);
|
Iterable<String> userPass = Splitter.on(':').split(login);
|
||||||
String user = Iterables.get(userPass, 0);
|
String user = Iterables.get(userPass, 0);
|
||||||
|
@ -287,9 +296,6 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi
|
||||||
LoginCredentials.builder().user(user).password(pass).authenticateSudo(auth).build());
|
LoginCredentials.builder().user(user).password(pass).authenticateSudo(auth).build());
|
||||||
} finally {
|
} finally {
|
||||||
if (context != null){
|
if (context != null){
|
||||||
// Need to clear persisted credentials; otherwise next time a ComputeServiceContext is created
|
|
||||||
// then it will have these "foo" credentials!
|
|
||||||
context.credentialStore().clear();
|
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue