Skip to content
Permalink
Browse files
The update method in the Claim API.
  • Loading branch information
Everett Toews committed Dec 16, 2013
1 parent 01222c9 commit 8c80afa37031b95c321200c7eb1edddd785bbdc6
Showing 3 changed files with 50 additions and 10 deletions.
@@ -22,6 +22,7 @@
import org.jclouds.openstack.marconi.v1.functions.ParseClaim;
import org.jclouds.openstack.marconi.v1.functions.ParseMessagesToList;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.PATCH;
import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
@@ -35,6 +36,7 @@
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.List;
@@ -116,15 +118,14 @@ List<Message> claim(@PayloadParam("ttl") int ttl,
* must be between 60 and 43200 seconds (12 hours). You must include a value for this attribute in
* your request.
*/
// TODO: revisit this when we figure out what's wrong with PATCH
// @Named("claim:update")
// @PATCH
// @Path("/claims/{claim_id}")
// @Fallback(FalseOnNotFoundOr404.class)
// @Payload("%7B\"ttl\":{ttl}%7D")
// @Produces(MediaType.APPLICATION_JSON)
// boolean update(@PathParam("claim_id") String claimId,
// @PayloadParam("ttl") int ttl);
@Named("claim:update")
@PATCH
@Path("/claims/{claim_id}")
@Fallback(FalseOnNotFoundOr404.class)
@Payload("%7B\"ttl\":{ttl}%7D")
@Produces(MediaType.APPLICATION_JSON)
boolean update(@PathParam("claim_id") String claimId,
@PayloadParam("ttl") int ttl);

/**
* This operation immediately releases a claim, making any remaining, undeleted messages that are associated with
@@ -109,6 +109,17 @@ public void getClaim() throws Exception {
}

@Test(dependsOnMethods = { "getClaim" })
public void updateClaim() throws Exception {
for (String zoneId : zones) {
ClaimApi claimApi = api.getClaimApiForZoneAndClientAndQueue(zoneId, CLIENT_ID, "jclouds-test");

boolean success = claimApi.update(claimIds.get(zoneId).get(0), 400);

assertTrue(success);
}
}

@Test(dependsOnMethods = { "updateClaim" })
public void releaseClaim() throws Exception {
for (String zoneId : zones) {
ClaimApi claimApi = api.getClaimApiForZoneAndClientAndQueue(zoneId, CLIENT_ID, "jclouds-test");
@@ -119,7 +130,7 @@ public void releaseClaim() throws Exception {
}
}

@Test(dependsOnMethods = { "getClaim" })
@Test(dependsOnMethods = { "releaseClaim" })
public void delete() throws Exception {
for (String zoneId : zones) {
QueueApi queueApi = api.getQueueApiForZone(zoneId, CLIENT_ID);
@@ -100,6 +100,34 @@ public void getClaim() throws Exception {
}
}

/**
* Disabled due to PATCH with an output (body content) is not supported over HTTP.
*
* See https://issues.apache.org/jira/browse/JCLOUDS-405
*/
@Test(enabled = false)
public void updateClaim() throws Exception {
MockWebServer server = mockOpenStackServer();
server.enqueue(new MockResponse().setBody(accessRackspace));
server.enqueue(new MockResponse().setResponseCode(204));

try {
MarconiApi api = api(server.getUrl("/").toString(), "openstack-marconi");
ClaimApi claimApi = api.getClaimApiForZoneAndClientAndQueue("DFW", CLIENT_ID, "jclouds-test");

boolean success = claimApi.update("52a8d23eb04a584f1bbd4f47", 400);

assertTrue(success);

assertEquals(server.getRequestCount(), 2);
assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1");
assertEquals(server.takeRequest().getRequestLine(), "PATCH /v1/123123/queues/jclouds-test/claims/52a8d23eb04a584f1bbd4f47 HTTP/1.1");
}
finally {
server.shutdown();
}
}

public void releaseClaim() throws Exception {
MockWebServer server = mockOpenStackServer();
server.enqueue(new MockResponse().setBody(accessRackspace));

0 comments on commit 8c80afa

Please sign in to comment.