|
19 | 19 |
|
20 | 20 | package com.aliyun.oss.common; |
21 | 21 |
|
| 22 | +import com.aliyun.oss.ClientConfiguration; |
| 23 | +import com.aliyun.oss.HttpMethod; |
| 24 | +import com.aliyun.oss.common.auth.CredentialsProvider; |
| 25 | +import com.aliyun.oss.common.auth.DefaultCredentialProvider; |
| 26 | +import com.aliyun.oss.common.comm.DefaultServiceClient; |
| 27 | +import com.aliyun.oss.common.comm.ExecutionContext; |
| 28 | +import com.aliyun.oss.common.comm.NoRetryStrategy; |
| 29 | +import com.aliyun.oss.common.comm.ServiceClient; |
22 | 30 | import com.aliyun.oss.common.utils.AuthUtils; |
23 | 31 | import com.aliyun.oss.common.utils.VersionInfoUtils; |
24 | | -import com.aliyun.oss.internal.Mimetypes; |
25 | | -import com.aliyun.oss.internal.OSSConstants; |
26 | | -import com.aliyun.oss.internal.RequestParameters; |
27 | | -import com.aliyun.oss.internal.SignParameters; |
| 32 | +import com.aliyun.oss.internal.*; |
| 33 | +import com.aliyun.oss.model.AbortMultipartUploadRequest; |
| 34 | +import com.aliyun.oss.model.InitiateMultipartUploadRequest; |
28 | 35 | import com.aliyun.oss.model.LocationConstraint; |
| 36 | +import com.aliyun.oss.model.WebServiceRequest; |
29 | 37 | import org.junit.Assert; |
30 | 38 | import org.junit.Test; |
31 | 39 |
|
@@ -64,4 +72,86 @@ public void testMimetypesClass() { |
64 | 72 | } |
65 | 73 |
|
66 | 74 | } |
| 75 | + |
| 76 | + static class TestOSSOperation extends OSSOperation { |
| 77 | + public TestOSSOperation(ServiceClient client, CredentialsProvider credsProvider) { |
| 78 | + super(client, credsProvider); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + protected boolean isRetryablePostRequest(WebServiceRequest request) { |
| 83 | + return super.isRetryablePostRequest(request); |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public ExecutionContext createDefaultContext(HttpMethod method, String bucketName, String key, WebServiceRequest originalRequest) { |
| 88 | + return super.createDefaultContext(method, bucketName, key, originalRequest); |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + static class TestOSSMultipartOperation extends OSSMultipartOperation { |
| 93 | + public TestOSSMultipartOperation(ServiceClient client, CredentialsProvider credsProvider) { |
| 94 | + super(client, credsProvider); |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + protected boolean isRetryablePostRequest(WebServiceRequest request) { |
| 99 | + return super.isRetryablePostRequest(request); |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public ExecutionContext createDefaultContext(HttpMethod method, String bucketName, String key, WebServiceRequest originalRequest) { |
| 104 | + return super.createDefaultContext(method, bucketName, key, originalRequest); |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + public void testOSSOperationClass() { |
| 110 | + ClientConfiguration config = new ClientConfiguration(); |
| 111 | + ServiceClient client = new DefaultServiceClient(config); |
| 112 | + CredentialsProvider cred = new DefaultCredentialProvider("ak", "sk"); |
| 113 | + TestOSSOperation operation = new TestOSSOperation(client, cred); |
| 114 | + InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest("bucket", "key"); |
| 115 | + Assert.assertEquals(operation.isRetryablePostRequest(request), false); |
| 116 | + |
| 117 | + Assert.assertEquals(operation.isRetryablePostRequest(null), false); |
| 118 | + |
| 119 | + ExecutionContext context = null; |
| 120 | + context = operation.createDefaultContext(HttpMethod.POST, "bucket", "key", request); |
| 121 | + Assert.assertTrue(context.getRetryStrategy() instanceof NoRetryStrategy); |
| 122 | + |
| 123 | + context = operation.createDefaultContext(HttpMethod.GET, "bucket", "key", request); |
| 124 | + Assert.assertEquals(context.getRetryStrategy(), null); |
| 125 | + Assert.assertFalse(context.getRetryStrategy() instanceof NoRetryStrategy); |
| 126 | + } |
| 127 | + |
| 128 | + @Test |
| 129 | + public void testTestOSSMultipartOperationClass() { |
| 130 | + ClientConfiguration config = new ClientConfiguration(); |
| 131 | + ServiceClient client = new DefaultServiceClient(config); |
| 132 | + CredentialsProvider cred = new DefaultCredentialProvider("ak", "sk"); |
| 133 | + TestOSSMultipartOperation operation = new TestOSSMultipartOperation(client, cred); |
| 134 | + InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest("bucket", "key"); |
| 135 | + Assert.assertEquals(operation.isRetryablePostRequest(request), true); |
| 136 | + |
| 137 | + Assert.assertEquals(operation.isRetryablePostRequest(null), false); |
| 138 | + |
| 139 | + ExecutionContext context = null; |
| 140 | + context = operation.createDefaultContext(HttpMethod.POST, "bucket", "key", request); |
| 141 | + Assert.assertEquals(context.getRetryStrategy(), null); |
| 142 | + Assert.assertFalse(context.getRetryStrategy() instanceof NoRetryStrategy); |
| 143 | + |
| 144 | + context = operation.createDefaultContext(HttpMethod.POST, "bucket", "key", null); |
| 145 | + Assert.assertNotNull(context.getRetryStrategy()); |
| 146 | + Assert.assertTrue(context.getRetryStrategy() instanceof NoRetryStrategy); |
| 147 | + |
| 148 | + context = operation.createDefaultContext(HttpMethod.POST, "bucket", "key", |
| 149 | + new AbortMultipartUploadRequest("bucket", "key", "id")); |
| 150 | + Assert.assertNotNull(context.getRetryStrategy()); |
| 151 | + Assert.assertTrue(context.getRetryStrategy() instanceof NoRetryStrategy); |
| 152 | + |
| 153 | + context = operation.createDefaultContext(HttpMethod.GET, "bucket", "key", |
| 154 | + new AbortMultipartUploadRequest("bucket", "key", "id")); |
| 155 | + Assert.assertEquals(context.getRetryStrategy(), null); |
| 156 | + } |
67 | 157 | } |
0 commit comments