Skip to content

Commit

Permalink
Revert "Refactored QueueApi and pushed name param up to MarconiApi."
Browse files Browse the repository at this point in the history
This reverts commit dc452f7.
Turns out you can't implement list messages with this refactoring.
  • Loading branch information
Everett Toews committed Nov 19, 2013
1 parent dc452f7 commit c0d9b1c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,10 @@ 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
@Path("/queues/{name}")
QueueApi getQueueApiForZoneAndQueue(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("name") String name);
QueueApi getQueueApiForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);

/**
* Provides access to Message features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,43 @@
@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();
boolean create(@PathParam("name") String name);

/**
* 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();
boolean delete(@PathParam("name") String name);

/**
* 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();
boolean exists(@PathParam("name") String name);

// TODO stream method!

Expand All @@ -80,34 +94,43 @@ 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("/metadata")
@Path("queues/{name}/metadata")
@Produces(MediaType.APPLICATION_JSON)
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
boolean setMetadata(@BinderParam(BindToJsonPayload.class) Map<String, String> metadata);
boolean setMetadata(@PathParam("name") String name,
@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("/metadata")
@Path("queues/{name}/metadata")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
Map<String, String> getMetadata();
Map<String, String> getMetadata(@PathParam("name") String name);


/**
* 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("/stats")
@Path("queues/{name}/stats")
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseQueueStats.class)
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
QueueStats getStats();
QueueStats getStats(@PathParam("name") String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public class MessageApiLiveTest extends BaseMarconiApiLiveTest {

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

assertTrue(success);
}
Expand Down Expand Up @@ -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.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
boolean success = queueApi.delete();
QueueApi queueApi = api.getQueueApiForZone(zoneId);
boolean success = queueApi.delete("jclouds-test");

assertTrue(success);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class QueueApiLiveTest extends BaseMarconiApiLiveTest {

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

assertTrue(success);
}
Expand All @@ -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.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
boolean success = queueApi.exists();
QueueApi queueApi = api.getQueueApiForZone(zoneId);
boolean success = queueApi.exists("jclouds-test");

assertTrue(success);
}
Expand All @@ -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.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
QueueApi queueApi = api.getQueueApiForZone(zoneId);
Map<String, String> metadata = ImmutableMap.of("key1", "value1");
boolean success = queueApi.setMetadata(metadata);
boolean success = queueApi.setMetadata("jclouds-test", metadata);

assertTrue(success);
}
Expand All @@ -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.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
Map<String, String> metadata = queueApi.getMetadata();
QueueApi queueApi = api.getQueueApiForZone(zoneId);
Map<String, String> metadata = queueApi.getMetadata("jclouds-test");

assertEquals(metadata.get("key1"), "value1");
}
Expand All @@ -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.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
QueueStats stats = queueApi.getStats();
QueueApi queueApi = api.getQueueApiForZone(zoneId);
QueueStats stats = queueApi.getStats("jclouds-test");

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

messageApi.create(clientId, message);

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

assertEquals(stats.getMessagesStats().getClaimed(), 0);
assertEquals(stats.getMessagesStats().getFree(), 1);
Expand All @@ -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.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
boolean success = queueApi.delete();
QueueApi queueApi = api.getQueueApiForZone(zoneId);
boolean success = queueApi.delete("jclouds-test");

assertTrue(success);
}
Expand All @@ -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.getQueueApiForZoneAndQueue(zoneId, "jclouds-test");
boolean success = queueApi.exists();
QueueApi queueApi = api.getQueueApiForZone(zoneId);
boolean success = queueApi.exists("jclouds-test");

assertFalse(success);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void createQueue() throws Exception {

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

assertTrue(success);

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

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

assertTrue(success);

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

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

assertTrue(success);

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

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

assertFalse(success);

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

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

assertTrue(success);

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

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

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

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

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

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

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

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

0 comments on commit c0d9b1c

Please sign in to comment.