mirror of https://github.com/apache/jclouds.git
Issue 86: add get messages to azurequeue
This commit is contained in:
parent
d7e366f390
commit
7855b1b087
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.azure.storage.queue;
|
package org.jclouds.azure.storage.queue;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
|
@ -33,9 +34,12 @@ import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication;
|
||||||
import org.jclouds.azure.storage.options.CreateOptions;
|
import org.jclouds.azure.storage.options.CreateOptions;
|
||||||
import org.jclouds.azure.storage.options.ListOptions;
|
import org.jclouds.azure.storage.options.ListOptions;
|
||||||
import org.jclouds.azure.storage.queue.binders.BindToXmlStringPayload;
|
import org.jclouds.azure.storage.queue.binders.BindToXmlStringPayload;
|
||||||
|
import org.jclouds.azure.storage.queue.domain.QueueMessage;
|
||||||
import org.jclouds.azure.storage.queue.domain.QueueMetadata;
|
import org.jclouds.azure.storage.queue.domain.QueueMetadata;
|
||||||
|
import org.jclouds.azure.storage.queue.options.GetOptions;
|
||||||
import org.jclouds.azure.storage.queue.options.PutMessageOptions;
|
import org.jclouds.azure.storage.queue.options.PutMessageOptions;
|
||||||
import org.jclouds.azure.storage.queue.xml.AccountNameEnumerationResultsHandler;
|
import org.jclouds.azure.storage.queue.xml.AccountNameEnumerationResultsHandler;
|
||||||
|
import org.jclouds.azure.storage.queue.xml.QueueMessagesListHandler;
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageHeaders;
|
import org.jclouds.azure.storage.reference.AzureStorageHeaders;
|
||||||
import org.jclouds.rest.annotations.BinderParam;
|
import org.jclouds.rest.annotations.BinderParam;
|
||||||
import org.jclouds.rest.annotations.Endpoint;
|
import org.jclouds.rest.annotations.Endpoint;
|
||||||
|
@ -64,7 +68,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
* during processing will be wrapped in an {@link ExecutionException} as documented in
|
* during processing will be wrapped in an {@link ExecutionException} as documented in
|
||||||
* {@link ListenableFuture#get()}.
|
* {@link ListenableFuture#get()}.
|
||||||
*
|
*
|
||||||
* @see <a href="http://msdn.microsoft.com/en-us/library/dd135733.aspx" />
|
* @see <a href="http://msdn.microsoft.com/en-us/library/dd179363%28v=MSDN.10%29.aspx" />
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@SkipEncoding('/')
|
@SkipEncoding('/')
|
||||||
|
@ -89,6 +93,14 @@ public interface AzureQueueAsyncClient {
|
||||||
@Path("{queue}")
|
@Path("{queue}")
|
||||||
ListenableFuture<Boolean> createQueue(@PathParam("queue") String queue, CreateOptions... options);
|
ListenableFuture<Boolean> createQueue(@PathParam("queue") String queue, CreateOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see AzureQueueClient#getMessages
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("{queue}/messages")
|
||||||
|
@XMLResponseParser(QueueMessagesListHandler.class)
|
||||||
|
ListenableFuture<Set<QueueMessage>> getMessages(@PathParam("queue") String queue, GetOptions... options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see AzureQueueClient#deleteQueue
|
* @see AzureQueueClient#deleteQueue
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -18,15 +18,19 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.azure.storage.queue;
|
package org.jclouds.azure.storage.queue;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.domain.BoundedSet;
|
import org.jclouds.azure.storage.domain.BoundedSet;
|
||||||
import org.jclouds.azure.storage.options.CreateOptions;
|
import org.jclouds.azure.storage.options.CreateOptions;
|
||||||
import org.jclouds.azure.storage.options.ListOptions;
|
import org.jclouds.azure.storage.options.ListOptions;
|
||||||
|
import org.jclouds.azure.storage.queue.domain.QueueMessage;
|
||||||
import org.jclouds.azure.storage.queue.domain.QueueMetadata;
|
import org.jclouds.azure.storage.queue.domain.QueueMetadata;
|
||||||
|
import org.jclouds.azure.storage.queue.options.GetOptions;
|
||||||
import org.jclouds.azure.storage.queue.options.PutMessageOptions;
|
import org.jclouds.azure.storage.queue.options.PutMessageOptions;
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
import org.jclouds.http.HttpResponseException;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
@ -106,6 +110,7 @@ public interface AzureQueueClient {
|
||||||
* it is added to the time it is retrieved and deleted. If a message is not retrieved before the
|
* it is added to the time it is retrieved and deleted. If a message is not retrieved before the
|
||||||
* time-to-live interval expires, the message is removed from the queue.
|
* time-to-live interval expires, the message is removed from the queue.
|
||||||
*
|
*
|
||||||
|
* @throws HttpResponseException
|
||||||
* If the message is too large, the service returns status code 400 (Bad Request).
|
* If the message is too large, the service returns status code 400 (Bad Request).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -123,4 +128,15 @@ public interface AzureQueueClient {
|
||||||
*/
|
*/
|
||||||
@Timeout(duration = 10, timeUnit = TimeUnit.MINUTES)
|
@Timeout(duration = 10, timeUnit = TimeUnit.MINUTES)
|
||||||
void clearMessages(String queue);
|
void clearMessages(String queue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Get Messages operation retrieves one or more messages from the front of the queue.
|
||||||
|
*
|
||||||
|
* @param queue
|
||||||
|
* the name of the queue to retrieve messages from
|
||||||
|
* @param options
|
||||||
|
* controls the number of messages to receive and the visibility window
|
||||||
|
*/
|
||||||
|
Set<QueueMessage> getMessages(String queue, GetOptions... options);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,162 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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.azure.storage.queue.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class QueueMessage {
|
||||||
|
private final String messageId;
|
||||||
|
private final Date insertionTime;
|
||||||
|
private final Date expirationTime;
|
||||||
|
private final int dequeueCount;
|
||||||
|
private final String popReceipt;
|
||||||
|
private final Date timeNextVisible;
|
||||||
|
private final String messageText;
|
||||||
|
|
||||||
|
public QueueMessage(String messageId, Date insertionTime, Date expirationTime, int dequeueCount,
|
||||||
|
String popReceipt, Date timeNextVisible, String messageText) {
|
||||||
|
this.messageId = checkNotNull(messageId, "messageId");
|
||||||
|
this.insertionTime = checkNotNull(insertionTime, "insertionTime");
|
||||||
|
this.expirationTime = checkNotNull(expirationTime, "expirationTime");
|
||||||
|
this.dequeueCount = dequeueCount;
|
||||||
|
checkArgument(dequeueCount >= 0, "dequeueCount not set");
|
||||||
|
this.popReceipt = checkNotNull(popReceipt, "popReceipt");
|
||||||
|
this.timeNextVisible = checkNotNull(timeNextVisible, "timeNextVisible");
|
||||||
|
this.messageText = checkNotNull(messageText, "messageText");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The MessageID element is a GUID value that identifies the message in the queue. This value is
|
||||||
|
* assigned to the message by the Queue service and is opaque to the client. This value may be
|
||||||
|
* used together with the value of the PopReceipt element to delete a message from the queue
|
||||||
|
* after it has been retrieved with the Get Messages operation.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public String getMessageId() {
|
||||||
|
return messageId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getInsertionTime() {
|
||||||
|
return insertionTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getExpirationTime() {
|
||||||
|
return expirationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DequeueCount element has a value of 1 the first time the message is dequeued. This value is
|
||||||
|
* incremented each time the message is subsequently dequeued.
|
||||||
|
* */
|
||||||
|
public int getDequeueCount() {
|
||||||
|
return dequeueCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value of PopReceipt is opaque to the client; its only purpose is to ensure that a message
|
||||||
|
* may be deleted with the Delete Message operation.
|
||||||
|
*/
|
||||||
|
public String getPopReceipt() {
|
||||||
|
return popReceipt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getTimeNextVisible() {
|
||||||
|
return timeNextVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessageText() {
|
||||||
|
return messageText;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + dequeueCount;
|
||||||
|
result = prime * result + ((expirationTime == null) ? 0 : expirationTime.hashCode());
|
||||||
|
result = prime * result + ((insertionTime == null) ? 0 : insertionTime.hashCode());
|
||||||
|
result = prime * result + ((messageId == null) ? 0 : messageId.hashCode());
|
||||||
|
result = prime * result + ((messageText == null) ? 0 : messageText.hashCode());
|
||||||
|
result = prime * result + ((popReceipt == null) ? 0 : popReceipt.hashCode());
|
||||||
|
result = prime * result + ((timeNextVisible == null) ? 0 : timeNextVisible.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
QueueMessage other = (QueueMessage) obj;
|
||||||
|
if (dequeueCount != other.dequeueCount)
|
||||||
|
return false;
|
||||||
|
if (expirationTime == null) {
|
||||||
|
if (other.expirationTime != null)
|
||||||
|
return false;
|
||||||
|
} else if (!expirationTime.equals(other.expirationTime))
|
||||||
|
return false;
|
||||||
|
if (insertionTime == null) {
|
||||||
|
if (other.insertionTime != null)
|
||||||
|
return false;
|
||||||
|
} else if (!insertionTime.equals(other.insertionTime))
|
||||||
|
return false;
|
||||||
|
if (messageId == null) {
|
||||||
|
if (other.messageId != null)
|
||||||
|
return false;
|
||||||
|
} else if (!messageId.equals(other.messageId))
|
||||||
|
return false;
|
||||||
|
if (messageText == null) {
|
||||||
|
if (other.messageText != null)
|
||||||
|
return false;
|
||||||
|
} else if (!messageText.equals(other.messageText))
|
||||||
|
return false;
|
||||||
|
if (popReceipt == null) {
|
||||||
|
if (other.popReceipt != null)
|
||||||
|
return false;
|
||||||
|
} else if (!popReceipt.equals(other.popReceipt))
|
||||||
|
return false;
|
||||||
|
if (timeNextVisible == null) {
|
||||||
|
if (other.timeNextVisible != null)
|
||||||
|
return false;
|
||||||
|
} else if (!timeNextVisible.equals(other.timeNextVisible))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "QueueMessage [dequeueCount=" + dequeueCount + ", expirationTime=" + expirationTime
|
||||||
|
+ ", insertionTime=" + insertionTime + ", messageId=" + messageId + ", messageText="
|
||||||
|
+ messageText + ", popReceipt=" + popReceipt + ", timeNextVisible="
|
||||||
|
+ timeNextVisible + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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.azure.storage.queue.options;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains common options supported in the REST API for the GET operation. <h2>
|
||||||
|
* Usage</h2> The recommended way to instantiate a GetOptions object is to statically import
|
||||||
|
* GetOptions.* and invoke a static creation method followed by an instance mutator (if needed):
|
||||||
|
* <p/>
|
||||||
|
* <code>
|
||||||
|
* import static org.jclouds.azure.storage.queue.options.GetOptions.Builder.*
|
||||||
|
* import org.jclouds.azure.storage.queue.AzureQueueClient;
|
||||||
|
* <p/>
|
||||||
|
* AzureQueueClient connection = // get connection
|
||||||
|
* messages = connection.getMessages("queueName", maxMessages(3));
|
||||||
|
* <code> *
|
||||||
|
*
|
||||||
|
* @see <a href="http://msdn.microsoft.com/en-us/library/dd179474%28v=MSDN.10%29.aspx" />
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class GetOptions extends BaseHttpRequestOptions {
|
||||||
|
public static final GetOptions NONE = new GetOptions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A nonzero integer value that specifies the number of messages to retrieve from the queue, up
|
||||||
|
* to a maximum of 32. By default, a single message is retrieved from the queue with this
|
||||||
|
* operation.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public GetOptions maxMessages(int count) {
|
||||||
|
checkArgument(count > 0&& count <= 32, "count must be a positive number; max 32");
|
||||||
|
queryParameters.replaceValues("numofmessages", Collections.singletonList(count + ""));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An integer value that specifies the message's visibility timeout in seconds. The maximum value
|
||||||
|
* is 2 hours. The default message visibility timeout is 30 seconds.
|
||||||
|
*/
|
||||||
|
public GetOptions visibilityTimeout(int timeout) {
|
||||||
|
checkArgument(timeout > 0 && timeout <= 2 * 60 * 60,
|
||||||
|
"timeout is in seconds; must be positive and maximum 2 hours");
|
||||||
|
queryParameters.replaceValues("visibilitytimeout", Collections.singletonList(timeout + ""));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GetOptions#maxMessages(int)
|
||||||
|
*/
|
||||||
|
public static GetOptions maxMessages(int count) {
|
||||||
|
GetOptions options = new GetOptions();
|
||||||
|
return options.maxMessages(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GetOptions#visibilityTimeout(int)
|
||||||
|
*/
|
||||||
|
public static GetOptions visibilityTimeout(int visibilityTimeout) {
|
||||||
|
GetOptions options = new GetOptions();
|
||||||
|
return options.visibilityTimeout(visibilityTimeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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.azure.storage.queue.xml;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.azure.storage.queue.domain.QueueMessage;
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the following XML document:
|
||||||
|
* <p/>
|
||||||
|
* QueueMessagesList
|
||||||
|
*
|
||||||
|
* @see <a href="http://msdn.microsoft.com/en-us/library/dd179474%28v=MSDN.10%29.aspx" />
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class QueueMessagesListHandler extends ParseSax.HandlerWithResult<Set<QueueMessage>> {
|
||||||
|
|
||||||
|
private Set<QueueMessage> messages = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
|
private String messageId;
|
||||||
|
private Date insertionTime;
|
||||||
|
private Date expirationTime;
|
||||||
|
private int dequeueCount;
|
||||||
|
private String popReceipt;
|
||||||
|
private Date timeNextVisible;
|
||||||
|
private String messageText;
|
||||||
|
|
||||||
|
private StringBuilder currentText = new StringBuilder();
|
||||||
|
|
||||||
|
private final DateService dateService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public QueueMessagesListHandler(DateService dateService) {
|
||||||
|
this.dateService = dateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<QueueMessage> getResult() {
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void endElement(String uri, String name, String qName) {
|
||||||
|
if (qName.equals("MessageId")) {
|
||||||
|
this.messageId = currentText.toString().trim();
|
||||||
|
} else if (qName.equals("InsertionTime")) {
|
||||||
|
this.insertionTime = parseDate();
|
||||||
|
} else if (qName.equals("ExpirationTime")) {
|
||||||
|
this.expirationTime = parseDate();
|
||||||
|
} else if (qName.equals("DequeueCount")) {
|
||||||
|
this.dequeueCount = Integer.parseInt(currentText.toString().trim());
|
||||||
|
} else if (qName.equals("PopReceipt")) {
|
||||||
|
this.popReceipt = currentText.toString().trim();
|
||||||
|
} else if (qName.equals("TimeNextVisible")) {
|
||||||
|
this.timeNextVisible = parseDate();
|
||||||
|
} else if (qName.equals("MessageText")) {
|
||||||
|
// TODO: figure out why we need to do trim. excess leading whitespace seems to be from
|
||||||
|
// outside the element
|
||||||
|
this.messageText = currentText.toString().trim();
|
||||||
|
} else if (qName.equals("QueueMessage")) {
|
||||||
|
messages.add(new QueueMessage(messageId, insertionTime, expirationTime, dequeueCount,
|
||||||
|
popReceipt, timeNextVisible, messageText));
|
||||||
|
messageId = null;
|
||||||
|
insertionTime = null;
|
||||||
|
expirationTime = null;
|
||||||
|
dequeueCount = -1;
|
||||||
|
popReceipt = null;
|
||||||
|
timeNextVisible = null;
|
||||||
|
messageText = null;
|
||||||
|
}
|
||||||
|
currentText = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Date parseDate() {
|
||||||
|
return dateService.rfc822DateParse(currentText.toString().trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void characters(char ch[], int start, int length) {
|
||||||
|
currentText.append(ch, start, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ package org.jclouds.azure.storage.queue;
|
||||||
|
|
||||||
import static org.jclouds.azure.storage.options.CreateOptions.Builder.withMetadata;
|
import static org.jclouds.azure.storage.options.CreateOptions.Builder.withMetadata;
|
||||||
import static org.jclouds.azure.storage.options.ListOptions.Builder.maxResults;
|
import static org.jclouds.azure.storage.options.ListOptions.Builder.maxResults;
|
||||||
|
import static org.jclouds.azure.storage.queue.options.GetOptions.Builder.maxMessages;
|
||||||
import static org.jclouds.azure.storage.queue.options.PutMessageOptions.Builder.withTTL;
|
import static org.jclouds.azure.storage.queue.options.PutMessageOptions.Builder.withTTL;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -31,8 +32,10 @@ import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication;
|
||||||
import org.jclouds.azure.storage.options.CreateOptions;
|
import org.jclouds.azure.storage.options.CreateOptions;
|
||||||
import org.jclouds.azure.storage.options.ListOptions;
|
import org.jclouds.azure.storage.options.ListOptions;
|
||||||
import org.jclouds.azure.storage.queue.config.AzureQueueRestClientModule;
|
import org.jclouds.azure.storage.queue.config.AzureQueueRestClientModule;
|
||||||
|
import org.jclouds.azure.storage.queue.options.GetOptions;
|
||||||
import org.jclouds.azure.storage.queue.options.PutMessageOptions;
|
import org.jclouds.azure.storage.queue.options.PutMessageOptions;
|
||||||
import org.jclouds.azure.storage.queue.xml.AccountNameEnumerationResultsHandler;
|
import org.jclouds.azure.storage.queue.xml.AccountNameEnumerationResultsHandler;
|
||||||
|
import org.jclouds.azure.storage.queue.xml.QueueMessagesListHandler;
|
||||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||||
|
@ -55,6 +58,44 @@ import com.google.inject.name.Names;
|
||||||
@Test(groups = "unit", testName = "azurequeue.AzureQueueAsyncClientTest")
|
@Test(groups = "unit", testName = "azurequeue.AzureQueueAsyncClientTest")
|
||||||
public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncClient> {
|
public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncClient> {
|
||||||
|
|
||||||
|
public void testGetMessages() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
|
Method method = AzureQueueAsyncClient.class.getMethod("getMessages", String.class,
|
||||||
|
GetOptions[].class);
|
||||||
|
GeneratedHttpRequest<AzureQueueAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"myqueue");
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://myaccount.queue.core.windows.net/myqueue/messages HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "x-ms-version: 2009-09-19\n");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseSax.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, QueueMessagesListHandler.class);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetMessagesOptions() throws SecurityException, NoSuchMethodException,
|
||||||
|
IOException {
|
||||||
|
Method method = AzureQueueAsyncClient.class.getMethod("getMessages", String.class,
|
||||||
|
GetOptions[].class);
|
||||||
|
GeneratedHttpRequest<AzureQueueAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"myqueue", maxMessages(1).visibilityTimeout(30));
|
||||||
|
|
||||||
|
assertRequestLineEquals(
|
||||||
|
httpRequest,
|
||||||
|
"GET https://myaccount.queue.core.windows.net/myqueue/messages?numofmessages=1&visibilitytimeout=30 HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "x-ms-version: 2009-09-19\n");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseSax.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, QueueMessagesListHandler.class);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
}
|
||||||
|
|
||||||
public void testListQueues() throws SecurityException, NoSuchMethodException, IOException {
|
public void testListQueues() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = AzureQueueAsyncClient.class.getMethod("listQueues", ListOptions[].class);
|
Method method = AzureQueueAsyncClient.class.getMethod("listQueues", ListOptions[].class);
|
||||||
GeneratedHttpRequest<AzureQueueAsyncClient> httpRequest = processor.createRequest(method);
|
GeneratedHttpRequest<AzureQueueAsyncClient> httpRequest = processor.createRequest(method);
|
||||||
|
|
|
@ -18,22 +18,26 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.azure.storage.queue;
|
package org.jclouds.azure.storage.queue;
|
||||||
|
|
||||||
|
import static org.jclouds.azure.storage.options.ListOptions.Builder.prefix;
|
||||||
|
import static org.jclouds.azure.storage.queue.options.GetOptions.Builder.maxMessages;
|
||||||
|
import static org.jclouds.azure.storage.queue.options.PutMessageOptions.Builder.withTTL;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.domain.BoundedSet;
|
import org.jclouds.azure.storage.domain.BoundedSet;
|
||||||
import org.jclouds.azure.storage.options.CreateOptions;
|
import org.jclouds.azure.storage.options.CreateOptions;
|
||||||
import org.jclouds.azure.storage.options.ListOptions;
|
import org.jclouds.azure.storage.queue.domain.QueueMessage;
|
||||||
import org.jclouds.azure.storage.queue.domain.QueueMetadata;
|
import org.jclouds.azure.storage.queue.domain.QueueMetadata;
|
||||||
import org.jclouds.azure.storage.queue.options.PutMessageOptions;
|
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,7 +45,7 @@ import com.google.inject.Injector;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", sequential = true, testName = "cloudservers.AzureQueueClientLiveTest")
|
@Test(groups = "live", sequential = true, testName = "azurequeue.AzureQueueClientLiveTest")
|
||||||
public class AzureQueueClientLiveTest {
|
public class AzureQueueClientLiveTest {
|
||||||
String account;
|
String account;
|
||||||
|
|
||||||
|
@ -96,8 +100,8 @@ public class AzureQueueClientLiveTest {
|
||||||
|
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateQueue" })
|
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateQueue" })
|
||||||
public void testListQueuesWithOptions() throws Exception {
|
public void testListQueuesWithOptions() throws Exception {
|
||||||
BoundedSet<QueueMetadata> response = connection.listQueues(ListOptions.Builder.prefix(
|
BoundedSet<QueueMetadata> response = connection
|
||||||
privateQueue).maxResults(1));
|
.listQueues(prefix(privateQueue).maxResults(1));
|
||||||
assert null != response;
|
assert null != response;
|
||||||
long initialQueueCount = response.size();
|
long initialQueueCount = response.size();
|
||||||
assertTrue(initialQueueCount >= 0);
|
assertTrue(initialQueueCount >= 0);
|
||||||
|
@ -107,11 +111,21 @@ public class AzureQueueClientLiveTest {
|
||||||
|
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateQueue" })
|
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateQueue" })
|
||||||
public void testPutMessage() throws Exception {
|
public void testPutMessage() throws Exception {
|
||||||
connection.putMessage(privateQueue, "holycow", PutMessageOptions.Builder.withTTL(4));
|
connection.putMessage(privateQueue, "holycow", withTTL(4));
|
||||||
// TODO loop for up to 30 seconds checking if they are really gone
|
connection.putMessage(privateQueue, "holymoo", withTTL(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testPutMessage" })
|
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testPutMessage" })
|
||||||
|
public void testGetMessages() throws Exception {
|
||||||
|
Set<QueueMessage> messages = connection.getMessages(privateQueue, maxMessages(2));
|
||||||
|
QueueMessage m1 = Iterables.get(messages, 0);
|
||||||
|
assertEquals(m1.getMessageText(), "holycow");
|
||||||
|
QueueMessage m2 = Iterables.get(messages, 1);
|
||||||
|
assertEquals(m2.getMessageText(), "holymoo");
|
||||||
|
assertEquals(connection.getMessages(privateQueue).size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testGetMessages" })
|
||||||
public void testDeleteQueue() throws Exception {
|
public void testDeleteQueue() throws Exception {
|
||||||
connection.clearMessages(privateQueue);
|
connection.clearMessages(privateQueue);
|
||||||
connection.deleteQueue(privateQueue);
|
connection.deleteQueue(privateQueue);
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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.azure.storage.queue.options;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code GetOptions}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "azurequeue.GetOptionsTest")
|
||||||
|
public class GetOptionsTest {
|
||||||
|
|
||||||
|
public void testMaxMessages() {
|
||||||
|
GetOptions options = new GetOptions().maxMessages(1);
|
||||||
|
assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("numofmessages"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
|
public void testMaxMessagesTooSmall() {
|
||||||
|
new GetOptions().maxMessages(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
|
public void testMaxMessagesTooBig() {
|
||||||
|
new GetOptions().maxMessages(33);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMaxMessagesStatic() {
|
||||||
|
GetOptions options = GetOptions.Builder.maxMessages(1);
|
||||||
|
assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("numofmessages"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testVisibilityTimeout() {
|
||||||
|
GetOptions options = new GetOptions().visibilityTimeout(1);
|
||||||
|
assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("visibilitytimeout"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
|
public void testVisibilityTimeoutTooSmall() {
|
||||||
|
new GetOptions().visibilityTimeout(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
|
public void testVisibilityTimeoutTooBig() {
|
||||||
|
new GetOptions().visibilityTimeout((2 * 60 * 60) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testVisibilityTimeoutStatic() {
|
||||||
|
GetOptions options = GetOptions.Builder.visibilityTimeout(1);
|
||||||
|
assertEquals(ImmutableList.of("1"), options.buildQueryParameters().get("visibilitytimeout"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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.azure.storage.queue.xml;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.jclouds.azure.storage.queue.domain.QueueMessage;
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
|
import org.jclouds.http.functions.BaseHandlerTest;
|
||||||
|
import org.testng.annotations.BeforeTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.inject.internal.ImmutableSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code QueueMessagesListHandler}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "azurequeue.QueueMessagesListHandlerTest")
|
||||||
|
public class QueueMessagesListHandlerTest extends BaseHandlerTest {
|
||||||
|
private DateService dateService;
|
||||||
|
|
||||||
|
@BeforeTest
|
||||||
|
protected void setUpInjector() {
|
||||||
|
super.setUpInjector();
|
||||||
|
dateService = injector.getInstance(DateService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testApplyInputStream() {
|
||||||
|
InputStream is = getClass().getResourceAsStream("/queue/test_get_messages.xml");
|
||||||
|
Set<QueueMessage> expected = ImmutableSet.<QueueMessage> of(
|
||||||
|
|
||||||
|
new QueueMessage("43190737-06f4-4ccf-b600-28f410707df3", dateService
|
||||||
|
.rfc822DateParse("Fri, 11 Jun 2010 18:35:08 GMT"), dateService
|
||||||
|
.rfc822DateParse("Fri, 11 Jun 2010 18:35:13 GMT"), 1,
|
||||||
|
"AgAAAAEAAADZcwAADlwO5JQJywE=", dateService
|
||||||
|
.rfc822DateParse("Fri, 11 Jun 2010 18:35:39 GMT"), "holycow"),
|
||||||
|
new QueueMessage("7b75a124-7efe-45a2-97e4-388664319718", dateService
|
||||||
|
.rfc822DateParse("Fri, 11 Jun 2010 18:35:09 GMT"), dateService
|
||||||
|
.rfc822DateParse("Fri, 11 Jun 2010 18:35:13 GMT"), 1,
|
||||||
|
"AgAAAAEAAADZcwAADlwO5JQJywE=", dateService
|
||||||
|
.rfc822DateParse("Fri, 11 Jun 2010 18:35:39 GMT"), "holymoo"));
|
||||||
|
|
||||||
|
Set<QueueMessage> result = factory.create(
|
||||||
|
injector.getInstance(QueueMessagesListHandler.class)).parse(is);
|
||||||
|
assertEquals(result, expected);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<QueueMessagesList>
|
||||||
|
<QueueMessage>
|
||||||
|
<MessageId>43190737-06f4-4ccf-b600-28f410707df3</MessageId>
|
||||||
|
<InsertionTime>Fri, 11 Jun 2010 18:35:08 GMT</InsertionTime>
|
||||||
|
<ExpirationTime>Fri, 11 Jun 2010 18:35:13 GMT</ExpirationTime>
|
||||||
|
<DequeueCount>1</DequeueCount>
|
||||||
|
<PopReceipt>AgAAAAEAAADZcwAADlwO5JQJywE=</PopReceipt>
|
||||||
|
<TimeNextVisible>Fri, 11 Jun 2010 18:35:39 GMT</TimeNextVisible>
|
||||||
|
<MessageText>holycow</MessageText>
|
||||||
|
</QueueMessage>
|
||||||
|
<QueueMessage>
|
||||||
|
<MessageId>7b75a124-7efe-45a2-97e4-388664319718</MessageId>
|
||||||
|
<InsertionTime>Fri, 11 Jun 2010 18:35:09 GMT</InsertionTime>
|
||||||
|
<ExpirationTime>Fri, 11 Jun 2010 18:35:13 GMT</ExpirationTime>
|
||||||
|
<DequeueCount>1</DequeueCount>
|
||||||
|
<PopReceipt>AgAAAAEAAADZcwAADlwO5JQJywE=</PopReceipt>
|
||||||
|
<TimeNextVisible>Fri, 11 Jun 2010 18:35:39 GMT</TimeNextVisible>
|
||||||
|
<MessageText>holymoo</MessageText>
|
||||||
|
</QueueMessage>
|
||||||
|
</QueueMessagesList>
|
Loading…
Reference in New Issue