本文整理汇总了Java中com.microsoft.azure.documentdb.DocumentClientException类的典型用法代码示例。如果您正苦于以下问题:Java DocumentClientException类的具体用法?Java DocumentClientException怎么用?Java DocumentClientException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DocumentClientException类属于com.microsoft.azure.documentdb包,在下文中一共展示了DocumentClientException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setUp
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
@Before
public void setUp() throws DocumentClientException {
asyncClient = new AsyncDocumentClient.Builder()
.withServiceEndpoint(TestConfigurations.HOST)
.withMasterKey(TestConfigurations.MASTER_KEY)
.withConnectionPolicy(ConnectionPolicy.GetDefault())
.withConsistencyLevel(ConsistencyLevel.Session)
.build();
// Clean up before setting up
this.cleanUpGeneratedDatabases();
databaseDefinition = new Database();
databaseDefinition.setId(DATABASE_ID);
collectionDefinition = new DocumentCollection();
collectionDefinition.setId(UUID.randomUUID().toString());
}
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:20,代码来源:DatabaseAndCollectionCreationAsyncAPITest.java
示例2: testCreateDatabase_toBlocking_DatabaseAlreadyExists_Fails
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
@Test
public void testCreateDatabase_toBlocking_DatabaseAlreadyExists_Fails() throws DocumentClientException {
// attempt to create a database which already exists
// - first create a database
// - Using the async api generate an async database creation observable
// - Converts the Observable to blocking using Observable.toBlocking() api
// - catch already exist failure (409)
asyncClient.createDatabase(databaseDefinition, null).toBlocking().single();
// Create the database for test.
Observable<ResourceResponse<Database>> databaseForTestObservable = asyncClient
.createDatabase(databaseDefinition, null);
try {
databaseForTestObservable
.toBlocking() //blocks
.single(); //gets the single result
assertThat("Should not reach here", false);
} catch (Exception e) {
assertThat("Database already exists.",
((DocumentClientException) e.getCause()).getStatusCode(), equalTo(409));
}
}
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:26,代码来源:DatabaseAndCollectionCreationAsyncAPITest.java
示例3: cleanUpGeneratedDatabases
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
private void cleanUpGeneratedDatabases() throws DocumentClientException {
LOGGER.info("cleanup databases invoked");
String[] allDatabaseIds = { DATABASE_ID };
for (String id : allDatabaseIds) {
try {
List<FeedResponsePage<Database>> feedResponsePages = asyncClient
.queryDatabases(new SqlQuerySpec("SELECT * FROM root r WHERE [email protected]",
new SqlParameterCollection(new SqlParameter("@id", id))), null).toList().toBlocking().single();
if (!feedResponsePages.get(0).getResults().isEmpty()) {
Database res = feedResponsePages.get(0).getResults().get(0);
LOGGER.info("deleting a database " + feedResponsePages.get(0));
asyncClient.deleteDatabase(res.getSelfLink(), null).toBlocking().single();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:23,代码来源:DatabaseAndCollectionCreationAsyncAPITest.java
示例4: testCreateDocument_toBlocking
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
@Test
public void testCreateDocument_toBlocking() throws DocumentClientException {
// create a document
// toBlocking() converts the observable to a blocking observable
Document doc = new Document(String.format("{ 'id': 'doc%d', 'counter': '%d'}", 1, 1));
Observable<ResourceResponse<Document>> createDocumentObservable =
asyncClient.createDocument(createdCollection.getSelfLink(), doc, null, true);
// toBlocking() converts to a blocking observable
// single() gets the only result
createDocumentObservable
.toBlocking() //converts the observable to a blocking observable
.single(); //gets the single result
}
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:17,代码来源:DocumentCRUDAsyncAPITest.java
示例5: testCreateDocument_toBlocking_DocumentAlreadyExists_Fails
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
@Test
public void testCreateDocument_toBlocking_DocumentAlreadyExists_Fails() throws DocumentClientException {
// attempt to create a document which already exists
// - first create a document
// - Using the async api generate an async document creation observable
// - Converts the Observable to blocking using Observable.toBlocking() api
// - catch already exist failure (409)
Document doc = new Document(String.format("{ 'id': 'doc%d', 'counter': '%d'}", 1, 1));
asyncClient.createDocument(createdCollection.getSelfLink(), doc, null, false).toBlocking().single();
// Create the document
Observable<ResourceResponse<Document>> createDocumentObservable = asyncClient
.createDocument(createdCollection.getSelfLink(), doc, null, false);
try {
createDocumentObservable
.toBlocking() //converts the observable to a blocking observable
.single(); //gets the single result
Assert.fail("Document Already Exists. Document Creation must fail");
} catch (Exception e) {
assertThat("Document already exists.",
((DocumentClientException) e.getCause()).getStatusCode(), equalTo(409));
}
}
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:26,代码来源:DocumentCRUDAsyncAPITest.java
示例6: cleanUpGeneratedDatabases
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
private void cleanUpGeneratedDatabases() throws DocumentClientException {
LOGGER.info("cleanup databases invoked");
String[] allDatabaseIds = { DATABASE_ID };
for (String id : allDatabaseIds) {
try {
List<FeedResponsePage<Database>> feedResponsePages = asyncClient
.queryDatabases(new SqlQuerySpec("SELECT * FROM root r WHERE [email protected]",
new SqlParameterCollection(new SqlParameter("@id", id))), null)
.toList().toBlocking().single();
if (!feedResponsePages.get(0).getResults().isEmpty()) {
Database res = feedResponsePages.get(0).getResults().get(0);
LOGGER.info("deleting a database " + feedResponsePages.get(0));
asyncClient.deleteDatabase(res.getSelfLink(), null).toBlocking().single();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:23,代码来源:DocumentQueryAsyncAPITest.java
示例7: createMultiPartitionCollection
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
private DocumentCollection createMultiPartitionCollection(String databaseLink, String collectionId,
String partitionKeyPath) throws DocumentClientException {
PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition();
ArrayList<String> paths = new ArrayList<String>();
paths.add(partitionKeyPath);
partitionKeyDef.setPaths(paths);
RequestOptions options = new RequestOptions();
options.setOfferThroughput(10100);
DocumentCollection collectionDefinition = new DocumentCollection();
collectionDefinition.setId(collectionId);
collectionDefinition.setPartitionKey(partitionKeyDef);
DocumentCollection createdCollection = asyncClient
.createCollection(databaseLink, collectionDefinition, options).toBlocking().single().getResource();
return createdCollection;
}
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:18,代码来源:DocumentQueryAsyncAPITest.java
示例8: doDelete
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
private Observable<DocumentServiceResponse> doDelete(RxDocumentServiceRequest request)
throws DocumentClientException {
Observable<DocumentServiceResponse> responseObservable = Observable.defer(() -> {
try {
return this.gatewayProxy.doDelete(request).doOnNext(response -> {
if (request.getResourceType() != ResourceType.DocumentCollection) {
this.captureSessionToken(request, response);
} else {
this.clearToken(request, response);
}
});
} catch (Exception e) {
return Observable.error(e);
}
}).retryWhen(createExecuteRequestRetryHandler(request));
return createPutMoreContentObservable(request, HttpConstants.HttpMethods.DELETE)
.doOnNext(req -> this.applySessionToken(request))
.flatMap(req -> responseObservable);
}
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:22,代码来源:RxDocumentClientImpl.java
示例9: doRead
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
private Observable<DocumentServiceResponse> doRead(RxDocumentServiceRequest request)
throws DocumentClientException {
Observable<DocumentServiceResponse> responseObservable = Observable.defer(() -> {
try {
return this.gatewayProxy.processMessage(request).doOnNext(response -> {
this.captureSessionToken(request, response);
});
} catch (Exception e) {
return Observable.error(e);
}
}).retryWhen(createExecuteRequestRetryHandler(request));
return createPutMoreContentObservable(request, HttpConstants.HttpMethods.GET)
.doOnNext(req -> this.applySessionToken(request))
.flatMap(req -> responseObservable);
}
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:18,代码来源:RxDocumentClientImpl.java
示例10: handleRetryAttemptInternal
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
private Observable<Long> handleRetryAttemptInternal(DocumentClientException e, int attemptNumber) throws DocumentClientException {
RetryPolicy retryPolicy = null;
if (e.getStatusCode() == HttpConstants.StatusCodes.BADREQUEST && e.getSubStatusCode() != null
&& e.getSubStatusCode() == HttpConstants.SubStatusCodes.PARTITION_KEY_MISMATCH) {
// If HttpStatusCode is 404 (NotFound) and SubStatusCode is
// 1001 (PartitionKeyMismatch), invoke the partition key mismatch retry policy
retryPolicy = keyMismatchRetryPolicy;
}
if (retryPolicy == null || !retryPolicy.shouldRetry(e)) {
LOGGER.trace("Execution encontured exception: {}, status code {} sub status code {}. Won't retry!",
e.getMessage(), e.getStatusCode(), e.getSubStatusCode());
return Observable.error(e);
}
LOGGER.trace("Execution encontured exception: {}, status code {} sub status code {}. Will retry in {}ms",
e.getMessage(), e.getStatusCode(), e.getSubStatusCode(), retryPolicy.getRetryAfterInMilliseconds());
long waitTime = retryPolicy.getRetryAfterInMilliseconds();
return Observable.just(waitTime);
}
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:22,代码来源:CreateDocumentRetryHandler.java
示例11: handleRetryAttempt
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
private static Observable<Long> handleRetryAttempt(Throwable t, int attemptNumber, RxRetryHandler retryPolicy) {
Throwable cause = extractDocumentClientCause(t, attemptNumber);
if (LOGGER.isDebugEnabled()) {
if (cause instanceof DocumentClientException) {
DocumentClientException ex = (DocumentClientException) cause;
LOGGER.debug("Handling Failure Attempt [{}], StatusCode [{}], SubStatusCode,"
+ " Error: [{}] ", attemptNumber, ex.getStatusCode(), ex.getSubStatusCode(), ex.getError(), ex);
} else {
LOGGER.debug("Handling Failure Attempt [{}], req [{}]", attemptNumber, cause);
}
}
try {
return retryPolicy.handleRetryAttempt(cause, attemptNumber);
} catch (Exception e) {
return Observable.error(e);
}
}
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:20,代码来源:RetryFunctionFactory.java
示例12: invalidQuerySytax
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
@Test(groups = { "simple" }, timeOut = TIMEOUT, enabled = false)
public void invalidQuerySytax() throws Exception {
// NOTE: this test passes on Linux but not on Windows in the presence of dlls
// ServiceJNIWrapper in DocumentClient throws IllegalArgumentException instead of DocumentClientException
// after the behavior is fixed enable this test
String query = "I am an invalid query";
FeedOptions options = new FeedOptions();
options.setEnableCrossPartitionQuery(true);
Observable<FeedResponsePage<Document>> queryObservable = client
.queryDocuments(getCollectionLink(), query, options);
FailureValidator validator = new FailureValidator.Builder()
.instanceOf(DocumentClientException.class)
.statusCode(400)
.notNullActivityId()
.build();
validateQueryFailure(queryObservable, validator);
}
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:21,代码来源:DocumentQueryTest.java
示例13: readDocument_DoesntExist
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
@Test(groups = { "simple" }, timeOut = TIMEOUT)
public void readDocument_DoesntExist() throws Exception {
Document docDefinition = getDocumentDefinition();
Document document = client
.createDocument(getCollectionLink(), docDefinition, null, false).toBlocking().single().getResource();
RequestOptions options = new RequestOptions();
options.setPartitionKey(new PartitionKey(document.get("mypk")));
client.deleteDocument(document.getSelfLink(), options).toBlocking().first();
options.setPartitionKey(new PartitionKey("looloo"));
Observable<ResourceResponse<Document>> readObservable = client.readDocument(document.getSelfLink(), options);
FailureValidator validator = new FailureValidator.Builder().instanceOf(DocumentClientException.class)
.statusCode(404).build();
validateFailure(readObservable, validator);
}
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:19,代码来源:DocumentCrudTest.java
示例14: setupSpySession
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
private void setupSpySession(final List<String> capturedRequestSessionTokenList, final List<String> capturedResponseSessionTokenList,
RxDocumentClientImpl spyClient, final RxDocumentClientImpl origClient) throws DocumentClientException {
Mockito.reset(spyClient);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
RxDocumentServiceRequest req = (RxDocumentServiceRequest) args[0];
DocumentServiceResponse resp = (DocumentServiceResponse) args[1];
capturedRequestSessionTokenList.add(req.getHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN));
capturedResponseSessionTokenList.add(resp.getResponseHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN));
origClient.captureSessionToken(req, resp);
return null;
}})
.when(spyClient).captureSessionToken(Mockito.any(RxDocumentServiceRequest.class), Mockito.any(DocumentServiceResponse.class));
}
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:20,代码来源:SessionTest.java
示例15: createTodoItem
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
@Override
public TodoItem createTodoItem(TodoItem todoItem) {
// Serialize the TodoItem as a JSON Document.
Document todoItemDocument = new Document(gson.toJson(todoItem));
// Annotate the document as a TodoItem for retrieval (so that we can
// store multiple entity types in the collection).
todoItemDocument.set("entityType", "todoItem");
try {
// Persist the document using the DocumentClient.
todoItemDocument = documentClient.createDocument(
getTodoCollection().getSelfLink(), todoItemDocument, null,
false).getResource();
} catch (DocumentClientException e) {
e.printStackTrace();
return null;
}
return gson.fromJson(todoItemDocument.toString(), TodoItem.class);
}
开发者ID:pivotal-partner-solution-architecture,项目名称:azure-service-broker-client,代码行数:22,代码来源:DocDbDao.java
示例16: updateTodoItem
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
@Override
public TodoItem updateTodoItem(String id, boolean isComplete) {
// Retrieve the document from the database
Document todoItemDocument = getDocumentById(id);
// You can update the document as a JSON document directly.
// For more complex operations - you could de-serialize the document in
// to a POJO, update the POJO, and then re-serialize the POJO back in to
// a document.
todoItemDocument.set("complete", isComplete);
try {
// Persist/replace the updated document.
todoItemDocument = documentClient.replaceDocument(todoItemDocument,
null).getResource();
} catch (DocumentClientException e) {
e.printStackTrace();
return null;
}
return gson.fromJson(todoItemDocument.toString(), TodoItem.class);
}
开发者ID:pivotal-partner-solution-architecture,项目名称:azure-service-broker-client,代码行数:23,代码来源:DocDbDao.java
示例17: deleteTodoItem
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
@Override
public boolean deleteTodoItem(String id) {
// DocumentDB refers to documents by self link rather than id.
// Query for the document to retrieve the self link.
Document todoItemDocument = getDocumentById(id);
try {
// Delete the document by self link.
documentClient.deleteDocument(todoItemDocument.getSelfLink(), null);
} catch (DocumentClientException e) {
e.printStackTrace();
return false;
}
return true;
}
开发者ID:pivotal-partner-solution-architecture,项目名称:azure-service-broker-client,代码行数:18,代码来源:DocDbDao.java
示例18: createTodoItem
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
@Override
public TodoItem createTodoItem(TodoItem todoItem) {
// Serialize the TodoItem as a JSON Document.
Document todoItemDocument = new Document(gson.toJson(todoItem));
// Annotate the document as a TodoItem for retrieval (so that we can
// store multiple entity types in the collection).
todoItemDocument.set("entityType", "todoItem");
try {
// Persist the document using the DocumentClient.
todoItemDocument = documentClient.createDocument(
getTodoCollection().getSelfLink(), todoItemDocument, null,
false).getResource();
} catch (DocumentClientException e) {
e.printStackTrace();
return null;
}
return gson.fromJson(todoItemDocument.toString(), TodoItem.class);
}
开发者ID:Azure-Samples,项目名称:documentdb-java-todo-app,代码行数:22,代码来源:DocDbDao.java
示例19: updateTodoItem
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
@Override
public TodoItem updateTodoItem(String id, boolean isComplete) {
// Retrieve the document from the database
Document todoItemDocument = getDocumentById(id);
// You can update the document as a JSON document directly.
// For more complex operations - you could de-serialize the document in
// to a POJO, update the POJO, and then re-serialize the POJO back in to
// a document.
todoItemDocument.set("complete", isComplete);
try {
// Persist/replace the updated document.
todoItemDocument = documentClient.replaceDocument(todoItemDocument,
null).getResource();
} catch (DocumentClientException e) {
e.printStackTrace();
return null;
}
return gson.fromJson(todoItemDocument.toString(), TodoItem.class);
}
开发者ID:Azure-Samples,项目名称:documentdb-java-todo-app,代码行数:23,代码来源:DocDbDao.java
示例20: deleteTodoItem
import com.microsoft.azure.documentdb.DocumentClientException; //导入依赖的package包/类
@Override
public boolean deleteTodoItem(String id) {
// DocumentDB refers to documents by self link rather than id.
// Query for the document to retrieve the self link.
Document todoItemDocument = getDocumentById(id);
try {
// Delete the document by self link.
documentClient.deleteDocument(todoItemDocument.getSelfLink(), null);
} catch (DocumentClientException e) {
e.printStackTrace();
return false;
}
return true;
}
开发者ID:Azure-Samples,项目名称:documentdb-java-todo-app,代码行数:18,代码来源:DocDbDao.java
注:本文中的com.microsoft.azure.documentdb.DocumentClientException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论