|
31 | 31 | import org.junit.AssumptionViolatedException;
|
32 | 32 | import org.junit.Ignore;
|
33 | 33 | import org.junit.Test;
|
| 34 | +import org.mockito.Mockito; |
34 | 35 |
|
35 | 36 | import org.apache.hadoop.fs.CommonPathCapabilities;
|
36 | 37 | import org.apache.hadoop.fs.Path;
|
37 | 38 | import org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants;
|
38 | 39 | import org.apache.hadoop.fs.azurebfs.constants.FSOperationType;
|
39 | 40 | import org.apache.hadoop.fs.azurebfs.enums.Trilean;
|
| 41 | +import org.apache.hadoop.fs.azurebfs.services.AbfsHttpOperation; |
40 | 42 | import org.apache.hadoop.fs.azurebfs.services.AbfsRestOperation;
|
41 | 43 | import org.apache.hadoop.fs.azurebfs.services.AuthType;
|
42 | 44 | import org.apache.hadoop.fs.azurebfs.utils.TracingContext;
|
@@ -198,4 +200,74 @@ public void testExternalOps() throws Exception {
|
198 | 200 | fs.getAbfsStore().setNamespaceEnabled(Trilean.TRUE);
|
199 | 201 | fs.access(new Path("/"), FsAction.READ);
|
200 | 202 | }
|
| 203 | + |
| 204 | + @Test |
| 205 | + public void testRetryPrimaryRequestIdWhenInitiallySuppliedEmpty() throws Exception { |
| 206 | + final AzureBlobFileSystem fs = getFileSystem(); |
| 207 | + final String fileSystemId = fs.getFileSystemId(); |
| 208 | + final String clientCorrelationId = fs.getClientCorrelationId(); |
| 209 | + final TracingHeaderFormat tracingHeaderFormat = TracingHeaderFormat.ALL_ID_FORMAT; |
| 210 | + TracingContext tracingContext = new TracingContext(clientCorrelationId, |
| 211 | + fileSystemId, FSOperationType.CREATE_FILESYSTEM, tracingHeaderFormat, new TracingHeaderValidator( |
| 212 | + fs.getAbfsStore().getAbfsConfiguration().getClientCorrelationId(), |
| 213 | + fs.getFileSystemId(), FSOperationType.CREATE_FILESYSTEM, false, |
| 214 | + 0)); |
| 215 | + AbfsHttpOperation abfsHttpOperation = Mockito.mock(AbfsHttpOperation.class); |
| 216 | + Mockito.doNothing().when(abfsHttpOperation).setRequestProperty(Mockito.anyString(), Mockito.anyString()); |
| 217 | + tracingContext.constructHeader(abfsHttpOperation, null); |
| 218 | + String header = tracingContext.getHeader(); |
| 219 | + String clientRequestIdUsed = header.split(":")[1]; |
| 220 | + String[] clientRequestIdUsedParts = clientRequestIdUsed.split("-"); |
| 221 | + String assertionPrimaryId = clientRequestIdUsedParts[clientRequestIdUsedParts.length - 1]; |
| 222 | + |
| 223 | + tracingContext.setRetryCount(1); |
| 224 | + tracingContext.setListener(new TracingHeaderValidator( |
| 225 | + fs.getAbfsStore().getAbfsConfiguration().getClientCorrelationId(), |
| 226 | + fs.getFileSystemId(), FSOperationType.CREATE_FILESYSTEM, false, |
| 227 | + 1)); |
| 228 | + |
| 229 | + tracingContext.constructHeader(abfsHttpOperation, "RT"); |
| 230 | + header = tracingContext.getHeader(); |
| 231 | + String primaryRequestId = header.split(":")[3]; |
| 232 | + |
| 233 | + Assertions.assertThat(primaryRequestId) |
| 234 | + .describedAs("PrimaryRequestId in a retried request's " |
| 235 | + + "tracingContext should be equal to last part of original " |
| 236 | + + "request's clientRequestId UUID") |
| 237 | + .isEqualTo(assertionPrimaryId); |
| 238 | + } |
| 239 | + |
| 240 | + @Test |
| 241 | + public void testRetryPrimaryRequestIdWhenInitiallySuppliedNonEmpty() throws Exception { |
| 242 | + final AzureBlobFileSystem fs = getFileSystem(); |
| 243 | + final String fileSystemId = fs.getFileSystemId(); |
| 244 | + final String clientCorrelationId = fs.getClientCorrelationId(); |
| 245 | + final TracingHeaderFormat tracingHeaderFormat = TracingHeaderFormat.ALL_ID_FORMAT; |
| 246 | + TracingContext tracingContext = new TracingContext(clientCorrelationId, |
| 247 | + fileSystemId, FSOperationType.CREATE_FILESYSTEM, tracingHeaderFormat, new TracingHeaderValidator( |
| 248 | + fs.getAbfsStore().getAbfsConfiguration().getClientCorrelationId(), |
| 249 | + fs.getFileSystemId(), FSOperationType.CREATE_FILESYSTEM, false, |
| 250 | + 0)); |
| 251 | + tracingContext.setPrimaryRequestID(); |
| 252 | + AbfsHttpOperation abfsHttpOperation = Mockito.mock(AbfsHttpOperation.class); |
| 253 | + Mockito.doNothing().when(abfsHttpOperation).setRequestProperty(Mockito.anyString(), Mockito.anyString()); |
| 254 | + tracingContext.constructHeader(abfsHttpOperation, null); |
| 255 | + String header = tracingContext.getHeader(); |
| 256 | + String assertionPrimaryId = header.split(":")[3]; |
| 257 | + |
| 258 | + tracingContext.setRetryCount(1); |
| 259 | + tracingContext.setListener(new TracingHeaderValidator( |
| 260 | + fs.getAbfsStore().getAbfsConfiguration().getClientCorrelationId(), |
| 261 | + fs.getFileSystemId(), FSOperationType.CREATE_FILESYSTEM, false, |
| 262 | + 1)); |
| 263 | + |
| 264 | + tracingContext.constructHeader(abfsHttpOperation, "RT"); |
| 265 | + header = tracingContext.getHeader(); |
| 266 | + String primaryRequestId = header.split(":")[3]; |
| 267 | + |
| 268 | + Assertions.assertThat(primaryRequestId) |
| 269 | + .describedAs("PrimaryRequestId in a retried request's tracingContext " |
| 270 | + + "should be equal to PrimaryRequestId in the original request.") |
| 271 | + .isEqualTo(assertionPrimaryId); |
| 272 | + } |
201 | 273 | }
|
0 commit comments