mirror of https://github.com/apache/jclouds.git
JCLOUDS-1077: Fix ProjectApiLiveTest in Google Compute Engine
This commit is contained in:
parent
e65950b858
commit
cf07407c2d
|
@ -16,11 +16,15 @@
|
|||
*/
|
||||
package org.jclouds.googlecomputeengine.features;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static org.jclouds.util.Predicates2.retry;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.jclouds.googlecomputeengine.domain.Metadata;
|
||||
import org.jclouds.googlecomputeengine.domain.Operation;
|
||||
import org.jclouds.googlecomputeengine.domain.Operation.Status;
|
||||
|
@ -28,6 +32,8 @@ import org.jclouds.googlecomputeengine.domain.Project;
|
|||
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
public class ProjectApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
|
||||
|
||||
private static final String METADATA_ITEM_KEY = "projectLiveTestTestProp";
|
||||
|
@ -71,12 +77,19 @@ public class ProjectApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
|
|||
|
||||
@Test(groups = "live", dependsOnMethods = "getProject")
|
||||
public void testSetUsageExportBucket() {
|
||||
Operation o = api.project().setUsageExportBucket("test-bucket", "test-");
|
||||
AtomicReference<Operation> o = new AtomicReference<Operation>(api.project().setUsageExportBucket(
|
||||
"unexisting-bucket", "test-"));
|
||||
|
||||
while (o.status() == Status.PENDING) {
|
||||
o = api.operations().get(o.selfLink());
|
||||
}
|
||||
assertEquals(o.error().errors().get(0).code(), "PERMISSIONS_ERROR");
|
||||
assertEquals(o.error().errors().get(0).message(), "Required 'owner' permission for 'test-bucket'");
|
||||
retry(new Predicate<AtomicReference<Operation>>() {
|
||||
@Override
|
||||
public boolean apply(AtomicReference<Operation> input) {
|
||||
input.set(api.operations().get(input.get().selfLink()));
|
||||
return Status.DONE == input.get().status();
|
||||
}
|
||||
}, operationDoneTimeout, operationDoneInterval, MILLISECONDS).apply(o);
|
||||
|
||||
assertEquals(o.get().status(), Status.DONE);
|
||||
assertEquals(o.get().error().errors().get(0).code(), "PERMISSIONS_ERROR");
|
||||
assertEquals(o.get().error().errors().get(0).message(), "Required 'read' permission for 'unexisting-bucket'");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.jclouds.googlecomputeengine.internal;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.googlecomputeengine.config.GoogleComputeEngineProperties.OPERATION_COMPLETE_INTERVAL;
|
||||
import static org.jclouds.googlecomputeengine.config.GoogleComputeEngineProperties.OPERATION_COMPLETE_TIMEOUT;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
|
@ -40,6 +42,7 @@ import com.google.inject.Injector;
|
|||
import com.google.inject.Key;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.name.Names;
|
||||
|
||||
public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleComputeEngineApi> {
|
||||
|
||||
|
@ -61,6 +64,8 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
|
|||
protected static final String GOOGLE_PROJECT = "google";
|
||||
|
||||
protected Predicate<AtomicReference<Operation>> operationDone;
|
||||
protected long operationDoneInterval;
|
||||
protected long operationDoneTimeout;
|
||||
protected URI projectUrl;
|
||||
|
||||
public BaseGoogleComputeEngineApiLiveTest() {
|
||||
|
@ -78,6 +83,8 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
|
|||
}));
|
||||
projectUrl = injector.getInstance(Key.get(new TypeLiteral<Supplier<URI>>() {
|
||||
}, CurrentProject.class)).get();
|
||||
operationDoneInterval = Long.parseLong(injector.getInstance(Key.get(String.class, Names.named(OPERATION_COMPLETE_INTERVAL))));
|
||||
operationDoneTimeout = Long.parseLong(injector.getInstance(Key.get(String.class, Names.named(OPERATION_COMPLETE_TIMEOUT))));
|
||||
return injector.getInstance(GoogleComputeEngineApi.class);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue