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.concurrent.Callable;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -83,12 +84,14 @@ import org.jclouds.domain.Credentials;
|
|||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.io.CopyInputStreamInputSupplierMap;
|
||||
import org.jclouds.logging.LoggingModules;
|
||||
import org.jclouds.logging.config.LoggingModule;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.config.CredentialStoreModule;
|
||||
import org.jclouds.scriptbuilder.domain.SaveHttpResponseTo;
|
||||
import org.jclouds.scriptbuilder.domain.Statements;
|
||||
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.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.InputSupplier;
|
||||
import com.google.common.net.InetAddresses;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
@ -130,6 +134,9 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv
|
|||
|
||||
protected Template template;
|
||||
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" })
|
||||
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||
|
@ -189,7 +196,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv
|
|||
overrides.setProperty(provider + ".identity", "MOMMA");
|
||||
overrides.setProperty(provider + ".credential", "MIA");
|
||||
context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
|
||||
ImmutableSet.<Module> of(getLoggingModule()), overrides);
|
||||
ImmutableSet.<Module> of(getLoggingModule(), credentialStoreModule), overrides);
|
||||
context.getComputeService().listNodes();
|
||||
} catch (AuthorizationException e) {
|
||||
throw e;
|
||||
|
|
|
@ -22,11 +22,13 @@ import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
|
@ -40,10 +42,12 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
|
|||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.io.CopyInputStreamInputSupplierMap;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.logging.LoggingModules;
|
||||
import org.jclouds.logging.config.LoggingModule;
|
||||
import org.jclouds.rest.config.CredentialStoreModule;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
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.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.io.InputSupplier;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Module;
|
||||
|
||||
|
@ -269,6 +274,10 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi
|
|||
}
|
||||
|
||||
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;
|
||||
try {
|
||||
Properties overrides = setupProperties();
|
||||
|
@ -278,7 +287,7 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi
|
|||
overrides.setProperty(propertyKey + ".image.authenticate-sudo", auth + "");
|
||||
|
||||
context = new ComputeServiceContextFactory().createContext(provider,
|
||||
ImmutableSet.<Module> of(getLoggingModule()), overrides);
|
||||
ImmutableSet.<Module> of(getLoggingModule(), credentialStoreModule), overrides);
|
||||
|
||||
Iterable<String> userPass = Splitter.on(':').split(login);
|
||||
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());
|
||||
} finally {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue