Search in sources :

Example 11 with AppendObjectRequest

use of com.aliyun.oss.model.AppendObjectRequest in project aliyun-oss-java-sdk by aliyun.

the class CRCChecksumTest method testAppendObjectCRCNegative.

@Test
public void testAppendObjectCRCNegative() {
    String key = "append-object-crc-neg";
    String content = "Hello OSS, Hi OSS.";
    try {
        AppendObjectRequest appendObjectRequest = new AppendObjectRequest(bucketName, key, new ByteArrayInputStream(content.getBytes())).withPosition(0L);
        appendObjectRequest.setInitCRC(1L);
        ossClient.appendObject(appendObjectRequest);
        Assert.fail("Append object should not be successful.");
    } catch (Exception e) {
        Assert.assertTrue(e instanceof InconsistentException);
        ossClient.deleteObject(bucketName, key);
        System.out.println(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AppendObjectRequest(com.aliyun.oss.model.AppendObjectRequest) InconsistentException(com.aliyun.oss.InconsistentException) InconsistentException(com.aliyun.oss.InconsistentException) Test(org.junit.Test)

Aggregations

AppendObjectRequest (com.aliyun.oss.model.AppendObjectRequest)11 Test (org.junit.Test)8 OSSException (com.aliyun.oss.OSSException)7 AppendObjectResult (com.aliyun.oss.model.AppendObjectResult)7 OSSObject (com.aliyun.oss.model.OSSObject)7 InputStream (java.io.InputStream)7 TestUtils.genFixedLengthInputStream (com.aliyun.oss.integrationtests.TestUtils.genFixedLengthInputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InconsistentException (com.aliyun.oss.InconsistentException)3 File (java.io.File)3 ClientException (com.aliyun.oss.ClientException)2 OSS (com.aliyun.oss.OSS)2 OSSClientBuilder (com.aliyun.oss.OSSClientBuilder)2 TestUtils.genFixedLengthFile (com.aliyun.oss.integrationtests.TestUtils.genFixedLengthFile)2 ObjectMetadata (com.aliyun.oss.model.ObjectMetadata)2 AbortMultipartUploadRequest (com.aliyun.oss.model.AbortMultipartUploadRequest)1 CompleteMultipartUploadRequest (com.aliyun.oss.model.CompleteMultipartUploadRequest)1 CompleteMultipartUploadResult (com.aliyun.oss.model.CompleteMultipartUploadResult)1 CopyObjectResult (com.aliyun.oss.model.CopyObjectResult)1 DeleteObjectsRequest (com.aliyun.oss.model.DeleteObjectsRequest)1