|
40 | 40 | import com.microsoft.azure.storage.blob.CloudBlobClient; |
41 | 41 | import com.microsoft.azure.storage.blob.CloudBlobContainer; |
42 | 42 | import com.microsoft.azure.storage.blob.CloudBlockBlob; |
43 | | -import com.microsoft.azure.storage.core.BaseRequest; |
44 | 43 | import com.microsoft.azure.storage.core.SR; |
45 | 44 | import com.microsoft.azure.storage.core.Utility; |
46 | 45 | import com.microsoft.azure.storage.queue.CloudQueue; |
@@ -247,176 +246,6 @@ public void testNullRetryPolicy() throws URISyntaxException, StorageException { |
247 | 246 | container.exists(); |
248 | 247 | } |
249 | 248 |
|
250 | | - @Test |
251 | | - @Category({ DevFabricTests.class, DevStoreTests.class, SecondaryTests.class }) |
252 | | - public void testMaximumExecutionTime() throws URISyntaxException, StorageException { |
253 | | - OperationContext opContext = new OperationContext(); |
254 | | - setDelay(opContext, 2500); |
255 | | - |
256 | | - // set the maximum execution time |
257 | | - BlobRequestOptions options = new BlobRequestOptions(); |
258 | | - options.setMaximumExecutionTimeInMs(2000); |
259 | | - |
260 | | - // set the location mode to secondary, secondary request should fail |
261 | | - // so set the timeout low to save time failing (or fail with a timeout) |
262 | | - options.setLocationMode(LocationMode.SECONDARY_THEN_PRIMARY); |
263 | | - options.setTimeoutIntervalInMs(1000); |
264 | | - |
265 | | - CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); |
266 | | - CloudBlobContainer container = blobClient.getContainerReference(generateRandomContainerName()); |
267 | | - |
268 | | - try { |
269 | | - // 1. download attributes will fail as the container does not exist |
270 | | - // 2. the executor will attempt to retry as it is accessing secondary |
271 | | - // 3. maximum execution time should prevent the retry from being made |
272 | | - container.downloadAttributes(null, options, opContext); |
273 | | - fail("Maximum execution time was reached but request did not fail."); |
274 | | - } |
275 | | - catch (StorageException e) { |
276 | | - assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getMessage()); |
277 | | - } |
278 | | - } |
279 | | - |
280 | | - @Test |
281 | | - @Category({ DevFabricTests.class, DevStoreTests.class, SlowTests.class }) |
282 | | - public void testMaximumExecutionTimeBlobWrites() throws URISyntaxException, StorageException, IOException { |
283 | | - byte[] buffer = BlobTestHelper.getRandomBuffer(80 * 1024 * 1024); |
284 | | - |
285 | | - // set the maximum execution time |
286 | | - BlobRequestOptions options = new BlobRequestOptions(); |
287 | | - options.setMaximumExecutionTimeInMs(5000); |
288 | | - |
289 | | - CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); |
290 | | - CloudBlobContainer container = blobClient.getContainerReference(generateRandomContainerName()); |
291 | | - |
292 | | - String blobName = "testBlob"; |
293 | | - final CloudBlockBlob blockBlobRef = container.getBlockBlobReference(blobName); |
294 | | - blockBlobRef.setStreamWriteSizeInBytes(1 * 1024 * 1024); |
295 | | - |
296 | | - ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer); |
297 | | - BlobOutputStream blobOutputStream = null; |
298 | | - |
299 | | - try { |
300 | | - container.createIfNotExists(); |
301 | | - |
302 | | - // make sure max timeout is thrown by Utility.writeToOutputStream() on upload |
303 | | - try { |
304 | | - blockBlobRef.upload(inputStream, buffer.length, null, options, null); |
305 | | - fail("Maximum execution time was reached but request did not fail."); |
306 | | - } |
307 | | - catch (StorageException e) { |
308 | | - assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getMessage()); |
309 | | - } |
310 | | - catch (IOException e) { |
311 | | - assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getCause().getMessage()); |
312 | | - } |
313 | | - assertFalse(blockBlobRef.exists()); |
314 | | - |
315 | | - // make sure max timeout applies on a per service request basis if the user creates the stream |
316 | | - // adds a delay so the first service request should fail |
317 | | - OperationContext opContext = new OperationContext(); |
318 | | - setDelay(opContext, 6000); |
319 | | - blobOutputStream = blockBlobRef.openOutputStream(null, options, opContext); |
320 | | - try { |
321 | | - blobOutputStream.write(inputStream, buffer.length); |
322 | | - fail("Maximum execution time was reached but request did not fail."); |
323 | | - } |
324 | | - catch (StorageException e) { |
325 | | - assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getCause().getMessage()); |
326 | | - } |
327 | | - catch (IOException e) { |
328 | | - assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getCause().getMessage()); |
329 | | - } |
330 | | - finally { |
331 | | - try { |
332 | | - blobOutputStream.close(); |
333 | | - } |
334 | | - catch (IOException e) { |
335 | | - assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getCause().getMessage()); |
336 | | - } |
337 | | - } |
338 | | - assertFalse(blockBlobRef.exists()); |
339 | | - |
340 | | - // make sure max timeout applies on a per service request basis if the user creates the stream |
341 | | - // adds a delay so the first service request should fail |
342 | | - blobOutputStream = blockBlobRef.openOutputStream(null, options, opContext); |
343 | | - try { |
344 | | - blobOutputStream.write(buffer); |
345 | | - fail("Maximum execution time was reached but request did not fail."); |
346 | | - } |
347 | | - catch (IOException e) { |
348 | | - assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getCause().getMessage()); |
349 | | - } |
350 | | - finally { |
351 | | - try { |
352 | | - blobOutputStream.close(); |
353 | | - } |
354 | | - catch (IOException e) { |
355 | | - assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getCause().getMessage()); |
356 | | - } |
357 | | - } |
358 | | - assertFalse(blockBlobRef.exists()); |
359 | | - |
360 | | - // make sure max timeout applies on a per service request basis only if the user creates the stream |
361 | | - // should succeed as even if all requests would exceed the timeout, each one won't |
362 | | - blobOutputStream = blockBlobRef.openOutputStream(null, options, null); |
363 | | - try { |
364 | | - blobOutputStream.write(inputStream, buffer.length); |
365 | | - } |
366 | | - finally { |
367 | | - blobOutputStream.close(); |
368 | | - } |
369 | | - assertTrue(blockBlobRef.exists()); |
370 | | - } |
371 | | - finally { |
372 | | - inputStream.close(); |
373 | | - container.deleteIfExists(); |
374 | | - } |
375 | | - } |
376 | | - |
377 | | - @Test |
378 | | - @Category({ DevFabricTests.class, DevStoreTests.class, SlowTests.class }) |
379 | | - public void testMaximumExecutionTimeBlobByteArray() throws URISyntaxException, StorageException, IOException { |
380 | | - int length = 10 * 1024 * 1024; |
381 | | - byte[] uploadBuffer = BlobTestHelper.getRandomBuffer(length); |
382 | | - byte[] downloadBuffer = new byte[length]; |
383 | | - |
384 | | - // set a delay in sending request |
385 | | - OperationContext opContext = new OperationContext(); |
386 | | - setDelay(opContext, 2500); |
387 | | - |
388 | | - // set the maximum execution time |
389 | | - BlobRequestOptions options = new BlobRequestOptions(); |
390 | | - options.setMaximumExecutionTimeInMs(2000); |
391 | | - |
392 | | - CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); |
393 | | - CloudBlobContainer container = blobClient.getContainerReference(generateRandomContainerName()); |
394 | | - |
395 | | - String blobName = "testBlob"; |
396 | | - final CloudBlockBlob blockBlobRef = container.getBlockBlobReference(blobName); |
397 | | - |
398 | | - ByteArrayInputStream inputStream = new ByteArrayInputStream(uploadBuffer); |
399 | | - |
400 | | - try { |
401 | | - container.createIfNotExists(); |
402 | | - |
403 | | - blockBlobRef.upload(inputStream, length); |
404 | | - assertTrue(blockBlobRef.exists()); |
405 | | - |
406 | | - try { |
407 | | - blockBlobRef.downloadToByteArray(downloadBuffer, 0, null, options, opContext); |
408 | | - fail("Maximum execution time was reached but request did not fail."); |
409 | | - } |
410 | | - catch (StorageException e) { |
411 | | - assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getCause().getMessage()); |
412 | | - } |
413 | | - } |
414 | | - finally { |
415 | | - inputStream.close(); |
416 | | - container.deleteIfExists(); |
417 | | - } |
418 | | - } |
419 | | - |
420 | 249 | @Test |
421 | 250 | public void testDateStringParsingWithRounding() throws ParseException { |
422 | 251 | String fullDateString = "1999-12-31T23:59:45.1234567Z"; |
@@ -543,20 +372,4 @@ private static String generateRandomContainerName() { |
543 | 372 | String containerName = "container" + UUID.randomUUID().toString(); |
544 | 373 | return containerName.replace("-", ""); |
545 | 374 | } |
546 | | - |
547 | | - private void setDelay(final OperationContext ctx, final int timeInMs) { |
548 | | - |
549 | | - ctx.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() { |
550 | | - |
551 | | - @Override |
552 | | - public void eventOccurred(SendingRequestEvent eventArg) { |
553 | | - try { |
554 | | - Thread.sleep(timeInMs); |
555 | | - } |
556 | | - catch (InterruptedException e) { |
557 | | - // do nothing |
558 | | - } |
559 | | - } |
560 | | - }); |
561 | | - } |
562 | 375 | } |
0 commit comments