@Override public void kill(DataSegment segment) throws SegmentLoadingException { log.info("Killing segment [%s]", segment); Map<String, Object> loadSpec = segment.getLoadSpec(); final String containerName = MapUtils.getString(loadSpec, "containerName"); final String blobPath = MapUtils.getString(loadSpec, "blobPath"); final String dirPath = Paths.get(blobPath).getParent().toString(); try { azureStorage.emptyCloudBlobDirectory(containerName, dirPath); } catch (StorageException e) { Object extendedInfo = e.getExtendedErrorInformation() == null ? null : e.getExtendedErrorInformation().getErrorMessage(); throw new SegmentLoadingException(e, "Couldn't kill segment[%s]: [%s]", segment.getId(), extendedInfo); } catch (URISyntaxException e) { throw new SegmentLoadingException(e, "Couldn't kill segment[%s]: [%s]", segment.getId(), e.getReason()); } }
if (extendedError != null) { bld.append(", ExtendedErrorInformation= {ErrorMessage= "); bld.append(extendedError.getErrorMessage());
private static void assertMessagesMatch(String expectedMessage, StorageException ex) { final String message = ex.getExtendedErrorInformation().getErrorMessage().split("\n")[0]; assertEquals(expectedMessage, message); }
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; }
@Override public void kill(DataSegment segment) throws SegmentLoadingException { log.info("Killing segment [%s]", segment); Map<String, Object> loadSpec = segment.getLoadSpec(); final String containerName = MapUtils.getString(loadSpec, "containerName"); final String blobPath = MapUtils.getString(loadSpec, "blobPath"); final String dirPath = Paths.get(blobPath).getParent().toString(); try { azureStorage.emptyCloudBlobDirectory(containerName, dirPath); } catch(StorageException e){ throw new SegmentLoadingException(e, "Couldn't kill segment[%s]: [%s]", segment.getIdentifier(), e.getExtendedErrorInformation() == null ? null : e.getExtendedErrorInformation().getErrorMessage()); } catch (URISyntaxException e) { throw new SegmentLoadingException(e, "Couldn't kill segment[%s]: [%s]", segment.getIdentifier(), e.getReason()); } }
@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 testBatchOver100Entities() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); TableBatchOperation batch = new TableBatchOperation(); try { for (int m = 0; m < 101; m++) { batch.insert(TableTestHelper.generateRandomEntity("jxscl_odata")); } this.table.execute(batch, options, null); fail("Batch with over 100 entities should fail."); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Bad Request"); String errorAfterSemiColon = ex.getExtendedErrorInformation().getErrorMessage(); errorAfterSemiColon = errorAfterSemiColon.substring(errorAfterSemiColon.indexOf(":") + 1); assertTrue(errorAfterSemiColon.startsWith("The batch request operation exceeds the maximum 100 changes per change set.")); assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.INVALID_INPUT); } }
@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"); } }
String errorAfterSemiColon = ex.getExtendedErrorInformation().getErrorMessage(); errorAfterSemiColon = errorAfterSemiColon.substring(errorAfterSemiColon.indexOf(":") + 1); assertTrue(errorAfterSemiColon.startsWith("The property name exceeds the maximum allowed length (255)."));
String errorAfterSemiColon = ex.getExtendedErrorInformation().getErrorMessage(); errorAfterSemiColon = errorAfterSemiColon.substring(errorAfterSemiColon.indexOf(":") + 1); assertTrue(errorAfterSemiColon.startsWith("The entity is larger than the maximum allowed size (1MB)."));
@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"); } }
@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 testBatchInsertFail() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); // insert entity Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(ref), options, null); try { TableBatchOperation batch = new TableBatchOperation(); batch.insert(ref); this.table.execute(batch, options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Conflict"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The specified entity already exists")); assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.ENTITY_ALREADY_EXISTS); } }
assertTrue(e.getExtendedErrorInformation().getErrorMessage() .startsWith("The requested URI does not represent any resource on the server."));
@Test public void testBatchMergeFail() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); TableBatchOperation batch = new TableBatchOperation(); addInsertBatch(batch); // Insert entity to merge Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(baseEntity), options, null); Class1 updatedEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); updatedEntity.setPartitionKey(baseEntity.getPartitionKey()); updatedEntity.setRowKey(baseEntity.getRowKey()); updatedEntity.setEtag(baseEntity.getEtag()); this.table.execute(TableOperation.replace(updatedEntity), options, null); // add merge to fail addMergeToBatch(baseEntity, batch); try { this.table.execute(batch, options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Precondition Failed"); String errorAfterSemiColon = ex.getExtendedErrorInformation().getErrorMessage(); errorAfterSemiColon = errorAfterSemiColon.substring(errorAfterSemiColon.indexOf(":") + 1); assertTrue(errorAfterSemiColon .startsWith("The update condition specified in the request was not satisfied.")); assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.UPDATE_CONDITION_NOT_SATISFIED); } }
} catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Precondition Failed"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The update condition specified in the request was not satisfied.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "UpdateConditionNotSatisfied"); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Not Found"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The specified resource does not exist.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "ResourceNotFound");
@Test public void testBatchReplaceFail() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); TableBatchOperation batch = new TableBatchOperation(); // Insert entity to merge Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(baseEntity), options, null); Class1 updatedEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); updatedEntity.setPartitionKey(baseEntity.getPartitionKey()); updatedEntity.setRowKey(baseEntity.getRowKey()); updatedEntity.setEtag(baseEntity.getEtag()); this.table.execute(TableOperation.replace(updatedEntity), options, null); // add merge to fail addReplaceToBatch(baseEntity, batch); try { this.table.execute(batch); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Precondition Failed"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The update condition specified in the request was not satisfied.")); assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.UPDATE_CONDITION_NOT_SATISFIED); } }
} catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Precondition Failed"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The update condition specified in the request was not satisfied.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "UpdateConditionNotSatisfied"); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Not Found"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The specified resource does not exist.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "ResourceNotFound");
@Test public void testBatchDeleteFail() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); TableBatchOperation batch = new TableBatchOperation(); // Insert entity to delete Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(baseEntity), options, null); Class1 updatedEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); updatedEntity.setPartitionKey(baseEntity.getPartitionKey()); updatedEntity.setRowKey(baseEntity.getRowKey()); updatedEntity.setEtag(baseEntity.getEtag()); this.table.execute(TableOperation.replace(updatedEntity), options, null); // add delete to fail batch.delete(baseEntity); try { this.table.execute(batch, options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Precondition Failed"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The update condition specified in the request was not satisfied.")); assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.UPDATE_CONDITION_NOT_SATISFIED); } }