try { this.extendedErrorInformation = TableStorageErrorDeserializer.getExtendedErrorInformation(reader, format); this.errorCode = this.extendedErrorInformation.getErrorCode();
this.extendedErrorInformation = TableStorageErrorDeserializer.getExtendedErrorInformation(reader, format); this.errorCode = this.extendedErrorInformation.getErrorCode();
private AzureBlobLease createLeaseIfNotExistsInternal(String partitionId, BlobRequestOptions options) throws URISyntaxException, IOException, StorageException { AzureBlobLease returnLease = null; try { CloudBlockBlob leaseBlob = this.consumerGroupDirectory.getBlockBlobReference(partitionId); // getBlockBlobReference does not take options returnLease = new AzureBlobLease(partitionId, leaseBlob, this.leaseOperationOptions); uploadLease(returnLease, leaseBlob, AccessCondition.generateIfNoneMatchCondition("*"), UploadActivity.Create, options); // Do not set metadata on creation. No metadata/no owner value indicates that the lease is unowned. TRACE_LOGGER.info(this.hostContext.withHostAndPartition(partitionId, "CreateLeaseIfNotExist OK - leaseContainerName: " + this.storageContainerName + " consumerGroupName: " + this.hostContext.getConsumerGroupName() + " storageBlobPrefix: " + this.storageBlobPrefix)); } catch (StorageException se) { StorageExtendedErrorInformation extendedErrorInfo = se.getExtendedErrorInformation(); if ((extendedErrorInfo != null) && ((extendedErrorInfo.getErrorCode().compareTo(StorageErrorCodeStrings.BLOB_ALREADY_EXISTS) == 0) || (extendedErrorInfo.getErrorCode().compareTo(StorageErrorCodeStrings.LEASE_ID_MISSING) == 0))) // occurs when somebody else already has leased the blob { // The blob already exists. TRACE_LOGGER.info(this.hostContext.withHostAndPartition(partitionId, "Lease already exists")); returnLease = getLeaseInternal(partitionId, options); } else { throw se; } } return returnLease; }
private boolean wasLeaseLost(StorageException se, String partitionId) { boolean retval = false; TRACE_LOGGER.debug(this.hostContext.withHostAndPartition(partitionId, "WAS LEASE LOST? Http " + se.getHttpStatusCode())); if (se.getExtendedErrorInformation() != null) { TRACE_LOGGER.debug(this.hostContext.withHostAndPartition(partitionId, "Http " + se.getExtendedErrorInformation().getErrorCode() + " :: " + se.getExtendedErrorInformation().getErrorMessage())); } if ((se.getHttpStatusCode() == 409) || // conflict (se.getHttpStatusCode() == 412)) // precondition failed { StorageExtendedErrorInformation extendedErrorInfo = se.getExtendedErrorInformation(); if (extendedErrorInfo != null) { String errorCode = extendedErrorInfo.getErrorCode(); TRACE_LOGGER.debug(this.hostContext.withHostAndPartition(partitionId, "Error code: " + errorCode)); TRACE_LOGGER.debug(this.hostContext.withHostAndPartition(partitionId, "Error message: " + extendedErrorInfo.getErrorMessage())); if ((errorCode.compareTo(StorageErrorCodeStrings.LEASE_LOST) == 0) || (errorCode.compareTo(StorageErrorCodeStrings.LEASE_ID_MISMATCH_WITH_LEASE_OPERATION) == 0) || (errorCode.compareTo(StorageErrorCodeStrings.LEASE_ID_MISMATCH_WITH_BLOB_OPERATION) == 0) || (errorCode.compareTo(StorageErrorCodeStrings.LEASE_ALREADY_PRESENT) == 0)) { retval = true; } } } return retval; }
private void appendBlock(ByteArrayInputStream blockData, long offset, long writeLength) { final CloudAppendBlob blobRef = (CloudAppendBlob) this.parentBlobRef; this.accessCondition.setIfAppendPositionEqual(offset); int previousResultsCount = this.opContext.getRequestResults().size(); try { blobRef.appendBlock(blockData, writeLength, this.accessCondition, this.options, this.opContext); } catch (final IOException e) { this.lastError = e; } catch (final StorageException e) { if (this.options.getAbsorbConditionalErrorsOnRetry() && e.getHttpStatusCode() == HttpURLConnection.HTTP_PRECON_FAILED && e.getExtendedErrorInformation() != null && e.getExtendedErrorInformation().getErrorCode() != null && (e.getExtendedErrorInformation().getErrorCode() .equals(StorageErrorCodeStrings.INVALID_APPEND_POSITION) || e.getExtendedErrorInformation() .getErrorCode().equals(StorageErrorCodeStrings.INVALID_MAX_BLOB_SIZE_CONDITION)) && (this.opContext.getRequestResults().size() - previousResultsCount > 1)) { // Pre-condition failure on a retry should be ignored in a single writer scenario since // the request succeeded in the first attempt. Logger.info(this.opContext, SR.PRECONDITION_FAILURE_IGNORED); } else { this.lastError = Utility.initIOException(e); } } }
if (extendedError != null) { translatedException = new StorageException(extendedError.getErrorCode(), responseMessage, responseCode, extendedError, cause); } else {
@Test public void testInsertEntityWithNumericProperty() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); DynamicTableEntity ref = new DynamicTableEntity(); String propName = ""; for (int m = 0; m < 255; m++) { propName = propName.concat(Integer.toString(m % 9)); } ref.getProperties().put(propName, new EntityProperty("test")); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); try { this.table.execute(TableOperation.insert(ref), options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Bad Request"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage().startsWith("The property name is invalid.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "PropertyNameInvalid"); } }
@Test public void testInsertEntityWithPropertyMoreThan255chars() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); DynamicTableEntity ref = new DynamicTableEntity(); String propName = ""; for (int m = 0; m < 256; m++) { propName = propName.concat("a"); } ref.getProperties().put(propName, new EntityProperty("test")); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); try { this.table.execute(TableOperation.insert(ref), options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Bad Request"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The property name exceeds the maximum allowed length (255).")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "PropertyNameTooLong"); } }
@Test public void testTableInvalidQuery() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); TableQuery<Class1> query = TableQuery.from(Class1.class).where( String.format("(PartitionKey ) and (RowKey ge '%s')", "000050")); try { table.executeSegmented(query, null, options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Bad Request"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("A binary operator with incompatible types was detected. Found operand types 'Edm.String' and 'Edm.Boolean' for operator kind 'And'.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "InvalidInput"); } }
@Test public void testInsertFail() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); Class1 ref = new Class1(); ref.setA("foo_A"); ref.setB("foo_B"); ref.setC("foo_C"); ref.setD(new byte[]{0, 1, 2}); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); TableOperation op = TableOperation.insert(ref); this.table.execute(op, options, null); try { this.table.execute(op, options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Conflict"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The specified entity already exists")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "EntityAlreadyExists"); } }
@Test public void testInsertEntityOver1MB() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); Class1 ref = new Class1(); ref.setA("foo_A"); ref.setB("foo_B"); ref.setC("foo_C"); // 1mb right here ref.setD(new byte[1024 * 1024]); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); try { this.table.execute(TableOperation.insert(ref), options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Bad Request"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The entity is larger than the maximum allowed size (1MB).")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "EntityTooLarge"); } }
assertEquals("AuthorizationFailure", e.getExtendedErrorInformation().getErrorCode()); assertEquals("AuthorizationFailure", e.getExtendedErrorInformation().getErrorCode());
assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The update condition specified in the request was not satisfied.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "UpdateConditionNotSatisfied"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The specified resource does not exist.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "ResourceNotFound");
assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The update condition specified in the request was not satisfied.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "UpdateConditionNotSatisfied"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The specified resource does not exist.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "ResourceNotFound");
assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The update condition specified in the request was not satisfied.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "UpdateConditionNotSatisfied"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The specified resource does not exist.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "ResourceNotFound");
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testDeleteQueueIfExists() throws URISyntaxException, StorageException { final CloudQueue queue = QueueTestHelper.getRandomQueueReference(); assertFalse(queue.deleteIfExists()); try { final OperationContext createQueueContext = new OperationContext(); queue.create(null, createQueueContext); assertEquals(createQueueContext.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); assertTrue(queue.deleteIfExists()); assertFalse(queue.deleteIfExists()); try { queue.create(); fail("Queue CreateIfNotExists did not throw exception while trying to create a queue in BeingDeleted State"); } catch (StorageException ex) { assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getHttpStatusCode(), HttpURLConnection.HTTP_CONFLICT); assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getExtendedErrorInformation() .getErrorCode(), StorageErrorCodeStrings.QUEUE_BEING_DELETED); } } finally { queue.delete(); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueCreateAfterDelete() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue = qClient.getQueueReference(queueName); assertEquals(queueName, queue.getName()); try { OperationContext createQueueContext1 = new OperationContext(); assertTrue(queue.createIfNotExists(null, createQueueContext1)); assertEquals(createQueueContext1.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); assertTrue(queue.deleteIfExists()); try { queue.create(); fail("Queue CreateIfNotExists did not throw exception while trying to create a queue in BeingDeleted State"); } catch (StorageException ex) { assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getHttpStatusCode(), HttpURLConnection.HTTP_CONFLICT); assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getExtendedErrorInformation() .getErrorCode(), StorageErrorCodeStrings.QUEUE_BEING_DELETED); } } finally { queue.deleteIfExists(); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueCreateIfNotExistsAfterDelete() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue = qClient.getQueueReference(queueName); assertEquals(queueName, queue.getName()); try { OperationContext createQueueContext1 = new OperationContext(); assertTrue(queue.createIfNotExists(null, createQueueContext1)); assertEquals(createQueueContext1.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); assertTrue(queue.deleteIfExists()); try { queue.createIfNotExists(); fail("Queue CreateIfNotExists did not throw exception while trying to create a queue in BeingDeleted State"); } catch (StorageException ex) { assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getHttpStatusCode(), HttpURLConnection.HTTP_CONFLICT); assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getExtendedErrorInformation() .getErrorCode(), StorageErrorCodeStrings.QUEUE_BEING_DELETED); } } finally { queue.deleteIfExists(); } }