You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ev...@apache.org on 2013/07/19 23:00:23 UTC

git commit: Move TroveUtils out of tests and into the utils package Removes the requirement to use a test maven dependency for TroveUtils

Updated Branches:
  refs/heads/master 40a05b9e5 -> de633a65d


Move TroveUtils out of tests and into the utils package
Removes the requirement to use a test maven dependency for TroveUtils


Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/commit/de633a65
Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/tree/de633a65
Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/diff/de633a65

Branch: refs/heads/master
Commit: de633a65d0772e09477a1f01407270fc60b63a3c
Parents: 40a05b9
Author: zack-shoylev <za...@rackspace.com>
Authored: Fri Jul 19 11:53:40 2013 -0500
Committer: Everett Toews <ev...@rackspace.com>
Committed: Fri Jul 19 15:57:55 2013 -0500

----------------------------------------------------------------------
 .../openstack/trove/v1/utils/TroveUtils.java    | 102 +++++++++++++++++++
 .../trove/v1/features/DatabaseApiLiveTest.java  |   2 +-
 .../trove/v1/features/InstanceApiLiveTest.java  |   2 +-
 .../trove/v1/features/UserApiLiveTest.java      |   2 +-
 .../openstack/trove/v1/internal/TroveUtils.java | 102 -------------------
 .../trove/v1/internal/TroveUtilsExpectTest.java |  66 ------------
 .../trove/v1/utils/TroveUtilsExpectTest.java    |  67 ++++++++++++
 7 files changed, 172 insertions(+), 171 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/de633a65/openstack-trove/src/main/java/org/jclouds/openstack/trove/v1/utils/TroveUtils.java
----------------------------------------------------------------------
diff --git a/openstack-trove/src/main/java/org/jclouds/openstack/trove/v1/utils/TroveUtils.java b/openstack-trove/src/main/java/org/jclouds/openstack/trove/v1/utils/TroveUtils.java
new file mode 100644
index 0000000..df674d8
--- /dev/null
+++ b/openstack-trove/src/main/java/org/jclouds/openstack/trove/v1/utils/TroveUtils.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openstack.trove.v1.utils;
+
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+
+import javax.annotation.Resource;
+
+import org.jclouds.openstack.trove.v1.TroveApi;
+import org.jclouds.openstack.trove.v1.domain.Instance;
+import org.jclouds.openstack.trove.v1.features.InstanceApi;
+import org.jclouds.openstack.trove.v1.predicates.InstancePredicates;
+import org.jclouds.logging.Logger;
+
+import com.google.common.util.concurrent.Uninterruptibles;
+
+/**
+ * @author Zack Shoylev
+ * 
+ *         Helper methods for dealing with instances that get created with
+ *         errors
+ */
+public class TroveUtils {
+   private final TroveApi api;
+   @Resource
+   protected Logger logger = Logger.NULL;
+
+   public TroveUtils(TroveApi api) {
+      this.api = api;
+   }
+
+   /**
+    * Create an ACTIVE operational instance
+    * 
+    * @see InstanceApi#create(String, int, String)
+    * 
+    * @param zone
+    *           The instance zone or region
+    * @param name
+    *           Instance name
+    * @param flavorId
+    *           Id of the flavor to be used when creating the instance
+    * @param size
+    *           Size of the instance
+    * @return Instance object in active state or NULL
+    */
+   public Instance getWorkingInstance(String zone, String name, String flavorId, int size) {
+      InstanceApi instanceApi = api.getInstanceApiForZone(zone);
+      for (int retries = 0; retries < 10; retries++) {
+         Instance instance = null;
+         try {
+            instance = instanceApi.create(flavorId, size, name);
+         } catch (Exception e) {
+
+            Uninterruptibles.sleepUninterruptibly(15, TimeUnit.SECONDS);
+
+            logger.error(e.getStackTrace().toString());
+            continue;
+         }
+
+         Instance updatedInstance = awaitAvailable(instance, instanceApi);
+         if (updatedInstance != null) {
+            return updatedInstance;
+         }
+         instanceApi.delete(instance.getId());
+         InstancePredicates.awaitDeleted(instanceApi).apply(instance);
+         
+      }
+      return null;
+   }
+
+   public Instance getWorkingInstance(String zone) {
+      return getWorkingInstance(zone, UUID.randomUUID().toString(), "1", 1);
+   }
+
+   private Instance awaitAvailable(Instance instance, InstanceApi iapi) {
+      for (int n = 0; n < 100; n = n + 1) {
+         Instance updatedInstance = iapi.get(instance.getId());
+         if (updatedInstance.getStatus() == Instance.Status.ACTIVE)
+            return updatedInstance;
+         if (updatedInstance.getStatus() == Instance.Status.UNRECOGNIZED)
+            return null; // fast fail
+         Uninterruptibles.sleepUninterruptibly(15, TimeUnit.SECONDS);
+      }
+      return null;
+   }
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/de633a65/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/DatabaseApiLiveTest.java
----------------------------------------------------------------------
diff --git a/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/DatabaseApiLiveTest.java b/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/DatabaseApiLiveTest.java
index 0bcd6a4..09d7829 100644
--- a/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/DatabaseApiLiveTest.java
+++ b/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/DatabaseApiLiveTest.java
@@ -24,7 +24,7 @@ import java.util.Map;
 
 import org.jclouds.openstack.trove.v1.domain.Instance;
 import org.jclouds.openstack.trove.v1.internal.BaseTroveApiLiveTest;
-import org.jclouds.openstack.trove.v1.internal.TroveUtils;
+import org.jclouds.openstack.trove.v1.utils.TroveUtils;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/de633a65/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/InstanceApiLiveTest.java
----------------------------------------------------------------------
diff --git a/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/InstanceApiLiveTest.java b/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/InstanceApiLiveTest.java
index d092dd7..7f671e3 100644
--- a/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/InstanceApiLiveTest.java
+++ b/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/InstanceApiLiveTest.java
@@ -29,7 +29,7 @@ import java.util.Map;
 
 import org.jclouds.openstack.trove.v1.domain.Instance;
 import org.jclouds.openstack.trove.v1.internal.BaseTroveApiLiveTest;
-import org.jclouds.openstack.trove.v1.internal.TroveUtils;
+import org.jclouds.openstack.trove.v1.utils.TroveUtils;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/de633a65/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/UserApiLiveTest.java
----------------------------------------------------------------------
diff --git a/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/UserApiLiveTest.java b/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/UserApiLiveTest.java
index ae92f55..0ad444b 100644
--- a/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/UserApiLiveTest.java
+++ b/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/features/UserApiLiveTest.java
@@ -31,7 +31,7 @@ import java.util.UUID;
 import org.jclouds.openstack.trove.v1.domain.Instance;
 import org.jclouds.openstack.trove.v1.domain.User;
 import org.jclouds.openstack.trove.v1.internal.BaseTroveApiLiveTest;
-import org.jclouds.openstack.trove.v1.internal.TroveUtils;
+import org.jclouds.openstack.trove.v1.utils.TroveUtils;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/de633a65/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/internal/TroveUtils.java
----------------------------------------------------------------------
diff --git a/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/internal/TroveUtils.java b/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/internal/TroveUtils.java
deleted file mode 100644
index 0a77c72..0000000
--- a/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/internal/TroveUtils.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.openstack.trove.v1.internal;
-
-import java.util.UUID;
-import java.util.concurrent.TimeUnit;
-
-import javax.annotation.Resource;
-
-import org.jclouds.openstack.trove.v1.TroveApi;
-import org.jclouds.openstack.trove.v1.domain.Instance;
-import org.jclouds.openstack.trove.v1.features.InstanceApi;
-import org.jclouds.openstack.trove.v1.predicates.InstancePredicates;
-import org.jclouds.logging.Logger;
-
-import com.google.common.util.concurrent.Uninterruptibles;
-
-/**
- * @author Zack Shoylev
- * 
- *         Helper methods for dealing with instances that get created with
- *         errors
- */
-public class TroveUtils {
-   private final TroveApi api;
-   @Resource
-   protected Logger logger = Logger.NULL;
-
-   public TroveUtils(TroveApi api) {
-      this.api = api;
-   }
-
-   /**
-    * Create an ACTIVE operational instance
-    * 
-    * @see InstanceApi#create(String, int, String)
-    * 
-    * @param zone
-    *           The instance zone or region
-    * @param name
-    *           Instance name
-    * @param flavorId
-    *           Id of the flavor to be used when creating the instance
-    * @param size
-    *           Size of the instance
-    * @return Instance object in active state or NULL
-    */
-   public Instance getWorkingInstance(String zone, String name, String flavorId, int size) {
-      InstanceApi instanceApi = api.getInstanceApiForZone(zone);
-      for (int retries = 0; retries < 10; retries++) {
-         Instance instance = null;
-         try {
-            instance = instanceApi.create(flavorId, size, name);
-         } catch (Exception e) {
-
-            Uninterruptibles.sleepUninterruptibly(15, TimeUnit.SECONDS);
-
-            logger.error(e.getStackTrace().toString());
-            continue;
-         }
-
-         Instance updatedInstance = awaitAvailable(instance, instanceApi);
-         if (updatedInstance != null) {
-            return updatedInstance;
-         }
-         instanceApi.delete(instance.getId());
-         InstancePredicates.awaitDeleted(instanceApi).apply(instance);
-         
-      }
-      return null;
-   }
-
-   public Instance getWorkingInstance(String zone) {
-      return getWorkingInstance(zone, UUID.randomUUID().toString(), "1", 1);
-   }
-
-   private Instance awaitAvailable(Instance instance, InstanceApi iapi) {
-      for (int n = 0; n < 100; n = n + 1) {
-         Instance updatedInstance = iapi.get(instance.getId());
-         if (updatedInstance.getStatus() == Instance.Status.ACTIVE)
-            return updatedInstance;
-         if (updatedInstance.getStatus() == Instance.Status.UNRECOGNIZED)
-            return null; // fast fail
-         Uninterruptibles.sleepUninterruptibly(15, TimeUnit.SECONDS);
-      }
-      return null;
-   }
-}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/de633a65/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/internal/TroveUtilsExpectTest.java
----------------------------------------------------------------------
diff --git a/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/internal/TroveUtilsExpectTest.java b/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/internal/TroveUtilsExpectTest.java
deleted file mode 100644
index 9ebda6f..0000000
--- a/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/internal/TroveUtilsExpectTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.openstack.trove.v1.internal;
-
-import static org.testng.Assert.assertEquals;
-
-import java.net.URI;
-import java.util.List;
-
-import javax.ws.rs.core.MediaType;
-
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.HttpResponse;
-import org.jclouds.openstack.trove.v1.TroveApi;
-import org.jclouds.openstack.trove.v1.domain.Instance;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-
-/**
- * Tests TroveUtils
- *
- * @author Zack Shoylev
- */
-@Test(groups = "unit", testName = "InstanceApiExpectTest")
-public class TroveUtilsExpectTest extends BaseTroveApiExpectTest {
-    
-    public void testHelperCreateInstance() {
-        HttpRequest createInstance = authenticatedGET().endpoint(URI.create("http://172.16.0.1:8776/v1/3456/instances"))
-                                                       .method("POST")
-                                                       .payload(payloadFromResourceWithContentType("/instance_create_request.json", MediaType.APPLICATION_JSON))
-                                                       .build();
-        HttpResponse createInstanceSuccess = HttpResponse.builder().statusCode(200).payload(payloadFromResource("/instance_create.json")).build();
-        HttpResponse createInstanceFail = HttpResponse.builder().statusCode(404).payload(payloadFromResource("/instance_create.json")).build();
-        HttpRequest getInstance = authenticatedGET().endpoint(URI.create("http://172.16.0.1:8776/v1/3456/instances/44b277eb-39be-4921-be31-3d61b43651d7")).build();
-        HttpResponse badStatus = HttpResponse.builder().statusCode(200).payload(payloadFromResource("/instance_get_bad_instance.json")).build();
-        HttpResponse goodStatus = HttpResponse.builder().statusCode(200).payload(payloadFromResource("/instance_get.json")).build();
-        HttpResponse deletedStatus = HttpResponse.builder().statusCode(404).payload(payloadFromResource("/instance_get.json")).build();
-        HttpRequest deleteInstance = authenticatedGET().endpoint(URI.create("http://172.16.0.1:8776/v1/3456/instances/44b277eb-39be-4921-be31-3d61b43651d7")).method("DELETE").build();
-        HttpResponse deleteInstanceResponse = HttpResponse.builder().statusCode(202).build();
-
-        List<HttpRequest> requests = ImmutableList.of(  keystoneAuthWithUsernameAndPasswordAndTenantName, createInstance,     createInstance,     createInstance,        getInstance, deleteInstance,         getInstance,   createInstance,     createInstance,        getInstance);
-        List<HttpResponse> responses = ImmutableList.of(responseWithKeystoneAccess,                       createInstanceFail, createInstanceFail, createInstanceSuccess, badStatus,   deleteInstanceResponse, deletedStatus, createInstanceFail, createInstanceSuccess, goodStatus); 
-
-        TroveApi api = orderedRequestsSendResponses(requests, responses);
-
-        TroveUtils utils = new TroveUtils(api);
-        Instance instance = utils.getWorkingInstance("RegionOne", "json_rack_instance", "1", 2);
-        assertEquals(instance.getSize(),2);
-        assertEquals(instance.getName(), "json_rack_instance");  
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/de633a65/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/utils/TroveUtilsExpectTest.java
----------------------------------------------------------------------
diff --git a/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/utils/TroveUtilsExpectTest.java b/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/utils/TroveUtilsExpectTest.java
new file mode 100644
index 0000000..2f41d09
--- /dev/null
+++ b/openstack-trove/src/test/java/org/jclouds/openstack/trove/v1/utils/TroveUtilsExpectTest.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openstack.trove.v1.utils;
+
+import static org.testng.Assert.assertEquals;
+
+import java.net.URI;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.trove.v1.TroveApi;
+import org.jclouds.openstack.trove.v1.domain.Instance;
+import org.jclouds.openstack.trove.v1.internal.BaseTroveApiExpectTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Tests TroveUtils
+ *
+ * @author Zack Shoylev
+ */
+@Test(groups = "unit", testName = "InstanceApiExpectTest")
+public class TroveUtilsExpectTest extends BaseTroveApiExpectTest {
+    
+    public void testHelperCreateInstance() {
+        HttpRequest createInstance = authenticatedGET().endpoint(URI.create("http://172.16.0.1:8776/v1/3456/instances"))
+                                                       .method("POST")
+                                                       .payload(payloadFromResourceWithContentType("/instance_create_request.json", MediaType.APPLICATION_JSON))
+                                                       .build();
+        HttpResponse createInstanceSuccess = HttpResponse.builder().statusCode(200).payload(payloadFromResource("/instance_create.json")).build();
+        HttpResponse createInstanceFail = HttpResponse.builder().statusCode(404).payload(payloadFromResource("/instance_create.json")).build();
+        HttpRequest getInstance = authenticatedGET().endpoint(URI.create("http://172.16.0.1:8776/v1/3456/instances/44b277eb-39be-4921-be31-3d61b43651d7")).build();
+        HttpResponse badStatus = HttpResponse.builder().statusCode(200).payload(payloadFromResource("/instance_get_bad_instance.json")).build();
+        HttpResponse goodStatus = HttpResponse.builder().statusCode(200).payload(payloadFromResource("/instance_get.json")).build();
+        HttpResponse deletedStatus = HttpResponse.builder().statusCode(404).payload(payloadFromResource("/instance_get.json")).build();
+        HttpRequest deleteInstance = authenticatedGET().endpoint(URI.create("http://172.16.0.1:8776/v1/3456/instances/44b277eb-39be-4921-be31-3d61b43651d7")).method("DELETE").build();
+        HttpResponse deleteInstanceResponse = HttpResponse.builder().statusCode(202).build();
+
+        List<HttpRequest> requests = ImmutableList.of(  keystoneAuthWithUsernameAndPasswordAndTenantName, createInstance,     createInstance,     createInstance,        getInstance, deleteInstance,         getInstance,   createInstance,     createInstance,        getInstance);
+        List<HttpResponse> responses = ImmutableList.of(responseWithKeystoneAccess,                       createInstanceFail, createInstanceFail, createInstanceSuccess, badStatus,   deleteInstanceResponse, deletedStatus, createInstanceFail, createInstanceSuccess, goodStatus); 
+
+        TroveApi api = orderedRequestsSendResponses(requests, responses);
+
+        TroveUtils utils = new TroveUtils(api);
+        Instance instance = utils.getWorkingInstance("RegionOne", "json_rack_instance", "1", 2);
+        assertEquals(instance.getSize(),2);
+        assertEquals(instance.getName(), "json_rack_instance");  
+    }
+}