Skip to content
Permalink
Browse files
Refactored QueueApi and pushed name param up to MarconiApi.
  • Loading branch information
Everett Toews committed Nov 19, 2013
1 parent 318da80 commit dc452f77605459921c2bc8a08c3d675a4d9d4bd4
Showing 5 changed files with 50 additions and 70 deletions.
@@ -47,10 +47,13 @@ public interface MarconiApi extends Closeable {
* Provides access to Queue features.
*
* @param zone The zone where this queue will live.
* @param name Name of the queue. The name must not exceed 64 bytes in length, and it is limited to US-ASCII
* letters, digits, underscores, and hyphens.
*/
@Delegate
QueueApi getQueueApiForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
@Path("/queues/{name}")
QueueApi getQueueApiForZoneAndQueue(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("name") String name);

/**
* Provides access to Message features.
@@ -46,43 +46,29 @@
@SkipEncoding({'/', '='})
@RequestFilters(AuthenticateRequest.class)
public interface QueueApi {
// TODO: Move name parameter into MarconiApi.getQueueApiForZone(String name, String zone)

/**
* Create a queue.
*
* @param name Name of the queue. The name must not exceed 64 bytes in length, and it is limited to US-ASCII
* letters, digits, underscores, and hyphens.
*/
@Named("queue:create")
@PUT
@Path("queues/{name}")
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
boolean create(@PathParam("name") String name);
boolean create();

/**
* Delete a queue.
*
* @param name Name of the queue. The name must not exceed 64 bytes in length, and it is limited to US-ASCII
* letters, digits, underscores, and hyphens.
*/
@Named("queue:delete")
@DELETE
@Path("queues/{name}")
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
boolean delete(@PathParam("name") String name);
boolean delete();

/**
* Check for a queue's existence.
*
* @param name Name of the queue. The name must not exceed 64 bytes in length, and it is limited to US-ASCII
* letters, digits, underscores, and hyphens.
*/
@Named("queue:get")
@GET
@Path("queues/{name}")
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
boolean exists(@PathParam("name") String name);
boolean exists();

// TODO stream method!

@@ -94,43 +80,34 @@ public interface QueueApi {
* This operation replaces any existing metadata document in its entirety. Ensure that you do not accidentally
* overwrite existing metadata that you want to retain.
*
* @param name Name of the queue. The name must not exceed 64 bytes in length, and it is limited to US-ASCII
* letters, digits, underscores, and hyphens.
* @param metadata Metadata in key/value pairs.
*/
@Named("queue:setMetadata")
@PUT
@Path("queues/{name}/metadata")
@Path("/metadata")
@Produces(MediaType.APPLICATION_JSON)
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
boolean setMetadata(@PathParam("name") String name,
@BinderParam(BindToJsonPayload.class) Map<String, String> metadata);
boolean setMetadata(@BinderParam(BindToJsonPayload.class) Map<String, String> metadata);

/**
* Gets metadata for the specified queue.
*
* @param name Name of the queue. The name must not exceed 64 bytes in length, and it is limited to US-ASCII
* letters, digits, underscores, and hyphens.
*/
@Named("queue:getMetadata")
@GET
@Path("queues/{name}/metadata")
@Path("/metadata")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
Map<String, String> getMetadata(@PathParam("name") String name);
Map<String, String> getMetadata();


/**
* Gets stats for the specified queue.
*
* @param name Name of the queue. The name must not exceed 64 bytes in length, and it is limited to US-ASCII
* letters, digits, underscores, and hyphens.
*/
@Named("queue:getStats")
@GET
@Path("queues/{name}/stats")
@Path("/stats")
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseQueueStats.class)
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
QueueStats getStats(@PathParam("name") String name);
QueueStats getStats();
}
@@ -38,8 +38,8 @@ public class MessageApiLiveTest extends BaseMarconiApiLiveTest {

public void createQueues() throws Exception {
for (String zoneId : api.getConfiguredZones()) {
QueueApi queueApi = api.getQueueApiForZone(zoneId);
boolean success = queueApi.create("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
boolean success = queueApi.create();

assertTrue(success);
}
@@ -138,8 +138,8 @@ public void streamManyPagesOfMessages() throws Exception {
@Test(dependsOnMethods = { "streamManyPagesOfMessages" })
public void delete() throws Exception {
for (String zoneId : api.getConfiguredZones()) {
QueueApi queueApi = api.getQueueApiForZone(zoneId);
boolean success = queueApi.delete("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
boolean success = queueApi.delete();

assertTrue(success);
}
@@ -37,8 +37,8 @@ public class QueueApiLiveTest extends BaseMarconiApiLiveTest {

public void create() throws Exception {
for (String zoneId : api.getConfiguredZones()) {
QueueApi queueApi = api.getQueueApiForZone(zoneId);
boolean success = queueApi.create("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
boolean success = queueApi.create();

assertTrue(success);
}
@@ -47,8 +47,8 @@ public void create() throws Exception {
@Test(dependsOnMethods = { "create" })
public void exists() throws Exception {
for (String zoneId : api.getConfiguredZones()) {
QueueApi queueApi = api.getQueueApiForZone(zoneId);
boolean success = queueApi.exists("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
boolean success = queueApi.exists();

assertTrue(success);
}
@@ -57,9 +57,9 @@ public void exists() throws Exception {
@Test(dependsOnMethods = { "exists" })
public void setMetadata() throws Exception {
for (String zoneId : api.getConfiguredZones()) {
QueueApi queueApi = api.getQueueApiForZone(zoneId);
QueueApi queueApi = api.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
Map<String, String> metadata = ImmutableMap.of("key1", "value1");
boolean success = queueApi.setMetadata("jclouds-test", metadata);
boolean success = queueApi.setMetadata(metadata);

assertTrue(success);
}
@@ -68,8 +68,8 @@ public void setMetadata() throws Exception {
@Test(dependsOnMethods = { "setMetadata" })
public void getMetadata() throws Exception {
for (String zoneId : api.getConfiguredZones()) {
QueueApi queueApi = api.getQueueApiForZone(zoneId);
Map<String, String> metadata = queueApi.getMetadata("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
Map<String, String> metadata = queueApi.getMetadata();

assertEquals(metadata.get("key1"), "value1");
}
@@ -78,8 +78,8 @@ public void getMetadata() throws Exception {
@Test(dependsOnMethods = { "getMetadata" })
public void getStatsWithoutTotal() throws Exception {
for (String zoneId : api.getConfiguredZones()) {
QueueApi queueApi = api.getQueueApiForZone(zoneId);
QueueStats stats = queueApi.getStats("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
QueueStats stats = queueApi.getStats();

assertEquals(stats.getMessagesStats().getClaimed(), 0);
assertEquals(stats.getMessagesStats().getFree(), 0);
@@ -101,8 +101,8 @@ public void getStatsWithTotal() throws Exception {

messageApi.create(clientId, message);

QueueApi queueApi = api.getQueueApiForZone(zoneId);
QueueStats stats = queueApi.getStats("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
QueueStats stats = queueApi.getStats();

assertEquals(stats.getMessagesStats().getClaimed(), 0);
assertEquals(stats.getMessagesStats().getFree(), 1);
@@ -117,8 +117,8 @@ public void getStatsWithTotal() throws Exception {
@Test(dependsOnMethods = { "getStatsWithTotal" })
public void delete() throws Exception {
for (String zoneId : api.getConfiguredZones()) {
QueueApi queueApi = api.getQueueApiForZone(zoneId);
boolean success = queueApi.delete("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
boolean success = queueApi.delete();

assertTrue(success);
}
@@ -127,8 +127,8 @@ public void delete() throws Exception {
@Test(dependsOnMethods = { "delete" })
public void doesNotExist() throws Exception {
for (String zoneId : api.getConfiguredZones()) {
QueueApi queueApi = api.getQueueApiForZone(zoneId);
boolean success = queueApi.exists("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
boolean success = queueApi.exists();

assertFalse(success);
}
@@ -45,8 +45,8 @@ public void createQueue() throws Exception {

try {
MarconiApi api = api(server.getUrl("/").toString(), "openstack-marconi");
QueueApi queueApi = api.getQueueApiForZone("DFW");
boolean success = queueApi.create("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue("DFW", "jclouds-test");
boolean success = queueApi.create();

assertTrue(success);

@@ -66,8 +66,8 @@ public void deleteQueue() throws Exception {

try {
MarconiApi api = api(server.getUrl("/").toString(), "openstack-marconi");
QueueApi queueApi = api.getQueueApiForZone("DFW");
boolean success = queueApi.delete("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue("DFW", "jclouds-test");
boolean success = queueApi.delete();

assertTrue(success);

@@ -87,8 +87,8 @@ public void existsQueue() throws Exception {

try {
MarconiApi api = api(server.getUrl("/").toString(), "openstack-marconi");
QueueApi queueApi = api.getQueueApiForZone("DFW");
boolean success = queueApi.exists("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue("DFW", "jclouds-test");
boolean success = queueApi.exists();

assertTrue(success);

@@ -108,8 +108,8 @@ public void doesNotExistQueue() throws Exception {

try {
MarconiApi api = api(server.getUrl("/").toString(), "openstack-marconi");
QueueApi queueApi = api.getQueueApiForZone("DFW");
boolean success = queueApi.exists("jclouds-blerg");
QueueApi queueApi = api.getQueueApiForZoneAndQueue("DFW", "jclouds-blerg");
boolean success = queueApi.exists();

assertFalse(success);

@@ -129,9 +129,9 @@ public void setMetadata() throws Exception {

try {
MarconiApi api = api(server.getUrl("/").toString(), "openstack-marconi");
QueueApi queueApi = api.getQueueApiForZone("DFW");
QueueApi queueApi = api.getQueueApiForZoneAndQueue("DFW", "jclouds-test");
Map<String, String> metadata = ImmutableMap.of("key1", "value1");
boolean success = queueApi.setMetadata("jclouds-test", metadata);
boolean success = queueApi.setMetadata(metadata);

assertTrue(success);

@@ -153,8 +153,8 @@ public void getMetadata() throws Exception {

try {
MarconiApi api = api(server.getUrl("/").toString(), "openstack-marconi");
QueueApi queueApi = api.getQueueApiForZone("DFW");
Map<String, String> metadata = queueApi.getMetadata("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue("DFW", "jclouds-test");
Map<String, String> metadata = queueApi.getMetadata();

assertEquals(metadata.get("key1"), "value1");

@@ -175,8 +175,8 @@ public void getQueueStatsWithoutTotal() throws Exception {

try {
MarconiApi api = api(server.getUrl("/").toString(), "openstack-marconi");
QueueApi queueApi = api.getQueueApiForZone("DFW");
QueueStats stats = queueApi.getStats("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue("DFW", "jclouds-test");
QueueStats stats = queueApi.getStats();

assertEquals(stats.getMessagesStats().getClaimed(), 0);
assertEquals(stats.getMessagesStats().getFree(), 0);
@@ -201,8 +201,8 @@ public void getQueueStatsWithTotal() throws Exception {

try {
MarconiApi api = api(server.getUrl("/").toString(), "openstack-marconi");
QueueApi queueApi = api.getQueueApiForZone("DFW");
QueueStats stats = queueApi.getStats("jclouds-test");
QueueApi queueApi = api.getQueueApiForZoneAndQueue("DFW", "jclouds-test");
QueueStats stats = queueApi.getStats();

assertEquals(stats.getMessagesStats().getClaimed(), 0);
assertEquals(stats.getMessagesStats().getFree(), 4);

0 comments on commit dc452f7

Please sign in to comment.